diff --git a/zsnes/ChangeLog b/zsnes/ChangeLog new file mode 100644 index 00000000..e69de29b diff --git a/zsnes/INSTALL.txt b/zsnes/INSTALL.txt new file mode 100644 index 00000000..9e8ea9a3 --- /dev/null +++ b/zsnes/INSTALL.txt @@ -0,0 +1,57 @@ +Compiling the Source Code: +-------------------------- + +Well, for the moment, zsnes sources may be a little hard to compile. Here +is a quick guide (based on my own experience and on a doc written by zsKnight) +explaining how to compile zsnes. With these tools, I can build both dos and +win version, I hope it will also work for you + + +First, you need the following software: + +Dos port : +- NASM v0.98 : http://www.cryogen.com/nasm/ + the version found on http://nasm.2y.net/ DOES NOT WORK + with zsnes sources. When you type nasm -r, you must get + 'NASM version 0.98' and not 'NASM version 0.98.08' if you + have the correct version +- DJGPP v2 or higher, (GCC also installed) : http://www.delorie.com/djgpp/ + using the zip picker, the default choices are ok if you + check C and C++ in the programming languages. You also need + to get zlib which is available with the full distribution + of djgpp. You can get it at : + ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2tk/zlib112b.zip + +Then to build the executable, go to the src directory and type: +make -f makefile.dos + +You may also want to compress zsnes.exe with upx (http://upx.tsx.org), it will +divide its size by 10. + + +Windows port : +- GNU Make : it comes with djgpp +- NASM v0.98 : http://nasm.2y.net/ or http://www.cryogen.com/nasm/ +- MSVC++ 6.0 or higher : not freely available, you'll have to buy it + You need to run VCVARS32.BAT. If you get an + out of environment space error, type 'command /e:32768' + (to create a new command.com entity with more + environment space) +- DX7.0 SDK or higher : you can get it at microsoft.com. It is quite big. + Also, edit makefile.win to set the correct path to your + SDK. I also had some problems with vc++ using its own + (old) directx headers instead of the sdk headers. I replaced + these old headers (in the include directory of vc++ dir) + with the newer ones. +- zlib : http://www.info-zip.org/pub/infozip/zlib/ + you need the Win9x/WinNT static library (the dll version doesn't + seem to work with zsnes). Name the static version zlib.lib and + put it somewhere where vc++ will find it (for example, the lib + directory in vc++ dir). + +Don't forget to set the correct path to the directx sdk in makefile.win! +Then to build the executable, go to the src directory and type: +make -f makefile.win + +You may also want to compress zsnesw.exe with upx (http://upx.tsx.org), it will +divide its size by 10. \ No newline at end of file diff --git a/zsnes/authors.txt b/zsnes/authors.txt new file mode 100644 index 00000000..de60ac21 --- /dev/null +++ b/zsnes/authors.txt @@ -0,0 +1,6 @@ +ZSNES Open Source Authors: +-------------------------- + +zsKnight +_Demo_ + diff --git a/zsnes/dos/guinotes.txt b/zsnes/dos/guinotes.txt new file mode 100644 index 00000000..4a93a1e4 --- /dev/null +++ b/zsnes/dos/guinotes.txt @@ -0,0 +1,506 @@ +Table of Contents +ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ +I. ) The Game Menu +II. ) The Quick Menu (Arrow Menu) +III.) The Config Menu +IV. ) The Cheat Menu +V. ) The MultiPlay Menu +VI. ) The Misc Menu + +---------------------------------------------------------------------------- + +Note : If any windows exists in the GUI field, pressing ESC always closes + the top-most window +Note : Pressing ESC when no window is active is equivalent to RUN. It will + not function if no game is loaded + +Notes on the filename box where you can manually type in the filename: + - Typing text into the box would automatically seek to the closest + matching filename in the box where the file selection cursor is located + - When you press enter with text in the box without any '\' or ':' in the + filename, ZSNES will first look for a directory matching the text and + changes its directory if one is found. Otherwise, it will load the + current file or directory highlighted by the selection cursor. + - You can type in the full filename or directory including path + (eg. d:\games\mario.smc) or the drive name (eg. d:) + +---------------------------------------------------------------------------- + +--------------------- +- I.) The Game Menu - +--------------------- + +Load : + Perform : Load File and Run + Usage : + Loading a File : + You can move through the list using either the mouse or the + keyboard. The keys for the keyboard are : + Up/Down - Move Up/Down through the list + Left/Right - Switch between the File and Directory Window + PageUp/PageDown/Home/End - Move through the list in larger + increments + A .. Z, \, : - Enters filename/directory into the load box + Enter - Load File or Change Directory (depending on which + window you are in) + Display Type : + You can select from either Normal 8.3 file format (Default), + Snes Header name, and Win95 long filename format. + Note : Win95 long filename format will not work in Pure DOS. + It will crash when using dosemu in Linux + Note : Snes Header Display will sometimes display garbled Lines. + This is normal since some images don't have a proper + name in the header or the header is not in english. + Whenever ZSNES detects a blank header name, it uses + the filename instead. + Also note that .ZIP files will not display the header name. + It's not efficient for the program to unzip every zip file + in the directory just to get the header names. + Show all Extensions : This will force the GUI to show + all of the file extensions instead of the default (.SMC,.SFC,...) + +Run : + Perform : Runs the game + +Reset : + Perform : Resets the game, but asks user for confirmation first + +Save State : + Perform : Saves the state (Equivalent to default F2), but asks + user for confirmation first +Load State : + Perform : Loads the state (Equivalent to default F4), but asks + user for confirmation first + +Pick State : + Perform : Allows user to select the state position to use + (Equivalent to default F3) + +Quit : + Perform : Quits ZSNES + +---------------------------------------------------------------------------- + +----------------------------------------------- +- II.) The Quick Menu (Displayed as an Arrow) - +----------------------------------------------- + +Perform : Allows the user to quickly select the last 10 games loaded off + the GUI. Also allows the user to freeze/clear the list. + +Tip : You can create a favorites list by first clearing the list then + loading up all the games (last game loaded will be at the top) and + turning freeze on. + +---------------------------------------------------------------------------- + +------------------------- +- III.) The Config Menu - +------------------------- + +Input #1-#5 : + Perform : Allows user to select the input device and control + keys for each player + Usage : + Selecting an Input Device : + Using your mouse, move through the list of input devices + until the device of your choice is highlighted. From + there, click on SET and the input device you selected + should appear after CDV: (CDV = Current Device) + Changing default keys : + Click on the key which you want to change using your + mouse and then press the key or joystick button/pad + which you want to change it to. Pressing ESC disables + the game key. + Joystick 209h usage : + Some dual joystick cards support dual joystick ports + (port 201h and 209h) which allows for 2 6-button joysticks + or 2 different types of joysticks (sidewinder and a + standard joystick). If you have one of these, check + the 'Use joystick port 209h' box. If you do not have + a dual joystick/dual port card and if you check the box, + then the joystick will not work. + +Options : + Perform : Allows the user to select some in-game options + Usage : + Auto Frame Rate - Enables Auto Frame Rate + Frame Skip - (Shown when Auto Frame Rate is disabled) + Sets the constant frame skip value used when a game plays + Max Frame Skip - (Shown when Auto Frame Rate is enabled) + Sets the maximum allowable frame skip in auto framerate mode + New Gfx Engine - Enables/Disables the New Graphics engine + in 256 color modes or 320x240x65536 mode + VSync - Enables vertical sync wait to reduce sheering of the + screen. Requires a very fast computer. + MMX Copy - Enables MMX Copying routines for a slight speed + increase (MMX processors only) + Use Pl1/2 as Pl3/4 - Allows the user to use 2 devices for 1 player + such as the keyboard and the joystick. (set keyboard as input + device 1 and joystick as input device 3). This, however, disables + multitap support + Sidewinder Fix - Click this when your sidewinder doesn't work + after disabling the sidewinder profiler and pressed the + mode button twice + FPS at Start - Checking this would make the FPS appear whenever + you start ZSNES + Use 30Hz for Turbo - When activated, Turbo will change at 30hz NTSC + or 25hz PAL. Otherwise, Turbo will change at 60hz NTSC or 50hz PAL + Enable Game Clock - Enabling this will show the system clock on-screen + Toggled Fast Fwd - Checking this will change the way how the fast forward + button functions. Having it checked will cause it to act as a switch + and having it unchecked will cause it to act as a push button. + SRam Check+Save - This will enable automatic Save Ram write detection and + save the sram (.srm) to disk approximately 10 seconds after. + Old Gfx Mode 2 - This will enable the Old Gfx Engine Mode 2 which fixes + many transparency bugs that currently plagues ZSNES in the current + engine, however, it also creates some new ones. This mode can be + slower at times so it's recommended that you only turn it on when + you need it. + Start at Latest Save - Checking this will automatically set the + save state pointer (F3 Menu) to the most recently saved location + whenever you load a rom image. + Auto State Save/Load - Enabling this will allow ZSNES to automatically + re-load the state whenever you return back to the game after a + proper exit. + Don't Save Current Path - This will prevent ZSNES from changing the + current start-up game path in the configuration. You can + access this in Config->Options. + Disable Sound CPU Emu - Selecting this would disable the SPC700 chip + that controls the sound. Using this would speed up emulation, + but the drawback is that you won't have sound and the gane + compatibility rate would be lower. +Add-ons: + Perform : Changes the current special input selected for the game + Usage : + None - Uses the regular snes controllers + SNES Mouse at Port #1 - Emulates the SNES mouse at controller port #1 + SNES Mouse at Port #2 - Emulates the SNES mouse at controller port #2 + Super Scope - Emulates the SNES Super Scope + Lethal Enforcer Gun - Simulates the mouse movements for Lethal + Enforcers 1 + +Video : + Perform : Changes the current video mode and sets some options + Usage : + Changing the video mode - Use the mouse to select the video mode + and click 'SET'. When the video mode changes and if the result + doesn't look right, wait for 10 seconds without pressing any key + or button and the display will return to the previous one. + Scanlines - Only available in 256x256x256 and VESA2 640x480 modes. + This mode adds a blank line in between every line to produce + a scanline effect similar, if not exact, to a TV. + Eagle Engine - Only available in VESA2 320x240x256. Setting + this would enable the Eagle Engine designed by Dirk Stevens + which basically locates 3 similar colored pixels together + and places a small dot in between to smooth out some graphics. + Interpolation - Only available in VESA2 640x480x65536. Setting + this enable interpolation which basically blends all the + inbetween colors to produce a blurry effect. However, this + slows down emulation. + Full Screen - Only available in VESA2 320x240 and 640x480 modes. + Setting this would scale the image to fit the screen. This, + however, slows down emulation. + Small Screen - Only available in VESA2 640x480 modes. Setting + this would display the image in a small, centered screen. This + greatly improves performance in 640x480 modes. + 50% Scanlines - Only available in 640x480x65536 video mode. This + will enable scanline mode except that each line is 50% darker than + the line above it. + 25% Scanlines - Only available in 640x480x65536 video mode. This + will enable scanline mode except that each line is 25% darker than + the line above it. + 2xSaI Engine - Setting this would enable Kreed's 2x Scale Advanced + Interpolation engine. + Super Eagle - Setting this would enable Kreed's Super Eagle engine. + Super 2xSaI Engine - Setting this would enable Kreed's Super 2x Scale + Advanced Interpolation engine. This mode would require a lot of + cpu power since it is written in C. + Triple Buffering - This will enable Triple Buffering if it is available + on your VESA drivers/Video Card. If it isn't available, then Zsnes + will use simulated Triple Buffering which is slower, but still does + the job. Note that Triple Buffering will not work with 2xSaI/Super + Eagle. + Hi-resolution Mode 7 - Enabling this would activate high resolution + mode 7 whenever standard mode 7 is used within a game. This mode + is only available in video modes that support it. + +Sound : + Perform : Allows user to change the sound configurations of ZSNES + Usage : + Enable Sound - Setting this turns on the sound + Stereo Sound - Enables Stereo Sound (Noticably slower though unless + you have a fast cpu) + Sound Rate - To change the sound rate, just click on the box + containing the value to rotate through all the + possible values. + Volume Level - To change, just slide the bar + Disable Noise Sim. (Disable Noise Simulation) - Setting this will + disable the noise filter which corrects many sound effects in + certain games, but will also ruin some others. + Surround Sound - Enables simulated 2 speaker surround sound + Sound Interpolation - Enables Sound Interpolation which smoothes out + the wave forms of lower frequency sounds + Reverse Stereo - This function swaps the L & R volume levels + in stereo mode + Low Pass Filter - The Low Pass Filter, when enabled, will produce + better bass in certain sound effects. However, the side effect + is that the sound will overall be more muffled. + +---------------------------------------------------------------------------- + +----------------------- +- IV.) The Cheat Menu - +----------------------- + +Add Code : + Perform : Enter Cheat Code Window and Set the keyboard cursor + on the cheat code entry box + Usage : Type in the code in either Game Genie, Pro Action Replay, or + Gold Finger format, press enter, then enter the description. + Note : Be sure to include the '-' when entering Game Genie codes + Note : You can also quickly modify the value of the currently selected + cheat code (in the browse window) by typing a 2 digit hex number + in the cheat code enter space + +Cheat Code Reflector - What this feature does is that it allows a value + of one cheat code to be mirrored from a value of another cheat code. To + enable this option, type an 'R' at the end of any cheat code as the + destination, then type another cheat code (Without the 'R') as the source. + For example, if you want address 7E1000 to reflect the value at address + 7F2000 (Whatever value written to 7E2000 from the game will also be + written to 7E1000), enter cheat code 7E1000FFR, then cheat code + 7F2000FF (where FF can be any value). + +Browse : + Perform : Enter Cheat Code Window and Set the keyboard cursor at the + browse box + Usage : Move through the list using either the mouse or keyboard and + select the cheat code you want to modify. Then click on the + buttons to the right or type in the key of the first letter + of the action. + Actions : + Toggle - Turns a cheat code on or off + Remove - Deletes the cheat code off the list + Save - Saves the current list into a .cht file which will + be located in the save directory + Load - Loads a previously saved list + Fix - Clicking this fixes some cheat codes that don't work, + but it will not always work + You can also toggle a cheat code on or off by double clicking on + them. + +Search : + Perform : Allows you to search for values in memory such as life, score, + etc. and allows you to change their values to your own preferred + choice. + Usage : + Select Size : You can choose what data size to search for. If you + know the numerical values of the data you're going to select, + select the smallest number range that fits the data values. + (eg. If you know the value cannot go higher than 50000, then + select 2 BYTES (0..65535) instead of 3 BYTES (0..16777215)). + Sometimes, you don't know the numerical value (in the case of + life bars) and you'd have to guess the size. + Select Format : DEC (Decimal, 0 .. 9), HEX (Hexadecimal, 0 .. F) + Most of the time, it's recommended that you'd use decimal, although + there are some cases that the values in memory are sometimes stored + as hex. + Search Type : + Exact Value Search - In this mode, you have to enter the exact + numerical value that you want to search for. Such as if you + have 3 lives left, then search for the value 3. The cheat + search engine also looks for value - 1 since even if a game + tells you that you have 3 lives left, it stores the value as + 2 in memory. + Comparitive Search - In this mode, you select whether the value + is less than, greater than, equal to, or not equal to the + previous value. Such as if you have a life bar and if the life + bar suddenly goes down, go back to the cheat search engine and + select less than to search for any value that has been decreased. + +---------------------------------------------------------------------------- + +------------------------ +- V.) The NetPlay Menu - +------------------------ + +Modem Mode : + +NOTE #1 : DOS Compatible modem is REQUIRED! + If you don't know your modem settings and you're in win95/98, go to + Control Panel -> System -> Device Manager -> Modem and select + your modem. Then click on your resources tab and the settings should + be there. + + 1.) Dial Menu - Allows you to enter the phone number to dial and then + dials and connects + 2.) Wait for Ring - Waits for ring + 3.) Config Modem - Allows you to configure your modem : + ComPort, IRQ, Baudrate - Sets your modem settings + Use Fossil Driver - Set this option if you want + ZSNES to use your a fossil driver. If you don't + know what a fossil driver is, just leave this + option unchecked and pretend it doesn't exist. + 4.) Manual - Allows you to connect manually through the terminal. + However, if both remote and local users select manual, + the player numbers will not be assigned. + +IPX : + + IPX mode currently connects at the first remote connection it detects. + This will probabily change in the future if there is a demand. + +Chat Mode : + + Latency - The lower the number, the better the control response time. + But setting it too low can cause a lot of frame skip problems. + This value should vary depending on the traffic of the connection + you are using. A value of 2 or 3 is recommended for modem. The + value for IPX varies. Latency is basically the amount of time + between a user input and that input being affected in the actual + game. The delay should be higher than the time it takes for data + to move from one end to the other. Latency value of 1 is + equivalent to 1/30th of a second on NTSC games or 1/25th of a + second on PAL games. + Player # boxes - This will allow you to select up to a 5 player multiplayer + game. Anything that is checked will be controlled locally + starting from player 1 as the lowest checked player. Anything + marked with an X will be controlled remotely. + For example, if players 2,3,5 are checked and 1,4 are X'ed : + local player 1 will control player 2 + local player 2 will control player 3 + local player 3 will control player 5 + remote player 1 will control player 1 + remote player 2 will control player 4 + +---------------------------------------------------------------------------- + +---------------------- +- VI.) The Misc Menu - +---------------------- + +Game Keys : + Perform : Allows user to change the game keys to their own preference + Usage : + Click on the key which you want to change using your + mouse and then press the key or joystick button/pad + which you want to change it to. Pressing ESC disables + the key. + +GUI Options : + Perform : Allows the user to customize some of the GUI + Usage : + Mouse Wrap - Allows the mouse pointer to wrap at the borders of the + screen + Mouse Shadow - Disables/Enables the Mouse Shadow + Keep Menu Positions - When enabled, re-entering the GUI from the + game does not automatically enter the Load Menu, but + the previous menu which you were on when you last exit + the GUI + Save Window Positions - When enabled, the GUI doesn't reset the locations + of the windows when you exit/enter the GUI + Click Enters/Exits GUI - When enabled, it allows the right mouse button + to automatically run and exit the game to the GUI. This + however, slows down emulation by a bit since it has to + check the mouse button status once in a while. In the + windows port, the right click button won't return back + to the game. + Use JoyPad1 to Control - When enabled, it allows Player 1's device + to be used to move through the GUI. This is mainly used + if you want to use your joystick in the GUI. The equivalent + SNES keys to the Keyboard keys are : + + SNES ControlPad = Move + SNES A = Enter + SNES B = ESC + SNES L = PageUp + SNES R = PageDown + Enable Water Effect - Enables the water effect in the GUI background + Enable Snow Effect - Enables the snow effect in the GUI background + +Key Comb. (Key Combination Editor) : + Perform : Allows you to specify certain keyboard combination routines + with a single keystroke/joystick button press. + Usage : + Description - Allows you type in the description of the combination key + Key - Clicking on this box will allow you to select which key/button to + use + Combination Keys - this window will display the sequence of events + selected by the user + P# - Selects which player # to use those keys as + > = Last - Enabling this would mean that the event symbol > will + mean the last left or right direction the user presses in the game and + the symbol < is the opposite of that direction. When disabled, > means + right and < means left. + Game Specfic (Game Specific) - Enabling this will tell Zsnes to use + separate Key Combination files for each individual game. + Clear - Clears the current key combination field + Add - Adds the key combination fields below as a new entry + Replace - Copies the contents of the key combination fields below + to the current highlighted key combination above + Delete - Deletes the highlighted key combination above + Events: + Press+Rel - The key will be pressed and held. It will be released + once another key is pressed after any amount of frame or second + delay. + Press Only - The key will be pressed and held + Rel Only - The key will be released if it is Pressed + by a pressed only event + Frame Delay - Delays for the specified number of frames + Second Delay - Delays for the specified number of seconds + Del - Deletes the event at the end of the Combination Keys list if + one exists + Note : A 1 frame delay exists after the combination key list has finished + processing + + Example Key Combination: (Down / Down+Right / Right / L) : + Method 1: + Press+Rel Down / 2 Frame Delay / Press+Rel Down / Press+Rel Right / + 2 Frame Delay / Press+Rel Right / 2 Frame Delay / Press+Rel L + Method 2: + Press Only Down / 2 Frame Delay / Press Only Right / 2 Frame Delay / + Rel Only Down / 2 Frame Delay / Rel Only Right / Press Only L + +Movie Options : + Perform : Allows you to record SNES Movies so that you can play them + back at a later date either to amuse your friends, torture + your friends, or whatever. Just don't play anything in + front of your enemies since they might break your computer. + Usage : + Movies are saved as .ZMV, .ZM1, .ZM2, etc. files. They should be + located in the same directory as your save files. A movie file + consists of a save state file, saveram data, and the recorded + controller data. The initial filesize of a .ZMV file is the + combination of a .zst and a .srm file (around 300kbytes) and + it averages around 7kbytes/minute (value varies) or 420kbytes/hour. + + You can record : + - Standard 1/2 player games + - 3-4 player Multitap games + - SNES Mouse games + - Network/Modem games + You cannot record : + - Super Scope Games + + GUI Usage : + Record - Begins recording the movie file + Play - Begins playing the movie file + Stop - Stops the movie process + The numbers at the right side selects which movie file to play/record. + + NOTE : Movies recorded without sound cannot be played when sound + is enabled and vice versa + NOTE : Loading another game, loading a state, or resetting the + game will halt the play/record process + NOTE : When you play a movie file, the SRAM data becomes invalid and + ZSNES won't save it until you load a game. This way, you don't have + to worry about your save ram when you load up a movie file. + +Save Cfg : + Perform : Saves the configuration files + +About : + Perform : Just displays the version # and the authors of ZSNES + + \ No newline at end of file diff --git a/zsnes/dos/readme.txt b/zsnes/dos/readme.txt new file mode 100644 index 00000000..2fe44e80 --- /dev/null +++ b/zsnes/dos/readme.txt @@ -0,0 +1,604 @@ + + ZSNES + by zsKnight, _Demo_, and Pharos + http://www.zsnes.com + + +ZSNES is a Super Nintendo Entertainment System emulator written mostly +in assembler. + +We would really like to thank the snes9x team for all their help and +also for an excellent snes emulator. We also wish them the very best +of luck! + +--------------------------------------------------------------------------- +Table of Contents +--------------------------------------------------------------------------- + +1.) What's New +2.) Disclaimer +3.) System Requirements +4.) Things you should know about ZSNES (Updated v1.00) +5.) Current Progress +6.) Future Progress +7.) ZSNES Default Keys +8.) Extra Pop-Up Menu (F1 Menu) +9.) Configuration File (ZSNES.CFG) +10.) Cheat Codes +11.) Extra Features (SNES Mouse/Super Scope/SuperFX/DSP1/MultiTap/IPS) +12.) Bugs Section +13.) Contact Information +14.) The Debugger +15.) Error Codes +16.) Credits + +--------------------------------------------------------------------------- +1.) What's New +--------------------------------------------------------------------------- + +See WHATSNEW.TXT + +--------------------------------------------------------------------------- +2.) Disclaimer +--------------------------------------------------------------------------- + +zsKnight, _Demo_, and Pharos are not responsible for any damages caused +by the use of this software. This software also must not be distributed +with ROMs. + +--------------------------------------------------------------------------- +3.) System Requirements +--------------------------------------------------------------------------- + +Somewhat Recommended System : + +- 486/100 processor +- Min 14.5MB of RAM (min 12.5MB free, only can run 2MB rom images) +- VGA card +- Sound Blaster or 100% compatible +* You might need to disable Sound CPU emu for this system (go to Config + -> Options) + +Strongly Recommended System : + +- Pentium processor (P133 or higher) +- 32MB of RAM (min 17.0MB free) +- SVGA card +- Sound Blaster 16 or 100% compatible + +Recommended System for 65536 (16-bit) color mode : + +- Fast Pentium processor (P166 or higher) +- 32MB of RAM (min 17.0MB free) +- SVGA card which supports 320x240x65536 or 640x480x65536 colors +- Sound Blaster 16 or 100% compatible + +Recommended System for SFX support : + +- Fast Pentium processor (P200 - P2-300 (depending on the game)) +- 32MB of RAM (min 17.0MB free) +- VGA card +- Sound Blaster 16 or 100% compatible + +Recommended System for SA-1 support : (Mario RPG) + +- Fast Pentium processor (P200 or higher) +- 32MB of RAM (min 17.0MB free) +- VGA card +- Sound Blaster 16 or 100% compatible + +- You need 17.0MB of RAM to run 48mbit(6megabytes) roms. +- An FPU is required for DSP1 emulation + +For SuperFX and SA-1 emulation, 17.0 megabytes of free memory is required +to run. + +--------------------------------------------------------------------------- +4.) Things you should know about ZSNES +--------------------------------------------------------------------------- + +- You can use both keyboard and joystick for player 1 or 2 with some + configuration adjustments. Refer to zsnes.faq for details +- If your sidewinder support doesn't work, a quick way of getting it to + work is to fully disable the windows driver from the control panel +- For modem mode, if you don't have a 16550A UART compatible modem + (It will tell you when the modem initializes), chances are that both + sides will go out of sync. +- IPX support seems to randomly lose packets in certain network + configurations which causes both sides to go out of sync +- Several special chip emulation (SA-1) have unknown bugs to + them +- Transparency effects are only available in 65536 color mode +- Using 320x240 resolution modes are faster than 640x480 modes. Use + 640x480 modes only if you can't run 320x240 modes or if you want the + added features of 640x480 modes +- To view 512 resolutions properly, use 640x480 mode. Only a few games + uses 512 resolution. One way to find out is to see if a game has + that feature is to look for text that looks squished. +- In 640x480 resolution, the image is scaled so it will look like 320x240 + resolution. Only use 640x480 resolution if you want to use scanlines, + interpolation, or if 320x240 doesn't work. +- SuperFX can be slow because it is an extra 10/20mhz cpu that has to be + emulated as well as the snes emulation +- Screen Snapshot and FPS counter are available through a menu by pressing + F1 during emulation +- Screen Snapshot currently saves as Image.PCX (256 colors) and Image.BMP + (65536 colors). This may change in the future. +- FPS counter currently only works when auto frame rate is on. +- To use the cheat function, be sure to have the ROM which you want to + patch loaded already. +- If the cheat codes do not work, chances are that you are using a different + version of the rom that was originally used to create them or the codes + are converted incorrectly from other code formats. +- Certain video cards/monitors cannot support ModeQ (default resolution) + If your video card/monitor doesn't support it, run ZSNES with -v 0. + If -v 0 doesn't work, use -v 2 (vesa 2 required) +- 16 bit mode in ZSNES requires a Scitech Display Doctor (v5.3+) to provide + high color, low resolution modes. You can obtain this software at + www.scitechsoft.com. If your video card already supports lo-res, + hi-color, then don't worry about getting this driver. +- There are still many bugs left in ZSNES so don't expect it to run all + your favorite games. +- VSync won't run well unless you specify a frame skip (eg. -f 0) But + this feature is highly recommended to be used on very fast machines + (eg. Pentium IIs) +- SNES Mouse support is still missing some features such as speed settings +- Pressing the Fast Forward key is equivalent to running ZSNES using -f 9 +- If ZSNES doesn't work for you, then don't use it. Use SNES9X, NLKE, + SNEESE, or SNEMUL instead! In fact, even if you use ZSNES, + use those emulators too! + +--------------------------------------------------------------------------- +5.) Current Progress +--------------------------------------------------------------------------- + +The following are implemented : +- complete 65816 instruction set +- SRAM support +- LoROM and HiROM support +- SlowROM and FastROM support +- Full DMA support +- HIRQ/VIRQ/NMI Interrupts +- Support for most snes file formats +- Multi file format support (.1,.2,.3,A.,B.,C.) +- Interleaved format support +- PAL/NTSC timing support + +The following are implemented in the new graphics engine 8 bit : +- Combination of line by line and tile based graphics engine +- Graphic Modes 0,1,2,3,4,5,6,7 +- 8x8, 16x16, 32x32 and 64x64 sprite support (flipped in all directions) +- 8x8 and 16x16 tiles +- 32x32,64x32,32x64,64x64 tile modes +- Full HDMA effects for wavy backgrounds, interesting mode 7 effects, etc. +- Mode 7 rotating and scaling effects +- BG priorities +- Sprite Priorities +- Add/sub of back area +- Mosaic Effects +- Offset per tile mode (mode 2/vertical only) +- High res 512 resolution and 448/478 vertical resolution +- Windowing effects +- High res Mode 7 (only in 640x480x256 video mode/disable Eagle/Scanlines) + +The following are implemented in the old graphics engine : +- Line by line based graphics engine +- Graphic Modes 0,1,2,3,4,5,6,7 +- 8x8, 16x16, 32x32 and 64x64 sprite support (flipped in all directions) +- Mosaic effects +- 8x8 and 16x16 tiles +- 32x32,64x32,32x64,64x64 tile modes +- Full HDMA effects for wavy backgrounds, interesting mode 7 effects, etc. +- Mode 7 rotating and scaling effects +- Single and Dual Windowing Routines +- BG priorities +- Sprite Priorities +- Add/sub of back area +- 16-bit graphics support +- offset per tile mode (mode 2/vertical only) +- High res 512 horizontal resolution (missing in 16x16) + +Following are present in 16-bit graphics mode : + +- Palette changing in the middle of a screen +- Screen Addition (full and half) +- Screen Subtraction (full) +- Fixed Color Addition/Subtraction +- Window clipping for Fixed Color + +The following are implemented in the new graphics engine 16 bit : +- All of old graphics engine 16bit +- Combination of line by line and tile based graphics engine +- High resolution mode 7 +- High resolution 16x16 tiles for mode 5 +- full 15bit color transparencies (instead of the previous 13bit speed + hack) for improved picture quality (MMX compatible CPUs only) + +The following are present in sound : + +- 16bit digital stereo sound +- SPC700 Sound CPU +- DSP Sound Processor + - Echo Effects + - FIR Filter + - ADSR volume effects + - GAIN volume effects + - Noise effects + - Pitch Modulation + +The following are extra features emulated : + +- Super NES Mouse Support +- Super NES Super Scope Support +- SuperFX support (Still has a bug or 2 left) +- MultiTap (Multiplayer 5) support (4 players on a single computer, 5 players + remote (ipx/modem)) +- DSP1 emulation (not complete) +- SA-1 emulation (not complete) + +The following are the features present in ZSNES : + +- Game State Save (F2=Save, F3=Select, F4=Load). + Warning : A state file takes 260 kbytes of HD space! +- Auto frame rate to give you constant Super Nintendo speed up to 9 + frame skips +- configuration file support (ZSNES.CFG) +- 2 player support w/ Joystick and Gamepad support + +The following features are missing : + +- Pseudo 512 snes horizontal resolution + (Haven't seen any game that uses them yet) +- Some modes in Offset Per Tile Mode +- Some Direct Color Modes (Haven't seen any game that uses them yet) + +What will not run (or not play properly) : + +- Some Super FX games such as Dirt Trax FX or Winter Gold (causes instability) +- DSP1 games such as Pilotwings +- Games with other special chips such Street Fighter Alpha 2, Star + Ocean (S-DD1), and Far East of Eden 2 (SPC7110) +- Games which doesn't have a valid header +- Games that hit a severe bug in the 65816/PPU/SPC700/DSP routines +- Games that require special timing + +--------------------------------------------------------------------------- +6.) Future Progress +--------------------------------------------------------------------------- + +This section is removed + +--------------------------------------------------------------------------- +7.) ZSNES Default Keys +--------------------------------------------------------------------------- + +Here are the default keys while running the emulator. They can be changed +through the GUI except for F1 and ESC : + +Disable Backgrounds 1,2,3,4 = 1,2,3,4 +Disable Sprites = 5 +Panic Key (enable all) = 6 +Enable SNES Mouse/SuperScope = 7 +Enable New Graphics Engine = 8 +Disable Windowing = 9 +Disable OffsetMode = 0 +Fast Forward Key = ~ +PopUp Extra Menu = F1 +Save State = F2 +Switch State = F3 +Load State = F4 +Disable Sound Channel = F5 - F12 +Quit = ESC + +Here are the default keys for the game play (unless modified through the GUI): + +Player 1 : + +Up,Down,Left,Right : Cursor Keys on Numerical Pad (You can also use + the non-numerical pad, but numerical pad is + strongly recommended) +A,B,X,Y : Home, End, Insert, Delete +L,R : Page Up, Page Down +Start, Select : Enter, RShift + +Player 2 : (You need to enable Player 2) + +Up,Down,Left,Right : K, M, N, < +A,B,X,Y : D, X, S, Z +L,R : F, C +Start, Select : Ctrl, Alt + +To run the emulator, just type ZSNES +To run it with sound, type ZSNES -s +To run it in 16-bit mode (VESA2 w/ video card that supports 320x240x65536 + required), type ZSNES -v 3 + or with sound, type ZSNES -v 3 -s + +--------------------------------------------------------------------------- +8.) Extra Pop-Up Menu (F1 Menu) +--------------------------------------------------------------------------- + +Save Snapshot - Saves a snapshot as either .PCX (8-bit color) or .BMP + (16-bit color) + +Show/Hide FPS - Shows or hides the frame per second display which appears + on the bottom-left corner of the screen. This can only + be enabled in auto-frame rate mode. + +Save SPC Data - Selecting this will search for the beginning of the next + song and save the data into a .spc file which saves it + similarly as a .srm file. To capture a song, it is best + recommended to initiate this feature approx 2 seconds + before the next song starts. This does have potential to + fail though so don't expect it to work all the time. + Also, this feature doesn't work in the new gfx engine. + +Sound Buffer Dump - This dumps the sound buffer in zsnes and also filters + out any unoccupied space. The sound buffer contains + decompressed samples which are written to when zsnes + plays/decodes a sample from sound memory. Because of the + way zsnes buffers the sound data, this can produce + inaccurate results. + +Snapshot/Increment Frame - Same as snapshot, but it returns to the F1 menu + after a couple frames. Useful for making animations. + +--------------------------------------------------------------------------- +9.) Configuration File (ZSNES.CFG) +--------------------------------------------------------------------------- + +Almost everything in zsnes.cfg should now be editable through the gui + +--------------------------------------------------------------------------- +10.) Cheat Codes +--------------------------------------------------------------------------- + +Currently, ZSNES supports Game Genie, Pro Action Replay and GoldFinger codes + +Here are the steps to get the codes working : + +1.) Load the ROM which you want to patch +2.) Exit to the GUI, enter the code of your choice in the cheat menu +3.) After that, you may have to RESET the game to get the cheat code to + work. Sometimes, it is not necessary. You also may have to click + on the FIX button. + +NOTE : Some cheat codes are meant to be for different versions of the game. + If a cheat code doesn't work and there is one for both Game Genie + and Pro Action Replay, try them both. + +--------------------------------------------------------------------------- +11.) Extra Features (SNES Mouse/Super Scope/SuperFX/DSP1/MultiTap) +--------------------------------------------------------------------------- + +To Enable SNES Mouse, Press 7 once for 1st player and twice for 2nd player +To Enable SNES Super Scope, Press 7 three times +To disable either one, either press 6 or press 7 until you see a disable + message onscreen. + +Here are the controls for the Super Scope : + + Fire = Left Mouse button + Cursor Mode Button = Right Mouse button + Pause = Backspace Key on keyboard + Enable/Disable Autofire = =/+ key on keyboard, should be located to the + left of the backspace key + +DSP1 is enabled automatically. Currently, it runs mario kart and some other + games, but it does not run pilotwings due to a lack of dsp1 functions + that are implemented. + +Zsnes auto-detects the SFX emulation from the header and enables it when + found. Also, take note that the SFX is an additional 10Mhz(Ver1) or + 20Mhz(Ver2) chip which also has to be emulated with the snes and will + most likely produce a very noticeable slow down in emulation if you + don't have a fast computer. + +Sometimes, the Multitap isn't compatible with some games. If that happens, + disable Multitap by setting Player3,4, and 5's input device to 'None' in + the GUI + +IPS patcher : + Rename your .IPS file to the rom filename with the .IPS extension + (eg. If your rom is SD3.SMC and your rom is SD3V05.IPS, rename SD3V05.IPS + to SD3.IPS) + and ZSNES will patch the rom realtime without modifying the rom file's + contents. + +--------------------------------------------------------------------------- +12.) Bugs Section +--------------------------------------------------------------------------- + +- 65816 lacks correct timing. Although ZSNES bases the timing on a + variable cycle/instruction, it does not deduct correct values such + as 16bit instructions should deduct 1 more cycle than 8bit instructions. + 100% cycles of zsnes isn't 100% cycles of a snes because of that. + This means that a lot of games either won't run or will produce horrible + displays. Sometimes adjusting the % of execution can fix those problems. + This is due to inaccurate documentation used when the 65816 was written. + There is no plans on re-writing the 65816 timing yet. +- Games sometimes tend to not display things properly because of graphic + features that aren't implemented yet +- The Sound DSP chip still has its bugs (not many though) + +--------------------------------------------------------------------------- +13.) Contact Information +--------------------------------------------------------------------------- + +The ZSNES homepage is located at : http://www.zsnes.com + +If you have any questions about zsnes and you have read ZSNES.FAQ, +README.TXT, and GUINOTES.TXT to make sure the answer isn't there. +And your question is NOT a ROM Request or asking about a newer +version, you can post your question at the zsnes www board located at : + +http://www.zsnes.com/board/ + +Remember : This board should be mainly used for zsnes related questions. +ROM requests (or asking for games, a link to a rom site, or where to +find them) are forbidden!!! Be sure to also read the RULES! +The rules are located at the top of the page. + +If you wish to contact the authors, you may contact them through : +(Remember - No ROM requests please! and don't send any files without + permission!) + +zsknight@zsnes.com +_demo_@zsnes.com +pharos@zsnes.com + +Try not to send a copy of your e-mail to all of us since that will just + waste our time. Also, don't expect to get a reply since we are often + busy. + +--------------------------------------------------------------------------- +14.) The Debugger +--------------------------------------------------------------------------- + +Note : The debugger is disabled when you don't enter zsnes with a -d + +Here are the keys: + +1 : Enable/Disable spc700 display +2 : Enable/Disable 65816 display +T : Trace (in 65816 opcodes) +B : 65816 break point +S : SPC break point +C : Clear Counter +M : 65816 modify +A : SPC modify +D : Debug Dump (SPC/DSPRam Dump Only) +W : Break at signal (Used only by the programmers) +F1 : Exit debugger and return to Game +F2 : Save State +F4 : Load State +ESC : Exit entire program + +--------------------------------------------------------------------------- +15.) Error Codes +--------------------------------------------------------------------------- + +Unable to Initialize VESA2 : + VBE not detected - ZSNES Failed to detect any VBE interrupts + (Your video card doesn't support VESA) + VESA not detected - ZSNES Failed to detect any VESA extensions + (Your video card doesn't support VESA) + VESA 2.0 or greater required - Your video card supports VESA, but + it has an old version of VESA. You may want + to use SDD (www.scitechsoft.com) to upgrade + your vesa driver unless you have an S3 video + card which you can get a vesa 2 driver from + www.s3.com. + VESA2 mode does not work on your video card/driver - Meaning that the + resolution you chose does not exist in the supported + resolutions of your video card. Chose a different + resolution or upgrade with SDD which can sometimes + help increase the number of resolutions supported + Unable to initialize video mode - A VESA 2.0 driver is found, but the video + mode failed to start. Possibly an error on the + video card setting or a defective hardware + Linear Frame Buffer not Detected - Meaning that your video card does not + support linear frame buffering which is required + for ZSNES' vesa 2 routines + +Modem Mode : + Modem Response Timeout - If this appears, then either your modem isn't + configured properly (Even though your COM port is + set up properly, chances are your IRQ isn't), some + other application is using the modem (such as an + internet connection), you don't have a DOS + compatible modem, or your baud rate isn't set up + to the speed of your modem (this isn't required for + all modems though, but for some, it's required) + Cannot Init Driver - This means that you have the FOSSIL DRIVER option + checked, but no fossil drivers are loaded + Carrier Detected (When you're not connected) - This Probabily means that + you have set your COM Port/IRQ incorrectly. This + also might mean that you don't have a dos + compatible modem or the modem is being used + somewhere else such as an internet account. + +After Connection (Modem and IPX Mode) : + Incompatible Version - This means that both sides are using different + versions of zsnes. Both sides must use the same + version in order for remote play to proceed. + Invalid Sound Setting - This means that one side has sound disabled while + the other has it enabled. Both sides have to either + have sound disabled or sound enabled because the + game timings of both settings are different. + +--------------------------------------------------------------------------- +16.) Credits +--------------------------------------------------------------------------- + +ZSNES uses NASM, DJGPP, WDOSX, and CWSDPMI (source codes & binary updates + located at http://www.dbit.com/pub/cwsdpmi ) as the compilers and dos + extenders. Thanks to those who produced these fine programs! + +Special thanks to wnelson! Without him, ZSNES would have never existed! +Also to Y0SHi for his excellent snes docs, his help, and his excellent + support! + +Also Thanks to : + The_Teach of snes9x for some great info and the nice chats! + Trepalium of snes9x for some great info and help! + Gary of Snes9x and Steve Snake of KGen for being the source of info for + sound decompression! + Gary of Snes9x for being the source of info for TCall/PCall and also + for lots of help! + MrGrim for his great support! + Crono for info on Sound Blaster Programming, Surround Sound, Sound + Interpolation, and other sound stuff! + Aquis for the zsnes logo! + Alucard for helping us with an issue in the 65816! + Vertigo for making a compatibility list! + EFX for being a great supporter and also giving a lot of help and stuff! + Zophar for being a great supporter and also maintaining the mirror site! + Chris Hickman for redesigning the ZSNES web page! + CSoft for hosting our web page! (www.csoft.net) + Marius Fodor for the code for VSync, Sidewinder, Gamepad Pro, and some + optimisation info! + Sardu for some great info and help! + Lord Esnes for some great help! + Robert Grubbs for the sidewinder info! + Nerlaska for some useful info on optimising and also for some help! + Diskdude for writing sneskart which we used for the info on cheat codes! + DarkForce a lot of great help! + Pharos for some keyboard coding help! + Ivar and Gary of the snes9x team for all the great help which includes + their superfx info and code, DSP1 info, info on interleave formats + (hirom & superfx), offset per tile mode, FIR filter, some spc700 + and hdma bugs! + WolfWings ShadowFlight for help on several issues of nasm! + Wildfire for some help! + A CoolMan for the algorithm for EAGLE! + X-Sykodad and darklore for maintaining the ZSNES www board! + Neill Corlett for some info on the .IPS format and also helping out + a lot on improving the sound engine! + Kreed (derek-liauw@usa.net) for the 2xSaI and Super Eagle Source Codes! + 2xSaI homepage: http://members.xoom.com/derek_liauw/index.html + Markus Oberhumer & Laszlo Molnar for the UPX compression utility + UPX homepage: http://cdata.tvnet.hu/~ml/upx.html + Jean-loup Gailly, Mark Adler, and Gilles Vollant for the unzip routines! + Kode54 for the low pass filter routines! + DCX for helping out fixing up some bugs! + Andy Goth for some help on the design of the key combination engine! + Antiriad for some testing help and for the chats! + Yamaha of XYZZ (Scott Scriven) for his water effect code + Yamaha's homepage: http://www.VIS.colostate.edu/~scriven/) + All those people who helped us by either sending us docs, + helping us, supporting us, and reporting bugs! + Special Thanks to : Ashley, Barubary, CyberWarriorX, DCX, DooMStalK, + Fanwen, GreenImp, Hucard, Kaiden, Stalphos Knight, Star Creator, + TeleKawaru, Tuxedo Mask, the people in #zsnes efnet, and the regulars + of the ZSNES message board! + And also to all those whom we forgot! + +Special Thanks to all our beta testers for being a great help! +Info on 256x256x256 scanlines mode is from the MAME source. Thanks to + those behind MAME! + +Also, good luck to all those who are writing emulators, especially those + who are writing snes emulators, including Snes9x, Nlke, SNEeSe, and + SNEMul! And also good luck to the makers of TheSE! + \ No newline at end of file diff --git a/zsnes/dos/zsnesfaq.txt b/zsnes/dos/zsnesfaq.txt new file mode 100644 index 00000000..fc72ef3b --- /dev/null +++ b/zsnes/dos/zsnesfaq.txt @@ -0,0 +1,527 @@ +================================================ + ZSNES Frequently Asked Questions - DOS Version +================================================ + +SOUND COMPATIBILITY ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : How come I don't get any sound? +Q : When do you think you'll support GUS/PAS sound cards? +Q : I get a sound initialization error using my SB Live! (or any other PCI + card) How do I fix it? + +TRANSPARENCY ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : Are there transparencies in ZSNES? +Q : How do you enable transparencies? +Q : There is this layer of fog blocking my view. What's wrong? + +GAME COMPATIBILITY ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : Why doesn't *name of game* work on zsnes? +Q : Can you get *name of game* working by the next release? +Q : Why is *name of game* not working in v.*version #* of zsnes? It + was working before. +Q : When do you think you will emulate the *DSP/SFX/C4* chip? My favorite + game *name of game with chip* won't run without it. +Q : This game tells me that it is not compatible with the MultiTap (or an + external device attached). What should I do? +Q : How do I improve the compatibility of ZSNES? +Q : How come Mario RPG doesn't work? +Q : Why am I experiencing problems with Chrono Trigger? +Q : Why doesn't Star Ocean/Street Fighter Alpha 2 work? +Q : Why doesn't MegamanX2/MegamanX3 work? +Q : Can you guys get Star Ocean/Street Fighter Alpha 2 + to work? + +SPEED ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : Why is zsnes slow? +Q : How do I speed up zsnes? +Q : Can you implement dynamic recompilation into zsnes? +Q : Why does the game slow down even though I'm using auto frame rate and + the FPS is pretty high? + +KEYBOARD/JOYSTICK ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : Why can't I press more than 2 keys at a time? +Q : How come my sidewinder pad doesn't work? +Q : How do I use more than one sidewinder pads? +Q : Why doesn't my Gamepad Pro work? +Q : Why doesn't my joystick work anymore? +Q : How come my joystick keeps holding in one direction? +Q : How do I use both my Keyboard and Joystick for the 1st player like v0.400? +Q : Why does JB5/JB6 keep getting pressed whenever I try to change a key? + +IN-GAME SOUND ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : Why is the sound in zsnes not very good? +Q : Why does ZSNES produce a lot of static? +Q : How come stereo is reversed? + +CHEAT ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : How come the game genie codes don't work? +Q : How do I use .CHT files? + +FREEZING/CRASHING ISSUES: +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +Q : How come ZSNES freezes when I run it under pure dos? +Q : When I load a ROM, how come ZSNES crashes? +Q : How come zsnes freezes when it tries to enter the GUI? + +MISC: +ΝΝΝΝΝ +Q : ZSNES gives me an out of memory error and I only have 16MB of RAM. + How do I fix this? +Q : How does the auto .IPS patching feature work? +Q : Does the modem mode work well? +Q : Why is modem mode so choppy and slow? +Q : Does the IPX support work well? +Q : Why does ZSNES display a blank (or messed) screen when I start it up on + my laptop? +Q : Can I run .ZIP files from the commandline? +Q : Where do I get the games? + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* SOUND COMPATIBILITY ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come I don't get any sound? + +A : There could be several situations : + + 1.) You haven't enabled sound. You can enable it through the GUI + 2.) Try ZSNES Version a instead of c (eg. If you have ZSNES v0.900c, + download ZSNES v0.900a) + 3.) Your windows 95 doesn't create a SET BLASTER string. To verify this, + type SET in DOS and look for a string starting with BLASTER= + If such a string exists, then this is not your problem. + 4.) You don't have a SB2.0 compatible sound card. If this is your + case, then there is nothing you can do at the moment. ZSNES + uses auto-initialization mode for sound which requires SB2.0+ + 5.) Your SB IRQ conflicts with another device. If this is the case, + then you might want to check your sound card settings through + Control Panel -> System. + 6.) Zsnes doesn't like your sound card + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : When do you think you'll support GUS/PAS sound cards? + +A : We've considered implementing those sound cards, but a lack of time + and also by the fact that we haven't really touched those cards before + prevents us from implementing it. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : I get a sound initialization error using my SB Live! (or any other PCI + card) How do I fix it? + +A : Here is a solution : (Thanks CyberGodz for the post on the wwwboard!) + +SB Live uses what is known as a NMI or Non Maskable Interrupt to emulate +SB 16 sound. Don't ask me exactly what it does (it's a type of IRQ) but +that is pretty much all it is good for. + +The problem is that many boards either lack NMI support or don't have it +enabled. (No NMI = No Dos Support) + +To try and solve this problem do the following : + +1. Check your BIOS. If there is an option for RAM Parity Checking ENABLE IT. +It usually turns on NMI support. If there is something that says NMI turn it +on + +2. If you don't find anything in your BIOS, then go to your motherboards +website and download the latest BIOS flash. Install it and try your dos +sound. (You may still have to enable the stuff in the BIOS after) + +3. Failing the first two things you will either have to get a new +motherboard or install a SB 16, or other Compatable sound card alongside +the Live. Just attach a cable from the Line Out of the SB 16 to the Line In +of the Live. Enable line in on the mixer of your SB Live and it should route +the sound through the old sound card. (Don't use the SPDIF to connect the +cards if you have one. Wave sound dosn't pass through SPDIF only MIDI) + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* TRANSPARENCY ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Are there transparencies in ZSNES? + +A : Yes. Transparencies are in zsnes. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How do you enable transparencies? + +A : First, try setting the video mode to a 16bit color video mode in + the GUI (If 320x240x16b doesn't work, then try 640x480x16b). If + it gives you an error that says that your video card isn't compatible + with vesa 2.0, you might want to get the Scitech Display Doctor which + is located at www.scitechsoft.com which provides certain cards with + vesa 2.0 support. Running with transparencies on is definitely slower + because of the extra math equations, memory, and video space involved. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : There is this layer of fog blocking my view. What's wrong? + +A : You need to either enable transparencies (see above) or you can + disable certain backgrounds by pressing the 1,2,3, or 4 keys. If + you get lost while pressing those keys, press 6 to re-enable all + the backgrounds. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* COMPATIBILITY ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why doesn't *name of game* work on zsnes? + +A : Getting the compatibility higher is a very hard task to do. We're always + trying to get more games working. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Can you get *name of game* working by the next release? + +A : We're always trying, but we can never guarantee a specific game will be + working because of the difficulties involved in bug fixing. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why is *name of game* not working in v.*version #* of zsnes? It + was working before. + +A : Whenever we change something in the emulation, whether it's optimisation + or bug fixes, it has a good potential to have caused a problem elsewhere. + Usually, these problems aren't discovered until after a release. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : When do you think you will emulate the *DSP/SFX/C4* chip? My favorite + game *name of game with chip* won't run without it. + +A : We will consider emulating extra chips only if decent information on + those chips are found. However, even if we find info on them, we + cannot guarantee to be able to implement them. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : This game tells me that it is not compatible with the MultiTap. + What should I do? + +A : Set both Player 3 and Player 4's input device to 'None' + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How do I improve the compatibility of ZSNES? + +A : Turning on sound helps a lot here. If you can't enable sound, run + zsnes using the commandlines -s and -dd. Also, try to keep the % of + execution at 100%. If a game still doesn't work, try tweaking + the percentage of execution to both 120% or 80% in zsnes.cfg. If + that still doesn't work, then it's either a corrupt rom, a game that + requires a special chip, or a bug in zsnes. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come Mario RPG doesn't work? + +A : If the emulator crashes, then your rom file is corrupt. If it only + displays a blank screen, then you need to enable sound (or use -s -dd + as the commandlines when running zsnes under dos) + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why am I experiencing problems with Chrono Trigger? + +A : - If there is a layer of fog blocking the view, then you need to either + enable transparencies or remove the fog layer by pressing one of + the 1,2,3 keys. + - If the game freezes after the switching character sequence, then + you need to enable sound (or use -s -dd as the commandlines when running + zsnes under dos) and do not load from a save state, instead load from + the game selection menu when you start the game normally. + - If you cannot press the L+R+A seqence, then you would need to assign + both the L and R key as the same key such as set L and R to PageUp and + set A to Home, then pressing PageUp+Home will be the same as pressing + L,R, and A together. This is a hardware limitation of the keyboard, + not a bug in zsnes. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why doesn't MegamanX2/MegamanX3/Star Ocean/Street Fighter Alpha 2 work? + +A : Star Ocean and Street Fighter Alpha 2 both uses the S-DD1 chip, which + uses an unknown compression routine that has to be figured out before + it can be emulated. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why doesn't MegamanX2/MegamanX3 work? + +A : If it crashes after the Capcom logo, then you have a corrupt rom dump. + The actual ROM size for both of them is about 2 megabytes. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Can you guys get Star Ocean/Street Fighter Alpha 2 + to work? + +A : We have already worked on them to an extent, however, we cannot go much + further until we gain knowledge on how to get them to work. + Unfortunately, we are not magicians. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* SPEED ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How do I speed up zsnes? + +A : Running zsnes under pure dos instead of in a windows box would help for + low-end systems. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Can you implement dynamic recompilation into zsnes? + +A : There is no plans to implement it since it doesn't seem necessary. + The snes only uses a 3mhz cpu compared to say a 33mhz on a playstation + or a 93mhz on an n64. Implementing a dynamic recompilation engine will + be hard work and won't improve performance by much. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why does the game slow down even though I'm using auto frame rate and + the FPS is pretty high? + +A : A game slows down like that when it executes its code beyond the speed of + cpu emulation that zsnes currently handles. To reduce such slowdowns, + increase the percentage of execution by using either -p or editing + zsnes.cfg. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* KEYBOARD/JOYSTICK ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why can't I press more than 2 keys at a time? + +A : It's mainly the limitation of the PC Keyboard. If you want to press + more than 2 keys at a time, either use a joystick or change the keyboard + keys around until you find a combination where you can press more than + 2 keys at a time. Another technique that works is to set multiple + buttons to a single key. That way, pressing that key presses multiple + buttons at the same time. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come my sidewinder pad doesn't work? + +A : First, for non-USB Sidewinders, the first thing you should try + is to first disable the sidewinder profiler from the Win9x icon + tray, run ZSNES, set Input #1 as SidewinderPad1, then press the + mode button a few times. If it doesn't work, then try the + following : + + - Disable the Win9x Sidewinder Profiler, run Zsnes and press the + Mode button a few times + - Try checking or unchecking the Sidewinder Fix in the Options menu + of the GUI and repeat the above steps + - Fully disable the Win9x Sidewinder Drivers by going to + Control Panel/Game Controllers. Then remove the sidewinder + (Thanks Scarlet-Slider for this info!) + - Run zsnes under pure dos + - Try checking or unchecking the Sidewinder Fix in the Options menu + of the GUI and repeat the above 2 steps + - Make sure your sidewinder is plugged in and not broken + + For USB Joysticks, you can either set ZSNES as a 6-button joystick + or simulate keyboard keys through the Sidewinder Profiler and + set Input #1 as a keyboard with those defined keys. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How do I use more than one sidewinder pads? + +A : First, run ZSNES, temporarily disconnect the second sidewinder pad + from the first one, get the first one to work, then re-connect + the second sidewinder pad. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why doesn't my Gamepad Pro work? + +A : For the non-USB version, be sure to have your Gamepad Pro set on 'GrIP' + mode. Then set the input device as Gamepad Pro P0. For the USB version, + you can use a keyboard emulator which should be included with the + software that came with your joystick. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why doesn't my joystick work anymore? + +A : You might have accidently clicked the 'Use Joystick Port 209' check box. + Just uncheck it. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come my joystick keeps holding in one direction? + +A : That happens when you hold a direction when ZSNES starts up. + If that happens, then exit ZSNES and reload to recalibrate. Clicking + on SET in the input device window also calibrates the joystick, but + it also resets the controls to the default joystick settings. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How do I use both my Keyboard and Joystick for the 1st player like + v0.400? + +A : In the GUI, enter the CONFIG -> OPTIONS menu. Then check + 'USE Pl1/2 AS Pl3/4'. Once you've done that, Player 3 controls + will control Player 1 so if you have joystick set on Player 1, + set Player 3 as keyboard. This disables multitap emulation however. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why does JB5/JB6 keep getting pressed whenever I try to change a key? + +A : Try changing your joystick type from a 6-button to a 4-button. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* IN-GAME SOUND ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why does ZSNES produce a lot of static? + +A : Try reducing your sampling rate or disable stereo sound + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come stereo is reversed? + +A : Click on the box by 'Reverse Stereo' in the Sound configuration in the + GUI + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* CHEAT ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come the game genie codes don't work? + +A : You probabily didn't insert the '-'. Otherwise, try clicking on the FIX + button once while the highlight is over the code. If it still doesn't + work, chances are that the code is for another version of the game you're + trying to run or the code is a fake. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How do I use .CHT files? + +A : Copy the .CHT file to the ROM Directory or if you have a save + directory defined, copy it to the Save Directory. Then rename + the .CHT file if necessary so that the filename before the . matches + the ROM file. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* FREEZING/CRASHING ISSUES: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come ZSNES freezes when I run it under pure dos? + +A : Try loading your mouse driver or run zsnes using -j. For the most + compatible result, use the Microsoft Mouse driver if possible + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : When I load a ROM, how come ZSNES crashes? + +A : It could be that ZSNES doesn't recognize your sound configuration + so to fix it, disable sound or try changing your sound configuration. + It could also be that the ROM you're loading isn't compatible with + ZSNES. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How come zsnes freezes when it tries to enter the GUI? + +A : Run zsnes using the commandline -j + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ +************* MISC: ************* +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : ZSNES gives me an out of memory error and I only have 16MB of RAM. + How do I fix this? + +A : First, create a shortcut to the DOS Prompt on the desktop (the filename + that it points at can be c:\command.com ) + + Then right-click on the icon and go to properties. + + Select the memory tab and look below for Protected Mode (DPMI) settings + and set a high value (like 20000). + + Then double click on that icon and load ZSNES as usual. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : How does the auto .IPS patching feature work? + +A : The auto .IPS feature works by copying the .IPS file to the directory + of your ROM file or if you have a save directory defined, then the + .IPS file goes into the save directory. Next, rename the .IPS file + so that it matches filename (eg. If your ROM filename is THISGAME.SMC, + then your .IPS filename is THISGAME.IPS.) + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Does the modem mode work well? + +A : It should work quite well. First, make sure that you are using a modem + that is compatible with dos (a non winmodem). It is recommended that + both sides has a modem that uses a 16550a UART, otherwise the game may + go out of sync. Also, be sure to load a fresh new Zsnes session before + starting a modem session. If it still doesn't work, then try running + Zsnes under pure dos since some modems doesn't seem to work in + windows in Zsnes while works in pure dos. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why is modem mode so choppy and slow? + +A : Try increasing the latency value one by one until the gameplay becomes + smooth + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Does the IPX support work well? + +A : No. It does not work very well unless you have a very fast LAN. + Otherwise, the game will easily go out of sync. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Why does ZSNES display a blank (or messed) screen when I start it up on + my laptop? + +A : Your laptop is probably not compatible with ZSNES default 256x256x256 + resolution. One way to fix it is to set the resolution to 320x240x256 + by using the DOS commandline -v 0. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Can I run .ZIP files from the commandline? + +A : Yes. But you have to specify the full path/drive + (eg. ZSNES D:\GAMES\GAME.ZIP) + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + +Q : Where do I get the games? + +A : The ZSNES Team will *NOT* provide any games or any links to games. + +ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ + \ No newline at end of file diff --git a/zsnes/license.txt b/zsnes/license.txt new file mode 100644 index 00000000..833c82d4 --- /dev/null +++ b/zsnes/license.txt @@ -0,0 +1,343 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + + + \ No newline at end of file diff --git a/zsnes/news.txt b/zsnes/news.txt new file mode 100644 index 00000000..152f9ed5 --- /dev/null +++ b/zsnes/news.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/zsnes/readme.txt b/zsnes/readme.txt new file mode 100644 index 00000000..183fcb93 --- /dev/null +++ b/zsnes/readme.txt @@ -0,0 +1,5 @@ +If you need help to compile zsnes, read install.txt. +If you need help to browse the sources, read srcinfo.txt. + +For more information about zsnes development, check http://zsnes.sourceforge.net +The official website is at http://www.zsnes.com \ No newline at end of file diff --git a/zsnes/src/betauser.mac b/zsnes/src/betauser.mac new file mode 100644 index 00000000..ed748076 --- /dev/null +++ b/zsnes/src/betauser.mac @@ -0,0 +1,29 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +%define USERNAMEN 'Public' +%define USERNAMEC 'P'^76,'b'^89,'-'^178,'|'^34,'-'^217 +%define USERNAMEI 0 ; 1 + + \ No newline at end of file diff --git a/zsnes/src/cfgload.asm b/zsnes/src/cfgload.asm new file mode 100644 index 00000000..ea87cbee --- /dev/null +++ b/zsnes/src/cfgload.asm @@ -0,0 +1,1874 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM CMDLineStr,JoyAC,JoyBC,JoyLC,JoyRC,JoySelec,JoyStart +EXTSYM JoyXC,JoyYC,LoadDir,LoadDrive,SRAMDrive,mode7tab +EXTSYM pl1selk,pl1startk,pl1upk,pl2Ak,pl2Bk,pl2Lk,pl2Rk +EXTSYM pl2Xk,pl2Yk,pl2contrl,pl2downk,pl2leftk,pl2rightk +EXTSYM pl2selk,pl2startk,pl2upk,DontSavePath +EXTSYM FPUCopy,Force8b,MusicRelVol,SRAMDir,SoundCompD,SoundQuality +EXTSYM StereoSound,antienab,cvidmode,enterpress,frameskip,guioff +EXTSYM newengen,per2exec,pl1Ak,pl1Bk,pl1Lk,pl1Rk,pl1Xk,pl1Yk +EXTSYM pl1contrl,pl1downk,pl1leftk,pl1rightk,scanlines,soundon +EXTSYM spcon,vsyncon,Open_File,Read_File + EXTSYM Create_File,Write_File,Close_File + + + + + + +; [BITS 32] +; [ORG 0] + +; .CFG variables +SECTION .data +NEWSYM cfgsoundon, db 0 +NEWSYM cfgSoundQuality, db 2 +NEWSYM cfgStereoSound, db 0 +NEWSYM cfgguioff, db 0 +NEWSYM cfgper2exec, db 100 +NEWSYM cfgcvidmode, db 1 +NEWSYM cfgscanline, db 0 +NEWSYM cfginterp, db 0 +NEWSYM cfgenterskip, db 0 +NEWSYM cfgforce8b, db 0 +NEWSYM cfgloadsdir, db 0 +NEWSYM cfgloadgdir, db 0 +NEWSYM cfgnewgfx, db 0 +NEWSYM cfgcopymethod, db 0 +NEWSYM cfgvsync, db 0 +NEWSYM cfgvolume, db 75 +NEWSYM cfgecho, db 0 +NEWSYM RevStereo, db 0 +NEWSYM JoyStatRead, db 0 +NEWSYM pl12s34, db 0 +NEWSYM cfgdontsave, db 0 +NEWSYM cfgreinittime, db 30 +NEWSYM LoadDriveB, db 2 +NEWSYM LoadDirB, times 128 db 0 +SECTION .text + +%macro checkitemcfg 3 + cmp al,%1 + jne %3 + mov al,%2 + jmp .insertnum +%3 +%endmacro + +%macro checkitemcfg2 3 + cmp al,%1 + jne %3 + mov eax,%2 + jmp .insertnum2 +%3 +%endmacro + + +%macro ConvertJoyMapHelp 2 + mov cl,[%1] + cmp cl,bl + ja %%skip + or cl,cl + jz %%skip + add cl,81h + mov [%2],cl +%%skip +%endmacro + +NEWSYM ConvertJoyMap + cmp byte[JoyStatRead],1 + je .convert + ret +.convert + call ConvertJoyMap1 + call ConvertJoyMap2 + ret + +NEWSYM ConvertJoyMap1 + pushad + mov al,[pl1contrl] + ; Convert if 2,4,6, or sidewinder + cmp al,2 + jne .no2button + mov byte[pl1Bk],83h + mov byte[pl1Yk],82h + mov byte[pl1upk],0CCh + mov byte[pl1downk],0CDh + mov byte[pl1leftk],0CEh + mov byte[pl1rightk],0CFh +.no2button + cmp al,3 + je .4button + xor bl,bl + cmp al,4 + jne .no4button +.4button + mov bl,4 +.no4button + cmp al,5 + jne .no6button + mov bl,6 +.no6button + cmp bl,0 + je near .nojoy1 + ; Convert button data + mov byte[pl1upk],0CCh + mov byte[pl1downk],0CDh + mov byte[pl1leftk],0CEh + mov byte[pl1rightk],0CFh + ConvertJoyMapHelp JoyStart,pl1startk + ConvertJoyMapHelp JoySelec,pl1selk + ConvertJoyMapHelp JoyBC,pl1Yk + ConvertJoyMapHelp JoyYC,pl1Xk + ConvertJoyMapHelp JoyAC,pl1Bk + ConvertJoyMapHelp JoyXC,pl1Ak + ConvertJoyMapHelp JoyLC,pl1Lk + ConvertJoyMapHelp JoyRC,pl1Rk +.nojoy1 + cmp al,6 + jne .nosw + mov byte[pl1upk],0D4h + mov byte[pl1downk],0D5h + mov byte[pl1leftk],0D6h + mov byte[pl1rightk],0D7h + mov byte[pl1startk],0C8h + mov byte[pl1selk],0C9h + mov byte[pl1Ak],089h + mov byte[pl1Bk],088h + mov byte[pl1Xk],08Ch + mov byte[pl1Yk],08Bh + mov byte[pl1Lk],08Eh + mov byte[pl1Rk],08Fh +.nosw + popad + ret + +NEWSYM ConvertJoyMap2 + pushad + mov al,[pl2contrl] + ; Convert if 2,4,6, or sidewinder + ;If pl1contrl=2 and pl2contrl=2, then set pl2 buttons to 3 & 4 + cmp al,2 + jne .no2button2 + cmp byte[pl1contrl],2 + je .pl2b2 + mov byte[pl2Bk],83h + mov byte[pl2Yk],82h + mov byte[pl2upk],0CCh + mov byte[pl2downk],0CDh + mov byte[pl2leftk],0CEh + mov byte[pl2rightk],0CFh + jmp .finpl2 +.pl2b2 + mov byte[pl2Bk],85h + mov byte[pl2Yk],84h + mov byte[pl2upk],0E8h + mov byte[pl2downk],0E9h + mov byte[pl2leftk],0EAh + mov byte[pl2rightk],0EBh +.no2button2 +.finpl2 + cmp al,3 + je .4button2 + xor bl,bl + cmp al,4 + jne .no4button2 +.4button2 + mov bl,4 +.no4button2 + cmp al,5 + jne .no6button2 + mov bl,6 +.no6button2 + cmp bl,0 + je near .nojoy2 + ; Convert button data + mov byte[pl2upk],0CCh + mov byte[pl2downk],0CDh + mov byte[pl2leftk],0CEh + mov byte[pl2rightk],0CFh + ConvertJoyMapHelp JoyStart,pl2startk + ConvertJoyMapHelp JoySelec,pl2selk + ConvertJoyMapHelp JoyBC,pl2Yk + ConvertJoyMapHelp JoyYC,pl2Xk + ConvertJoyMapHelp JoyAC,pl2Bk + ConvertJoyMapHelp JoyXC,pl2Ak + ConvertJoyMapHelp JoyLC,pl2Lk + ConvertJoyMapHelp JoyRC,pl2Rk +.nojoy2 + ;If both sidewinder, set pl2 buttons to sw2 + cmp al,6 + jne near .nosw2 + cmp byte[pl1contrl],6 + je .pl2sw2 + mov byte[pl2upk],0D4h + mov byte[pl2downk],0D5h + mov byte[pl2leftk],0D6h + mov byte[pl2rightk],0D7h + mov byte[pl2startk],0C8h + mov byte[pl2selk],0C9h + mov byte[pl2Ak],089h + mov byte[pl2Bk],088h + mov byte[pl2Xk],08Ch + mov byte[pl2Yk],08Bh + mov byte[pl2Lk],08Eh + mov byte[pl2Rk],08Fh + jmp .nosw2 +.pl2sw2 + mov byte[pl2upk],0DCh + mov byte[pl2downk],0DDh + mov byte[pl2leftk],0DEh + mov byte[pl2rightk],0DFh + mov byte[pl2startk],0D0h + mov byte[pl2selk],0D1h + mov byte[pl2Ak],091h + mov byte[pl2Bk],090h + mov byte[pl2Xk],094h + mov byte[pl2Yk],093h + mov byte[pl2Lk],096h + mov byte[pl2Rk],097h + mov byte[pl2contrl],7 +.nosw2 + popad + ret + +NEWSYM DOScreatenewcfg + ; make a new file + ; copy .cfgfiledata to mode7tab, replacing each % + mov esi,.cfgfiledata + mov edi,mode7tab + xor ecx,ecx + mov edx,.cfgfilesize +.loop + mov al,[esi] + cmp al,'%' + je .look4item + mov [edi],al + inc esi + inc edi + inc ecx + dec edx + jnz .loop + cmp byte[cfgdontsave],1 + je .failed + push ecx + ; Save .CFG file + mov edx,CMDLineStr + call Create_File + pop ecx + jc .failed + ; Save 65816 status, etc. + mov bx,ax + mov edx,mode7tab + call Write_File + call Close_File +.failed + ret + +.look4item + inc esi + dec edx + mov al,[esi] + inc esi + dec edx + mov byte[.temp],0 + mov byte[.temp2],1 + mov bl,[frameskip] + cmp bl,0 + je .yframeskip + dec bl + mov [.temp],bl + mov byte[.temp2],0 +.yframeskip + checkitemcfg '1', [.temp],.check1 + checkitemcfg '2', [.temp2],.check2 + checkitemcfg '3', [pl1contrl],.check3 + checkitemcfg '4', [pl2contrl],.check4 + checkitemcfg2 '5', [pl1rightk],.check5 + checkitemcfg2 '6', [pl1leftk],.check6 + checkitemcfg2 '7', [pl1downk],.check7 + checkitemcfg2 '8', [pl1upk],.check8 + checkitemcfg2 '9', [pl1startk],.check9 + checkitemcfg2 'A', [pl1selk],.checkA + checkitemcfg2 'B', [pl1Bk],.checkB + checkitemcfg2 'C', [pl1Yk],.checkC + checkitemcfg2 'D', [pl1Ak],.checkD + checkitemcfg2 'E', [pl1Xk],.checkE + checkitemcfg2 'F', [pl1Lk],.checkF + checkitemcfg2 'G', [pl1Rk],.checkG + checkitemcfg2 'H', [pl2rightk],.checkH + checkitemcfg2 'I', [pl2leftk],.checkI + checkitemcfg2 'J', [pl2downk],.checkJ + checkitemcfg2 'K', [pl2upk],.checkK + checkitemcfg2 'L', [pl2startk],.checkL + checkitemcfg2 'M', [pl2selk],.checkM + checkitemcfg2 'N', [pl2Bk],.checkN + checkitemcfg2 'O', [pl2Yk],.checkO + checkitemcfg2 'P', [pl2Ak],.checkP + checkitemcfg2 'Q', [pl2Xk],.checkQ + checkitemcfg2 'R', [pl2Lk],.checkR + checkitemcfg2 'S', [pl2Rk],.checkS + checkitemcfg 'T', [cfgper2exec],.checkT + checkitemcfg 'U', [cfgcvidmode],.checkU + checkitemcfg 'V', [cfgsoundon],.checkV + checkitemcfg 'W', [cfgSoundQuality],.checkW + checkitemcfg 'X', [cfgStereoSound],.checkX + checkitemcfg 'Y', [cfgguioff],.checkY + checkitemcfg 'Z', [cfgscanline],.checkZ + checkitemcfg 'a', [cfginterp],.checka + checkitemcfg 'b', [cfgenterskip],.checkb + checkitemcfg 'c', [cfgforce8b],.checkc + cmp al,'d' + je near .insertdira + cmp al,'e' + je near .insertdirb + checkitemcfg 'f', [JoyStart],.checkf + checkitemcfg 'g', [JoySelec],.checkg + checkitemcfg 'h', [JoyBC],.checkh + checkitemcfg 'i', [JoyYC],.checki + checkitemcfg 'j', [JoyAC],.checkj + checkitemcfg 'k', [JoyXC],.checkk + checkitemcfg 'l', [JoyLC],.checkl + checkitemcfg 'm', [JoyRC],.checkm + checkitemcfg 'n', [cfgnewgfx],.checkn + checkitemcfg 'o', [cfgcopymethod],.checko + checkitemcfg 'p', [cfgvsync],.checkp + checkitemcfg 'q', [cfgvolume],.checkq + checkitemcfg 'r', [cfgecho],.checkr + checkitemcfg 's', [RevStereo],.checks + checkitemcfg 't', [pl12s34],.checkt + checkitemcfg 'u', [cfgdontsave],.checku + checkitemcfg 'v', [cfgreinittime],.checkv + jmp .loop + +.temp db 0 +.temp2 db 0 + +.insertnum + ; preserve ecx and edx, output al into edi + cmp al,0 + jne .nozero + mov byte[edi],'0' + inc edi + inc ecx + jmp .loop +.nozero + cmp al,99 + ja .digits3 + xor ah,ah + mov bl,10 + div bl + add al,48 + add ah,48 + cmp al,48 + jne .digits2 + mov byte[edi],ah + inc edi + inc ecx + jmp .loop +.digits2 + mov byte[edi],al + mov byte[edi+1],ah + add edi,2 + add ecx,2 + jmp .loop +.digits3 + xor ah,ah + mov bl,100 + div bl + add al,48 + mov byte[edi],al + mov al,ah + xor ah,ah + mov bl,10 + div bl + add al,48 + add ah,48 + mov byte[edi+1],al + mov byte[edi+2],ah + add edi,3 + add ecx,3 + jmp .loop + +.insertnum2 + ; preserve ecx and edx, output al into edi + cmp eax,0 + jne .nozeroi + mov byte[edi],'0' + inc edi + inc ecx + jmp .loop +.nozeroi + cmp eax,99 + ja .digits3i + xor ah,ah + mov bl,10 + div bl + add al,48 + add ah,48 + cmp al,48 + jne .digits2i + mov byte[edi],ah + inc edi + inc ecx + jmp .loop +.digits2i + mov byte[edi],al + mov byte[edi+1],ah + add edi,2 + add ecx,2 + jmp .loop +.digits3i + mov bl,100 + div bl + add al,48 + mov byte[edi],al + mov al,ah + xor ah,ah + mov bl,10 + div bl + add al,48 + add ah,48 + mov byte[edi+1],al + mov byte[edi+2],ah + add edi,3 + add ecx,3 + jmp .loop + +.insertdira + cmp byte[cfgloadsdir],1 + je .yesloadsdir + jmp .loop +.yesloadsdir + mov al,[SRAMDrive] + add al,65 + mov [edi],al + mov byte[edi+1],':' + mov byte[edi+2],'\' + add edi,3 + add ecx,3 + mov ebx,SRAMDir +.nextinsertdira + mov al,[ebx] + cmp al,0 + je .nomoredira + mov [edi],al + inc edi + inc ecx + inc ebx + jmp .nextinsertdira +.nomoredira + jmp .loop + +.insertdirb + cmp byte[DontSavePath],1 + je .insertdirc + mov al,[LoadDrive] + add al,65 + mov [edi],al + mov byte[edi+1],':' + mov byte[edi+2],'\' + add edi,3 + add ecx,3 + mov ebx,LoadDir +.nextinsertdir + mov al,[ebx] + cmp al,0 + je .nomoredir + mov [edi],al + inc edi + inc ecx + inc ebx + jmp .nextinsertdir +.nomoredir + jmp .loop + +.insertdirc + mov al,[LoadDriveB] + add al,65 + mov [edi],al + mov byte[edi+1],':' + mov byte[edi+2],'\' + add edi,3 + add ecx,3 + mov ebx,LoadDirB +.nextinsertdirc + mov al,[ebx] + cmp al,0 + je .nomoredirc + mov [edi],al + inc edi + inc ecx + inc ebx + jmp .nextinsertdirc +.nomoredirc + jmp .loop + +.cfgfiledata +db '; ZSNES Configuration file',13,10 +db '',13,10 +db '; Frame Skip = 0 .. 9',13,10 +db '',13,10 +db 'FrameSkip = %1',13,10 +db '',13,10 +db '; Auto Frame Skip = 0 or 1 (1 = ON)',13,10 +db '',13,10 +db 'AutoFrameSkip = %2',13,10 +db '',13,10 +db '; Player 1/2 Input Device. Use the GUI to set these values',13,10 +db '; NOTE : Using this to select joysticks manually will NOT work!',13,10 +db '',13,10 +db 'Player1Device = %3',13,10 +db 'Player2Device = %4',13,10 +db '',13,10 +db '; Keyboard Scancodes/Joystick Mappings for Keyboard 1 & 2',13,10 +db '; In order of Right, Left, Down, Up, Start, Select, B, Y, A, X, L, R',13,10 +db '; Use the GUI to set these values',13,10 +db '',13,10 +db 'ScanKey1 = %5, %6, %7, %8, %9, %A, %B, %C, %D, %E, %F, %G',13,10 +db 'ScanKey2 = %H, %I, %J, %K, %L, %M, %N, %O, %P, %Q, %R, %S',13,10 +db '',13,10 +db '; Share Player 3 and 4 control inputs with Player 1 and 2 to allow',13,10 +db '; 2 devices to be shared on a single player. This feature automatically',13,10 +db '; disables MultiTap (Multiplayer 5) support. Set this to 1 to enable.',13,10 +db '',13,10 +db 'Pl34to12Share = %t',13,10 +db '',13,10 +db '; Percent to Execute [50 .. 150]',13,10 +db '',13,10 +db 'Execute = %T',13,10 +db '',13,10 +;db '; Copy Method, 0 = Normal, 2 = MMX',13,10 +;db '',13,10 +;db 'CopyMethod = %o',13,10 +;db '',13,10 +db '; Video Mode, 0 - 3',13,10 +db '; 0 = 320x240x256 1 = 256x256x256',13,10 +db '; 2 = 320x240x256 VESA2 3 = 320x240x65536 VESA2',13,10 +db '; 4 = 640x480x256 VESA2 5 = 640x480x65536 VESA2',13,10 +db '; 6 = 512x384x256 VESA2 7 = 512x384x65536 VESA2',13,10 +db '; 8 = 640x480x65536 VESA1.2 9 = 320x480x256 VESA2',13,10 +db '; 10 = 320x480x65536 VESA2',13,10 +db '',13,10 +db 'VideoMode = %U',13,10 +db '',13,10 +db '; Sound Emulation = 0 or 1 (1 = ON)',13,10 +db '',13,10 +db 'Sound = %V',13,10 +db '',13,10 +db '; Sound Sampling Rate',13,10 +db '; 0 = 8000Hz, 1 = 11025Hz, 2 = 22050Hz, 3 = 44100Hz',13,10 +db '; 4 = 16000Hz, 5 = 32000Hz',13,10 +db '',13,10 +db 'SoundRate = %W',13,10 +db '',13,10 +db '; Stereo (0 = off, 1 = on)',13,10 +db '',13,10 +db 'Stereo = %X',13,10 +db '',13,10 +db '; Stereo Reversed (0 = off, 1 = L <-> R)',13,10 +db '',13,10 +db 'ReverseStereo = %s',13,10 +db '',13,10 +db '; GUI Disable (1 = Disable GUI, 0 = Enable GUI)',13,10 +db '',13,10 +db 'GUIDisable = %Y',13,10 +db '',13,10 +db '; New Graphics Engine (1 = Enable, 0 = Disable)',13,10 +db '; All 256 color modes and 320x240x65536 supported',13,10 +db '',13,10 +db 'NewGfx = %n',13,10 +db '',13,10 +db '; Scanlines (0 = Disable, 1 = Full, 2 = 25%, 3 = 50%)',13,10 +db '; 256x256x256 or 640x480 modes only (25% and 50% in 640x480x65536 mode only)',13,10 +db '',13,10 +db 'Scanlines = %Z',13,10 +db '',13,10 +db '; Interpolation (1 = Enable, 0 = Disable) - 640x480x65536 mode only',13,10 +db '; This option also Enables EAGLE - 640x480x256 mode only',13,10 +db '',13,10 +db 'Interpolation = %a',13,10 +db '',13,10 +db '; VSync (1 = Enable, 0 = Disable) - Wait for Vertical Sync (Fast cpu reqd)',13,10 +db '',13,10 +db 'VSync = %p',13,10 +db '',13,10 +db '; Skip Enter Press at Beginning (1 = Yes, 0 = No)',13,10 +db '',13,10 +db 'EnterSkip = %b',13,10 +db '',13,10 +db '; Force 8-bit sound on (1 = Yes, 0 = No)',13,10 +db '',13,10 +db 'Force8bit = %c',13,10 +db '',13,10 +db '; Disable Echo (1 = Yes, 0 = No)',13,10 +db '',13,10 +db 'EchoDisable = %r',13,10 +db '',13,10 +db '; Sound Volume Level (0 .. 100)',13,10 +db '; Note : Setting this too high can cause sound overflow which degrades quality',13,10 +db '',13,10 +db 'Volume = %q',13,10 +db '',13,10 +db '; Set this to 1 if you do not want ZSNES to save the configuration files.',13,10 +db '',13,10 +db 'DontSave = %u',13,10 +db '',13,10 +db '; Savefile directory. Leave it blank if you want the save files to be in the',13,10 +db '; same directory as the games. It should be in a format like : C:\dir\dir',13,10 +db '',13,10 +db 'SaveDirectory = %d',13,10 +db '',13,10 +db '; Game directory. This is the directory where the GUI starts at.',13,10 +db '; ZSNES automatically writes the current directory here apon exit.',13,10 +db '',13,10 +db 'GameDirectory = %e',13,10 +.cfgfilesize equ $-.cfgfiledata + +NEWSYM getcfg + mov byte[.forceauto],0 + ; open file + mov edx,CMDLineStr + call Open_File + jc .failed + mov [.fileloc],ax + mov byte[.eofile],0 +.noteof + call .readstring + cmp dword[.stralen],1 + jbe .skipstpr + call .splitstring +.skipstpr + cmp byte[.eofile],0 + je .noteof + + mov bx,[.fileloc] + call Close_File + ret + +.failed + call DOScreatenewcfg + ret + +.readstring: + mov dword[.strlen],0 + mov dword[.stralen],0 + mov byte[.ignore],0 +.startloop + mov bx,[.fileloc] + mov ecx,1 + mov edx,.cchar + call Read_File + cmp eax,0 + je .endoffile + cmp byte[.cchar],';' + je .comment + cmp byte[.cchar],13 + je .eoline + cmp byte[.cchar],10 + je .startloop + mov ecx,[.strlen] + mov al,[.cchar] + cmp ecx,127 + ja .nocopy + cmp byte[.ignore],1 + je .nocopy + mov [.string+ecx],al + inc dword[.stralen] +.nocopy + inc dword[.strlen] + jmp .startloop + ret +.comment + inc dword[.strlen] + mov byte[.ignore],1 + jmp .startloop + ret +.eoline + ret +.endoffile + mov byte[.eofile],1 + ret + +.splitstring: + ; search for ='s + mov ecx,[.stralen] + dec ecx + xor eax,eax + xor ebx,ebx +.next + cmp byte[.string+eax],'=' + jne .noeq + inc ebx +.noeq + inc eax + dec ecx + jnz .next + cmp ebx,1 + je .onequal + ret + +.onequal + xor eax,eax + xor ebx,ebx + mov ecx,[.stralen] + mov dword[.strlena],0 + mov dword[.strlenb],0 +.loopa + mov dl,[.string+eax] + cmp dl,'=' + je .nextb + cmp dl,' ' + je .skipcopy + cmp dl,'a' + jb .nocapneeded + cmp dl,'z' + ja .nocapneeded + sub dl,'a'-'A' +.nocapneeded + mov [.stringa+ebx],dl + inc dword[.strlena] + inc ebx +.skipcopy + inc eax + dec ecx + jnz .loopa + ret +.nextb + inc eax + dec ecx + jnz .noblank +.yesblank + ret +.noblank + xor ebx,ebx + mov byte[.usespace],0 +.loopb + mov dl,[.string+eax] + cmp byte[.usespace],0 + jne .nospaceskip + cmp dl,' ' + je .skipcopyb +.nospaceskip + cmp dl,'a' + jb .nocapneededb + cmp dl,'z' + ja .nocapneededb + sub dl,'a'-'A' +.nocapneededb + mov byte[.usespace],1 + mov [.stringb+ebx],dl + inc dword[.strlenb] + inc ebx +.skipcopyb + inc eax + dec ecx + jnz .loopb + cmp dword[.strlena],0 + je .nostr + cmp dword[.strlenb],0 + je .nostr + jmp .process +.nostr + ret + +.process + mov ecx,[.strlena] + cmp ecx,[.stra] + jne .nostra + mov edx,.stra+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostra + call .getframeskip +.nostra + mov ecx,[.strlena] + cmp ecx,[.strb] + jne .nostrb + mov edx,.strb+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrb + call .getautoframeskip +.nostrb + mov ecx,[.strlena] + cmp ecx,[.strc] + jne .nostrc + mov edx,.strc+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrc + call .getplayer1device +.nostrc + mov ecx,[.strlena] + cmp ecx,[.strd] + jne .nostrd + mov edx,.strd+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrd + call .getplayer2device +.nostrd + mov ecx,[.strlena] + cmp ecx,[.stre] + jne .nostre + mov edx,.stre+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostre + call .getscankey1 +.nostre + mov ecx,[.strlena] + cmp ecx,[.strf] + jne .nostrf + mov edx,.strf+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrf + call .getscankey2 +.nostrf + mov ecx,[.strlena] + cmp ecx,[.strg] + jne .nostrg + mov edx,.strg+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrg + call .getsound +.nostrg + mov ecx,[.strlena] + cmp ecx,[.strh] + jne .nostrh + mov edx,.strh+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrh + call .getsoundrate +.nostrh + mov ecx,[.strlena] + cmp ecx,[.stri] + jne .nostri + mov edx,.stri+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostri + call .getvideo +.nostri + mov ecx,[.strlena] + cmp ecx,[.strj] + jne .nostrj + mov edx,.strj+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrj + call .getexecute +.nostrj + mov ecx,[.strlena] + cmp ecx,[.strk] + jne .nostrk + mov edx,.strk+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrk + call .getbufdisable +.nostrk + mov ecx,[.strlena] + cmp ecx,[.strm] + jne .nostrm + mov edx,.strm+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrm + call .getstereo +.nostrm + mov ecx,[.strlena] + cmp ecx,[.strn] + jne .nostrn + mov edx,.strn+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrn + call .guidisable +.nostrn + mov ecx,[.strlena] + cmp ecx,[.stro] + jne .nostro + mov edx,.stro+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostro + call .scanlines +.nostro + mov ecx,[.strlena] + cmp ecx,[.strp] + jne .nostrp + mov edx,.strp+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrp + call .interpolation +.nostrp + mov ecx,[.strlena] + cmp ecx,[.strq] + jne .nostrq + mov edx,.strq+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrq + call .enterskip +.nostrq + mov ecx,[.strlena] + cmp ecx,[.strr] + jne .nostrr + mov edx,.strr+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrr + call .force8b +.nostrr + mov ecx,[.strlena] + cmp ecx,[.strs] + jne .nostrs + mov edx,.strs+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrs + call .getsavedir +.nostrs + mov ecx,[.strlena] + cmp ecx,[.strt] + jne .nostrt + mov edx,.strt+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrt + call .getloaddir +.nostrt + mov ecx,[.strlena] + cmp ecx,[.stru] + jne .nostru + mov edx,.stru+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostru + call .getjoymapping +.nostru + mov ecx,[.strlena] + cmp ecx,[.strv] + jne .nostrv + mov edx,.strv+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrv + call .getnewgfx +.nostrv + mov ecx,[.strlena] + cmp ecx,[.strw] + jne .nostrw + mov edx,.strw+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrw + call .getcopymethod +.nostrw + mov ecx,[.strlena] + cmp ecx,[.strx] + jne .nostrx + mov edx,.strx+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrx + call .getvsync +.nostrx + mov ecx,[.strlena] + cmp ecx,[.stry] + jne .nostry + mov edx,.stry+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostry + call .getvolume +.nostry + mov ecx,[.strlena] + cmp ecx,[.strz] + jne .nostrz + mov edx,.strz+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostrz + call .getecho +.nostrz + mov ecx,[.strlena] + cmp ecx,[.str1] + jne .nostr1 + mov edx,.str1+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostr1 + call .getreverses +.nostr1 + mov ecx,[.strlena] + cmp ecx,[.str2] + jne .nostr2 + mov edx,.str2+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostr2 + call .getplay1234 +.nostr2 + mov ecx,[.strlena] + cmp ecx,[.str3] + jne .nostr3 + mov edx,.str3+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostr3 + call .getdontsave +.nostr3 + mov ecx,[.strlena] + cmp ecx,[.str4] + jne .nostr4 + mov edx,.str4+4 + mov eax,.stringa + call .cmpstr + cmp bl,1 + je .nostr4 + call .getreinit +.nostr4 + ret + +.cmpstr + xor bl,bl +.loopcmp + mov bh,[eax] + cmp [edx],bh + jne .nocmp + inc eax + inc edx + dec ecx + jnz .loopcmp + ret +.nocmp + mov bl,1 + ret + +.getframeskip + cmp dword[.strlenb],1 + jne .noframeskip + mov al,[.stringb] + cmp al,'0' + jb .noframeskip + cmp al,'9' + ja .noframeskip + cmp byte[.forceauto],1 + je .noframeskip + sub al,47 + mov [frameskip],al +.noframeskip + ret + +.getautoframeskip + cmp dword[.strlenb],1 + jne .noautoframeskip + cmp byte[.stringb],'1' + jne .noautoframeskip + mov byte[.forceauto],1 + mov byte[frameskip],0 +.noautoframeskip + ret + +.getplayer1device + cmp dword[.strlenb],2 + je .double + cmp dword[.strlenb],1 + jne .noplay1 + mov al,[.stringb] + cmp al,'0' + jb .noplay1 + cmp al,'9' + ja .noplay1 + sub al,48 + mov [pl1contrl],al +.noplay1 + ret +.double + mov al,[.stringb] + cmp al,'1' + jne .noplay1 + mov al,[.stringb+1] + cmp al,'0' + jb .noplay1 + cmp al,'8' + ja .noplay1 + sub al,38 + mov [pl1contrl],al + ret + +.getplayer2device + cmp dword[.strlenb],2 + je .double2 + cmp dword[.strlenb],1 + jne .noplay2 + mov al,[.stringb] + cmp al,'0' + jb .noplay2 + cmp al,'9' + ja .noplay2 + sub al,48 + mov [pl2contrl],al +.noplay2 + ret +.double2 + mov al,[.stringb] + cmp al,'1' + jne .noplay2 + mov al,[.stringb+1] + cmp al,'0' + jb .noplay2 + cmp al,'8' + ja .noplay2 + sub al,38 + mov [pl2contrl],al + ret + +.getscankey1 + mov ecx,.stringb + xor ebx,ebx + xor eax,eax +.checknextscan1 + cmp dword[.strlenb],0 + je near .noscankey1 + mov bl,[ecx] + inc ecx + dec dword[.strlenb] + cmp bl,',' + je near .finstr1 + cmp bl,'0' + jb near .nextstr1 + cmp bl,'9' + ja near .nextstr1 + sub bl,48 + push ebx + mov ebx,10 + mul ebx + pop ebx + mov edx,ebx + and edx,0FFh + add eax,edx + cmp dword[.strlenb],0 + je near .finstr1 + jmp .nextstr1 +.finstr1 + ; determine which variable according to bh & write + ; In order of Right, Left, Down, Up, Start, Select, A, B, X, Y, L, R + cmp bh,0 + jne .nextaa + mov [pl1rightk],eax +.nextaa + cmp bh,1 + jne .nextba + mov [pl1leftk],eax +.nextba + cmp bh,2 + jne .nextca + mov [pl1downk],eax +.nextca + cmp bh,3 + jne .nextda + mov [pl1upk],eax +.nextda + cmp bh,4 + jne .nextea + mov [pl1startk],eax +.nextea + cmp bh,5 + jne .nextfa + mov [pl1selk],eax +.nextfa + cmp bh,6 + jne .nextga + mov [pl1Bk],eax +.nextga + cmp bh,7 + jne .nextha + mov [pl1Yk],eax +.nextha + cmp bh,8 + jne .nextia + mov [pl1Ak],eax +.nextia + cmp bh,9 + jne .nextja + mov [pl1Xk],eax +.nextja + cmp bh,10 + jne .nextka + mov [pl1Lk],eax +.nextka + cmp bh,11 + jne .nextla + mov [pl1Rk],eax +.nextla + xor eax,eax + inc bh +.nextstr1 + jmp .checknextscan1 +.noscankey1 + ret + +.getscankey2 + mov ecx,.stringb + xor ebx,ebx + xor eax,eax +.checknextscan2 + cmp dword[.strlenb],0 + je near .noscankey2 + mov bl,[ecx] + inc ecx + dec dword[.strlenb] + cmp bl,',' + je near .finstr2 + cmp bl,'0' + jb near .nextstr2 + cmp bl,'9' + ja near .nextstr2 + sub bl,48 + push ebx + mov ebx,10 + mul ebx + pop ebx + mov edx,ebx + and edx,0FFh + add eax,edx + cmp dword[.strlenb],0 + je near .finstr2 + jmp .nextstr2 +.finstr2 + ; determine which variable according to bh & write + ; In order of Right, Left, Down, Up, Start, Select, A, B, X, Y, L, R + cmp bh,0 + jne .nextaa2 + mov [pl2rightk],eax +.nextaa2 + cmp bh,1 + jne .nextba2 + mov [pl2leftk],eax +.nextba2 + cmp bh,2 + jne .nextca2 + mov [pl2downk],eax +.nextca2 + cmp bh,3 + jne .nextda2 + mov [pl2upk],eax +.nextda2 + cmp bh,4 + jne .nextea2 + mov [pl2startk],eax +.nextea2 + cmp bh,5 + jne .nextfa2 + mov [pl2selk],eax +.nextfa2 + cmp bh,6 + jne .nextga2 + mov [pl2Bk],eax +.nextga2 + cmp bh,7 + jne .nextha2 + mov [pl2Yk],eax +.nextha2 + cmp bh,8 + jne .nextia2 + mov [pl2Ak],eax +.nextia2 + cmp bh,9 + jne .nextja2 + mov [pl2Xk],eax +.nextja2 + cmp bh,10 + jne .nextka2 + mov [pl2Lk],eax +.nextka2 + cmp bh,11 + jne .nextla2 + mov [pl2Rk],eax +.nextla2 + xor eax,eax + inc bh +.nextstr2 + jmp .checknextscan2 +.noscankey2 + ret + +.getsound + cmp dword[.strlenb],1 + jne .nosound + mov al,[.stringb] + cmp al,'1' + jne .nosound + mov byte[spcon],1 ; SPC Enabled + mov byte[soundon],1 + mov byte[cfgsoundon],1 +.nosound + ret + +.getsoundrate + cmp dword[.strlenb],1 + jne .nosoundrate + mov al,[.stringb] + cmp al,'0' + jb .nosoundrate + cmp al,'6' + ja .nosoundrate + sub al,48 + mov [SoundQuality],al + mov [cfgSoundQuality],al +.nosoundrate + ret + +.getvideo + cmp dword[.strlenb],2 + je .videob + cmp dword[.strlenb],1 + jne .novideo + mov al,[.stringb] + cmp al,'0' + jb .novideo + cmp al,'9' + ja .novideo + sub al,48 + mov [cvidmode],al + mov [cfgcvidmode],al +.novideo + ret +.videob + cmp byte[.stringb],'1' + jne .novideo + mov al,[.stringb+1] + sub al,38 + mov [cvidmode],al + mov [cfgcvidmode],al + ret + +.getexecute + cmp dword[.strlenb],0 + je .noexecute + mov cl,[.strlenb] + mov esi,.stringb + mov byte[.per2exec],0 +.getnextperc + mov bl,10 + mov al,[.per2exec] + cmp al,100 + jae .noexecute + mul bl + mov [.per2exec],al + mov al,[esi] + cmp al,'0' + jb .noexecute + cmp al,'9' + ja .noexecute + sub al,48 + add [.per2exec],al + inc esi ; next character + dec cl + jz .nonextperc + jmp .getnextperc +.nonextperc + cmp byte[.per2exec],150 + ja .noexecute + cmp byte[.per2exec],50 + jb .noexecute + mov al,[.per2exec] + mov [per2exec],al + mov [cfgper2exec],al +.noexecute + ret + +.getreinit + cmp dword[.strlenb],0 + je .nogetreinit + mov cl,[.strlenb] + mov esi,.stringb + mov byte[.per2exec],0 +.getnextgetreinit + mov bl,10 + mov al,[.per2exec] + cmp al,100 + jae .nogetreinit + mul bl + mov [.per2exec],al + mov al,[esi] + cmp al,'0' + jb .nogetreinit + cmp al,'9' + ja .nogetreinit + sub al,48 + add [.per2exec],al + inc esi ; next character + dec cl + jz .nonextgetreinit + jmp .getnextgetreinit +.nonextgetreinit + cmp byte[.per2exec],150 + ja .nogetreinit + cmp byte[.per2exec],5 + jb .nogetreinit + mov al,[.per2exec] + mov [cfgreinittime],al +.nogetreinit + ret + +.getbufdisable + cmp dword[.strlenb],1 + jne .nobufdisable + cmp byte[.stringb],'1' + jne .nobufdisable + mov byte[SoundCompD],1 +.nobufdisable + ret + +.getstereo + cmp dword[.strlenb],1 + jne .nostereo + cmp byte[.stringb],'1' + jne .nostereo + mov byte[StereoSound],1 + mov byte[cfgStereoSound],1 +.nostereo + ret + +.guidisable + cmp dword[.strlenb],1 + jne .noguidisable + cmp byte[.stringb],'1' + jne .noguidisable + mov byte[guioff],1 + mov byte[cfgguioff],1 +.noguidisable + ret + +.scanlines + cmp dword[.strlenb],1 + jne .noscanlines + cmp byte[.stringb],'1' + jne .noscanlines + mov byte[scanlines],1 + mov byte[cfgscanline],1 +.noscanlines + cmp byte[.stringb],'2' + jne .noscanlinesh2 + mov byte[scanlines],2 + mov byte[cfgscanline],2 +.noscanlinesh2 + cmp byte[.stringb],'3' + jne .noscanlinesh3 + mov byte[scanlines],3 + mov byte[cfgscanline],3 +.noscanlinesh3 + ret + +.interpolation + cmp dword[.strlenb],1 + jne .nointerpolation + cmp byte[.stringb],'1' + jne .nointerpolation + mov byte[antienab],1 + mov byte[cfginterp],1 +.nointerpolation + ret + +.enterskip + cmp dword[.strlenb],1 + jne .noenterskip + cmp byte[.stringb],'1' + jne .noenterskip + mov byte[enterpress],1 + mov byte[cfgenterskip],1 +.noenterskip + ret + +.force8b + cmp dword[.strlenb],1 + jne .noforce8b + cmp byte[.stringb],'1' + jne .noforce8b + mov byte[Force8b],1 + mov byte[cfgforce8b],1 +.noforce8b + ret + +.getsavedir + cmp dword[.strlenb],3 + jb .nosavedir + cmp byte[.stringb+1],':' + jne .nosavedir + cmp byte[.stringb+2],'\' + jne .nosavedir + mov byte[cfgloadsdir],1 + mov al,[.stringb] + sub al,65 + mov [SRAMDrive],al + push ecx + push esi + push edi + mov ecx,[.strlenb] + sub ecx,3 + mov esi,.stringb+3 + mov edi,SRAMDir + cmp ecx,0 + je .ndird +.ndirc + mov al,[esi] + mov [edi],al + inc esi + inc edi + dec ecx + jnz .ndirc +.ndird + mov byte[edi],0 + pop edi + pop esi + pop ecx +.nosavedir + ret + +.getloaddir + cmp dword[.strlenb],3 + jb .noloaddir + cmp byte[.stringb+1],':' + jne .noloaddir + cmp byte[.stringb+2],'\' + jne .noloaddir + mov byte[cfgloadgdir],1 + mov al,[.stringb] + sub al,65 + mov [LoadDrive],al + mov [LoadDriveB],al + push ecx + push esi + push edi + push ebx + mov ecx,[.strlenb] + sub ecx,3 + mov esi,.stringb+3 + mov edi,LoadDir + mov ebx,LoadDirB + cmp ecx,0 + je .ndirb +.ndir + mov al,[esi] + mov [edi],al + mov [ebx],al + inc esi + inc edi + inc ebx + dec ecx + jnz .ndir +.ndirb + mov byte[edi],0 + pop ebx + pop edi + pop esi + pop ecx +.noloaddir + ret + +.getjoymapping + mov byte[JoyStatRead],1 + mov ecx,.stringb + xor ebx,ebx + xor eax,eax +.checknextscan3 + cmp dword[.strlenb],0 + je near .noscankey3 + mov bl,[ecx] + inc ecx + dec dword[.strlenb] + cmp bl,',' + je near .finstr3 + cmp bl,'0' + jb near .nextstr3 + cmp bl,'9' + ja near .nextstr3 + sub bl,48 + mov dl,10 + mul dl + add al,bl + cmp dword[.strlenb],0 + je near .finstr3 + jmp .nextstr3 +.finstr3 + ; determine which variable according to bh & write + ; In order of Start, Select, B, Y, A, X, L, R + cmp bh,0 + jne .nextaa3 + mov byte[JoyStart],al +.nextaa3 + cmp bh,1 + jne .nextba3 + mov byte[JoySelec],al +.nextba3 + cmp bh,2 + jne .nextca3 + mov byte[JoyBC],al +.nextca3 + cmp bh,3 + jne .nextda3 + mov byte[JoyYC],al +.nextda3 + cmp bh,4 + jne .nextea3 + mov byte[JoyAC],al +.nextea3 + cmp bh,5 + jne .nextfa3 + mov byte[JoyXC],al +.nextfa3 + cmp bh,6 + jne .nextga3 + mov byte[JoyLC],al +.nextga3 + cmp bh,7 + jne .nextha3 + mov byte[JoyRC],al +.nextha3 + xor eax,eax + inc bh +.nextstr3 + jmp .checknextscan3 +.noscankey3 + ret + +.getnewgfx + cmp dword[.strlenb],1 + jne .nonewgfx + cmp byte[.stringb],'1' + jne .nonewgfx + mov byte[newengen],1 + mov byte[cfgnewgfx],1 +.nonewgfx + ret + +.getcopymethod + cmp dword[.strlenb],1 + jne .nocopymethod + cmp byte[.stringb],'1' + jne .nofpu + mov byte[FPUCopy],0 + mov byte[cfgcopymethod],1 + jmp .nocopymethod +.nofpu + cmp byte[.stringb],'2' + jne .nocopymethod + mov byte[FPUCopy],2 + mov byte[cfgcopymethod],2 +.nocopymethod + ret + +.getvsync + cmp dword[.strlenb],1 + jne .novsync + cmp byte[.stringb],'1' + jne .novsync + mov byte[vsyncon],1 + mov byte[cfgvsync],1 +.novsync + ret + +.getecho + cmp dword[.strlenb],1 + jne .nodecho + cmp byte[.stringb],'1' + jne .nodecho + mov byte[cfgecho],1 +.nodecho + ret + +.getplay1234 + cmp dword[.strlenb],1 + jne .nop1234 + cmp byte[.stringb],'1' + jne .nop1234 + mov byte[pl12s34],1 +.nop1234 + ret + +.getdontsave + cmp dword[.strlenb],1 + jne .nodontsave + cmp byte[.stringb],'1' + jne .nodontsave + mov byte[cfgdontsave],1 +.nodontsave + ret + +.getreverses + cmp dword[.strlenb],1 + jne .nors + cmp byte[.stringb],'1' + jne .nors + mov byte[RevStereo],1 +.nors + ret + +.getvolume + cmp dword[.strlenb],0 + je .novolume + mov cl,[.strlenb] + mov esi,.stringb + mov byte[.volume],0 +.getnextvol + mov bl,10 + mov al,[.volume] + cmp al,100 + jae .novolume + mul bl + mov [.volume],al + mov al,[esi] + cmp al,'0' + jb .novolume + cmp al,'9' + ja .novolume + sub al,48 + add [.volume],al + inc esi ; next character + dec cl + jz .nonextvol + jmp .getnextvol +.nonextvol + cmp byte[.volume],100 + ja .novolume + mov al,[.volume] + mov [MusicRelVol],al + mov [cfgvolume],al +.novolume + ret + +SECTION .data + +.per2exec db 0 +.volume db 0 +.fileloc dw 0 +.eofile db 0 +.ignore db 0 +.strlen dd 0 +.stralen dd 0 ; actual string length +.strlena dd 0 +.strlenb dd 0 +.cchar db 0 +.forceauto db 0 +.string times 128 db 0 ; full string +.stringa times 128 db 0 +.stringb times 128 db 0 +.cfgfname db 'zsnes.cfg',0 +.stra dd 9 + db 'FRAMESKIP' +.strb dd 13 + db 'AUTOFRAMESKIP' +.strc dd 13 + db 'PLAYER1DEVICE' +.strd dd 13 + db 'PLAYER2DEVICE' +.stre dd 8 + db 'SCANKEY1' +.strf dd 8 + db 'SCANKEY2' +.strg dd 5 + db 'SOUND' +.strh dd 9 + db 'SOUNDRATE' +.stri dd 9 + db 'VIDEOMODE' +.strj dd 7 + db 'EXECUTE' +.strk dd 15 + db 'SOUNDBUFDISABLE' +.strm dd 6 + db 'STEREO' +.strn dd 10 + db 'GUIDISABLE' +.stro dd 9 + db 'SCANLINES' +.strp dd 13 + db 'INTERPOLATION' +.strq dd 9 + db 'ENTERSKIP' +.strr dd 9 + db 'FORCE8BIT' +.strs dd 13 + db 'SAVEDIRECTORY' +.strt dd 13 + db 'GAMEDIRECTORY' +.stru dd 7 + db 'JOYMAP1' +.strv dd 6 + db 'NEWGFX' +.strw dd 10 + db 'COPYMETHOD' +.strx dd 5 + db 'VSYNC' +.stry dd 6 + db 'VOLUME' +.strz dd 11 + db 'ECHODISABLE' +.str1 dd 13 + db 'REVERSESTEREO' +.str2 dd 13 + db 'PL34TO12SHARE' +.str3 dd 8 + db 'DONTSAVE' +.str4 dd 10 + db 'REINITTIME' +.usespace db 0 + +SECTION .text + + \ No newline at end of file diff --git a/zsnes/src/chips/dsp1emu.c b/zsnes/src/chips/dsp1emu.c new file mode 100644 index 00000000..6b6c0321 --- /dev/null +++ b/zsnes/src/chips/dsp1emu.c @@ -0,0 +1,953 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include +#include + +#define DebugDSP1 + +// uncomment some lines to test +//#define printinfo +//#define debug02 +//#define debug0A +//#define debug06 + + +#ifdef DebugDSP1 + +FILE * LogFile = NULL; + +void Log_Message (char *Message, ...) +{ + char Msg[400]; + va_list ap; + + va_start(ap,Message); + vsprintf(Msg,Message,ap ); + va_end(ap); + + strcat(Msg,"\r\n\0"); + fwrite(Msg,strlen(Msg),1,LogFile); +} + +void Start_Log (void) +{ + char LogFileName[255]; + char *p; + + strcpy(LogFileName,"dsp1emu.log\0"); + + LogFile = fopen(LogFileName,"wb"); +} + +void Stop_Log (void) +{ + if (LogFile) + { + fclose(LogFile); + LogFile = NULL; + } +} + +#endif + + +/***************************************************************************\ +* Math tables * +\***************************************************************************/ + +int CosTable2[256]={65536,65516,65457,65358,65220,65043,64826,64571,64276,63943,63571,63161,62713,62227,61704,61144,60546,59912,59243,58537,57796, +57020,56210,55367,54489,53579,52637,51663,50658,49622,48556,47461,46338,45187,44008,42803,41572, +40316,39036,37732,36406,35057,33688,32298,30889,29461,28015,26553,25074,23581,22073,20552,19018,17473,15918,14353,12779,11198,9610,8016,6417,4814, +3209,1601,-6,-1615,-3222,-4828,-6430,-8029,-9623,-11211,-12792,-14366,-15931,-17486,-19031,-20565,-22086,-23593,-25087,-26565,-28028,-29473, +-30901,-32310,-33700,-35069,-36417,-37743,-39047,-40327,-41583,-42813,-44018,-45197,-46348,-47471,-48565, +-49631,-50666,-51671,-52645,-53587,-54497,-55374,-56217,-57027,-57802,-58543,-59248,-59918,-60551,-61148, +-61709,-62232,-62717,-63165,-63575,-63946,-64279,-64573,-64828,-65044,-65221,-65359,-65457,-65516,-65535, +-65515,-65456,-65357,-65219,-65041,-64824,-64568,-64273,-63940,-63568,-63158,-62709,-62223,-61699,-61139, +-60541,-59907,-59237,-58531,-57790,-57014,-56203,-55359,-54482,-53571,-52629,-51654,-50649,-49613,-48547, +-47452,-46328,-45177,-43998,-42793,-41562,-40306,-39025,-37721,-36395,-35046,-33676,-32286,-30877,-29449, +-28003,-26540,-25062,-23568,-22060,-20539,-19005,-17460,-15905,-14340,-12766,-11184,-9596,-8002,-6403, +-4801,-3195,-1588,20,1628,3236,4841,6444,8043,9636,11224,12806,14379,15944,17500,19044,20578,22099, +23606,25099,26578,28040,29485,30913,32322,33711,35080,36428,37754,39058,40338,41593,42824,44028, +45206,46357,47480,48575,49640,50675,51680,52653,53595,54504,55381,56224,57034,57809,58549,59254, +59923,60557,61153,61713,62236,62721,63168,63578,63949,64281,64575,64830,65046,65223,65360,65458,65516}; + +int SinTable2[256]={0,1608,3215,4821,6424,8022,9616,11204,12786,14359,15924,17480,19025,20558,22079, +23587,25081,26559,28021,29467,30895,32304,33694,35063,36411,37738,39041,40322,41577,42808,44013, +45192,46343,47466,48561,49626,50662,51667,52641,53583,54493,55370,56214,57024,57799,58540,59245, +59915,60549,61146,61706,62229,62715,63163,63573,63944,64277,64572,64827,65043,65221,65358,65457, +65516,65535,65516,65456,65357,65219,65042,64825,64569,64275,63941,63570,63159,62711,62225,61702, +61141,60544,59910,59240,58534,57793,57017,56207,55363,54486,53575,52633,51659,50653,49617,48552, +47457,46333,45182,44003,42798,41567,40311,39031,37727,36400,35052,33682,32292,30883,29455,28009, +26547,25068,23574,22067,20545,19012,17467,15911,14346,12772,11191,9603,8009,6410,4807,3202,1594, +-13,-1622,-3229,-4834,-6437,-8036,-9630,-11218,-12799,-14373,-15938,-17493,-19038,-20571,-22092, +-23600,-25093,-26571,-28034,-29479,-30907,-32316,-33705,-35075,-36423,-37749,-39052,-40332,-41588,-42818,-44023,-45201,-46352,-47476,-48570,-49635,-50671,-51675,-52649,-53591,-54501,-55377,-56221,-57030,-57806,-58546,-59251,-59921,-60554,-61151,-61711, +-62234,-62719,-63167,-63576,-63947,-64280,-64574,-64829,-65045,-65222,-65359,-65458,-65516,-65535, +-65515,-65456,-65356,-65218,-65040,-64823,-64567,-64272,-63938,-63566,-63156,-62707,-62221,-61697, +-61136,-60538,-59904,-59234,-58528,-57786,-57010,-56200,-55356,-54478,-53567,-52625,-51650,-50645, +-49609,-48543,-47447,-46324,-45172,-43993,-42788,-41556,-40300,-39020,-37716,-36389,-35040,-33670, +-32280,-30871,-29443,-27997,-26534,-25056,-23562,-22054,-20532,-18999,-17454,-15898,-14333,-12759, +-11178,-9589,-7995,-6397,-4794,-3188,-1581}; + + + +/***************************************************************************\ +* C4 C code * +\***************************************************************************/ + + +short C4WFXVal; +short C4WFYVal; +short C4WFZVal; +short C4WFX2Val; +short C4WFY2Val; +short C4WFDist; +short C4WFScale; +double tanval; +double c4x,c4y,c4z; +double c4x2,c4y2,c4z2; + +C4TransfWireFrame() +{ + c4x=(double)C4WFXVal; + c4y=(double)C4WFYVal; + c4z=(double)C4WFZVal-0x95; + + // Rotate X + tanval=-(double)C4WFX2Val*3.14159265*2/128; + c4y2=c4y*cos(tanval)-c4z*sin(tanval); + c4z2=c4y*sin(tanval)+c4z*cos(tanval); + + // Rotate Y + tanval=-(double)C4WFY2Val*3.14159265*2/128; + c4x2=c4x*cos(tanval)+c4z2*sin(tanval); + c4z=c4x*-sin(tanval)+c4z2*cos(tanval); + + // Rotate Z + tanval=-(double)C4WFDist*3.14159265*2/128; + c4x=c4x2*cos(tanval)-c4y2*sin(tanval); + c4y=c4x2*sin(tanval)+c4y2*cos(tanval); + + // Scale + C4WFXVal=c4x*(double)C4WFScale/(0x90*(c4z+0x95))*0x95; + C4WFYVal=c4y*(double)C4WFScale/(0x90*(c4z+0x95))*0x95; +} + +C4TransfWireFrame2() +{ + c4x=(double)C4WFXVal; + c4y=(double)C4WFYVal; + c4z=(double)C4WFZVal; + + // Rotate X + tanval=-(double)C4WFX2Val*3.14159265*2/128; + c4y2=c4y*cos(tanval)-c4z*sin(tanval); + c4z2=c4y*sin(tanval)+c4z*cos(tanval); + + // Rotate Y + tanval=-(double)C4WFY2Val*3.14159265*2/128; + c4x2=c4x*cos(tanval)+c4z2*sin(tanval); + c4z=c4x*-sin(tanval)+c4z2*cos(tanval); + + // Rotate Z + tanval=-(double)C4WFDist*3.14159265*2/128; + c4x=c4x2*cos(tanval)-c4y2*sin(tanval); + c4y=c4x2*sin(tanval)+c4y2*cos(tanval); + + // Scale + C4WFXVal=c4x*(double)C4WFScale/0x100; + C4WFYVal=c4y*(double)C4WFScale/0x100; +} + +C4CalcWireFrame() +{ + C4WFXVal=C4WFX2Val-C4WFXVal; + C4WFYVal=C4WFY2Val-C4WFYVal; + if (abs(C4WFXVal)>abs(C4WFYVal)){ + C4WFDist=abs(C4WFXVal)+1; + C4WFYVal=256*(double)C4WFYVal/abs((double)C4WFXVal); + if (C4WFXVal<0) C4WFXVal=-256; + else C4WFXVal=256; + } + else + if (C4WFYVal!=0) { + C4WFDist=abs(C4WFYVal)+1; + C4WFXVal=256*(double)C4WFXVal/abs((double)C4WFYVal); + if (C4WFYVal<0) C4WFYVal=-256; + else C4WFYVal=256; + } + else C4WFDist=0; +} + +short C41FXVal; +short C41FYVal; +short C41FAngleRes; +short C41FDist; +short C41FDistVal; + +C4Op1F() +{ + if (C41FXVal == 0) { + if (C41FYVal>0) C41FAngleRes=0x80; + else C41FAngleRes=0x180; + } + else { + tanval = ((double)C41FYVal)/((double)C41FXVal); + C41FAngleRes=atan(tanval)/(3.141592675*2)*512; + C41FAngleRes=C41FAngleRes; + if (C41FXVal<0) C41FAngleRes+=0x100; + C41FAngleRes&=0x1FF; + } +} + +C4Op15() +{ + tanval=sqrt(((double)C41FYVal)*((double)C41FYVal)+((double)C41FXVal)* + ((double)C41FXVal)); + C41FDist=tanval; +} + +C4Op0D() +{ + tanval=sqrt(((double)C41FYVal)*((double)C41FYVal)+((double)C41FXVal)* + ((double)C41FXVal)); + tanval=(double)C41FDistVal/tanval; + C41FYVal=((double)C41FYVal*tanval)*0.99; + C41FXVal=((double)C41FXVal*tanval)*0.98; +} + + +/***************************************************************************\ +* DSP1 code * +\***************************************************************************/ + + +void InitDSP(void) +{ +#ifdef DebugDSP1 + Start_Log(); +#endif +} + + +short Op00Multiplicand; +short Op00Multiplier; +short Op00Result; + +DSPOp00() +{ + Op00Result=Op00Multiplicand*Op00Multiplier/32768; + #ifdef DebugDSP1 + Log_Message("OP00 MULT %d*%d/32768=%d",Op00Multiplicand,Op00Multiplier,Op00Result); + #endif +} + + +short Op10Coefficient; +short Op10Exponent; +short Op10CoefficientR; +short Op10ExponentR; + +// To fix... + +DSPOp10() +{ + +#ifdef DebugDSP1 + Log_Message("OP10 NOT IMPLEMENTED"); +#endif + + Op10ExponentR=-Op10Exponent; + Op10CoefficientR=1/Op10Coefficient; +} + + +short Op04Angle; +unsigned short Op04Radius; +short Op04Sin; +short Op04Cos; + +DSPOp04() +{ + Op04Sin=SinTable2[(Op04Angle/256)&255]*Op04Radius/65536; + Op04Cos=CosTable2[(Op04Angle/256)&255]*Op04Radius/65536; + #ifdef DebugDSP1 + Log_Message("OP04 Angle:%d Radius:%d",(Op04Angle/256)&255,Op04Radius); + Log_Message("OP04 SIN:%d COS:%d",Op04Sin,Op04Cos); + #endif +} + + +short Op08X; +short Op08Y; +short Op08Z; +int Op08Size; + +DSPOp08Radius() +{ + Op08Size=(Op08X*Op08X+Op08Y*Op08Y+Op08Z*Op08Z)*2; + + #ifdef DebugDSP1 + Log_Message("OP08 %d,%d,%d",Op08X,Op08Y,Op08Z); + Log_Message("OP08 ((Op08X^2)+(Op08Y^2)+(Op08X^2))*2=%d",Op08Size ); + #endif +} + +short Op18X; +short Op18Y; +short Op18Z; +short Op18R; +short Op18Difference; + +DSPOp18() +{ + Op18Difference=((Op18X*Op18X+Op18Y*Op18Y+Op18Z*Op18Z-Op18R*Op18R)*2)/65536; + #ifdef DebugDSP1 + Log_Message("OP18 DIFF %d",Op18Difference); + #endif +} + +short Op28X; +short Op28Y; +short Op28Z; +short Op28R; + +DSPOp28() +{ + Op28R=sqrt(abs(Op28X*Op28X+Op28Y*Op28Y+Op28Z*Op28Z)); + #ifdef DebugDSP1 + Log_Message("OP28 X:%d Y:%d Z:%d",Op18X,Op18Y,Op18Z); + Log_Message("OP28 Vector Length %d",Op18R); + #endif +} + +unsigned short Op0CA; +short Op0CX1; +short Op0CY1; +short Op0CX2; +short Op0CY2; + +DSPOp0C() +{ + Op0CX2=(Op0CX1*CosTable2[(Op0CA/256)&255]+Op0CY1*SinTable2[(Op0CA/256)&255])/65536; + Op0CY2=(Op0CX1*-SinTable2[(Op0CA/256)&255]+Op0CY1*CosTable2[(Op0CA/256)&255])/65536; + #ifdef DebugDSP1 + Log_Message("OP0C Angle:%d X:%d Y:%d CX:%d CY:%d",(Op0CA/256)&255,Op0CX1,Op0CY1,Op0CX2,Op0CY2); + #endif +} + +unsigned short Op1CAZ; +unsigned short Op1CAX; +unsigned short Op1CAY; +short Op1CX; +short Op1CY; +short Op1CZ; +short Op1CX1; +short Op1CY1; +short Op1CZ1; +short Op1CX2; +short Op1CY2; +short Op1CZ2; +short Op1CX3; +short Op1CY3; +short Op1CZ3; + +DSPOp1C() +{ + // rotate around Y + Op1CX1=(Op1CX*CosTable2[(Op1CAY/256)&255]+Op1CZ*SinTable2[(Op1CAY/256)&255])/65536; + Op1CY1=Op1CY; + Op1CZ1=(Op1CX*-SinTable2[(Op1CAY/256)&255]+Op1CZ*CosTable2[(Op1CAY/256)&255])/65536; + // rotate around X + Op1CX2=Op1CX1; + Op1CY2=(Op1CY1*CosTable2[(Op1CAX/256)&255]+Op1CZ1*-SinTable2[(Op1CAX/256)&255])/65536; + Op1CZ2=(Op1CY1*SinTable2[(Op1CAX/256)&255]+Op1CZ1*CosTable2[(Op1CAX/256)&255])/65536; + // rotate around Z + Op1CX3=(Op1CX2*CosTable2[(Op1CAZ/256)&255]+Op1CY2*-SinTable2[(Op1CAZ/256)&255])/65536; + Op1CY3=(Op1CX2*SinTable2[(Op1CAZ/256)&255]+Op1CY2*CosTable2[(Op1CAZ/256)&255])/65536; + Op1CZ3=Op1CZ2; + + #ifdef DebugDSP1 + Log_Message("OP1C Apply Matrix CX:%d CY:%d CZ",Op1CX3,Op1CY3,Op1CZ3); + #endif +} + + + + +short Op02FX; +short Op02FY; +short Op02FZ; +short Op02LFE; +short Op02LES; +unsigned short Op02AAS; +unsigned short Op02AZS; +unsigned short Op02VOF; +unsigned short Op02VVA; + +short Op02CX; +short Op02CY; +double Op02CXF; +double Op02CYF; +double ViewerX0; +double ViewerY0; +double ViewerZ0; +double ViewerX1; +double ViewerY1; +double ViewerZ1; +double ViewerX; +double ViewerY; +double ViewerZ; +int ViewerAX; +int ViewerAY; +int ViewerAZ; +double NumberOfSlope; +double ScreenX; +double ScreenY; +double ScreenZ; +double TopLeftScreenX; +double TopLeftScreenY; +double TopLeftScreenZ; +double BottomRightScreenX; +double BottomRightScreenY; +double BottomRightScreenZ; +double Ready; +double RasterLX; +double RasterLY; +double RasterLZ; +double ScreenLX1; +double ScreenLY1; +double ScreenLZ1; + +DSPOp02() +{ + ViewerZ1=-cos(Op02AZS*6.2832/65536.0); + ViewerX1=sin(Op02AZS*6.2832/65536.0)*sin(Op02AAS*6.2832/65536.0); + ViewerY1=sin(Op02AZS*6.2832/65536.0)*cos(-Op02AAS*6.2832/65536.0); + + #ifdef debug02 + printf("\nViewerX1 : %f ViewerY1 : %f ViewerZ1 : %f\n",ViewerX1,ViewerY1, + ViewerZ1); + getch(); + #endif + ViewerX=Op02FX-ViewerX1*Op02LFE; + ViewerY=Op02FY-ViewerY1*Op02LFE; + ViewerZ=Op02FZ-ViewerZ1*Op02LFE; + + ScreenX=Op02FX+ViewerX1*(Op02LES-Op02LFE); + ScreenY=Op02FY+ViewerY1*(Op02LES-Op02LFE); + ScreenZ=Op02FZ+ViewerZ1*(Op02LES-Op02LFE); + + #ifdef debug02 + printf("ViewerX : %f ViewerY : %f ViewerZ : %f\n",ViewerX,ViewerY,ViewerZ); + printf("Op02FX : %d Op02FY : %d Op02FZ : %d\n",Op02FX,Op02FY,Op02FZ); + printf("ScreenX : %f ScreenY : %f ScreenZ : %f\n",ScreenX,ScreenY,ScreenZ); + getch(); + #endif + if (ViewerZ1==0)ViewerZ1++; + NumberOfSlope=ViewerZ/-ViewerZ1; + + Op02CX=ViewerX+ViewerX1*NumberOfSlope; + Op02CY=ViewerY+ViewerY1*NumberOfSlope; + + Op02CXF=ViewerX+ViewerX1*NumberOfSlope; + Op02CYF=ViewerY+ViewerY1*NumberOfSlope; + + Op02VOF=0x0000; + if(Op02LFE==0x2200)Op02VVA=0xFECD; + else Op02VVA=0xFFB2; + #ifdef DebugDSP1 + Log_Message("OP02 FX:%d FY:%d FZ:%d LFE:%d LES:%d",Op02FX,Op02FY,Op02FZ,Op02LFE,Op02LES); + Log_Message(" AAS:%d AZS:%d VOF:%d VVA:%d",Op02AAS,Op02AZS,Op02VOF,Op02VVA); + #endif + +} + +short Op0AVS; +short Op0AA; +short Op0AB; +short Op0AC; +short Op0AD; + +double RasterRX; +double RasterRY; +double RasterRZ; +double RasterLSlopeX; +double RasterLSlopeY; +double RasterLSlopeZ; +double RasterRSlopeX; +double RasterRSlopeY; +double RasterRSlopeZ; +double GroundLX; +double GroundLY; +double GroundRX; +double GroundRY; +double Distance; + +DSPOp0A() +{ + if(Op0AVS==0)Op0AVS++; + + ScreenLZ1=-cos((Op02AZS-16384.0)*6.2832/65536.0); // -16384.0 + ScreenLX1=sin((Op02AZS-16384.0)*6.2832/65536.0)*-sin(Op02AAS*6.2832/65536.0); + ScreenLY1=-sin((Op02AZS-16384.0)*6.2832/65536.0)*-cos(-Op02AAS*6.2832/65536.0); + + RasterRX=RasterLX=ScreenX+(Op0AVS)*ScreenLX1; + RasterRY=RasterLY=ScreenY+(Op0AVS)*ScreenLY1; + RasterRZ=RasterLZ=ScreenZ+(Op0AVS)*ScreenLZ1; + + ScreenLX1=sin((Op02AAS+16384.0)*6.2832/65536); + ScreenLY1=cos(-(Op02AAS+16384.0)*6.2832/65536); + + RasterLX=RasterLX-128*ScreenLX1; + RasterLY=RasterLY-128*ScreenLY1; + + RasterRX=RasterRX+128*ScreenLX1; + RasterRY=RasterRY+128*ScreenLY1; + + Distance=Op02LFE; + if(Distance==0)Distance=1; + + RasterLSlopeX=(RasterLX-ViewerX)/Distance; + RasterLSlopeY=(RasterLY-ViewerY)/Distance; + RasterLSlopeZ=(RasterLZ-ViewerZ)/Distance; + + RasterRSlopeX=(RasterRX-ViewerX)/Distance; + RasterRSlopeY=(RasterRY-ViewerY)/Distance; + RasterRSlopeZ=(RasterRZ-ViewerZ)/Distance; + + if(RasterLSlopeZ==0) RasterLSlopeZ++; // divide by 0 + + NumberOfSlope=ViewerZ/-RasterLSlopeZ; + + GroundLX=ViewerX+RasterLSlopeX*NumberOfSlope; + GroundLY=ViewerY+RasterLSlopeY*NumberOfSlope; + + if(RasterRSlopeZ==0) RasterRSlopeZ++; // divide by 0 + + NumberOfSlope=ViewerZ/-RasterRSlopeZ; + + GroundRX=ViewerX+RasterRSlopeX*NumberOfSlope; + GroundRY=ViewerY+RasterRSlopeY*NumberOfSlope; + + + if(Op02LES==0)Op02LES=1; + + Op0AA=(GroundRX-GroundLX); + Op0AB=(GroundRY-GroundLY); //0x300/Op02LES*2; + + if(Op0AVS!=0) + { + Op0AC=(((Op02CXF)-((GroundRX+GroundLX)/2)))/Op0AVS; + Op0AD=(((Op02CYF)-((GroundRY+GroundLY)/2)))/Op0AVS*256; + } + else + { + Op0AC=0; + Op0AD=0; + } + Op0AVS+=1; +} + +short Op06X; +short Op06Y; +short Op06Z; +short Op06H; +short Op06V; +unsigned short Op06S; + +double ObjPX; +double ObjPY; +double ObjPZ; +double ObjPX1; +double ObjPY1; +double ObjPZ1; +double ObjPX2; +double ObjPY2; +double ObjPZ2; +double DivideOp06; +int Temp; + +DSPOp06() +{ + + ObjPX=Op06X-Op02CXF; + ObjPY=Op06Y-Op02CYF; + ObjPZ=Op06Z; + + // rotate around Z + ObjPX1=(ObjPX*cos((-Op02AAS+32768)/65536.0*6.2832)+ObjPY*-sin((-Op02AAS+32768)/65536.0*6.2832)); + ObjPY1=(ObjPX*sin((-Op02AAS+32768)/65536.0*6.2832)+ObjPY*cos((-Op02AAS+32768)/65536.0*6.2832)); + ObjPZ1=ObjPZ; + + // rotate around X + ObjPX2=ObjPX1; + ObjPY2=(ObjPY1*cos((-Op02AZS)/65536.0*6.2832)+ObjPZ1*-sin((-Op02AZS)/65536.0*6.2832)); + ObjPZ2=(ObjPY1*sin((-Op02AZS)/65536.0*6.2832)+ObjPZ1*cos((-Op02AZS)/65536.0*6.2832)); + + #ifdef debug06 + printf("ObjPX2: %f ObjPY2: %f ObjPZ2: %f\n",ObjPX2,ObjPY2,ObjPZ2); + #endif + + ObjPZ2=ObjPZ2-Op02LFE; + + if (ObjPZ2<0) + { + Op06H=-ObjPX2*Op02LES/-(ObjPZ2); //-ObjPX2*256/-ObjPZ2; + Op06V=-ObjPY2*Op02LES/-(ObjPZ2); //-ObjPY2*256/-ObjPZ2; + Op06S=256*Op02LES/-ObjPZ2; + } + else + { + Op06H=0; + Op06V=14*16; + } + + #ifdef DebugDSP1 + Log_Message("OP06 X:%d Y:%d Z:%d",Op06X,Op06Y,Op06Z); + Log_Message("OP06 H:%d V:%d S:%d",Op06H,Op06V,Op06S); + #endif +} + + + +double matrix[4][4]; +double smat[4][4]; +double tmat[4][4]; +double xmat[4][4]; +double ymat[4][4]; +double zmat[4][4]; +double matrix0[4][4]; +double matrix1[4][4]; +double matrix2[4][4]; +double matrixI0[4][4]; +double matrixI1[4][4]; +double matrixI2[4][4]; + +void InitMatrix() +{ + matrix[0][0]=1; matrix[0][1]=0; matrix[0][2]=0; matrix[0][3]=0; + matrix[1][0]=0; matrix[1][1]=1; matrix[1][2]=0; matrix[1][3]=0; + matrix[2][0]=0; matrix[2][1]=0; matrix[2][2]=1; matrix[2][3]=0; + matrix[3][0]=0; matrix[3][1]=0; matrix[3][2]=0; matrix[3][3]=1; +} + + +void MultMatrix(double result[4][4],double mat1[4][4],double mat2[4][4]) +{ + result[0][0]=0; + result[0][0]+=(mat1[0][0]*mat2[0][0]+mat1[0][1]*mat2[1][0]+mat1[0][2]*mat2[2][0]+mat1[0][3]*mat2[3][0]); + result[0][1]=0; + result[0][1]+=(mat1[0][0]*mat2[0][1]+mat1[0][1]*mat2[1][1]+mat1[0][2]*mat2[2][1]+mat1[0][3]*mat2[3][1]); + result[0][2]=0; + result[0][2]+=(mat1[0][0]*mat2[0][2]+mat1[0][1]*mat2[1][2]+mat1[0][2]*mat2[2][2]+mat1[0][3]*mat2[3][2]); + result[0][3]=0; + result[0][3]+=(mat1[0][0]*mat2[0][3]+mat1[0][1]*mat2[1][3]+mat1[0][2]*mat2[2][3]+mat1[0][3]*mat2[3][3]); + + result[1][0]=0; + result[1][0]+=(mat1[1][0]*mat2[0][0]+mat1[1][1]*mat2[1][0]+mat1[1][2]*mat2[2][0]+mat1[1][3]*mat2[3][0]); + result[1][1]=0; + result[1][1]+=(mat1[1][0]*mat2[0][1]+mat1[1][1]*mat2[1][1]+mat1[1][2]*mat2[2][1]+mat1[1][3]*mat2[3][1]); + result[1][2]=0; + result[1][2]+=(mat1[1][0]*mat2[0][2]+mat1[1][1]*mat2[1][2]+mat1[1][2]*mat2[2][2]+mat1[1][3]*mat2[3][2]); + result[1][3]=0; + result[1][3]+=(mat1[1][0]*mat2[0][3]+mat1[1][1]*mat2[1][3]+mat1[1][2]*mat2[2][3]+mat1[1][3]*mat2[3][3]); + + result[2][0]=0; + result[2][0]+=(mat1[2][0]*mat2[0][0]+mat1[2][1]*mat2[1][0]+mat1[2][2]*mat2[2][0]+mat1[2][3]*mat2[3][0]); + result[2][1]=0; + result[2][1]+=(mat1[2][0]*mat2[0][1]+mat1[2][1]*mat2[1][1]+mat1[2][2]*mat2[2][1]+mat1[2][3]*mat2[3][1]); + result[2][2]=0; + result[2][2]+=(mat1[2][0]*mat2[0][2]+mat1[2][1]*mat2[1][2]+mat1[2][2]*mat2[2][2]+mat1[2][3]*mat2[3][2]); + result[2][3]=0; + result[2][3]+=(mat1[2][0]*mat2[0][3]+mat1[2][1]*mat2[1][3]+mat1[2][2]*mat2[2][3]+mat1[2][3]*mat2[3][3]); + + result[3][0]=0; + result[3][0]+=(mat1[3][0]*mat2[0][0]+mat1[3][1]*mat2[1][0]+mat1[3][2]*mat2[2][0]+mat1[3][3]*mat2[3][0]); + result[3][1]=0; + result[3][1]+=(mat1[3][0]*mat2[0][1]+mat1[3][1]*mat2[1][1]+mat1[3][2]*mat2[2][1]+mat1[3][3]*mat2[3][1]); + result[3][2]=0; + result[3][2]+=(mat1[3][0]*mat2[0][2]+mat1[3][1]*mat2[1][2]+mat1[3][2]*mat2[2][2]+mat1[3][3]*mat2[3][2]); + result[3][3]=0; + result[3][3]+=(mat1[3][0]*mat2[0][3]+mat1[3][1]*mat2[1][3]+mat1[3][2]*mat2[2][3]+mat1[3][3]*mat2[3][3]); +} + +void CopyMatrix(double dest[4][4],double source[4][4]) +{ + dest[0][0]=source[0][0]; + dest[0][1]=source[0][1]; + dest[0][2]=source[0][2]; + dest[0][3]=source[0][3]; + dest[1][0]=source[1][0]; + dest[1][1]=source[1][1]; + dest[1][2]=source[1][2]; + dest[1][3]=source[1][3]; + dest[2][0]=source[2][0]; + dest[2][1]=source[2][1]; + dest[2][2]=source[2][2]; + dest[2][3]=source[2][3]; + dest[3][0]=source[3][0]; + dest[3][1]=source[3][1]; + dest[3][2]=source[3][2]; + dest[3][3]=source[3][3]; +} + +void scale(double sf) +{ + double mat[4][4]; + smat[0][0]=sf; smat[0][1]=0; smat[0][2]=0; smat[0][3]=0; + smat[1][0]=0; smat[1][1]=sf; smat[1][2]=0; smat[1][3]=0; + smat[2][0]=0; smat[2][1]=0; smat[2][2]=sf; smat[2][3]=0; + smat[3][0]=0; smat[3][1]=0; smat[3][2]=0; smat[3][3]=1; + MultMatrix(mat,smat,matrix); + CopyMatrix(matrix,mat); +} + +void translate(double xt,double yt,double zt) +{ + double mat[4][4]; + tmat[0][0]=1; tmat[0][1]=0; tmat[0][2]=0; tmat[0][3]=0; + tmat[1][0]=0; tmat[1][1]=1; tmat[1][2]=0; tmat[1][3]=0; + tmat[2][0]=0; tmat[2][1]=0; tmat[2][2]=1; tmat[2][3]=0; + tmat[3][0]=xt; tmat[3][1]=yt; tmat[3][2]=zt; tmat[3][3]=1; + MultMatrix(mat,matrix,tmat); + CopyMatrix(matrix,mat); +} + +void rotate(double ax,double ay,double az) +{ + double mat1[4][4]; + double mat2[4][4]; + xmat[0][0]=1; xmat[0][1]=0; xmat[0][2]=0; xmat[0][3]=0; + xmat[1][0]=0; xmat[1][1]=cos(ax); xmat[1][2]=sin(ax); xmat[1][3]=0; + xmat[2][0]=0; xmat[2][1]=-(sin(ax)); xmat[2][2]=cos(ax); xmat[2][3]=0; + xmat[3][0]=0; xmat[3][1]=0; xmat[3][2]=0; xmat[3][3]=1; + MultMatrix(mat1,xmat,matrix); + ymat[0][0]=cos(ay); ymat[0][1]=0; ymat[0][2]=-(sin(ay)); ymat[0][3]=0; + ymat[1][0]=0; ymat[1][1]=1; ymat[1][2]=0; ymat[1][3]=0; + ymat[2][0]=sin(ay); ymat[2][1]=0; ymat[2][2]=cos(ay); ymat[2][3]=0; + ymat[3][0]=0; ymat[3][1]=0; ymat[3][2]=0; ymat[3][3]=1; + MultMatrix(mat2,ymat,mat1); + zmat[0][0]=cos(az); zmat[0][1]=sin(az); zmat[0][2]=0; zmat[0][3]=0; + zmat[1][0]=-(sin(az)); zmat[1][1]=cos(az); zmat[1][2]=0; zmat[1][3]=0; + zmat[2][0]=0; zmat[2][1]=0; zmat[2][2]=1; zmat[2][3]=0; + zmat[3][0]=0; zmat[3][1]=0; zmat[3][2]=0; zmat[3][3]=1; + MultMatrix(matrix,zmat,mat2); +} + +short Op01m; +short Op01Zr; +short Op01Xr; +short Op01Yr; + +DSPOp01() +{ + InitMatrix(); + rotate(Op01Xr/65536.0*6.2832,Op01Yr/65536.0*6.2832,Op01Zr/65536.0*6.2832); + CopyMatrix(matrix0,matrix); + InitMatrix(); + rotate(0,0,Op01Zr/65536.0*6.2832); + rotate(Op01Xr/65536.0*6.2832,0,0); + rotate(0,Op01Yr/65536.0*6.2832,0); + CopyMatrix(matrixI0,matrix); + #ifdef DebugDSP1 + Log_Message("OP01"); + #endif +} + +DSPOp11() +{ + InitMatrix(); + rotate(Op01Xr/65536.0*6.2832,Op01Yr/65536.0*6.2832,Op01Zr/65536.0*6.2832); + CopyMatrix(matrix1,matrix); + InitMatrix(); + rotate(0,0,Op01Zr/65536.0*6.2832); + rotate(Op01Xr/65536.0*6.2832,0,0); + rotate(0,Op01Yr/65536.0*6.2832,0); + CopyMatrix(matrixI1,matrix); + #ifdef DebugDSP1 + Log_Message("OP11"); + #endif + +} + +DSPOp21() +{ + InitMatrix(); + rotate(Op01Xr/65536.0*6.2832,Op01Yr/65536.0*6.2832,Op01Zr/65536.0*6.2832); + CopyMatrix(matrix2,matrix); + InitMatrix(); + rotate(0,0,Op01Zr/65536.0*6.2832); + rotate(Op01Xr/65536.0*6.2832,0,0); + rotate(0,Op01Yr/65536.0*6.2832,0); + CopyMatrix(matrixI2,matrix); + #ifdef DebugDSP1 + Log_Message("OP21"); + #endif +} + + + +short Op0DX; +short Op0DY; +short Op0DZ; +short Op0DF; +short Op0DL; +short Op0DU; + +DSPOp0D() +{ + Op0DF=(double)(Op0DX*matrixI0[0][0]+Op0DY*matrixI0[1][0]+Op0DZ*matrixI0[2][0]+matrixI0[3][0]); + Op0DL=(double)(Op0DX*matrixI0[0][1]+Op0DY*matrixI0[1][1]+Op0DZ*matrixI0[2][1]+matrixI0[3][1]); + Op0DU=(double)(Op0DX*matrixI0[0][2]+Op0DY*matrixI0[1][2]+Op0DZ*matrixI0[2][2]+matrixI0[3][2]); + #ifdef DebugDSP1 + Log_Message("OP0D"); + #endif +} + +DSPOp1D() +{ + Op0DF=(double)(Op0DX*matrixI1[0][0]+Op0DY*matrixI1[1][0]+Op0DZ*matrixI1[2][0]+matrixI1[3][0]); + Op0DL=(double)(Op0DX*matrixI1[0][1]+Op0DY*matrixI1[1][1]+Op0DZ*matrixI1[2][1]+matrixI1[3][1]); + Op0DU=(double)(Op0DX*matrixI1[0][2]+Op0DY*matrixI1[1][2]+Op0DZ*matrixI1[2][2]+matrixI1[3][2]); + #ifdef DebugDSP1 + Log_Message("OP1D"); + #endif +} + +DSPOp2D() +{ + Op0DF=(double)(Op0DX*matrixI2[0][0]+Op0DY*matrixI2[1][0]+Op0DZ*matrixI2[2][0]+matrixI2[3][0]); + Op0DL=(double)(Op0DX*matrixI2[0][1]+Op0DY*matrixI2[1][1]+Op0DZ*matrixI2[2][1]+matrixI2[3][1]); + Op0DU=(double)(Op0DX*matrixI2[0][2]+Op0DY*matrixI2[1][2]+Op0DZ*matrixI2[2][2]+matrixI2[3][2]); + #ifdef DebugDSP1 + Log_Message("OP2D"); + #endif +} + +short Op03F; +short Op03L; +short Op03U; +short Op03X; +short Op03Y; +short Op03Z; + +DSPOp03() +{ + Op03X=(double)(Op03F*matrix0[0][0]+Op03L*matrix0[1][0]+Op03U*matrix0[2][0]+matrix0[3][0]); + Op03Y=(double)(Op03F*matrix0[0][1]+Op03L*matrix0[1][1]+Op03U*matrix0[2][1]+matrix0[3][1]); + Op03Z=(double)(Op03F*matrix0[0][2]+Op03L*matrix0[1][2]+Op03U*matrix0[2][2]+matrix0[3][2]); + #ifdef DebugDSP1 + Log_Message("OP03"); + #endif +} + +DSPOp13() +{ + Op03X=(double)(Op03F*matrix1[0][0]+Op03L*matrix1[1][0]+Op03U*matrix1[2][0]+matrix1[3][0]); + Op03Y=(double)(Op03F*matrix1[0][1]+Op03L*matrix1[1][1]+Op03U*matrix1[2][1]+matrix1[3][1]); + Op03Z=(double)(Op03F*matrix1[0][2]+Op03L*matrix1[1][2]+Op03U*matrix1[2][2]+matrix1[3][2]); + #ifdef DebugDSP1 + Log_Message("OP13"); + #endif +} + +DSPOp23() +{ + Op03X=(double)(Op03F*matrix2[0][0]+Op03L*matrix2[1][0]+Op03U*matrix2[2][0]+matrix2[3][0]); + Op03Y=(double)(Op03F*matrix2[0][1]+Op03L*matrix2[1][1]+Op03U*matrix2[2][1]+matrix2[3][1]); + Op03Z=(double)(Op03F*matrix2[0][2]+Op03L*matrix2[1][2]+Op03U*matrix2[2][2]+matrix2[3][2]); + #ifdef DebugDSP1 + Log_Message("OP23"); + #endif +} + +short Op14Zr; +short Op14Xr; +short Op14Yr; +short Op14U; +short Op14F; +short Op14L; +short Op14Zrr; +short Op14Xrr; +short Op14Yrr; + +double Op14Temp; +DSPOp14() +{ + Op14Temp=(Op14Zr*6.2832/65536.0)+(1/cos(Op14Xr*6.2832/65536.0))*((Op14U*6.2832/65536.0)*cos(Op14Yr*6.2832/65536.0)-(Op14F*6.2832/65536.0)*sin(Op14Yr*6.2832/65536.0)); + Op14Zrr=Op14Temp*65536.0/6.2832; + Op14Temp=(Op14Xr*6.2832/65536.0)+((Op14U*6.2832/65536.0)*sin(Op14Yr*6.2832/65536.0)+(Op14F*6.2832/65536.0)*cos(Op14Yr*6.2832/65536.0)); + Op14Xrr=Op14Temp*65536.0/6.2832; + Op14Temp=(Op14Yr*6.2832/65536.0)-tan(Op14Xr*6.2832/65536.0)*((Op14U*6.2832/65536.0)*cos(Op14Yr*6.2832/65536.0)+(Op14F*6.2832/65536.0)*sin(Op14Yr*6.2832/65536.0))+(Op14L*6.2832/65536.0); + Op14Yrr=Op14Temp*65536.0/6.2832; + #ifdef DebugDSP1 + Log_Message("OP14 X:%d Y%d Z:%D U:%d F:%d L:%d",Op14Xr,Op14Yr,Op14Zr,Op14U,Op14F,Op14L); + Log_Message("OP14 X:%d Y%d Z:%D",Op14Xrr,Op14Yrr,Op14Zrr); + #endif +} + +short Op0EH; +short Op0EV; +short Op0EX; +short Op0EY; +DSPOp0E() +{ + + // screen Directions UP + ScreenLZ1=-cos((Op02AZS-16384.0)*6.2832/65536.0); // -16384.0 + ScreenLX1=sin((Op02AZS-16384.0)*6.2832/65536.0)*-sin(Op02AAS*6.2832/65536.0); + ScreenLY1=-sin((Op02AZS-16384.0)*6.2832/65536.0)*-cos(-Op02AAS*6.2832/65536.0); + + RasterLX=ScreenX+(Op0EV)*ScreenLX1; + RasterLY=ScreenY+(Op0EV)*ScreenLY1; + RasterLZ=ScreenZ+(Op0EV)*ScreenLZ1; + + // screen direction right + ScreenLX1=sin((Op02AAS+16384.0)*6.2832/65536); + ScreenLY1=cos(-(Op02AAS+16384.0)*6.2832/65536); + + RasterLX=RasterLX+Op0EH*ScreenLX1; + RasterLY=RasterLY+Op0EH*ScreenLY1; + + Distance=Op02LFE; + + if(Distance==0)Distance=1; + + RasterLSlopeX=(RasterLX-ViewerX)/Distance; + RasterLSlopeY=(RasterLY-ViewerY)/Distance; + RasterLSlopeZ=(RasterLZ-ViewerZ)/Distance; + + if(RasterLSlopeZ==0)RasterLSlopeZ++; + + NumberOfSlope=ViewerZ/-RasterLSlopeZ; + + GroundLX=ViewerX+RasterLSlopeX*NumberOfSlope; + GroundLY=ViewerY+RasterLSlopeY*NumberOfSlope; + + Op0EX=GroundLX; + Op0EY=GroundLY; + + #ifdef DebugDSP1 + Log_Message("OP0E COORDINATE H:%d V:%d",Op0EH,Op0EV); + Log_Message(" X:%d Y:%d",Op0EX,Op0EY); + #endif +} + + \ No newline at end of file diff --git a/zsnes/src/chips/dsp1proc.asm b/zsnes/src/chips/dsp1proc.asm new file mode 100644 index 00000000..a64f68f1 --- /dev/null +++ b/zsnes/src/chips/dsp1proc.asm @@ -0,0 +1,639 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM regaccessbankr8,regaccessbankr16,regaccessbankw8,regaccessbankw16 +EXTSYM DSPOp0A,Op0AA,Op0AB,Op0AC,Op0AD,Op0AVS +EXTSYM debstop +EXTSYM DSPOp00,Op00Multiplicand,Op00Multiplier +EXTSYM Op00Result +;EXTSYM DSPOp10,Op10a,Op10b,Op10A,Op10B +EXTSYM DSPOp04,Op04Angle,Op04Cos,Op04Radius,Op04Sin +EXTSYM DSPOp28,Op28R,Op28X,Op28Y,Op28Z +EXTSYM DSPOp0C,Op0CA,Op0CX1,Op0CX2,Op0CY1,Op0CY2 +EXTSYM DSPOp02,Op02AAS,Op02AZS,Op02CX,Op02CY,Op02FX,Op02FY +EXTSYM Op02FZ,Op02LES,Op02LFE,Op02VOF,Op02VVA +EXTSYM DSPOp06,Op06X,Op06Y,Op06Z,Op06H,Op06V,Op06S +EXTSYM DSPOp0E,Op0EH,Op0EV,Op0EX,Op0EY +EXTSYM Op01m, Op01Zr, Op01Xr, Op01Yr, DSPOp01 +EXTSYM Op0DX, Op0DY, Op0DZ, Op0DF, Op0DL, Op0DU, DSPOp0D +EXTSYM Op03X, Op03Y, Op03Z, Op03F, Op03L, Op03U, DSPOp03 +EXTSYM Op14Zr, Op14Xr, Op14Yr, Op14U, Op14F, Op14L +EXTSYM Op14Zrr,Op14Xrr,Op14Yrr, DSPOp14 + + + + + + + +NEWSYM dsp1ptr, dd 0 +NEWSYM dsp1array, times 4096 db 0 + +;******************************************************* +; DSP1 Read Functions +;******************************************************* + +NEWSYM DSP1Read8b3F + test ecx,8000h + jnz .dsp1area + jmp regaccessbankr8 +.dsp1area + cmp ecx,0C000h + jae .doC000 + mov al,080h + ret +.doC000 + mov al,80h + ret + + +NEWSYM DSP1Read16b3F + test ecx,8000h + jnz .dsp1area + jmp regaccessbankr16 +.dsp1area + cmp ecx,0C000h + jae .doC000 + cmp byte[DSP1RLeft],0 + jne .movestuff + mov ax,08000h + ret +.doC000 + mov ax,08000h + ret +.movestuff + push ebx + xor ebx,ebx + mov bl,[DSP1CPtrR] + mov ax,[DSP1RET+ebx*2] + pop ebx + inc byte[DSP1CPtrR] + dec byte[DSP1RLeft] + jz .nomore +.goback + ret +.nomore + cmp byte[DSP1COp],0Ah + jne .goback + push eax + pushad + call DSPOp0A + popad + mov ax,[Op0AA] + mov [DSP1RET],ax + mov ax,[Op0AB] + mov [DSP1RET+2],ax + mov ax,[Op0AC] + mov [DSP1RET+4],ax + mov ax,[Op0AD] + mov [DSP1RET+6],ax + mov byte[DSP1RLeft],4 + mov byte[DSP1CPtrR],0 + pop eax + ret + +NEWSYM DSP1Read8b +; mov byte[debstop],1 + cmp ecx,7000h + jae .do7000 + xor al,al + ret +.do7000 + mov al,80h + test ecx,1 + jz .no1 + mov al,80h +.no1 + ret + +NEWSYM DSP1Read16b +; mov byte[debstop],1 + cmp ecx,7000h + jae .do7000 + cmp byte[DSP1RLeft],0 + jne .movestuff + mov ax,0FFFFh + ret +.do7000 + mov ax,8000h + test ecx,01h + jz .norev + mov ax,0080h +.norev + ret +.movestuff + push ebx + xor ebx,ebx + mov bl,[DSP1CPtrR] + mov ax,[DSP1RET+ebx*2] + pop ebx + inc byte[DSP1CPtrR] + dec byte[DSP1RLeft] + jz .nomore +.goback + ret +.nomore + cmp byte[DSP1COp],0Ah + jne .goback + push eax + pushad + call DSPOp0A + popad + mov ax,[Op0AA] + mov [DSP1RET],ax + mov ax,[Op0AB] + mov [DSP1RET+2],ax + mov ax,[Op0AC] + mov [DSP1RET+4],ax + mov ax,[Op0AD] + mov [DSP1RET+6],ax + mov byte[DSP1RLeft],4 + mov byte[DSP1CPtrR],0 + pop eax + ret + +%macro DSP1WriteInit 2 + cmp al,%1 + jne %%no + mov byte[DSP1WLeft],%2 +%%no +%endmacro + +NEWSYM DSP1Write8b3F + test ecx,8000h + jnz .dsp1area + jmp regaccessbankw8 +.dsp1area + call DSP1Write8b + ret + +NEWSYM DSP1Write16b3F + test ecx,8000h + jnz .dsp1area + jmp regaccessbankw16 +.dsp1area + call DSP1Write16b + ret + +NEWSYM DSP1Write8b + push ebx + xor ebx,ebx + mov bl,al + mov byte[DSPFuncUsed+ebx],1 + pop ebx + mov byte[DSP1COp],al + mov byte[DSP1CPtrW],0 + DSP1WriteInit 00h, 2 ; 16-bit multiply + DSP1WriteInit 10h, 2 ; Inverse + DSP1WriteInit 04h, 2 ; Trigonometric + DSP1WriteInit 08h, 3 ; Vector Size + DSP1WriteInit 18h, 4 ; Vector Size Comparison + DSP1WriteInit 28h, 3 ; Vector Absolute Value + DSP1WriteInit 0Ch, 3 ; Coordinate Rotation + DSP1WriteInit 1Ch, 4 ; 3D Coordinate Rotation + DSP1WriteInit 02h, 7 ; Vector Size + DSP1WriteInit 0Ah, 1 ; Raster Data Calculation via DMA + DSP1WriteInit 1Ah, 1 ; Raster Data Calculation w/o DMA + DSP1WriteInit 06h, 3 ; Object Projection Calculation + DSP1WriteInit 0Eh, 2 ; Coordinate Calculation of a point onscreen + DSP1WriteInit 01h, 4 ; Set Attitude Matrix A + DSP1WriteInit 11h, 4 ; Set Attitude Matrix B + DSP1WriteInit 21h, 4 ; Set Attitude Matrix C + DSP1WriteInit 0Dh, 3 ; Convert from global to object coords Matrix A + DSP1WriteInit 1Dh, 3 ; Convert from global to object coords Matrix B + DSP1WriteInit 2Dh, 3 ; Convert from global to object coords Matrix C + DSP1WriteInit 03h, 3 ; Convert from object to global coords Matrix A + DSP1WriteInit 13h, 3 ; Convert from object to global coords Matrix B + DSP1WriteInit 23h, 3 ; Convert from object to global coords Matrix C + DSP1WriteInit 0Bh, 3 ; Calculation of inner product Matrix A + DSP1WriteInit 1Bh, 3 ; Calculation of inner product Matrix B + DSP1WriteInit 2Bh, 3 ; Calculation of inner product Matrix C + DSP1WriteInit 14h, 6 ; 3D angle rotation + ret + +%macro DSP1WriteProc 2 + cmp byte[DSP1COp],%1 + jne %%no + pushad + call %2 + popad +%%no +%endmacro + +NEWSYM DSP1Write16b +; mov byte[debstop],1 + cmp byte[DSP1WLeft],0 + jne .yesleft + ret +.yesleft + push ebx + xor ebx,ebx + mov bl,[DSP1CPtrW] + mov [DSP1VARS+ebx*2],ax + pop ebx + inc byte[DSP1CPtrW] + dec byte[DSP1WLeft] + jz .ProcessDSP1 + ret +.ProcessDSP1 + mov byte[DSP1CPtrR],0 + mov byte[DSP1RLeft],0 + DSP1WriteProc 00h, DSP1_00 ; 16-bit multiply + DSP1WriteProc 10h, DSP1_10 ; Inverse + DSP1WriteProc 04h, DSP1_04 ; Trigonometric + DSP1WriteProc 08h, DSP1_08 ; Vector Size + DSP1WriteProc 18h, DSP1_18 ; Vector Size Comparison + DSP1WriteProc 28h, DSP1_28 ; Vector Absolute Value + DSP1WriteProc 0Ch, DSP1_0C ; Coordinate Rotation + DSP1WriteProc 1Ch, DSP1_1C ; 3D Coordinate Rotation + DSP1WriteProc 02h, DSP1_02 ; Vector Size + DSP1WriteProc 0Ah, DSP1_0A ; Raster Data Calculation via DMA + DSP1WriteProc 1Ah, DSP1_0A ; Raster Data Calculation w/o DMA + DSP1WriteProc 06h, DSP1_06 ; Object Projection Calculation + DSP1WriteProc 0Eh, DSP1_0E ; Coordinate Calculation of a point onscreen + DSP1WriteProc 01h, DSP1_01 ; Set Attitude Matrix A + DSP1WriteProc 11h, DSP1_11 ; Set Attitude Matrix B + DSP1WriteProc 21h, DSP1_21 ; Set Attitude Matrix C + DSP1WriteProc 0Dh, DSP1_0D ; Convert from global to object coords Matrix A + DSP1WriteProc 1Dh, DSP1_1D ; Convert from global to object coords Matrix B + DSP1WriteProc 2Dh, DSP1_2D ; Convert from global to object coords Matrix C + DSP1WriteProc 03h, DSP1_03 ; Convert from object to global coords Matrix A + DSP1WriteProc 13h, DSP1_13 ; Convert from object to global coords Matrix B + DSP1WriteProc 23h, DSP1_23 ; Convert from object to global coords Matrix C + DSP1WriteProc 0Bh, DSP1_0B ; Calculation of inner product Matrix A + DSP1WriteProc 1Bh, DSP1_1B ; Calculation of inner product Matrix B + DSP1WriteProc 2Bh, DSP1_2B ; Calculation of inner product Matrix C + DSP1WriteProc 14h, DSP1_14 ; 3D angle rotation + ret + +NEWSYM DSP1COp, db 0 +NEWSYM DSP1RLeft, db 0 +NEWSYM DSP1WLeft, db 0 +NEWSYM DSP1CPtrW, db 0 +NEWSYM DSP1CPtrR, db 0 +NEWSYM DSP1VARS, times 16 dw 0 +NEWSYM DSP1RET, times 16 dw 0 +NEWSYM DSPDet, db 0 + +NEWSYM DSPFuncUsed, times 256 db 0 + +;******************************************************* +; DSP1 Conversion Functions +;******************************************************* +DSP1_00: ; 16-bit multiply + or byte[DSPDet],01h + push eax + mov ax,[DSP1VARS] + mov [Op00Multiplicand],ax + mov ax,[DSP1VARS+2] + mov [Op00Multiplier],ax + pushad + call DSPOp00 + popad + mov ax,[Op00Result] + mov [DSP1RET],ax + mov byte[DSP1RLeft],1 + pop eax + ret +DSP1_10: ; Inverse + push eax + mov ax,[DSP1VARS] +; mov [Op10a],ax + mov ax,[DSP1VARS+2] +; mov [Op10b],ax + pushad +; call DSPOp10 + popad +; mov ax,[Op10A] + mov [DSP1RET],ax +; mov ax,[Op10B] + mov [DSP1RET+2],ax + mov byte[DSP1RLeft],2 + pop eax + ret + +DSP1_04: ; Trigonometric + or byte[DSPDet],02h + push eax + mov ax,[DSP1VARS] + mov [Op04Angle],ax + mov ax,[DSP1VARS+2] + mov [Op04Radius],ax + pushad + call DSPOp04 + popad + mov ax,[Op04Sin] + mov [DSP1RET],ax + mov ax,[Op04Cos] + mov [DSP1RET+2],ax + mov byte[DSP1RLeft],2 + pop eax + ret +DSP1_08: ; Vector Size + ret +DSP1_18: ; Vector Size Comparison + ret + +DSP1_28: ; Vector Absolute Value + or byte[DSPDet],04h + push eax + mov ax,[DSP1VARS] + mov [Op28X],ax + mov ax,[DSP1VARS+2] + mov [Op28Y],ax + mov ax,[DSP1VARS+4] + mov [Op28Z],ax + pushad + call DSPOp28 + popad + mov ax,[Op28R] + mov [DSP1RET],ax + mov byte[DSP1RLeft],1 + pop eax + ret + + +DSP1_0C: ; Coordinate Rotation + or byte[DSPDet],08h + push eax + mov ax,[DSP1VARS] + mov [Op0CA],ax + mov ax,[DSP1VARS+2] + mov [Op0CX1],ax + mov ax,[DSP1VARS+4] + mov [Op0CY1],ax + pushad + call DSPOp0C + popad + mov ax,[Op0CX2] + mov [DSP1RET],ax + mov ax,[Op0CY2] + mov [DSP1RET+2],ax + mov byte[DSP1RLeft],2 + pop eax + ret +DSP1_1C: ; 3D Coordinate Rotation + ret + + +DSP1_02: ; Vector Size + or byte[DSPDet],10h + push eax +;Op02FX dw 0 +;Op02FY dw 0 +;Op02FZ dw 0 +;Op02LFE dw 0 +;Op02LES dw 0 +;Op02AAS dw 0 +;Op02AZS dw 0 + mov ax,[DSP1VARS] + mov [Op02FX],ax + mov ax,[DSP1VARS+2] + mov [Op02FY],ax + mov ax,[DSP1VARS+4] + mov [Op02FZ],ax + mov ax,[DSP1VARS+6] + mov [Op02LFE],ax + mov ax,[DSP1VARS+8] + mov [Op02LES],ax + mov ax,[DSP1VARS+10] + mov [Op02AAS],ax + mov ax,[DSP1VARS+12] + mov [Op02AZS],ax + pushad + call DSPOp02 + popad +;Op02VOF dw 0 +;Op02VVA dw 0 +;Op02CX dw 0 +;Op02CY dw 0 + mov ax,[Op02VOF] + mov [DSP1RET],ax + mov ax,[Op02VVA] + mov [DSP1RET+2],ax + mov ax,[Op02CX] + mov [DSP1RET+4],ax + mov ax,[Op02CY] + mov [DSP1RET+6],ax + mov byte[DSP1RLeft],4 + pop eax + ret + mov eax,dsp1array + add eax,[dsp1ptr] + push ebx + mov byte[eax],02h + mov bx,[Op02FX] + mov [eax+1],bx + mov bx,[Op02FY] + mov [eax+3],bx + mov bx,[Op02FZ] + mov [eax+5],bx + mov bx,[Op02LFE] + mov [eax+7],bx + mov bx,[Op02LES] + mov [eax+9],bx + mov bx,[Op02AAS] + mov [eax+11],bx + mov bx,[Op02AZS] + mov [eax+13],bx + mov bx,[Op02VOF] + mov [eax+15],bx + mov bx,[Op02VVA] + mov [eax+17],bx + mov bx,[Op02CX] + mov [eax+19],bx + mov bx,[Op02CY] + mov [eax+21],bx + pop ebx + add dword[dsp1ptr],23 +DSP1_0A: ; Raster Data Calculation via DMA + mov byte[DSP1COp],0Ah + or byte[DSPDet],20h + push eax + mov ax,[DSP1VARS] + mov [Op0AVS],ax + pushad + call DSPOp0A + popad + mov ax,[Op0AA] + mov [DSP1RET],ax + mov ax,[Op0AB] + mov [DSP1RET+2],ax + mov ax,[Op0AC] + mov [DSP1RET+4],ax + mov ax,[Op0AD] + mov [DSP1RET+6],ax + mov byte[DSP1RLeft],4 + pop eax + ret +DSP1_06: ; Object Projection Calculation + or byte[DSPDet],40h + push eax + mov ax,[DSP1VARS] + mov [Op06X],ax + mov ax,[DSP1VARS+2] + mov [Op06Y],ax + mov ax,[DSP1VARS+4] + mov [Op06Z],ax + pushad + call DSPOp06 + popad + mov ax,[Op06H] + mov word[DSP1RET],ax + mov ax,[Op06V] + mov word[DSP1RET+2],ax + mov ax,[Op06S] + mov word[DSP1RET+4],ax + mov byte[DSP1RLeft],3 + pop eax + ret + mov eax,dsp1array + add eax,[dsp1ptr] + push ebx + mov byte[eax],06h + mov bx,[Op06X] + mov [eax+1],bx + mov bx,[Op06Y] + mov [eax+3],bx + mov bx,[Op06Z] + mov [eax+5],bx + mov bx,[Op06H] + mov [eax+7],bx + mov bx,[Op06V] + mov [eax+9],bx + mov bx,[Op06S] + mov [eax+11],bx + pop ebx + add dword[dsp1ptr],13 +DSP1_0E: ; Coordinate Calculation of a point onscreen + push eax + mov ax,[DSP1VARS] + mov [Op0EH],ax + mov ax,[DSP1VARS+2] + mov [Op0EV],ax + pushad + call DSPOp0E + popad + mov ax,[Op0EX] + mov word[DSP1RET],ax + mov ax,[Op0EY] + mov word[DSP1RET+2],ax + mov byte[DSP1RLeft],2 + pop eax + ret +DSP1_01: ; Set Attitude Matrix A + push eax + mov ax,[DSP1VARS] + mov [Op01m],ax + mov ax,[DSP1VARS+2] + mov [Op01Zr],ax + mov ax,[DSP1VARS+4] + mov [Op01Xr],ax + mov ax,[DSP1VARS+6] + mov [Op01Yr],ax + pushad + call DSPOp01 + popad + pop eax + ret +DSP1_11: ; Set Attitude Matrix B + ret +DSP1_21: ; Set Attitude Matrix C + ret +DSP1_0D: ; Convert from global to object coords Matrix A + push eax + mov ax,[DSP1VARS] + mov [Op0DX],ax + mov ax,[DSP1VARS+2] + mov [Op0DY],ax + mov ax,[DSP1VARS+4] + mov [Op0DZ],ax + pushad + call DSPOp0D + popad + mov ax,[Op0DF] + mov word[DSP1RET],ax + mov ax,[Op0DL] + mov word[DSP1RET+2],ax + mov ax,[Op0DU] + mov word[DSP1RET+4],ax + mov byte[DSP1RLeft],3 + pop eax + ret +DSP1_1D: ; Convert from global to object coords Matrix B + ret +DSP1_2D: ; Convert from global to object coords Matrix C + ret +DSP1_03: ; Convert from object to global coords Matrix A + push eax + mov ax,[DSP1VARS] + mov [Op03F],ax + mov ax,[DSP1VARS+2] + mov [Op03L],ax + mov ax,[DSP1VARS+4] + mov [Op03U],ax + pushad + call DSPOp03 + popad + mov ax,[Op03X] + mov word[DSP1RET],ax + mov ax,[Op03Y] + mov word[DSP1RET+2],ax + mov ax,[Op03Z] + mov word[DSP1RET+4],ax + mov byte[DSP1RLeft],3 + pop eax + ret +DSP1_13: ; Convert from object to global coords Matrix B + ret +DSP1_23: ; Convert from object to global coords Matrix C + ret +DSP1_0B: ; Calculation of inner product Matrix A + ret +DSP1_1B: ; Calculation of inner product Matrix B + ret +DSP1_2B: ; Calculation of inner product Matrix C + ret +DSP1_14: ; 3D angle rotation + push eax + mov ax,[DSP1VARS] + mov [Op14Zr],ax + mov ax,[DSP1VARS+2] + mov [Op14Xr],ax + mov ax,[DSP1VARS+4] + mov [Op14Yr],ax + mov ax,[DSP1VARS+6] + mov [Op14U],ax + mov ax,[DSP1VARS+8] + mov [Op14F],ax + mov ax,[DSP1VARS+10] + mov [Op14L],ax + pushad + call DSPOp14 + popad + mov ax,[Op14Zrr] + mov word[DSP1RET],ax + mov ax,[Op14Xrr] + mov word[DSP1RET+2],ax + mov ax,[Op14Yrr] + mov word[DSP1RET+4],ax + mov byte[DSP1RLeft],3 + pop eax + ret + \ No newline at end of file diff --git a/zsnes/src/chips/fxemu2.asm b/zsnes/src/chips/fxemu2.asm new file mode 100644 index 00000000..8917a4ad --- /dev/null +++ b/zsnes/src/chips/fxemu2.asm @@ -0,0 +1,2683 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM FxTable,FxTableb,FxTablec,FxTabled,SfxMemTable,flagnz,fxbit01,fxbit23 +EXTSYM fxxand,sfx128lineloc,sfx160lineloc,sfx192lineloc,sfxobjlineloc +EXTSYM sfxramdata,fxbit45,fxbit67,SFXProc,ChangeOps +EXTSYM PLOTJmpa,PLOTJmpb + +%include "chips/fxemu2.mac" + + + + + + +; * Optimise PLOT, COLOR! +SECTION .text +NEWSYM FlushCache + ; Copy 512 bytes from pb:eax to SfxCACHERAM + ret + +SECTION .data +NEWSYM tempsfx, db 0,0,0 + +ALIGN32 + +; FxChip emulation by _Demo_ +; Optimised by zsKnight +; based on fxemu by lestat + +NEWSYM SfxR0, dd 0 ; default source/destination register +NEWSYM SfxR1, dd 0 ; pixel plot X position register +NEWSYM SfxR2, dd 0 ; pixel plot Y position register +NEWSYM SfxR3, dd 0 ; +NEWSYM SfxR4, dd 0 ; lower 16 bit result of lmult +NEWSYM SfxR5, dd 0 ; +NEWSYM SfxR6, dd 0 ; multiplier for fmult and lmult +NEWSYM SfxR7, dd 0 ; fixed point texel X position for merge +NEWSYM SfxR8, dd 0 ; fixed point texel Y position for merge +NEWSYM SfxR9, dd 0 ; +NEWSYM SfxR10, dd 0 ; +NEWSYM SfxR11, dd 0 ; return address set by link +NEWSYM SfxR12, dd 0 ; loop counter +NEWSYM SfxR13, dd 0 ; loop point address +NEWSYM SfxR14, dd 0 ; rom address for getb, getbh, getbl, getbs +NEWSYM SfxR15, dd 0 ; program counter + +NEWSYM SfxSFR, dd 0 ; status flag register (16bit) +;SFR status flag register bits: +; 0 - +; 1 Z Zero flag +; 2 CY Carry flag +; 3 S Sign flag +; 4 OV Overflow flag +; 5 G Go flag (set to 1 when the GSU is running) +; 6 R Set to 1 when reading ROM using R14 address +; 7 - +; 8 ALT1 Mode set-up flag for the next instruction +; 9 ALT2 Mode set-up flag for the next instruction +;10 IL Immediate lower 8-bit flag +;11 IH Immediate higher 8-bit flag +;12 B Set to 1 when the WITH instruction is executed +;13 - +;14 - +;15 IRQ Set to 1 when GSU caused an interrupt +; Set to 0 when read by 658c16 + +NEWSYM SfxBRAMR, dd 0 ; backup ram read only on/off (8bit) +NEWSYM SfxPBR, dd 0 ; program bank register (8bit) +NEWSYM SfxROMBR, dd 0 ; rom bank register (8bit) +NEWSYM SfxCFGR, dd 0 ; control flags register (8bit) +NEWSYM SfxSCBR, dd 0 ; screen bank register (8bit) +NEWSYM SfxCLSR, dd 0 ; clock speed register (8bit) +NEWSYM SfxSCMR, dd 0 ; screen mode register (8bit) +NEWSYM SfxVCR, dd 0 ; version code register (8bit) +NEWSYM SfxRAMBR, dd 0 ; ram bank register (8bit) +NEWSYM SfxCBR, dd 0 ; cache base register (16bit) + +NEWSYM SfxCOLR, dd 0 ; Internal color register +NEWSYM SfxPOR, dd 0 ; Plot option register + +NEWSYM SfxCacheFlags, dd 0 ; Saying what parts of the cache was written to +NEWSYM SfxLastRamAdr, dd 0 ; Last RAM address accessed +NEWSYM SfxDREG, dd 0 ; Current destination register index +NEWSYM SfxSREG, dd 0 ; Current source register index +NEWSYM SfxRomBuffer, dd 0 ; Current byte read by R14 +NEWSYM SfxPIPE, dd 0 ; Instructionset pipe +NEWSYM SfxPipeAdr, dd 0 ; The address of where the pipe was read from + +NEWSYM SfxnRamBanks, dd 4 ; Number of 64kb-banks in FxRam (Don't confuse it with SNES-Ram!!!) +NEWSYM SfxnRomBanks, dd 0 ; Number of 32kb-banks in Cart-ROM + +NEWSYM SfxvScreenHeight, dd 0 ; 128, 160 or 192 +NEWSYM SfxvScreenSize, dd 0 + +NEWSYM SfxCacheActive, dd 0 ; Cache Active + +NEWSYM SfxCarry, dd 0 ; Carry flag +NEWSYM SfxSignZero, dd 0 ; Sign and Zero flag +NEWSYM SfxB, dd 0 ; B flag (1 when with instruction executed) +NEWSYM SfxOverflow, dd 0 ; Overflow flag + +NEWSYM SfxCACHERAM, times 512 db 0 ; 512 bytes of GSU cache memory +num2writesfxreg equ $-SfxR0 +; pharos equ hack *sigh* +NEWSYM PHnum2writesfxreg, dd num2writesfxreg + +NEWSYM SfxCPB, dd 0 +NEWSYM SfxCROM, dd 0 +NEWSYM SfxRAMMem, dd 0 +NEWSYM withr15sk, dd 0 +NEWSYM sfxclineloc, dd 0 +NEWSYM SCBRrel, dd 0 +NEWSYM fxbit01pcal, dd 0 +NEWSYM fxbit23pcal, dd 0 +NEWSYM fxbit45pcal, dd 0 +NEWSYM fxbit67pcal, dd 0 + +;SfxRAM times 256*1024 db 0 + +; If we need this later... + +SECTION .text +NEWSYM FxOp00 ; STOP stop GSU execution (and maybe generate an IRQ) ; Verified. + FETCHPIPE + mov [SfxPIPE],cl + and dword [SfxSFR],0FFFFh-32 ; Clear Go flag (set to 1 when the GSU is running) + test dword [SfxCFGR],080h ; Check if the interrupt generation is on + jnz .NoIRQ + or dword [SfxSFR],08000h ; Set IRQ Flag +.NoIRQ + CLRFLAGS + inc ebp + mov eax,[NumberOfOpcodes] + add eax,0F0000000h + add [ChangeOps],eax + mov dword [NumberOfOpcodes],1 + mov dword[SFXProc],0 + xor cl,cl + ret + +NEWSYM FxOp01 ; NOP no operation ; Verified. + FETCHPIPE + CLRFLAGS + inc ebp ; Increase program counter + ret + +NEWSYM FxOp02 ; CACHE reintialize GSU cache + mov eax,ebp + FETCHPIPE + sub eax,[SfxCPB] + and eax,0FFF0h + cmp dword [SfxCBR],eax + je .SkipUpdate + cmp byte [SfxCacheActive],1 + je .SkipUpdate + mov dword [SfxCBR],eax + mov dword [SfxCacheActive],1 + call FlushCache +.SkipUpdate + CLRFLAGS + inc ebp ; Increase program counter + ret + +NEWSYM FxOp03 ; LSR logic shift right ; Verified. + mov eax,[esi] ; Read Source + FETCHPIPE + mov [SfxCarry],al + and byte[SfxCarry],1 + shr ax,1 ; logic shift right + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp04 ; ROL rotate left (RCL?) ; V + shr byte[SfxCarry],1 + mov eax,[esi] ; Read Source + FETCHPIPE + rcl ax,1 + rcl byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp05 ; BRA branch always ; Verified. + movsx eax,byte[ebp] + mov cl,[ebp+1] + inc ebp + add ebp,eax + call [FxTable+ecx*4] + ret + +NEWSYM FxOp06 ; BGE branch on greater or equals ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp07 ; BLT branch on lesss than ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp08 ; BNE branch on not equal ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp09 ; BEQ branch on equal (z=1) ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp0A ; BPL branch on plus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp0B ; BMI branch on minus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp0C ; BCC branch on carry clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp0D ; BCS branch on carry set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp0E ; BVC branch on overflow clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp0F ; BVS branch on overflow set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + ret +.nojump + inc ebp + call [FxTable+ecx*4] + ret + +NEWSYM FxOp10 ; TO RN set register n as destination register + TORN 0 +NEWSYM FxOp11 ; TO RN set register n as destination register + TORN 1 +NEWSYM FxOp12 ; TO RN set register n as destination register + TORN 2 +NEWSYM FxOp13 ; TO RN set register n as destination register + TORN 3 +NEWSYM FxOp14 ; TO RN set register n as destination register + TORN 4 +NEWSYM FxOp15 ; TO RN set register n as destination register + TORN 5 +NEWSYM FxOp16 ; TO RN set register n as destination register + TORN 6 +NEWSYM FxOp17 ; TO RN set register n as destination register + TORN 7 +NEWSYM FxOp18 ; TO RN set register n as destination register + TORN 8 +NEWSYM FxOp19 ; TO RN set register n as destination register + TORN 9 +NEWSYM FxOp1A ; TO RN set register n as destination register + TORN 10 +NEWSYM FxOp1B ; TO RN set register n as destination register + TORN 11 +NEWSYM FxOp1C ; TO RN set register n as destination register + TORN 12 +NEWSYM FxOp1D ; TO RN set register n as destination register + TORN 13 +NEWSYM FxOp1E ; TO RN set register n as destination register + FETCHPIPE + mov edi,SfxR0+14*4 + inc ebp + call [FxTable+ecx*4] + mov edi,SfxR0 + UpdateR14 + ret +NEWSYM FxOp1F ; TO RN set register n as destination register + FETCHPIPE + mov edi,SfxR0+15*4 + inc ebp + call [FxTable+ecx*4] + mov ebp,[SfxCPB] + add ebp,[SfxR15] + mov edi,SfxR0 + ret + +NEWSYM FxOp20 ; WITH set register n as source and destination register + WITH 0 +NEWSYM FxOp21 ; WITH set register n as source and destination register + WITH 1 +NEWSYM FxOp22 ; WITH set register n as source and destination register + WITH 2 +NEWSYM FxOp23 ; WITH set register n as source and destination register + WITH 3 +NEWSYM FxOp24 ; WITH set register n as source and destination register + WITH 4 +NEWSYM FxOp25 ; WITH set register n as source and destination register + WITH 5 +NEWSYM FxOp26 ; WITH set register n as source and destination register + WITH 6 +NEWSYM FxOp27 ; WITH set register n as source and destination register + WITH 7 +NEWSYM FxOp28 ; WITH set register n as source and destination register + WITH 8 +NEWSYM FxOp29 ; WITH set register n as source and destination register + WITH 9 +NEWSYM FxOp2A ; WITH set register n as source and destination register + WITH 10 +NEWSYM FxOp2B ; WITH set register n as source and destination register + WITH 11 +NEWSYM FxOp2C ; WITH set register n as source and destination register + WITH 12 +NEWSYM FxOp2D ; WITH set register n as source and destination register + WITH 13 +NEWSYM FxOp2E ; WITH set register n as source and destination register + FETCHPIPE + mov esi,SfxR0+14*4 + mov edi,SfxR0+14*4 + mov dword [SfxB],1 + inc ebp + call [FxTablec+ecx*4] + mov dword [SfxB],0 ; Clear B Flag + mov esi,SfxR0 + mov edi,SfxR0 + UpdateR14 + ret +NEWSYM FxOp2F ; WITH set register n as source and destination register + FETCHPIPE + mov esi,SfxR0+15*4 + mov edi,SfxR0+15*4 + mov dword [SfxB],1 + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov dword[withr15sk],0 + mov [SfxR15],eax + call [FxTableb+ecx*4] + cmp dword[withr15sk],1 + je .skip + mov ebp,[SfxCPB] + add ebp,[SfxR15] +.skip + mov dword [SfxB],0 ; Clear B Flag + mov esi,SfxR0 + mov edi,SfxR0 + ret + +NEWSYM FxOp30 ; STW RN store word + STWRN 0 +NEWSYM FxOp31 ; STW RN store word + STWRN 1 +NEWSYM FxOp32 ; STW RN store word + STWRN 2 +NEWSYM FxOp33 ; STW RN store word + STWRN 3 +NEWSYM FxOp34 ; STW RN store word + STWRN 4 +NEWSYM FxOp35 ; STW RN store word + STWRN 5 +NEWSYM FxOp36 ; STW RN store word + STWRN 6 +NEWSYM FxOp37 ; STW RN store word + STWRN 7 +NEWSYM FxOp38 ; STW RN store word + STWRN 8 +NEWSYM FxOp39 ; STW RN store word + STWRN 9 +NEWSYM FxOp3A ; STW RN store word + STWRN 10 +NEWSYM FxOp3B ; STW RN store word + STWRN 11 + +NEWSYM FxOp30A1 ; STB RN store byte + STBRN 0 +NEWSYM FxOp31A1 ; STB RN store byte + STBRN 1 +NEWSYM FxOp32A1 ; STB RN store byte + STBRN 2 +NEWSYM FxOp33A1 ; STB RN store byte + STBRN 3 +NEWSYM FxOp34A1 ; STB RN store byte + STBRN 4 +NEWSYM FxOp35A1 ; STB RN store byte + STBRN 5 +NEWSYM FxOp36A1 ; STB RN store byte + STBRN 6 +NEWSYM FxOp37A1 ; STB RN store byte + STBRN 7 +NEWSYM FxOp38A1 ; STB RN store byte + STBRN 8 +NEWSYM FxOp39A1 ; STB RN store byte + STBRN 9 +NEWSYM FxOp3AA1 ; STB RN store byte + STBRN 10 +NEWSYM FxOp3BA1 ; STB RN store byte + STBRN 11 + +NEWSYM FxOp3C ; LOOP decrement loop counter, and branch on not zero ; V + dec word [SfxR12] ; decrement loop counter + FETCHPIPE + mov eax,[SfxR12] + mov [SfxSignZero],eax + or eax,eax + jz .NoBranch + mov eax,dword [SfxR13] + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + ret +.NoBranch + inc ebp + CLRFLAGS + ret + +NEWSYM FxOp3D ; ALT1 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,01h + inc ebp + call [FxTable+ecx*4] + xor ch,ch + ret + +NEWSYM FxOp3E ; ALT2 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,02h + inc ebp + call [FxTable+ecx*4] + xor ch,ch + ret + +NEWSYM FxOp3F ; ALT3 set alt3 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,03h + inc ebp + call [FxTable+ecx*4] + xor ch,ch + ret + +NEWSYM FxOp40 ; LDW RN load word from RAM + LDWRN 0 +NEWSYM FxOp41 ; LDW RN load word from RAM + LDWRN 1 +NEWSYM FxOp42 ; LDW RN load word from RAM + LDWRN 2 +NEWSYM FxOp43 ; LDW RN load word from RAM + LDWRN 3 +NEWSYM FxOp44 ; LDW RN load word from RAM + LDWRN 4 +NEWSYM FxOp45 ; LDW RN load word from RAM + LDWRN 5 +NEWSYM FxOp46 ; LDW RN load word from RAM + LDWRN 6 +NEWSYM FxOp47 ; LDW RN load word from RAM + LDWRN 7 +NEWSYM FxOp48 ; LDW RN load word from RAM + LDWRN 8 +NEWSYM FxOp49 ; LDW RN load word from RAM + LDWRN 9 +NEWSYM FxOp4A ; LDW RN load word from RAM + LDWRN 10 +NEWSYM FxOp4B ; LDW RN load word from RAM + LDWRN 11 + +NEWSYM FxOp40A1 ; LDB RN load byte from RAM + LDBRN 0 +NEWSYM FxOp41A1 ; LDB RN load byte from RAM + LDBRN 1 +NEWSYM FxOp42A1 ; LDB RN load byte from RAM + LDBRN 2 +NEWSYM FxOp43A1 ; LDB RN load byte from RAM + LDBRN 3 +NEWSYM FxOp44A1 ; LDB RN load byte from RAM + LDBRN 4 +NEWSYM FxOp45A1 ; LDB RN load byte from RAM + LDBRN 5 +NEWSYM FxOp46A1 ; LDB RN load byte from RAM + LDBRN 6 +NEWSYM FxOp47A1 ; LDB RN load byte from RAM + LDBRN 7 +NEWSYM FxOp48A1 ; LDB RN load byte from RAM + LDBRN 8 +NEWSYM FxOp49A1 ; LDB RN load byte from RAM + LDBRN 9 +NEWSYM FxOp4AA1 ; LDB RN load byte from RAM + LDBRN 10 +NEWSYM FxOp4BA1 ; LDB RN load byte from RAM + LDBRN 11 + +NEWSYM FxOp4C1284b ; PLOT 4bit + plotlines4b plotb +NEWSYM FxOp4C1284bz ; PLOT 4bit, zero check + plotlines4b plotbz +NEWSYM FxOp4C1284bd ; PLOT 4bit, dither + plotlines4b plotbd +NEWSYM FxOp4C1284bzd ; PLOT 4bit, zero check + dither + plotlines4b plotbzd + +NEWSYM FxOp4C1282b ; PLOT 2bit + plotlines2b plotb +NEWSYM FxOp4C1282bz ; PLOT 2bit, zero check + plotlines2b plotbz +NEWSYM FxOp4C1282bd ; PLOT 2bit, dither + plotlines2b plotbd +NEWSYM FxOp4C1282bzd ; PLOT 2bit, zero check + dither + plotlines2b plotbzd + +NEWSYM FxOp4C1288b ; PLOT 8bit + plotlines8b plotb +NEWSYM FxOp4C1288bz ; PLOT 8bit, zero check + plotlines8b plotbz +NEWSYM FxOp4C1288bd ; PLOT 8bit, dither + plotlines8b plotbd +NEWSYM FxOp4C1288bzd ; PLOT 8bit, zero check + dither + plotlines8b plotbzd + +NEWSYM FxOp4C1288bl ; PLOT 8bit + plotlines8bl plotb +NEWSYM FxOp4C1288bzl ; PLOT 8bit, zero check + plotlines8bl plotbz +NEWSYM FxOp4C1288bdl ; PLOT 8bit, dither + plotlines8bl plotbd +NEWSYM FxOp4C1288bzdl ; PLOT 8bit, zero check + dither + plotlines8bl plotbzd + +NEWSYM FxOp4C ; PLOT plot pixel with R1,R2 as x,y and the color register as the color + jmp FxOp4C1284b + FETCHPIPE + inc ebp + CLRFLAGS + mov ebx,[SfxR2] + mov bh,[SfxR1] + mov eax,[sfxclineloc] + mov ebx,[eax+ebx*4] + cmp ebx,0FFFFFFFFh + je near .nodraw + xor eax,eax + ; bits 5/2 : 00 = 128 pixels, 01 = 160 pixels, 10 = 192 pixels, 11 = obj + ; bits 1/0 : 00 = 4 color, 01 = 16-color, 10 = not used, 11 = 256 color + ; 192 pixels = 24 tiles, 160 pixels = 20 tiles, 128 pixels = 16 tiles + ; 16+8(4/3) 16+4(4/2) 16(4/0) + push ecx + mov al,[SfxSCMR] + and al,00000011b ; 4 + 32 + cmp al,0 + je near .colors4 + cmp al,3 + je near .colors256 + + shl ebx,5 ; x32 (16 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + test byte[SfxPOR],01h + jnz .nozerocheck_16 + test byte[SfxCOLR],0Fh + jz .nodraw +.nozerocheck_16 + mov dl,[SfxCOLR] + test byte[SfxPOR],02h + jz .nodither4b + mov dh,[SfxR1] + xor dh,[SfxR2] + test dh,01h + jz .nodither4b + shr dh,4 +.nodither4b + and byte[eax],bh + and byte[eax+1],bh + and byte[eax+16],bh + and byte[eax+17],bh + test dl,01h + jz .nodraw_16 + or byte[eax], bl +.nodraw_16 + test dl,02h + jz .nodraw2_16 + or byte[eax+1], bl +.nodraw2_16 + test dl,04h + jz .nodraw3_16 + or byte[eax+16],bl +.nodraw3_16 + test dl,08h + jz .nodraw4_16 + or byte[eax+17],bl +.nodraw4_16 +.nodraw + inc word [SfxR1] + ret + +.colors4 + shl ebx,4 ; x16 (4 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + test byte[SfxPOR],01h + jnz .nozerocheck_4 + test byte[SfxCOLR],03h + jz .noplot_4 +.nozerocheck_4 + mov dl,[SfxCOLR] + test byte[SfxPOR],02h + jz .nodither2b + mov dh,[SfxR1] + xor dh,[SfxR2] + test dh,01h + jz .nodither2b + shr dh,4 +.nodither2b + and byte[eax],bh + and byte[eax+1],bh + test dl,01h + jz .nodraw_4 + or byte[eax], bl +.nodraw_4 + test dl,02h + jz .nodraw2_4 + or byte[eax+1], bl +.nodraw2_4 +.noplot_4 + inc word [SfxR1] + ret + +.colors256 + shl ebx,6 ; x64 (256 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + test byte[SfxPOR],01h + jnz .nozerocheck_256 + mov dl,0FFh + test byte[SfxPOR],08h + jz .nozerocheckb_256 + mov dl,0Fh +.nozerocheckb_256 + test byte[SfxCOLR],dl + jz .noplot_256 +.nozerocheck_256 + mov dl,[SfxCOLR] + and byte[eax],bh + and byte[eax+1],bh + and byte[eax+16],bh + and byte[eax+17],bh + and byte[eax+32],bh + and byte[eax+33],bh + and byte[eax+48],bh + and byte[eax+49],bh + test dl,01h + jz .nodraw_256 + or byte[eax], bl +.nodraw_256 + test dl,02h + jz .nodraw2_256 + or byte[eax+1], bl +.nodraw2_256 + test dl,04h + jz .nodraw3_256 + or byte[eax+16],bl +.nodraw3_256 + test dl,08h + jz .nodraw4_256 + or byte[eax+17],bl +.nodraw4_256 + test dl,10h + jz .nodraw5_256 + or byte[eax+32], bl +.nodraw5_256 + test dl,20h + jz .nodraw6_256 + or byte[eax+33], bl +.nodraw6_256 + test dl,40h + jz .nodraw7_256 + or byte[eax+48],bl +.nodraw7_256 + test dl,80h + jz .nodraw8_256 + or byte[eax+49],bl +.nodraw8_256 +.noplot_256 + inc word [SfxR1] + ret + +.prevx dw 0 +.prevy dw 0 + +sfxwarning db 0 + +NEWSYM FxOp4CA1 ; RPIX read color of the pixel with R1,R2 as x,y + FETCHPIPE + mov ebx,[SfxR2] + mov bh,[SfxR1] + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov ebx,[eax+ebx*4] + cmp ebx,0FFFFFFFFh + je near .nodraw + xor eax,eax + ; bits 5/2 : 00 = 128 pixels, 01 = 160 pixels, 10 = 192 pixels, 11 = obj + ; bits 1/0 : 00 = 4 color, 01 = 16-color, 10 = not used, 11 = 256 color + ; 192 pixels = 24 tiles, 160 pixels = 20 tiles, 128 pixels = 16 tiles + ; 16+8(4/3) 16+4(4/2) 16(4/0) + push ecx + mov al,[SfxSCMR] + and al,00000011b ; 4 + 32 + + cmp al,0 + je near .colors4 + cmp al,3 + je near .colors256 + + shl ebx,5 ; x32 (16 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + pop ecx + xor bh,bh + test byte[eax],bl + jz .nodraw_16 + or bh,01h +.nodraw_16 + test byte[eax+1],bl + jz .nodraw2_16 + or bh,02h +.nodraw2_16 + test byte[eax+16],bl + jz .nodraw3_16 + or bh,04h +.nodraw3_16 + test byte[eax+17],bl + jz .nodraw4_16 + or bh,08h +.nodraw4_16 +.nodraw + mov bl,bh + and ebx,0FFh + inc ebp +; UpdateR14 + CLRFLAGS + mov [edi],ebx ; Write Destination + mov [flagnz],ebx + ret + +.colors4 + shl ebx,4 ; x16 (4 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + xor bh,bh + test byte[eax],bl + jz .nodraw_4 + or bh,01h +.nodraw_4 + test byte[eax+1],bl + jz .nodraw2_4 + or bh,02h +.nodraw2_4 + mov bl,bh + and ebx,0FFh + inc ebp +; UpdateR14 + CLRFLAGS + mov [edi],ebx ; Write Destination + mov [flagnz],ebx + ret + +.colors256 + shl ebx,6 ; x64 (256 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + xor bh,bh + test byte[eax],bl + jz .nodraw_256 + or bh,01h +.nodraw_256 + test byte[eax+1],bl + jz .nodraw2_256 + or bh,02h +.nodraw2_256 + test byte[eax+16],bl + jz .nodraw3_256 + or bh,04h +.nodraw3_256 + test byte[eax+17],bl + jz .nodraw4_256 + or bh,08h +.nodraw4_256 + test byte[eax+32],bl + jz .nodraw5_256 + or bh,10h +.nodraw5_256 + test byte[eax+33],bl + jz .nodraw6_256 + or bh,20h +.nodraw6_256 + test byte[eax+48],bl + jz .nodraw7_256 + or bh,40h +.nodraw7_256 + test byte[eax+49],bl + jz .nodraw8_256 + or bh,80h +.nodraw8_256 + mov bl,bh + and ebx,0FFh + inc ebp +; UpdateR14 + CLRFLAGS + mov [edi],ebx ; Write Destination + mov [flagnz],ebx + ret + +NEWSYM FxOp4D ; SWAP swap upper and lower byte of a register ; V + mov eax,[esi] ; Read Source + FETCHPIPE + ror ax,8 + inc ebp ; Increase program counter + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp4E ; COLOR copy source register to color register ; V + FETCHPIPE + mov eax,[esi] ; Read Source + ; if bit 3 of SfxPOR is set, then don't modify the upper 4 bits + test byte[SfxPOR],04h + jz .nohighnibble + mov bl,al + shr bl,4 + and al,0F0h + or al,bl +.nohighnibble + test byte[SfxPOR],08h + jnz .preserveupper + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx +.nocolchange + CLRFLAGS + inc ebp ; Increase program counter + ret +.preserveupper + mov bl,[SfxCOLR] + and al,0Fh + and bl,0F0h + or al,bl + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + CLRFLAGS + inc ebp ; Increase program counter + ret + +NEWSYM FxOp4EA1 ; CMODE set plot option register ; V + FETCHPIPE + mov eax,[esi] ; Read Source + inc ebp ; Increase program counter + mov dword [SfxPOR],eax + + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + + + push ebx + mov al,[SfxSCMR] + and eax,00000011b + mov bl,[SfxPOR] + and bl,0Fh + shl bl,2 + or al,bl + mov ebx,[PLOTJmpb+eax*4] + mov eax,[PLOTJmpa+eax*4] + mov dword [FxTable+4Ch*4],eax + mov dword [FxTableb+4Ch*4],eax + mov dword [FxTablec+4Ch*4],eax + mov dword [FxTabled+4Ch*4],ebx + pop ebx + + CLRFLAGS + ret + +NEWSYM FxOp4F ; NOT perform exclusive exor with 1 on all bits ; V + mov eax,[esi] ; Read Source + FETCHPIPE + xor eax,0FFFFh + inc ebp ; Increase program counter + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp50 ; ADD RN add, register + register + ADDRN 0 +NEWSYM FxOp51 ; ADD RN add, register + register + ADDRN 1 +NEWSYM FxOp52 ; ADD RN add, register + register + ADDRN 2 +NEWSYM FxOp53 ; ADD RN add, register + register + ADDRN 3 +NEWSYM FxOp54 ; ADD RN add, register + register + ADDRN 4 +NEWSYM FxOp55 ; ADD RN add, register + register + ADDRN 5 +NEWSYM FxOp56 ; ADD RN add, register + register + ADDRN 6 +NEWSYM FxOp57 ; ADD RN add, register + register + ADDRN 7 +NEWSYM FxOp58 ; ADD RN add, register + register + ADDRN 8 +NEWSYM FxOp59 ; ADD RN add, register + register + ADDRN 9 +NEWSYM FxOp5A ; ADD RN add, register + register + ADDRN 10 +NEWSYM FxOp5B ; ADD RN add, register + register + ADDRN 11 +NEWSYM FxOp5C ; ADD RN add, register + register + ADDRN 12 +NEWSYM FxOp5D ; ADD RN add, register + register + ADDRN 13 +NEWSYM FxOp5E ; ADD RN add, register + register + ADDRN 14 +NEWSYM FxOp5F ; ADD RN add, register + register + FETCHPIPE + mov eax, [esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + add ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp50A1 ; ADC RN add with carry, register + register + ADCRN 0 +NEWSYM FxOp51A1 ; ADC RN add with carry, register + register + ADCRN 1 +NEWSYM FxOp52A1 ; ADC RN add with carry, register + register + ADCRN 2 +NEWSYM FxOp53A1 ; ADC RN add with carry, register + register + ADCRN 3 +NEWSYM FxOp54A1 ; ADC RN add with carry, register + register + ADCRN 4 +NEWSYM FxOp55A1 ; ADC RN add with carry, register + register + ADCRN 5 +NEWSYM FxOp56A1 ; ADC RN add with carry, register + register + ADCRN 6 +NEWSYM FxOp57A1 ; ADC RN add with carry, register + register + ADCRN 7 +NEWSYM FxOp58A1 ; ADC RN add with carry, register + register + ADCRN 8 +NEWSYM FxOp59A1 ; ADC RN add with carry, register + register + ADCRN 9 +NEWSYM FxOp5AA1 ; ADC RN add with carry, register + register + ADCRN 10 +NEWSYM FxOp5BA1 ; ADC RN add with carry, register + register + ADCRN 11 +NEWSYM FxOp5CA1 ; ADC RN add with carry, register + register + ADCRN 12 +NEWSYM FxOp5DA1 ; ADC RN add with carry, register + register + ADCRN 13 +NEWSYM FxOp5EA1 ; ADC RN add with carry, register + register + ADCRN 14 +NEWSYM FxOp5FA1 ; ADC RN add with carry, register + register + FETCHPIPE + mov eax, [esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + shr byte[SfxCarry],1 + adc ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +; Weird opcode (FxOp50A2, add 0, wow!) +NEWSYM FxOp50A2 ; ADI RN add, register + immediate + ADIRN 0 +NEWSYM FxOp51A2 ; ADI RN add, register + immediate + ADIRN 1 +NEWSYM FxOp52A2 ; ADI RN add, register + immediate + ADIRN 2 +NEWSYM FxOp53A2 ; ADI RN add, register + immediate + ADIRN 3 +NEWSYM FxOp54A2 ; ADI RN add, register + immediate + ADIRN 4 +NEWSYM FxOp55A2 ; ADI RN add, register + immediate + ADIRN 5 +NEWSYM FxOp56A2 ; ADI RN add, register + immediate + ADIRN 6 +NEWSYM FxOp57A2 ; ADI RN add, register + immediate + ADIRN 7 +NEWSYM FxOp58A2 ; ADI RN add, register + immediate + ADIRN 8 +NEWSYM FxOp59A2 ; ADI RN add, register + immediate + ADIRN 9 +NEWSYM FxOp5AA2 ; ADI RN add, register + immediate + ADIRN 10 +NEWSYM FxOp5BA2 ; ADI RN add, register + immediate + ADIRN 11 +NEWSYM FxOp5CA2 ; ADI RN add, register + immediate + ADIRN 12 +NEWSYM FxOp5DA2 ; ADI RN add, register + immediate + ADIRN 13 +NEWSYM FxOp5EA2 ; ADI RN add, register + immediate + ADIRN 14 +NEWSYM FxOp5FA2 ; ADI RN add, register + immediate + ADIRN 15 + +; Another very useful opcode +NEWSYM FxOp50A3 ; ADCIRN add with carry, register + immediate + ADCIRN 0 +NEWSYM FxOp51A3 ; ADCIRN add with carry, register + immediate + ADCIRN 1 +NEWSYM FxOp52A3 ; ADCIRN add with carry, register + immediate + ADCIRN 2 +NEWSYM FxOp53A3 ; ADCIRN add with carry, register + immediate + ADCIRN 3 +NEWSYM FxOp54A3 ; ADCIRN add with carry, register + immediate + ADCIRN 4 +NEWSYM FxOp55A3 ; ADCIRN add with carry, register + immediate + ADCIRN 5 +NEWSYM FxOp56A3 ; ADCIRN add with carry, register + immediate + ADCIRN 6 +NEWSYM FxOp57A3 ; ADCIRN add with carry, register + immediate + ADCIRN 7 +NEWSYM FxOp58A3 ; ADCIRN add with carry, register + immediate + ADCIRN 8 +NEWSYM FxOp59A3 ; ADCIRN add with carry, register + immediate + ADCIRN 9 +NEWSYM FxOp5AA3 ; ADCIRN add with carry, register + immediate + ADCIRN 10 +NEWSYM FxOp5BA3 ; ADCIRN add with carry, register + immediate + ADCIRN 11 +NEWSYM FxOp5CA3 ; ADCIRN add with carry, register + immediate + ADCIRN 12 +NEWSYM FxOp5DA3 ; ADCIRN add with carry, register + immediate + ADCIRN 13 +NEWSYM FxOp5EA3 ; ADCIRN add with carry, register + immediate + ADCIRN 14 +NEWSYM FxOp5FA3 ; ADCIRN add with carry, register + immediate + ADCIRN 15 + +NEWSYM FxOp60 ; SUBRN subtract, register - register + SUBRN 0 +NEWSYM FxOp61 ; SUBRN subtract, register - register + SUBRN 1 +NEWSYM FxOp62 ; SUBRN subtract, register - register + SUBRN 2 +NEWSYM FxOp63 ; SUBRN subtract, register - register + SUBRN 3 +NEWSYM FxOp64 ; SUBRN subtract, register - register + SUBRN 4 +NEWSYM FxOp65 ; SUBRN subtract, register - register + SUBRN 5 +NEWSYM FxOp66 ; SUBRN subtract, register - register + SUBRN 6 +NEWSYM FxOp67 ; SUBRN subtract, register - register + SUBRN 7 +NEWSYM FxOp68 ; SUBRN subtract, register - register + SUBRN 8 +NEWSYM FxOp69 ; SUBRN subtract, register - register + SUBRN 9 +NEWSYM FxOp6A ; SUBRN subtract, register - register + SUBRN 10 +NEWSYM FxOp6B ; SUBRN subtract, register - register + SUBRN 11 +NEWSYM FxOp6C ; SUBRN subtract, register - register + SUBRN 12 +NEWSYM FxOp6D ; SUBRN subtract, register - register + SUBRN 13 +NEWSYM FxOp6E ; SUBRN subtract, register - register + SUBRN 14 +NEWSYM FxOp6F ; SUBRN subtract, register - register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp60A1 ; SBCRN subtract with carry, register - register + SBCRN 0 +NEWSYM FxOp61A1 ; SBCRN subtract with carry, register - register + SBCRN 1 +NEWSYM FxOp62A1 ; SBCRN subtract with carry, register - register + SBCRN 2 +NEWSYM FxOp63A1 ; SBCRN subtract with carry, register - register + SBCRN 3 +NEWSYM FxOp64A1 ; SBCRN subtract with carry, register - register + SBCRN 4 +NEWSYM FxOp65A1 ; SBCRN subtract with carry, register - register + SBCRN 5 +NEWSYM FxOp66A1 ; SBCRN subtract with carry, register - register + SBCRN 6 +NEWSYM FxOp67A1 ; SBCRN subtract with carry, register - register + SBCRN 7 +NEWSYM FxOp68A1 ; SBCRN subtract with carry, register - register + SBCRN 8 +NEWSYM FxOp69A1 ; SBCRN subtract with carry, register - register + SBCRN 9 +NEWSYM FxOp6AA1 ; SBCRN subtract with carry, register - register + SBCRN 10 +NEWSYM FxOp6BA1 ; SBCRN subtract with carry, register - register + SBCRN 11 +NEWSYM FxOp6CA1 ; SBCRN subtract with carry, register - register + SBCRN 12 +NEWSYM FxOp6DA1 ; SBCRN subtract with carry, register - register + SBCRN 13 +NEWSYM FxOp6EA1 ; SBCRN subtract with carry, register - register + SBCRN 14 +NEWSYM FxOp6FA1 ; SBCRN subtract with carry, register - register + mov eax,[esi] ; Read Source + mov ebx,ebp + FETCHPIPE + sub ebx,[SfxCPB] + cmp byte[SfxCarry],1 + sbb ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp60A2 ; SUBIRN subtract, register - immediate + SUBIRN 0 +NEWSYM FxOp61A2 ; SUBIRN subtract, register - immediate + SUBIRN 1 +NEWSYM FxOp62A2 ; SUBIRN subtract, register - immediate + SUBIRN 2 +NEWSYM FxOp63A2 ; SUBIRN subtract, register - immediate + SUBIRN 3 +NEWSYM FxOp64A2 ; SUBIRN subtract, register - immediate + SUBIRN 4 +NEWSYM FxOp65A2 ; SUBIRN subtract, register - immediate + SUBIRN 5 +NEWSYM FxOp66A2 ; SUBIRN subtract, register - immediate + SUBIRN 6 +NEWSYM FxOp67A2 ; SUBIRN subtract, register - immediate + SUBIRN 7 +NEWSYM FxOp68A2 ; SUBIRN subtract, register - immediate + SUBIRN 8 +NEWSYM FxOp69A2 ; SUBIRN subtract, register - immediate + SUBIRN 9 +NEWSYM FxOp6AA2 ; SUBIRN subtract, register - immediate + SUBIRN 10 +NEWSYM FxOp6BA2 ; SUBIRN subtract, register - immediate + SUBIRN 11 +NEWSYM FxOp6CA2 ; SUBIRN subtract, register - immediate + SUBIRN 12 +NEWSYM FxOp6DA2 ; SUBIRN subtract, register - immediate + SUBIRN 13 +NEWSYM FxOp6EA2 ; SUBIRN subtract, register - immediate + SUBIRN 14 +NEWSYM FxOp6FA2 ; SUBIRN subtract, register - immediate + SUBIRN 15 + +NEWSYM FxOp60A3 ; CMPRN compare, register, register + CMPRN 0 +NEWSYM FxOp61A3 ; CMPRN compare, register, register + CMPRN 1 +NEWSYM FxOp62A3 ; CMPRN compare, register, register + CMPRN 2 +NEWSYM FxOp63A3 ; CMPRN compare, register, register + CMPRN 3 +NEWSYM FxOp64A3 ; CMPRN compare, register, register + CMPRN 4 +NEWSYM FxOp65A3 ; CMPRN compare, register, register + CMPRN 5 +NEWSYM FxOp66A3 ; CMPRN compare, register, register + CMPRN 6 +NEWSYM FxOp67A3 ; CMPRN compare, register, register + CMPRN 7 +NEWSYM FxOp68A3 ; CMPRN compare, register, register + CMPRN 8 +NEWSYM FxOp69A3 ; CMPRN compare, register, register + CMPRN 9 +NEWSYM FxOp6AA3 ; CMPRN compare, register, register + CMPRN 10 +NEWSYM FxOp6BA3 ; CMPRN compare, register, register + CMPRN 11 +NEWSYM FxOp6CA3 ; CMPRN compare, register, register + CMPRN 12 +NEWSYM FxOp6DA3 ; CMPRN compare, register, register + CMPRN 13 +NEWSYM FxOp6EA3 ; CMPRN compare, register, register + CMPRN 14 +NEWSYM FxOp6FA3 ; CMPRN compare, register, register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + mov [SfxSignZero],eax + CLRFLAGS + inc ebp ; Increase program counter + ret + +NEWSYM FxOp70 ; MERGE R7 as upper byte, R8 as lower byte (used for texture-mapping) */ + ; V + xor eax,eax + FETCHPIPE + mov ah,byte [SfxR7+1] + mov al,byte [SfxR8+1] + inc ebp + mov [edi],eax ; Write Destination + mov dword[SfxSignZero],0001h + test eax,0F0F0h + jz .nozero + mov dword[SfxSignZero],0000h +.nozero + test eax,08080h + jz .nosign + or dword [SfxSignZero],80000h +.nosign + mov dword [SfxOverflow],1 + test ax,0c0c0h + jnz .Overflow + mov dword [SfxOverflow],0 +.Overflow + mov dword [SfxCarry],1 + test ax,0e0e0h + jnz .Carry + mov dword [SfxCarry],0 +.Carry + CLRFLAGS + ret + +NEWSYM FxOp71 ; AND RN register & register + ANDRN 1 +NEWSYM FxOp72 ; AND RN register & register + ANDRN 2 +NEWSYM FxOp73 ; AND RN register & register + ANDRN 3 +NEWSYM FxOp74 ; AND RN register & register + ANDRN 4 +NEWSYM FxOp75 ; AND RN register & register + ANDRN 5 +NEWSYM FxOp76 ; AND RN register & register + ANDRN 6 +NEWSYM FxOp77 ; AND RN register & register + ANDRN 7 +NEWSYM FxOp78 ; AND RN register & register + ANDRN 8 +NEWSYM FxOp79 ; AND RN register & register + ANDRN 9 +NEWSYM FxOp7A ; AND RN register & register + ANDRN 10 +NEWSYM FxOp7B ; AND RN register & register + ANDRN 11 +NEWSYM FxOp7C ; AND RN register & register + ANDRN 12 +NEWSYM FxOp7D ; AND RN register & register + ANDRN 13 +NEWSYM FxOp7E ; AND RN register & register + ANDRN 14 +NEWSYM FxOp7F ; AND RN register & register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp71A1 ; BIC RN register & ~register + BICRN 1 +NEWSYM FxOp72A1 ; BIC RN register & ~register + BICRN 2 +NEWSYM FxOp73A1 ; BIC RN register & ~register + BICRN 3 +NEWSYM FxOp74A1 ; BIC RN register & ~register + BICRN 4 +NEWSYM FxOp75A1 ; BIC RN register & ~register + BICRN 5 +NEWSYM FxOp76A1 ; BIC RN register & ~register + BICRN 6 +NEWSYM FxOp77A1 ; BIC RN register & ~register + BICRN 7 +NEWSYM FxOp78A1 ; BIC RN register & ~register + BICRN 8 +NEWSYM FxOp79A1 ; BIC RN register & ~register + BICRN 9 +NEWSYM FxOp7AA1 ; BIC RN register & ~register + BICRN 10 +NEWSYM FxOp7BA1 ; BIC RN register & ~register + BICRN 11 +NEWSYM FxOp7CA1 ; BIC RN register & ~register + BICRN 12 +NEWSYM FxOp7DA1 ; BIC RN register & ~register + BICRN 13 +NEWSYM FxOp7EA1 ; BIC RN register & ~register + BICRN 14 +NEWSYM FxOp7FA1 ; BIC RN register & ~register + FETCHPIPE + mov ebx,ebp + sub ebx,[SfxCPB] + mov eax,[esi] ; Read Source + xor ebx,0FFFFh + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp71A2 ; ANDIRN and #n - register & immediate + ANDIRN 1 +NEWSYM FxOp72A2 ; ANDIRN and #n - register & immediate + ANDIRN 2 +NEWSYM FxOp73A2 ; ANDIRN and #n - register & immediate + ANDIRN 3 +NEWSYM FxOp74A2 ; ANDIRN and #n - register & immediate + ANDIRN 4 +NEWSYM FxOp75A2 ; ANDIRN and #n - register & immediate + ANDIRN 5 +NEWSYM FxOp76A2 ; ANDIRN and #n - register & immediate + ANDIRN 6 +NEWSYM FxOp77A2 ; ANDIRN and #n - register & immediate + ANDIRN 7 +NEWSYM FxOp78A2 ; ANDIRN and #n - register & immediate + ANDIRN 8 +NEWSYM FxOp79A2 ; ANDIRN and #n - register & immediate + ANDIRN 9 +NEWSYM FxOp7AA2 ; ANDIRN and #n - register & immediate + ANDIRN 10 +NEWSYM FxOp7BA2 ; ANDIRN and #n - register & immediate + ANDIRN 11 +NEWSYM FxOp7CA2 ; ANDIRN and #n - register & immediate + ANDIRN 12 +NEWSYM FxOp7DA2 ; ANDIRN and #n - register & immediate + ANDIRN 13 +NEWSYM FxOp7EA2 ; ANDIRN and #n - register & immediate + ANDIRN 14 +NEWSYM FxOp7FA2 ; ANDIRN and #n - register & immediate + ANDIRN 15 + +NEWSYM FxOp71A3 ; BICIRN register & ~immediate + BICIRN 1 ^ 0FFFFh +NEWSYM FxOp72A3 ; BICIRN register & ~immediate + BICIRN 2 ^ 0FFFFh +NEWSYM FxOp73A3 ; BICIRN register & ~immediate + BICIRN 3 ^ 0FFFFh +NEWSYM FxOp74A3 ; BICIRN register & ~immediate + BICIRN 4 ^ 0FFFFh +NEWSYM FxOp75A3 ; BICIRN register & ~immediate + BICIRN 5 ^ 0FFFFh +NEWSYM FxOp76A3 ; BICIRN register & ~immediate + BICIRN 6 ^ 0FFFFh +NEWSYM FxOp77A3 ; BICIRN register & ~immediate + BICIRN 7 ^ 0FFFFh +NEWSYM FxOp78A3 ; BICIRN register & ~immediate + BICIRN 8 ^ 0FFFFh +NEWSYM FxOp79A3 ; BICIRN register & ~immediate + BICIRN 9 ^ 0FFFFh +NEWSYM FxOp7AA3 ; BICIRN register & ~immediate + BICIRN 10 ^ 0FFFFh +NEWSYM FxOp7BA3 ; BICIRN register & ~immediate + BICIRN 11 ^ 0FFFFh +NEWSYM FxOp7CA3 ; BICIRN register & ~immediate + BICIRN 12 ^ 0FFFFh +NEWSYM FxOp7DA3 ; BICIRN register & ~immediate + BICIRN 13 ^ 0FFFFh +NEWSYM FxOp7EA3 ; BICIRN register & ~immediate + BICIRN 14 ^ 0FFFFh +NEWSYM FxOp7FA3 ; BICIRN register & ~immediate + BICIRN 15 ^ 0FFFFh + +NEWSYM FxOp80 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 0 +NEWSYM FxOp81 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 1 +NEWSYM FxOp82 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 2 +NEWSYM FxOp83 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 3 +NEWSYM FxOp84 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 4 +NEWSYM FxOp85 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 5 +NEWSYM FxOp86 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 6 +NEWSYM FxOp87 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 7 +NEWSYM FxOp88 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 8 +NEWSYM FxOp89 ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 9 +NEWSYM FxOp8A ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 10 +NEWSYM FxOp8B ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 11 +NEWSYM FxOp8C ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 12 +NEWSYM FxOp8D ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 13 +NEWSYM FxOp8E ; MULTRN 8 bit to 16 bit signed multiply, register * register + MULTRN 14 +NEWSYM FxOp8F ; MULTRN 8 bit to 16 bit signed multiply, register * register + FETCHPIPE + mov ebx,ebp + mov al,byte [esi] ; Read Source + sub ebx,[SfxCPB] + imul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp80A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 0 +NEWSYM FxOp81A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 1 +NEWSYM FxOp82A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 2 +NEWSYM FxOp83A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 3 +NEWSYM FxOp84A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 4 +NEWSYM FxOp85A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 5 +NEWSYM FxOp86A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 6 +NEWSYM FxOp87A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 7 +NEWSYM FxOp88A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 8 +NEWSYM FxOp89A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 9 +NEWSYM FxOp8AA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 10 +NEWSYM FxOp8BA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 11 +NEWSYM FxOp8CA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 12 +NEWSYM FxOp8DA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 13 +NEWSYM FxOp8EA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRN 14 +NEWSYM FxOp8FA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + FETCHPIPE + mov ebx,ebp + mov al,byte [esi] ; Read Source + sub ebx,[SfxCPB] + mul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret + +NEWSYM FxOp80A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 0 +NEWSYM FxOp81A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 1 +NEWSYM FxOp82A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 2 +NEWSYM FxOp83A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 3 +NEWSYM FxOp84A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 4 +NEWSYM FxOp85A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 5 +NEWSYM FxOp86A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 6 +NEWSYM FxOp87A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 7 +NEWSYM FxOp88A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 8 +NEWSYM FxOp89A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 9 +NEWSYM FxOp8AA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 10 +NEWSYM FxOp8BA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 11 +NEWSYM FxOp8CA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 12 +NEWSYM FxOp8DA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 13 +NEWSYM FxOp8EA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 14 +NEWSYM FxOp8FA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRN 15 + +NEWSYM FxOp80A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 0 +NEWSYM FxOp81A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 1 +NEWSYM FxOp82A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 2 +NEWSYM FxOp83A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 3 +NEWSYM FxOp84A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 4 +NEWSYM FxOp85A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 5 +NEWSYM FxOp86A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 6 +NEWSYM FxOp87A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 7 +NEWSYM FxOp88A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 8 +NEWSYM FxOp89A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 9 +NEWSYM FxOp8AA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 10 +NEWSYM FxOp8BA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 11 +NEWSYM FxOp8CA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 12 +NEWSYM FxOp8DA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 13 +NEWSYM FxOp8EA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 14 +NEWSYM FxOp8FA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRN 15 + +NEWSYM FxOp90 ; SBK store word to last accessed RAM address ; V + mov ebx,[SfxLastRamAdr] ; Load last ram address + mov eax,[esi] ; Read Source + FETCHPIPE + mov [ebx],al ; Store Word + sub ebx,[SfxRAMMem] + xor ebx,1 + add ebx,[SfxRAMMem] + inc ebp ; Increase program counter + mov [ebx],ah ; Store Word + CLRFLAGS + ret + +NEWSYM FxOp91 ; LINK#n R11 = R15 + immediate + LINK 1 +NEWSYM FxOp92 ; LINK#n R11 = R15 + immediate + LINK 2 +NEWSYM FxOp93 ; LINK#n R11 = R15 + immediate + LINK 3 +NEWSYM FxOp94 ; LINK#n R11 = R15 + immediate + LINK 4 + +NEWSYM FxOp95 ; SEX sign extend 8 bit to 16 bit ; V + movsx eax, byte [esi] ; Read Source + FETCHPIPE + and eax,0FFFFh + inc ebp + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp96 ; ASR aritmethic shift right by one ; V + mov eax,[esi] ; Read Source + FETCHPIPE + mov [SfxCarry],al + and byte[SfxCarry],1 + sar ax,1 ; logic shift right + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp96A1 ; DIV2 aritmethic shift right by one ; V + mov eax,[esi] ; Read Source + FETCHPIPE + cmp ax,-1 + je .minusone + mov [SfxCarry],al + and byte[SfxCarry],1 + sar ax,1 ; logic shift right + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + ret +.minusone + mov byte[SfxCarry],1 + xor eax,eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp97 ; ROR rotate right by one ; V + FETCHPIPE + mov eax,[esi] ; Read Source + shr byte[SfxCarry],1 + rcr ax,1 + setc byte[SfxCarry] + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp98 ; JMPRN jump to address of register + JMPRN 8 +NEWSYM FxOp99 ; JMPRN jump to address of register + JMPRN 9 +NEWSYM FxOp9A ; JMPRN jump to address of register + JMPRN 10 +NEWSYM FxOp9B ; JMPRN jump to address of register + JMPRN 11 +NEWSYM FxOp9C ; JMPRN jump to address of register + JMPRN 12 +NEWSYM FxOp9D ; JMPRN jump to address of register + JMPRN 13 + +NEWSYM FxOp98A1 ; LJMPRN set program bank to source register and jump to address of register + LJMPRN 8 +NEWSYM FxOp99A1 ; LJMPRN set program bank to source register and jump to address of register + LJMPRN 9 +NEWSYM FxOp9AA1 ; LJMPRN set program bank to source register and jump to address of register + LJMPRN 10 +NEWSYM FxOp9BA1 ; LJMPRN set program bank to source register and jump to address of register + LJMPRN 11 +NEWSYM FxOp9CA1 ; LJMPRN set program bank to source register and jump to address of register + LJMPRN 12 +NEWSYM FxOp9DA1 ; LJMPRN set program bank to source register and jump to address of register + LJMPRN 13 + +NEWSYM FxOp9E ; LOB set upper byte to zero (keep low byte) ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,0FFh + inc ebp + mov [edi],eax ; Write Destination + shl eax,8 + mov dword [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOp9F ; FMULT 16 bit to 32 bit signed multiplication, upper 16 bits only + ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR6] + FETCHPIPE + imul bx + inc ebp + and edx,0FFFFh + mov [SfxSignZero],edx + mov [edi],edx ; Write Destination + shr ax,15 + mov [SfxCarry],al + CLRFLAGS + ret + +NEWSYM FxOp9FA1 ; LMULT 16 bit to 32 bit signed multiplication ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR6] + FETCHPIPE + imul bx + and edx,0FFFFh + inc ebp + mov [edi],edx ; Write Destination + mov [SfxR4],ax + mov [SfxSignZero],edx + shr ax,15 + mov [SfxCarry],al + CLRFLAGS + ret + +NEWSYM FxOpA0 ; IBTRN,#PP immediate byte transfer + IBTRN 0 +NEWSYM FxOpA1 ; IBTRN,#PP immediate byte transfer + IBTRN 1 +NEWSYM FxOpA2 ; IBTRN,#PP immediate byte transfer + IBTRN 2 +NEWSYM FxOpA3 ; IBTRN,#PP immediate byte transfer + IBTRN 3 +NEWSYM FxOpA4 ; IBTRN,#PP immediate byte transfer + IBTRN 4 +NEWSYM FxOpA5 ; IBTRN,#PP immediate byte transfer + IBTRN 5 +NEWSYM FxOpA6 ; IBTRN,#PP immediate byte transfer + IBTRN 6 +NEWSYM FxOpA7 ; IBTRN,#PP immediate byte transfer + IBTRN 7 +NEWSYM FxOpA8 ; IBTRN,#PP immediate byte transfer + IBTRN 8 +NEWSYM FxOpA9 ; IBTRN,#PP immediate byte transfer + IBTRN 9 +NEWSYM FxOpAA ; IBTRN,#PP immediate byte transfer + IBTRN 10 +NEWSYM FxOpAB ; IBTRN,#PP immediate byte transfer + IBTRN 11 +NEWSYM FxOpAC ; IBTRN,#PP immediate byte transfer + IBTRN 12 +NEWSYM FxOpAD ; IBTRN,#PP immediate byte transfer + IBTRN 13 +NEWSYM FxOpAE ; IBTRN,#PP immediate byte transfer + movsx eax,byte[ebp] + mov cl,[ebp+1] + add ebp,2 + mov [SfxR0+14*4],ax + UpdateR14 + CLRFLAGS + ret +NEWSYM FxOpAF ; IBTRN,#PP immediate byte transfer + movsx eax,byte[ebp] + mov cl,[ebp+1] + and eax,0FFFFh + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + ret + +NEWSYM FxOpA0A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 0 +NEWSYM FxOpA1A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 1 +NEWSYM FxOpA2A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 2 +NEWSYM FxOpA3A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 3 +NEWSYM FxOpA4A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 4 +NEWSYM FxOpA5A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 5 +NEWSYM FxOpA6A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 6 +NEWSYM FxOpA7A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 7 +NEWSYM FxOpA8A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 8 +NEWSYM FxOpA9A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 9 +NEWSYM FxOpAAA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 10 +NEWSYM FxOpABA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 11 +NEWSYM FxOpACA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 12 +NEWSYM FxOpADA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRN 13 +NEWSYM FxOpAEA1 ; LMS rn,(yy) load word from RAM (short address) + xor eax,eax + mov al,[ebp] + add eax,eax + inc ebp + add eax,[SfxRAMMem] + mov cl,[ebp] + mov dword [SfxLastRamAdr],eax + mov ebx,[eax] ; Read word from ram + inc ebp + mov [SfxR0+14*4],bx ; Write data + UpdateR14 + CLRFLAGS + ret +NEWSYM FxOpAFA1 ; LMS rn,(yy) load word from RAM (short address) + xor eax,eax + mov al,[ebp] + add eax,eax + inc ebp + add eax,[SfxRAMMem] + mov cl,[ebp] + mov dword [SfxLastRamAdr],eax + mov ebx,[eax] ; Read word from ram + and ebx,0FFFFh + mov ebp,[SfxCPB] + add ebp,ebx + CLRFLAGS + ret + +NEWSYM FxOpA0A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 0 +NEWSYM FxOpA1A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 1 +NEWSYM FxOpA2A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 2 +NEWSYM FxOpA3A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 3 +NEWSYM FxOpA4A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 4 +NEWSYM FxOpA5A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 5 +NEWSYM FxOpA6A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 6 +NEWSYM FxOpA7A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 7 +NEWSYM FxOpA8A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 8 +NEWSYM FxOpA9A2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 9 +NEWSYM FxOpAAA2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 10 +NEWSYM FxOpABA2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 11 +NEWSYM FxOpACA2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 12 +NEWSYM FxOpADA2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 13 +NEWSYM FxOpAEA2 ; SMS (yy),rn store word in RAM (short address) + SMSRN 14 +NEWSYM FxOpAFA2 ; SMS (yy),rn store word in RAM (short address) + xor eax,eax + mov ebx,ebp + sub ebx,[SfxCPB] + mov al,[ebp] + inc ebp + add eax,eax + FETCHPIPE + add eax,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax + inc ebp + mov [eax],bx ; Write word to ram + CLRFLAGS + ret + +NEWSYM FxOpB0 ; FROM rn set source register + FROMRN 0 +NEWSYM FxOpB1 ; FROM rn set source register + FROMRN 1 +NEWSYM FxOpB2 ; FROM rn set source register + FROMRN 2 +NEWSYM FxOpB3 ; FROM rn set source register + FROMRN 3 +NEWSYM FxOpB4 ; FROM rn set source register + FROMRN 4 +NEWSYM FxOpB5 ; FROM rn set source register + FROMRN 5 +NEWSYM FxOpB6 ; FROM rn set source register + FROMRN 6 +NEWSYM FxOpB7 ; FROM rn set source register + FROMRN 7 +NEWSYM FxOpB8 ; FROM rn set source register + FROMRN 8 +NEWSYM FxOpB9 ; FROM rn set source register + FROMRN 9 +NEWSYM FxOpBA ; FROM rn set source register + FROMRN 10 +NEWSYM FxOpBB ; FROM rn set source register + FROMRN 11 +NEWSYM FxOpBC ; FROM rn set source register + FROMRN 12 +NEWSYM FxOpBD ; FROM rn set source register + FROMRN 13 +NEWSYM FxOpBE ; FROM rn set source register + FROMRN 14 +NEWSYM FxOpBF ; FROM rn set source register + FETCHPIPE + mov esi,SfxR0+15*4 + inc ebp ; Increase program counter + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTableb+ecx*4] + mov esi,SfxR0 + ret + +NEWSYM FxOpC0 ; HIB move high-byte to low-byte ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,0FF00h + mov dword [SfxSignZero],eax + shr eax,8 + inc ebp + mov [edi],eax + CLRFLAGS + ret + +NEWSYM FxOpC1 ; OR rn or rn + ORRN 1 +NEWSYM FxOpC2 ; OR rn or rn + ORRN 2 +NEWSYM FxOpC3 ; OR rn or rn + ORRN 3 +NEWSYM FxOpC4 ; OR rn or rn + ORRN 4 +NEWSYM FxOpC5 ; OR rn or rn + ORRN 5 +NEWSYM FxOpC6 ; OR rn or rn + ORRN 6 +NEWSYM FxOpC7 ; OR rn or rn + ORRN 7 +NEWSYM FxOpC8 ; OR rn or rn + ORRN 8 +NEWSYM FxOpC9 ; OR rn or rn + ORRN 9 +NEWSYM FxOpCA ; OR rn or rn + ORRN 10 +NEWSYM FxOpCB ; OR rn or rn + ORRN 11 +NEWSYM FxOpCC ; OR rn or rn + ORRN 12 +NEWSYM FxOpCD ; OR rn or rn + ORRN 13 +NEWSYM FxOpCE ; OR rn or rn + ORRN 14 +NEWSYM FxOpCF ; OR rn or rn + mov eax,[esi] ; Read Source + mov ebx,ebp + FETCHPIPE + sub ebx,[SfxCPB] + or eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOpC1A1 ; XOR rn xor rn + XORRN 1 +NEWSYM FxOpC2A1 ; XOR rn xor rn + XORRN 2 +NEWSYM FxOpC3A1 ; XOR rn xor rn + XORRN 3 +NEWSYM FxOpC4A1 ; XOR rn xor rn + XORRN 4 +NEWSYM FxOpC5A1 ; XOR rn xor rn + XORRN 5 +NEWSYM FxOpC6A1 ; XOR rn xor rn + XORRN 6 +NEWSYM FxOpC7A1 ; XOR rn xor rn + XORRN 7 +NEWSYM FxOpC8A1 ; XOR rn xor rn + XORRN 8 +NEWSYM FxOpC9A1 ; XOR rn xor rn + XORRN 9 +NEWSYM FxOpCAA1 ; XOR rn xor rn + XORRN 10 +NEWSYM FxOpCBA1 ; XOR rn xor rn + XORRN 11 +NEWSYM FxOpCCA1 ; XOR rn xor rn + XORRN 12 +NEWSYM FxOpCDA1 ; XOR rn xor rn + XORRN 13 +NEWSYM FxOpCEA1 ; XOR rn xor rn + XORRN 14 +NEWSYM FxOpCFA1 ; XOR rn xor rn + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + xor eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + ret + +NEWSYM FxOpC1A2 ; OR #n OR #n + ORI 1 +NEWSYM FxOpC2A2 ; OR #n OR #n + ORI 2 +NEWSYM FxOpC3A2 ; OR #n OR #n + ORI 3 +NEWSYM FxOpC4A2 ; OR #n OR #n + ORI 4 +NEWSYM FxOpC5A2 ; OR #n OR #n + ORI 5 +NEWSYM FxOpC6A2 ; OR #n OR #n + ORI 6 +NEWSYM FxOpC7A2 ; OR #n OR #n + ORI 7 +NEWSYM FxOpC8A2 ; OR #n OR #n + ORI 8 +NEWSYM FxOpC9A2 ; OR #n OR #n + ORI 9 +NEWSYM FxOpCAA2 ; OR #n OR #n + ORI 10 +NEWSYM FxOpCBA2 ; OR #n OR #n + ORI 11 +NEWSYM FxOpCCA2 ; OR #n OR #n + ORI 12 +NEWSYM FxOpCDA2 ; OR #n OR #n + ORI 13 +NEWSYM FxOpCEA2 ; OR #n OR #n + ORI 14 +NEWSYM FxOpCFA2 ; OR #n OR #n + ORI 15 + +NEWSYM FxOpC1A3 ; XOR #n xor #n + XORI 1 +NEWSYM FxOpC2A3 ; XOR #n xor #n + XORI 2 +NEWSYM FxOpC3A3 ; XOR #n xor #n + XORI 3 +NEWSYM FxOpC4A3 ; XOR #n xor #n + XORI 4 +NEWSYM FxOpC5A3 ; XOR #n xor #n + XORI 5 +NEWSYM FxOpC6A3 ; XOR #n xor #n + XORI 6 +NEWSYM FxOpC7A3 ; XOR #n xor #n + XORI 7 +NEWSYM FxOpC8A3 ; XOR #n xor #n + XORI 8 +NEWSYM FxOpC9A3 ; XOR #n xor #n + XORI 9 +NEWSYM FxOpCAA3 ; XOR #n xor #n + XORI 10 +NEWSYM FxOpCBA3 ; XOR #n xor #n + XORI 11 +NEWSYM FxOpCCA3 ; XOR #n xor #n + XORI 12 +NEWSYM FxOpCDA3 ; XOR #n xor #n + XORI 13 +NEWSYM FxOpCEA3 ; XOR #n xor #n + XORI 14 +NEWSYM FxOpCFA3 ; XOR #n xor #n + XORI 15 + +NEWSYM FxOpD0 ; INC rn increase by one + INCRN 0 +NEWSYM FxOpD1 ; INC rn increase by one + INCRN 1 +NEWSYM FxOpD2 ; INC rn increase by one + INCRN 2 +NEWSYM FxOpD3 ; INC rn increase by one + INCRN 3 +NEWSYM FxOpD4 ; INC rn increase by one + INCRN 4 +NEWSYM FxOpD5 ; INC rn increase by one + INCRN 5 +NEWSYM FxOpD6 ; INC rn increase by one + INCRN 6 +NEWSYM FxOpD7 ; INC rn increase by one + INCRN 7 +NEWSYM FxOpD8 ; INC rn increase by one + INCRN 8 +NEWSYM FxOpD9 ; INC rn increase by one + INCRN 9 +NEWSYM FxOpDA ; INC rn increase by one + INCRN 10 +NEWSYM FxOpDB ; INC rn increase by one + INCRN 11 +NEWSYM FxOpDC ; INC rn increase by one + INCRN 12 +NEWSYM FxOpDD ; INC rn increase by one + INCRN 13 +NEWSYM FxOpDE ; INC rn increase by one + FETCHPIPE + mov eax,[SfxR0+14*4] ; Read Source + inc ax + mov [SfxR0+14*4],eax + mov [SfxSignZero],eax + CLRFLAGS + inc ebp + UpdateR14 + ret + +NEWSYM FxOpDF ; GETC transfer ROM buffer to color register + mov eax,[SfxRomBuffer] + FETCHPIPE + mov eax,[eax] + test byte[SfxPOR],04h + jz .nohighnibble + mov bl,al + shr bl,4 + and al,0F0h + or al,bl +.nohighnibble + test byte[SfxPOR],08h + jnz .preserveupper + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx +.nocolchange + CLRFLAGS + inc ebp ; Increase program counter + ret +.preserveupper + mov bl,[SfxCOLR] + and al,0Fh + and bl,0F0h + or al,bl + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + CLRFLAGS + inc ebp ; Increase program counter + ret + +NEWSYM FxOpDFA2 ; RAMB set current RAM bank ; Verified + mov eax,[esi] ; Read Source + mov ebx,[SfxnRamBanks] + FETCHPIPE + dec ebx + and eax,ebx + mov dword [SfxRAMBR],eax + shl eax,16 + add eax,[sfxramdata] + mov dword [SfxRAMMem],eax + CLRFLAGS + inc ebp + ret + +NEWSYM FxOpDFA3 ; ROMB set current ROM bank ; Verified + mov eax,[esi] ; Read Source + and eax,07Fh + FETCHPIPE + mov dword [SfxROMBR],eax + mov eax,[SfxMemTable+eax*4] + mov [SfxCROM],eax + CLRFLAGS + inc ebp + ret + +NEWSYM FxOpE0 ; DEC rn decrement by one + DECRN 0 +NEWSYM FxOpE1 ; DEC rn decrement by one + DECRN 1 +NEWSYM FxOpE2 ; DEC rn decrement by one + DECRN 2 +NEWSYM FxOpE3 ; DEC rn decrement by one + DECRN 3 +NEWSYM FxOpE4 ; DEC rn decrement by one + DECRN 4 +NEWSYM FxOpE5 ; DEC rn decrement by one + DECRN 5 +NEWSYM FxOpE6 ; DEC rn decrement by one + DECRN 6 +NEWSYM FxOpE7 ; DEC rn decrement by one + DECRN 7 +NEWSYM FxOpE8 ; DEC rn decrement by one + DECRN 8 +NEWSYM FxOpE9 ; DEC rn decrement by one + DECRN 9 +NEWSYM FxOpEA ; DEC rn decrement by one + DECRN 10 +NEWSYM FxOpEB ; DEC rn decrement by one + DECRN 11 +NEWSYM FxOpEC ; DEC rn decrement by one + DECRN 12 +NEWSYM FxOpED ; DEC rn decrement by one + DECRN 13 +NEWSYM FxOpEE ; DEC rn decrement by one + dec word[SfxR0+14*4] + FETCHPIPE + mov eax,[SfxR0+14*4] ; Read Source + mov [SfxSignZero],eax + UpdateR14 + CLRFLAGS + inc ebp + ret + +NEWSYM FxOpEF ; getb get byte from ROM at address R14 ; V + FETCHPIPE + mov eax,[SfxRomBuffer] + inc ebp + mov eax,[eax] + and eax,0FFh +; cmp edi,SfxR15 +; je .nor15 + mov [edi],eax ; Write DREG + CLRFLAGS + ret +.nor15 +; mov eax,ebp +; sub eax,[SfxCPB] +; mov [SfxR15],al + or eax,8000h + mov [edi],eax ; Write DREG + CLRFLAGS + ret + +NEWSYM FxOpEFA1 ; getbh get high-byte from ROM at address R14 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxRomBuffer] + and eax,0FFh + FETCHPIPE + mov ah,[ebx] + inc ebp + mov [edi],eax ; Write DREG + CLRFLAGS + ret + +NEWSYM FxOpEFA2 ; getbl get low-byte from ROM at address R14 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxRomBuffer] + and eax,0FF00h + FETCHPIPE + mov al,[ebx] + inc ebp + mov [edi],eax ; Write DREG + CLRFLAGS + ret + +NEWSYM FxOpEFA3 ; getbs get sign extended byte from ROM at address R14 ; V + mov ebx,[SfxRomBuffer] + FETCHPIPE + movsx eax,byte[ebx] + inc ebp + mov [edi],ax ; Write DREG + CLRFLAGS + ret + +NEWSYM FxOpF0 ; IWT RN,#xx immediate word transfer to register + IWTRN 0 +NEWSYM FxOpF1 ; IWT RN,#xx immediate word transfer to register + IWTRN 1 +NEWSYM FxOpF2 ; IWT RN,#xx immediate word transfer to register + IWTRN 2 +NEWSYM FxOpF3 ; IWT RN,#xx immediate word transfer to register + IWTRN 3 +NEWSYM FxOpF4 ; IWT RN,#xx immediate word transfer to register + IWTRN 4 +NEWSYM FxOpF5 ; IWT RN,#xx immediate word transfer to register + IWTRN 5 +NEWSYM FxOpF6 ; IWT RN,#xx immediate word transfer to register + IWTRN 6 +NEWSYM FxOpF7 ; IWT RN,#xx immediate word transfer to register + IWTRN 7 +NEWSYM FxOpF8 ; IWT RN,#xx immediate word transfer to register + IWTRN 8 +NEWSYM FxOpF9 ; IWT RN,#xx immediate word transfer to register + IWTRN 9 +NEWSYM FxOpFA ; IWT RN,#xx immediate word transfer to register + IWTRN 10 +NEWSYM FxOpFB ; IWT RN,#xx immediate word transfer to register + IWTRN 11 +NEWSYM FxOpFC ; IWT RN,#xx immediate word transfer to register + IWTRN 12 +NEWSYM FxOpFD ; IWT RN,#xx immediate word transfer to register + IWTRN 13 +NEWSYM FxOpFE ; IWT RN,#xx immediate word transfer to register + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + add ebp,3 + mov [SfxR0+14*4],eax + UpdateR14 + CLRFLAGS + ret +NEWSYM FxOpFF ; IWT RN,#xx immediate word transfer to register + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + ret + +NEWSYM FxOpF0A1 ; LM RN,(XX) load word from RAM + LMRN 0 +NEWSYM FxOpF1A1 ; LM RN,(XX) load word from RAM + LMRN 1 +NEWSYM FxOpF2A1 ; LM RN,(XX) load word from RAM + LMRN 2 +NEWSYM FxOpF3A1 ; LM RN,(XX) load word from RAM + LMRN 3 +NEWSYM FxOpF4A1 ; LM RN,(XX) load word from RAM + LMRN 4 +NEWSYM FxOpF5A1 ; LM RN,(XX) load word from RAM + LMRN 5 +NEWSYM FxOpF6A1 ; LM RN,(XX) load word from RAM + LMRN 6 +NEWSYM FxOpF7A1 ; LM RN,(XX) load word from RAM + LMRN 7 +NEWSYM FxOpF8A1 ; LM RN,(XX) load word from RAM + LMRN 8 +NEWSYM FxOpF9A1 ; LM RN,(XX) load word from RAM + LMRN 9 +NEWSYM FxOpFAA1 ; LM RN,(XX) load word from RAM + LMRN 10 +NEWSYM FxOpFBA1 ; LM RN,(XX) load word from RAM + LMRN 11 +NEWSYM FxOpFCA1 ; LM RN,(XX) load word from RAM + LMRN 12 +NEWSYM FxOpFDA1 ; LM RN,(XX) load word from RAM + LMRN 13 +NEWSYM FxOpFEA1 ; LM RN,(XX) load word from RAM + xor eax,eax + mov cl,[ebp+2] + mov ax,[ebp] + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov dl,[eax+ebx] + xor eax,1 + add ebp,3 + mov dh,[eax+ebx] + mov word [SfxR0+14*4],dx ; Store Word + UpdateR14 + CLRFLAGS + ret +NEWSYM FxOpFFA1 ; LM RN,(XX) load word from RAM + FETCHPIPE + mov eax,ecx + inc ebp + FETCHPIPE + inc ebp + mov ah,cl + FETCHPIPE + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov dl,[eax+ebx] + xor eax,1 + mov dh,[eax+ebx] + and edx,0FFFFh + mov ebp,[SfxCPB] + add ebp,edx + CLRFLAGS + ret + +NEWSYM FxOpF0A2 ; SM (XX),RN store word in RAM + SMRN 0 +NEWSYM FxOpF1A2 ; SM (XX),RN store word in RAM + SMRN 1 +NEWSYM FxOpF2A2 ; SM (XX),RN store word in RAM + SMRN 2 +NEWSYM FxOpF3A2 ; SM (XX),RN store word in RAM + SMRN 3 +NEWSYM FxOpF4A2 ; SM (XX),RN store word in RAM + SMRN 4 +NEWSYM FxOpF5A2 ; SM (XX),RN store word in RAM + SMRN 5 +NEWSYM FxOpF6A2 ; SM (XX),RN store word in RAM + SMRN 6 +NEWSYM FxOpF7A2 ; SM (XX),RN store word in RAM + SMRN 7 +NEWSYM FxOpF8A2 ; SM (XX),RN store word in RAM + SMRN 8 +NEWSYM FxOpF9A2 ; SM (XX),RN store word in RAM + SMRN 9 +NEWSYM FxOpFAA2 ; SM (XX),RN store word in RAM + SMRN 10 +NEWSYM FxOpFBA2 ; SM (XX),RN store word in RAM + SMRN 11 +NEWSYM FxOpFCA2 ; SM (XX),RN store word in RAM + SMRN 12 +NEWSYM FxOpFDA2 ; SM (XX),RN store word in RAM + SMRN 13 +NEWSYM FxOpFEA2 ; SM (XX),RN store word in RAM + SMRN 14 +NEWSYM FxOpFFA2 ; SM (XX),RN store word in RAM + FETCHPIPE + mov ebx,ebp + sub ebx,[SfxCPB] + mov eax,ecx + inc ebp + FETCHPIPE + inc ebp + mov ah,cl + FETCHPIPE + mov dx,bx + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov [eax+ebx],dl + xor eax,1 + inc ebp + mov [eax+ebx],dh + CLRFLAGS + ret + +ALIGN32 +NEWSYM NumberOfOpcodes, dd 0 ; Number of opcodes to execute +NEWSYM NumberOfOpcodesBU, dd 0 ; Number of opcodes to execute backup value +NEWSYM sfxwarningb, db 0 + +NEWSYM MainLoop + mov eax,[SfxPBR] + and eax,0FFh +; mov byte[fxtrace+eax],1 + mov ebp,[SfxCPB] + add ebp,[SfxR15] + xor ecx,ecx + mov cl,[SfxPIPE] + mov ch,[SfxSFR+1] + and ch,03h + ; pack esi/edi + PackEsiEdi + jmp [FxTabled+ecx*4] + jmp .LoopAgain +ALIGN16 +.LoopAgain + call [FxTable+ecx*4] + dec dword [NumberOfOpcodes] + jnz .LoopAgain +.EndLoop +NEWSYM FXEndLoop + sub ebp,[SfxCPB] + mov [SfxR15],ebp + mov [SfxPIPE],cl + and byte[SfxSFR+1],0FFh-03h + or [SfxSFR+1],ch + UnPackEsiEdi + ret + +SECTION .data +NEWSYM fxtrace, db 0; times 65536 db 0 + + \ No newline at end of file diff --git a/zsnes/src/chips/fxemu2.mac b/zsnes/src/chips/fxemu2.mac new file mode 100644 index 00000000..001c27c3 --- /dev/null +++ b/zsnes/src/chips/fxemu2.mac @@ -0,0 +1,835 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + + +%macro FETCHPIPE 0 +; mov edx,[SfxPBR] +; mov edx,[SfxMemTable+edx*4] +; mov edx,[SfxCPB] +; mov edx,[SfxR15] + mov cl,[ebp] +%endmacro + +%macro UpdateR14 0 +; mov edx,[SfxROMBR] +; mov edx,[SfxMemTable+edx*4] + mov eax,[SfxCROM] +; and dword[SfxR14],0FFFFh + add eax,[SfxR14] + mov [SfxRomBuffer],eax +%endmacro + +%macro UpdateR15 0 + mov ebp,[SfxCPB] + add ebp,[SfxR15] +%endmacro + +%macro CLRFLAGS 0 + ;and dword [SfxSFR],0FFFFh-0100h-0200h-1000h ; Clear ALT1,ALT2 and B Flags +; xor ch,ch +; mov dword [SfxB],0 ; Clear B Flag +; mov esi,SfxR0 +; mov edi,SfxR0 +%endmacro + +%macro TORN 1 ; V + FETCHPIPE + mov edi, SfxR0+%1*4 + inc ebp ; Increase program counter + call [FxTable+ecx*4] + mov edi,SfxR0 + ret +%endmacro + +%macro WITH 1 ; Verified. + FETCHPIPE + mov esi,SfxR0+%1*4 + mov edi,SfxR0+%1*4 + mov dword [SfxB],1 + inc ebp ; Increase program counter + call [FxTablec+ecx*4] + mov esi,SfxR0 + mov edi,SfxR0 + mov dword [SfxB],0 ; Clear B Flag + ret +%endmacro + +%macro STWRN 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + mov ebx,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax ; Save last ram address + add dword [SfxLastRamAdr],ebx ; Save last ram address + mov edx,[esi] ; Read Source + FETCHPIPE + mov [ebx+eax],dl ; Store Word + xor eax,1 + inc ebp ; Increase program counter + mov [ebx+eax],dh ; Store Word + CLRFLAGS + ret +%endmacro + +%macro STBRN 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + FETCHPIPE + add eax,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax ; Save last ram address + mov ebx,[esi] ; Read Source + mov byte [eax],bl ; Store Byte + CLRFLAGS + inc ebp ; Increase program counter + ret +%endmacro + +%macro LDWRN 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + mov ebx,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax ; Save last ram address + FETCHPIPE + mov dl,[ebx+eax] ; Store Word + add dword [SfxLastRamAdr],ebx ; Save last ram address + xor eax,1 + and edx,0FFFFh + inc ebp ; Increase program counter + mov dh,[ebx+eax] ; Store Word + mov [edi],edx ; Read Source + CLRFLAGS + ret +%endmacro + +%macro LDBRN 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + FETCHPIPE + add eax,[SfxRAMMem] + xor ebx,ebx + mov dword [SfxLastRamAdr],eax ; Save last ram address + mov bl,[eax] ; Read Byte + inc ebp ; Increase program counter + mov [edi],ebx ; Store Result + CLRFLAGS + ret +%endmacro + +; test byte[SfxPOR],01h +; jnz .nozerocheck +; test byte[SfxPOR],02h +; jz .nodither + +; **** Can pre-calculate [SfxSCBR] << 10 + [sfxramdata] +; Pre-calculate fxbit values from color register + +%macro drawpix4b 0 + and [eax],edx + and [eax+16],edx + xor edx,0FFFFFFFFh + mov ebx,[fxbit01pcal] + and ebx,edx + or [eax], ebx + and edx,[fxbit23pcal] + or [eax+16], edx +%endmacro + +%macro drawpix4bd 0 + and [eax],edx + and [eax+16],edx + xor edx,0FFFFFFFFh + mov ebx,[fxbit45pcal] + and ebx,edx + or [eax], ebx + and edx,[fxbit67pcal] + or [eax+16], edx +%endmacro + +%macro drawpix2b 0 + and [eax],edx + xor edx,0FFFFFFFFh + and edx,[fxbit01pcal] + or [eax], edx +%endmacro + +%macro drawpix2bd 0 + and [eax],edx + xor edx,0FFFFFFFFh + and edx,[fxbit45pcal] + or [eax], edx +%endmacro + +%macro drawpix8b 0 + and [eax],edx + and [eax+16],edx + and [eax+32],edx + and [eax+48],edx + xor edx,0FFFFFFFFh + mov ebx,[fxbit01pcal] + and ebx,edx + or [eax], ebx + mov ebx,[fxbit23pcal] + and ebx,edx + or [eax+16], ebx + mov ebx,[fxbit45pcal] + and ebx,edx + or [eax+32], ebx + and edx,[fxbit67pcal] + or [eax+48], edx +%endmacro + +%macro drawpix8bd 0 + and [eax],edx + and [eax+16],edx + and [eax+32],edx + and [eax+48],edx + xor edx,0FFFFFFFFh + mov ebx,[fxbit45pcal] + and ebx,edx + or [eax], ebx + mov ebx,[fxbit67pcal] + and ebx,edx + or [eax+16], ebx + mov ebx,[fxbit01pcal] + and ebx,edx + or [eax+32], ebx + and edx,[fxbit23pcal] + or [eax+48], edx +%endmacro + +%macro plotb 5 + shl eax,%3 + and ebx,07h + add ebx,ebx + add eax,ebx + add eax,[SCBRrel] + mov bl,[SfxR1] + mov edx,[fxxand+ebx*4] + %2 +%endmacro + +%macro plotbz 5 + shl eax,%3 + and ebx,07h + add ebx,ebx + add eax,ebx + add eax,[SCBRrel] + mov bl,[SfxR1] + mov edx,[fxxand+ebx*4] + test byte[SfxCOLR],%5 + jz .nodraw + %2 +%endmacro + +%macro plotbd 5 + shl eax,%3 + and ebx,07h + add ebx,ebx + add eax,ebx + add eax,[SCBRrel] + mov bl,[SfxR1] + mov edx,[fxxand+ebx*4] + mov bl,[SfxR1] + xor bl,[SfxR2] + test bl,01h + jz near .nodither4b + %4 + inc word [SfxR1] + %1 +.nodither4b + %2 +%endmacro + +%macro plotbzd 5 + shl eax,%3 + and ebx,07h + add ebx,ebx + add eax,ebx + add eax,[SCBRrel] + mov bl,[SfxR1] + mov edx,[fxxand+ebx*4] + test byte[SfxCOLR],%5 + jz near .nodraw + mov bl,[SfxR1] + xor bl,[SfxR2] + test bl,01h + jz .nodither4b + %4 + inc word [SfxR1] + %1 +.nodither4b + %2 +%endmacro + +%macro plotlines4b 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 ret, drawpix4b, 5, drawpix4bd, 0Fh +.nodraw + inc word [SfxR1] + ret +%endmacro + +%macro plotlines4bb 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 FXReturn, drawpix4b, 5, drawpix4bd, 0Fh +.nodraw + inc word [SfxR1] + FXReturn +%endmacro + +%macro plotlines2b 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 ret, drawpix2b, 4, drawpix2bd, 03h +.nodraw + inc word [SfxR1] + ret +%endmacro + +%macro plotlines2bb 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 FXReturn, drawpix2b, 4, drawpix2bd, 03h +.nodraw + inc word [SfxR1] + FXReturn +%endmacro + +%macro plotlines8b 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 ret, drawpix8b, 6, drawpix8bd, 0FFh +.nodraw + inc word [SfxR1] + ret +%endmacro + +%macro plotlines8bb 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 FXReturn, drawpix8b, 6, drawpix8bd, 0FFh +.nodraw + inc word [SfxR1] + FXReturn +%endmacro + +%macro plotlines8bl 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 ret, drawpix8b, 6, drawpix8bd, 0Fh +.nodraw + inc word [SfxR1] + ret +%endmacro + +%macro plotlines8bbl 1 + mov ebx,[SfxR2] + FETCHPIPE + mov bh,[SfxR1] + mov eax,[sfxclineloc] + inc ebp + mov eax,[eax+ebx*4] + cmp eax,0FFFFFFFFh + je near .nodraw + %1 FXReturn, drawpix8b, 6, drawpix8bd, 0Fh +.nodraw + inc word [SfxR1] + FXReturn +%endmacro + +%macro ADDRN 1 ; V + mov eax, [esi] ; Read Source + mov ebx, [SfxR0+%1*4] + FETCHPIPE + add ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro ADCRN 1 ; V + FETCHPIPE + mov eax, [esi] ; Read Source + mov ebx, [SfxR0+%1*4] + shr byte[SfxCarry],1 + adc ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro ADIRN 1 ; V + mov eax, [esi] ; Read Source + FETCHPIPE + add ax,%1 + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro ADCIRN 1 ; V + FETCHPIPE + mov eax, [esi] ; Read Source + shr byte[SfxCarry],1 + adc ax,%1 + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro SUBRN 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] + FETCHPIPE + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro SBCRN 1 ; V + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] + cmp byte[SfxCarry],1 + sbb ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro SUBIRN 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + sub ax,%1 + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro CMPRN 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] + FETCHPIPE + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + mov [SfxSignZero],eax + CLRFLAGS + inc ebp ; Increase program counter + ret +%endmacro + +%macro ANDRN 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] ; Read RN + FETCHPIPE + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro BICRN 1 ; V + mov ebx,[SfxR0+%1*4] ; Read RN + mov eax,[esi] ; Read Source + xor ebx,0FFFFh + FETCHPIPE + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro ANDIRN 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,%1 + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro BICIRN 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,%1 + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro MULTRN 1 ; V + mov al,byte [esi] ; Read Source + mov bl,byte [SfxR0+%1*4] ; Read RN + FETCHPIPE + imul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro UMULTRN 1 ; V + mov al,byte [esi] ; Read Source + mov bl,byte [SfxR0+%1*4] ; Read RN + FETCHPIPE + mul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro MULTIRN 1 ; V + mov al,byte [esi] ; Read Source + mov bl,%1 ; Read RN + FETCHPIPE + imul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro UMULTIRN 1 ; V + mov al,byte [esi] ; Read Source + mov bl,%1 ; Read RN + FETCHPIPE + mul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + ret +%endmacro + +%macro LINK 1 ; Verified. + mov eax,ebp + sub eax,[SfxCPB] + add eax,%1 + FETCHPIPE + mov word [SfxR11],ax + CLRFLAGS + inc ebp + ret +%endmacro + +%macro JMPRN 1 ; V + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read RN + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + ret +%endmacro + +%macro LJMPRN 1 ; V + FETCHPIPE + mov eax,[SfxR0+%1*4] + and eax,07Fh + mov byte[SfxPBR],al +; mov byte[fxtrace+eax],1 + mov eax,[SfxMemTable+eax*4] + mov [SfxCPB],eax + mov ebp,eax + add ebp,[esi] ; Read RN + mov dword [SfxCacheActive],0 + push ecx + call FxOp02 + pop ecx + dec ebp + ret +%endmacro + +%macro IBTRN 1 ; V + movsx eax,byte[ebp] + mov cl,[ebp+1] + add ebp,2 + mov [SfxR0+%1*4],ax + CLRFLAGS + ret +%endmacro + +%macro LMSRN 1 ; Verified. + xor eax,eax + mov al,[ebp] + add eax,eax + inc ebp + add eax,[SfxRAMMem] + mov cl,[ebp] + mov dword [SfxLastRamAdr],eax + mov ebx,[eax] ; Read word from ram + inc ebp + mov [SfxR0+%1*4],bx ; Write data + CLRFLAGS + ret +%endmacro + +%macro SMSRN 1 ; Verified. + xor eax,eax + mov al,[ebp] + inc ebp + add eax,eax + mov cl,[ebp] + add eax,[SfxRAMMem] + mov ebx,[SfxR0+%1*4] ; Read data + mov dword [SfxLastRamAdr],eax + inc ebp + mov [eax],bx ; Write word to ram + CLRFLAGS + ret +%endmacro + +%macro FROMRN 1 ; V + FETCHPIPE + mov esi,SfxR0+%1*4 + inc ebp ; Increase program counter + call [FxTable+ecx*4] + mov esi,SfxR0 + ret +%endmacro + +%macro ORRN 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] ; Read + FETCHPIPE + or eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro XORRN 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] ; Read + FETCHPIPE + xor eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro ORI 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + or eax,%1 + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro XORI 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + xor eax,%1 + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + ret +%endmacro + +%macro INCRN 1 ; Verified + inc word[SfxR0+%1*4] + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read Source + mov [SfxSignZero],eax + CLRFLAGS + inc ebp + ret +%endmacro + +%macro DECRN 1 ; Verified + dec word[SfxR0+%1*4] + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read Source + mov [SfxR0+%1*4],eax + mov [SfxSignZero],eax + CLRFLAGS + inc ebp + ret +%endmacro + +%macro IWTRN 1 ; aka LEA ; Verified. + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + add ebp,3 + mov [SfxR0+%1*4],eax + CLRFLAGS + ret +%endmacro + +%macro LMRN 1 ; Verified! + xor eax,eax + mov cl,[ebp+2] + mov ax,[ebp] + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov dl,[eax+ebx] + xor eax,1 + add ebp,3 + mov dh,[eax+ebx] + mov word [SfxR0+%1*4],dx ; Store Word + CLRFLAGS + ret +%endmacro + +%macro SMRN 1 ; Verified + mov ebx,[SfxR0+%1*4] + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + mov dx,bx + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov [eax+ebx],dl + xor eax,1 + add ebp,3 + mov [eax+ebx],dh + CLRFLAGS + ret +%endmacro + +%macro PackEsiEdi 0 + mov eax,[SfxSREG] + shl eax,2 + add eax,SfxR0 + mov esi,eax + mov eax,[SfxDREG] + shl eax,2 + add eax,SfxR0 + mov edi,eax + mov eax,[SfxRAMBR] + shl eax,16 + add eax,[sfxramdata] + mov dword [SfxRAMMem],eax +%endmacro + +%macro UnPackEsiEdi 0 + mov eax,esi + sub eax,SfxR0 + shr eax,2 + mov [SfxSREG],eax + mov eax,edi + sub eax,SfxR0 + shr eax,2 + mov [SfxDREG],eax +%endmacro + \ No newline at end of file diff --git a/zsnes/src/chips/fxemu2b.asm b/zsnes/src/chips/fxemu2b.asm new file mode 100644 index 00000000..2d161006 --- /dev/null +++ b/zsnes/src/chips/fxemu2b.asm @@ -0,0 +1,614 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM FxTable,FxTableb,FxTablec,SfxB,SfxCPB,SfxCROM,SfxCarry,SfxOverflow +EXTSYM SfxR0,SfxR14,SfxR15,SfxRomBuffer,SfxSignZero,withr15sk + +%include "chips/fxemu2.mac" +%include "chips/fxemu2b.mac" + + + + + + +NEWSYM FxOpb05 ; BRA branch always ; Verified. + movsx eax,byte[ebp] + mov cl,[ebp+1] + inc ebp + add ebp,eax + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb06 ; BGE branch on greater or equals ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jnz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb07 ; BLT branch on lesss than ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb08 ; BNE branch on not equal ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb09 ; BEQ branch on equal (z=1) ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb0A ; BPL branch on plus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb0B ; BMI branch on minus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb0C ; BCC branch on carry clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb0D ; BCS branch on carry set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb0E ; BVC branch on overflow clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb0F ; BVS branch on overflow set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTableb+ecx*4] + ret +.nojump + inc ebp + call [FxTableb+ecx*4] + ret + +NEWSYM FxOpb10 ; TO RN set register n as destination register + TORNb 0 +NEWSYM FxOpb11 ; TO RN set register n as destination register + TORNb 1 +NEWSYM FxOpb12 ; TO RN set register n as destination register + TORNb 2 +NEWSYM FxOpb13 ; TO RN set register n as destination register + TORNb 3 +NEWSYM FxOpb14 ; TO RN set register n as destination register + TORNb 4 +NEWSYM FxOpb15 ; TO RN set register n as destination register + TORNb 5 +NEWSYM FxOpb16 ; TO RN set register n as destination register + TORNb 6 +NEWSYM FxOpb17 ; TO RN set register n as destination register + TORNb 7 +NEWSYM FxOpb18 ; TO RN set register n as destination register + TORNb 8 +NEWSYM FxOpb19 ; TO RN set register n as destination register + TORNb 9 +NEWSYM FxOpb1A ; TO RN set register n as destination register + TORNb 10 +NEWSYM FxOpb1B ; TO RN set register n as destination register + TORNb 11 +NEWSYM FxOpb1C ; TO RN set register n as destination register + TORNb 12 +NEWSYM FxOpb1D ; TO RN set register n as destination register + TORNb 13 +NEWSYM FxOpb1E ; TO RN set register n as destination register + FETCHPIPE + test dword [SfxB],1 + jnz .VersionB + mov edi,SfxR0+14*4 + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov dword[withr15sk],1 + mov [SfxR15],eax + call [FxTableb+ecx*4] + mov edi,SfxR0 + UpdateR14 + ret +.VersionB + mov eax,[esi] ; Read Source + mov dword[withr15sk],1 + mov [SfxR0+14*4],eax ; Write + CLRFLAGS + UpdateR14 + inc ebp ; Increase program counter + ret +NEWSYM FxOpb1F ; TO RN set register n as destination register + FETCHPIPE + test dword [SfxB],1 + jnz .VersionB + mov edi,SfxR0+15*4 + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTableb+ecx*4] + mov ebp,[SfxCPB] + mov dword[withr15sk],1 + add ebp,[SfxR15] + mov edi,SfxR0 + ret +.VersionB + mov eax,[esi] ; Read Source + mov ebp,[SfxCPB] + mov dword[withr15sk],1 + add ebp,eax + CLRFLAGS + ret + +NEWSYM FxOpb3D ; ALT1 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,01h + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTableb+ecx*4] + xor ch,ch + ret + +NEWSYM FxOpb3E ; ALT2 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,02h + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTable+ecx*4] + xor ch,ch + ret + +NEWSYM FxOpb3F ; ALT3 set alt3 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,03h + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTable+ecx*4] + xor ch,ch + ret + +NEWSYM FxOpbB0 ; FROM rn set source register + FROMRNb 0 +NEWSYM FxOpbB1 ; FROM rn set source register + FROMRNb 1 +NEWSYM FxOpbB2 ; FROM rn set source register + FROMRNb 2 +NEWSYM FxOpbB3 ; FROM rn set source register + FROMRNb 3 +NEWSYM FxOpbB4 ; FROM rn set source register + FROMRNb 4 +NEWSYM FxOpbB5 ; FROM rn set source register + FROMRNb 5 +NEWSYM FxOpbB6 ; FROM rn set source register + FROMRNb 6 +NEWSYM FxOpbB7 ; FROM rn set source register + FROMRNb 7 +NEWSYM FxOpbB8 ; FROM rn set source register + FROMRNb 8 +NEWSYM FxOpbB9 ; FROM rn set source register + FROMRNb 9 +NEWSYM FxOpbBA ; FROM rn set source register + FROMRNb 10 +NEWSYM FxOpbBB ; FROM rn set source register + FROMRNb 11 +NEWSYM FxOpbBC ; FROM rn set source register + FROMRNb 12 +NEWSYM FxOpbBD ; FROM rn set source register + FROMRNb 13 +NEWSYM FxOpbBE ; FROM rn set source register + FROMRNb 14 +NEWSYM FxOpbBF ; FROM rn set source register + test dword [SfxB],1 + jnz .VersionB + mov esi,SfxR0+15*4 + inc ebp ; Increase program counter + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTableb+ecx*4] + mov esi,SfxR0 + ret +.VersionB + FETCHPIPE + mov eax,ebp + sub eax,[SfxCPB] + inc ebp + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + shr al,7 + mov byte[SfxOverflow],al + CLRFLAGS + ret + +NEWSYM FxOpc05 ; BRA branch always ; Verified. + movsx eax,byte[ebp] + mov cl,[ebp+1] + inc ebp + add ebp,eax + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc06 ; BGE branch on greater or equals ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jnz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc07 ; BLT branch on lesss than ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc08 ; BNE branch on not equal ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc09 ; BEQ branch on equal (z=1) ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc0A ; BPL branch on plus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc0B ; BMI branch on minus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc0C ; BCC branch on carry clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc0D ; BCS branch on carry set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc0E ; BVC branch on overflow clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc0F ; BVS branch on overflow set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTablec+ecx*4] + ret +.nojump + inc ebp + call [FxTablec+ecx*4] + ret + +NEWSYM FxOpc10 ; TO RN set register n as destination register + TORNc 0 +NEWSYM FxOpc11 ; TO RN set register n as destination register + TORNc 1 +NEWSYM FxOpc12 ; TO RN set register n as destination register + TORNc 2 +NEWSYM FxOpc13 ; TO RN set register n as destination register + TORNc 3 +NEWSYM FxOpc14 ; TO RN set register n as destination register + TORNc 4 +NEWSYM FxOpc15 ; TO RN set register n as destination register + TORNc 5 +NEWSYM FxOpc16 ; TO RN set register n as destination register + TORNc 6 +NEWSYM FxOpc17 ; TO RN set register n as destination register + TORNc 7 +NEWSYM FxOpc18 ; TO RN set register n as destination register + TORNc 8 +NEWSYM FxOpc19 ; TO RN set register n as destination register + TORNc 9 +NEWSYM FxOpc1A ; TO RN set register n as destination register + TORNc 10 +NEWSYM FxOpc1B ; TO RN set register n as destination register + TORNc 11 +NEWSYM FxOpc1C ; TO RN set register n as destination register + TORNc 12 +NEWSYM FxOpc1D ; TO RN set register n as destination register + TORNc 13 +NEWSYM FxOpc1E ; TO RN set register n as destination register + FETCHPIPE + mov eax,[esi] ; Read Source + mov [SfxR0+14*4],eax ; Write + CLRFLAGS + UpdateR14 + inc ebp ; Increase program counter + ret +NEWSYM FxOpc1F ; TO RN set register n as destination register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebp,[SfxCPB] + mov [SfxR15],eax + add ebp,eax + CLRFLAGS + ret + +NEWSYM FxOpc3D ; ALT1 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,01h + inc ebp + call [FxTablec+ecx*4] + xor ch,ch + ret + +NEWSYM FxOpc3E ; ALT2 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,02h + inc ebp + call [FxTablec+ecx*4] + xor ch,ch + ret + +NEWSYM FxOpc3F ; ALT3 set alt3 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,03h + inc ebp + call [FxTablec+ecx*4] + xor ch,ch + ret + +NEWSYM FxOpcB0 ; FROM rn set source register + FROMRNc 0 +NEWSYM FxOpcB1 ; FROM rn set source register + FROMRNc 1 +NEWSYM FxOpcB2 ; FROM rn set source register + FROMRNc 2 +NEWSYM FxOpcB3 ; FROM rn set source register + FROMRNc 3 +NEWSYM FxOpcB4 ; FROM rn set source register + FROMRNc 4 +NEWSYM FxOpcB5 ; FROM rn set source register + FROMRNc 5 +NEWSYM FxOpcB6 ; FROM rn set source register + FROMRNc 6 +NEWSYM FxOpcB7 ; FROM rn set source register + FROMRNc 7 +NEWSYM FxOpcB8 ; FROM rn set source register + FROMRNc 8 +NEWSYM FxOpcB9 ; FROM rn set source register + FROMRNc 9 +NEWSYM FxOpcBA ; FROM rn set source register + FROMRNc 10 +NEWSYM FxOpcBB ; FROM rn set source register + FROMRNc 11 +NEWSYM FxOpcBC ; FROM rn set source register + FROMRNc 12 +NEWSYM FxOpcBD ; FROM rn set source register + FROMRNc 13 +NEWSYM FxOpcBE ; FROM rn set source register + FROMRNc 14 +NEWSYM FxOpcBF ; FROM rn set source register + FETCHPIPE + mov eax,ebp + sub eax,[SfxCPB] + inc ebp + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + shr al,7 + mov byte[SfxOverflow],al + CLRFLAGS + ret + \ No newline at end of file diff --git a/zsnes/src/chips/fxemu2b.mac b/zsnes/src/chips/fxemu2b.mac new file mode 100644 index 00000000..22594ebb --- /dev/null +++ b/zsnes/src/chips/fxemu2b.mac @@ -0,0 +1,89 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + + +%macro TORNb 1 ; V + FETCHPIPE + test dword [SfxB],1 + jnz .VersionB + mov edi, SfxR0+%1*4 + inc ebp ; Increase program counter + mov eax,ebp + sub eax,[SfxCPB] + mov dword[withr15sk],1 + mov [SfxR15],eax + call [FxTableb+ecx*4] + mov edi,SfxR0 + ret +.VersionB + mov eax,[esi] ; Read Source + mov dword[withr15sk],1 + inc ebp ; Increase program counter + mov [SfxR0+%1*4],eax ; Write + CLRFLAGS + ret +%endmacro + +%macro FROMRNb 1 ; V + FETCHPIPE + test dword [SfxB],1 + jnz .VersionB + mov esi,SfxR0+%1*4 + inc ebp ; Increase program counter + call [FxTable+ecx*4] + mov esi,SfxR0 + ret +.VersionB + mov eax,[SfxR0+%1*4] ; Read + inc ebp + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + shr al,7 + mov byte[SfxOverflow],al + CLRFLAGS + ret +%endmacro + +%macro TORNc 1 ; V + FETCHPIPE + mov eax,[esi] ; Read Source + inc ebp ; Increase program counter + mov [SfxR0+%1*4],eax ; Write + CLRFLAGS + ret +%endmacro + + +%macro FROMRNc 1 ; V + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read + inc ebp + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + shr al,7 + mov byte[SfxOverflow],al + CLRFLAGS + ret +%endmacro + \ No newline at end of file diff --git a/zsnes/src/chips/fxemu2c.asm b/zsnes/src/chips/fxemu2c.asm new file mode 100644 index 00000000..55de504a --- /dev/null +++ b/zsnes/src/chips/fxemu2c.asm @@ -0,0 +1,2551 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM FXEndLoop,FlushCache,FxOp02,FxTable,FxTableb,FxTablec,FxTabled +EXTSYM NumberOfOpcodes,SfxB,SfxCBR,SfxCFGR,SfxCOLR,SfxCPB,SfxCROM +EXTSYM SfxCacheActive,SfxCarry,SfxLastRamAdr,SfxMemTable,SfxOverflow +EXTSYM SfxPBR,SfxPIPE,SfxPOR,SfxR0,SfxR1,SfxR11,SfxR12,SfxR13,SfxR14 +EXTSYM SfxR15,SfxR2,SfxR4,SfxR6,SfxR7,SfxR8,SfxRAMBR,SfxRAMMem,SfxROMBR +EXTSYM SfxRomBuffer,SfxSCBR,SfxSCMR,SfxSFR,SfxSignZero,SfxnRamBanks,flagnz +EXTSYM sfx128lineloc,sfx160lineloc,sfx192lineloc,sfxobjlineloc,sfxramdata +EXTSYM withr15sk,sfxclineloc,SCBRrel,ChangeOps +EXTSYM fxbit01pcal,fxbit23pcal,fxbit45pcal,fxbit67pcal +EXTSYM fxbit01,fxbit23,fxbit45,fxbit67 +EXTSYM fxxand +EXTSYM PLOTJmpa,PLOTJmpb + +%include "chips/fxemu2.mac" +%include "chips/fxemu2b.mac" +%include "chips/fxemu2c.mac" + + + + + + +ALIGN32 +NEWSYM FxOpd00 ; STOP stop GSU execution (and maybe generate an IRQ) ; Verified. + FETCHPIPE + mov [SfxPIPE],cl + and dword [SfxSFR],0FFFFh-32 ; Clear Go flag (set to 1 when the GSU is running) + test dword [SfxCFGR],080h ; Check if the interrupt generation is on + jnz .NoIRQ + or dword [SfxSFR],08000h ; Set IRQ Flag +.NoIRQ + CLRFLAGS + inc ebp + mov eax,[NumberOfOpcodes] + add eax,0F0000000h + add [ChangeOps],eax + mov dword [NumberOfOpcodes],1 + jmp FXEndLoop + FXReturn + +NEWSYM FxOpd01 ; NOP no operation ; Verified. + FETCHPIPE + CLRFLAGS + inc ebp ; Increase program counter + FXReturn + +NEWSYM FxOpd02 ; CACHE reintialize GSU cache + mov eax,ebp + FETCHPIPE + sub eax,[SfxCPB] + and eax,0FFF0h + cmp dword [SfxCBR],eax + je .SkipUpdate + cmp byte [SfxCacheActive],1 + je .SkipUpdate + mov dword [SfxCBR],eax + mov dword [SfxCacheActive],1 + call FlushCache +.SkipUpdate + CLRFLAGS + inc ebp ; Increase program counter + FXReturn + +NEWSYM FxOpd03 ; LSR logic shift right ; Verified. + mov eax,[esi] ; Read Source + FETCHPIPE + mov [SfxCarry],al + and byte[SfxCarry],1 + shr ax,1 ; logic shift right + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd04 ; ROL rotate left (RCL?) ; V + shr byte[SfxCarry],1 + mov eax,[esi] ; Read Source + FETCHPIPE + rcl ax,1 + rcl byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd05 ; BRA branch always ; Verified. + movsx eax,byte[ebp] + mov cl,[ebp+1] + inc ebp + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd06 ; BGE branch on greater or equals ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd07 ; BLT branch on lesss than ; Verified. + movsx eax,byte[ebp] + mov ebx,[SfxSignZero] + shr ebx,15 + inc ebp + xor bl,[SfxOverflow] + mov cl,[ebp] + test bl,01h + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd08 ; BNE branch on not equal ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd09 ; BEQ branch on equal (z=1) ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],0FFFFh + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd0A ; BPL branch on plus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd0B ; BMI branch on minus ; Verified. + movsx eax,byte[ebp] + inc ebp + test dword[SfxSignZero],088000h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd0C ; BCC branch on carry clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd0D ; BCS branch on carry set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxCarry],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd0E ; BVC branch on overflow clear ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jnz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd0F ; BVS branch on overflow set ; Verified. + movsx eax,byte[ebp] + inc ebp + test byte[SfxOverflow],01h + mov cl,[ebp] + jz .nojump + add ebp,eax + call [FxTable+ecx*4] + FXReturn2 +.nojump + inc ebp + call [FxTable+ecx*4] + FXReturn2 + +NEWSYM FxOpd10 ; TO RN set register n as destination register + TORNd 0 +NEWSYM FxOpd11 ; TO RN set register n as destination register + TORNd 1 +NEWSYM FxOpd12 ; TO RN set register n as destination register + TORNd 2 +NEWSYM FxOpd13 ; TO RN set register n as destination register + TORNd 3 +NEWSYM FxOpd14 ; TO RN set register n as destination register + TORNd 4 +NEWSYM FxOpd15 ; TO RN set register n as destination register + TORNd 5 +NEWSYM FxOpd16 ; TO RN set register n as destination register + TORNd 6 +NEWSYM FxOpd17 ; TO RN set register n as destination register + TORNd 7 +NEWSYM FxOpd18 ; TO RN set register n as destination register + TORNd 8 +NEWSYM FxOpd19 ; TO RN set register n as destination register + TORNd 9 +NEWSYM FxOpd1A ; TO RN set register n as destination register + TORNd 10 +NEWSYM FxOpd1B ; TO RN set register n as destination register + TORNd 11 +NEWSYM FxOpd1C ; TO RN set register n as destination register + TORNd 12 +NEWSYM FxOpd1D ; TO RN set register n as destination register + TORNd 13 +NEWSYM FxOpd1E ; TO RN set register n as destination register + FETCHPIPE + mov edi,SfxR0+14*4 + inc ebp + call [FxTable+ecx*4] + mov edi,SfxR0 + UpdateR14 + FXReturn +NEWSYM FxOpd1F ; TO RN set register n as destination register + FETCHPIPE + mov edi,SfxR0+15*4 + inc ebp + call [FxTable+ecx*4] + mov ebp,[SfxCPB] + add ebp,[SfxR15] + mov edi,SfxR0 + FXReturn + +NEWSYM FxOpd20 ; WITH set register n as source and destination register + WITHc 0 +NEWSYM FxOpd21 ; WITH set register n as source and destination register + WITHc 1 +NEWSYM FxOpd22 ; WITH set register n as source and destination register + WITHc 2 +NEWSYM FxOpd23 ; WITH set register n as source and destination register + WITHc 3 +NEWSYM FxOpd24 ; WITH set register n as source and destination register + WITHc 4 +NEWSYM FxOpd25 ; WITH set register n as source and destination register + WITHc 5 +NEWSYM FxOpd26 ; WITH set register n as source and destination register + WITHc 6 +NEWSYM FxOpd27 ; WITH set register n as source and destination register + WITHc 7 +NEWSYM FxOpd28 ; WITH set register n as source and destination register + WITHc 8 +NEWSYM FxOpd29 ; WITH set register n as source and destination register + WITHc 9 +NEWSYM FxOpd2A ; WITH set register n as source and destination register + WITHc 10 +NEWSYM FxOpd2B ; WITH set register n as source and destination register + WITHc 11 +NEWSYM FxOpd2C ; WITH set register n as source and destination register + WITHc 12 +NEWSYM FxOpd2D ; WITH set register n as source and destination register + WITHc 13 +NEWSYM FxOpd2E ; WITH set register n as source and destination register + FETCHPIPE + mov esi,SfxR0+14*4 + mov edi,SfxR0+14*4 + mov dword [SfxB],1 + inc ebp + call [FxTablec+ecx*4] + mov dword [SfxB],0 ; Clear B Flag + mov esi,SfxR0 + mov edi,SfxR0 + UpdateR14 + FXReturn +NEWSYM FxOpd2F ; WITH set register n as source and destination register + FETCHPIPE + mov esi,SfxR0+15*4 + mov edi,SfxR0+15*4 + mov dword [SfxB],1 + inc ebp + mov eax,ebp + sub eax,[SfxCPB] + mov dword[withr15sk],0 + mov [SfxR15],eax + call [FxTableb+ecx*4] + cmp dword[withr15sk],1 + je .skip + mov ebp,[SfxCPB] + add ebp,[SfxR15] +.skip + mov dword [SfxB],0 ; Clear B Flag + mov esi,SfxR0 + mov edi,SfxR0 + FXReturn + +NEWSYM FxOpd30 ; STW RN store word + STWRNc 0 +NEWSYM FxOpd31 ; STW RN store word + STWRNc 1 +NEWSYM FxOpd32 ; STW RN store word + STWRNc 2 +NEWSYM FxOpd33 ; STW RN store word + STWRNc 3 +NEWSYM FxOpd34 ; STW RN store word + STWRNc 4 +NEWSYM FxOpd35 ; STW RN store word + STWRNc 5 +NEWSYM FxOpd36 ; STW RN store word + STWRNc 6 +NEWSYM FxOpd37 ; STW RN store word + STWRNc 7 +NEWSYM FxOpd38 ; STW RN store word + STWRNc 8 +NEWSYM FxOpd39 ; STW RN store word + STWRNc 9 +NEWSYM FxOpd3A ; STW RN store word + STWRNc 10 +NEWSYM FxOpd3B ; STW RN store word + STWRNc 11 + +NEWSYM FxOpd30A1 ; STB RN store byte + STBRNc 0 +NEWSYM FxOpd31A1 ; STB RN store byte + STBRNc 1 +NEWSYM FxOpd32A1 ; STB RN store byte + STBRNc 2 +NEWSYM FxOpd33A1 ; STB RN store byte + STBRNc 3 +NEWSYM FxOpd34A1 ; STB RN store byte + STBRNc 4 +NEWSYM FxOpd35A1 ; STB RN store byte + STBRNc 5 +NEWSYM FxOpd36A1 ; STB RN store byte + STBRNc 6 +NEWSYM FxOpd37A1 ; STB RN store byte + STBRNc 7 +NEWSYM FxOpd38A1 ; STB RN store byte + STBRNc 8 +NEWSYM FxOpd39A1 ; STB RN store byte + STBRNc 9 +NEWSYM FxOpd3AA1 ; STB RN store byte + STBRNc 10 +NEWSYM FxOpd3BA1 ; STB RN store byte + STBRNc 11 + +NEWSYM FxOpd3C ; LOOP decrement loop counter, and branch on not zero ; V + dec word [SfxR12] ; decrement loop counter + FETCHPIPE + mov eax,[SfxR12] + mov [SfxSignZero],eax + or eax,eax + jz .NoBranch + mov eax,dword [SfxR13] + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + FXReturn +.NoBranch + inc ebp + CLRFLAGS + FXReturn + +NEWSYM FxOpd3D ; ALT1 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,01h + inc ebp + call [FxTable+ecx*4] + xor ch,ch + FXReturn + +NEWSYM FxOpd3E ; ALT2 set alt1 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,02h + inc ebp + call [FxTable+ecx*4] + xor ch,ch + FXReturn + +NEWSYM FxOpd3F ; ALT3 set alt3 mode ; Verified. + FETCHPIPE + mov dword [SfxB],0 + or ch,03h + inc ebp + call [FxTable+ecx*4] + xor ch,ch + FXReturn + +NEWSYM FxOpd40 ; LDW RN load word from RAM + LDWRNc 0 +NEWSYM FxOpd41 ; LDW RN load word from RAM + LDWRNc 1 +NEWSYM FxOpd42 ; LDW RN load word from RAM + LDWRNc 2 +NEWSYM FxOpd43 ; LDW RN load word from RAM + LDWRNc 3 +NEWSYM FxOpd44 ; LDW RN load word from RAM + LDWRNc 4 +NEWSYM FxOpd45 ; LDW RN load word from RAM + LDWRNc 5 +NEWSYM FxOpd46 ; LDW RN load word from RAM + LDWRNc 6 +NEWSYM FxOpd47 ; LDW RN load word from RAM + LDWRNc 7 +NEWSYM FxOpd48 ; LDW RN load word from RAM + LDWRNc 8 +NEWSYM FxOpd49 ; LDW RN load word from RAM + LDWRNc 9 +NEWSYM FxOpd4A ; LDW RN load word from RAM + LDWRNc 10 +NEWSYM FxOpd4B ; LDW RN load word from RAM + LDWRNc 11 + +NEWSYM FxOpd40A1 ; LDB RN load byte from RAM + LDBRNc 0 +NEWSYM FxOpd41A1 ; LDB RN load byte from RAM + LDBRNc 1 +NEWSYM FxOpd42A1 ; LDB RN load byte from RAM + LDBRNc 2 +NEWSYM FxOpd43A1 ; LDB RN load byte from RAM + LDBRNc 3 +NEWSYM FxOpd44A1 ; LDB RN load byte from RAM + LDBRNc 4 +NEWSYM FxOpd45A1 ; LDB RN load byte from RAM + LDBRNc 5 +NEWSYM FxOpd46A1 ; LDB RN load byte from RAM + LDBRNc 6 +NEWSYM FxOpd47A1 ; LDB RN load byte from RAM + LDBRNc 7 +NEWSYM FxOpd48A1 ; LDB RN load byte from RAM + LDBRNc 8 +NEWSYM FxOpd49A1 ; LDB RN load byte from RAM + LDBRNc 9 +NEWSYM FxOpd4AA1 ; LDB RN load byte from RAM + LDBRNc 10 +NEWSYM FxOpd4BA1 ; LDB RN load byte from RAM + LDBRNc 11 + + +NEWSYM FxOpd4C1284b ; PLOT 4bit + plotlines4bb plotb +NEWSYM FxOpd4C1284bz ; PLOT 4bit, zero check + plotlines4bb plotbz +NEWSYM FxOpd4C1284bd ; PLOT 4bit, dither + plotlines4bb plotbd +NEWSYM FxOpd4C1284bzd ; PLOT 4bit, zero check + dither + plotlines4bb plotbzd + +NEWSYM FxOpd4C1282b ; PLOT 2bit + plotlines2bb plotb +NEWSYM FxOpd4C1282bz ; PLOT 2bit, zero check + plotlines2bb plotbz +NEWSYM FxOpd4C1282bd ; PLOT 2bit, dither + plotlines2bb plotbd +NEWSYM FxOpd4C1282bzd ; PLOT 2bit, zero check + dither + plotlines2bb plotbzd + +NEWSYM FxOpd4C1288b ; PLOT 8bit + plotlines8bb plotb +NEWSYM FxOpd4C1288bz ; PLOT 8bit, zero check + plotlines8bb plotbz +NEWSYM FxOpd4C1288bd ; PLOT 8bit, dither + plotlines8bb plotb +NEWSYM FxOpd4C1288bzd ; PLOT 8bit, zero check + dither + plotlines8bb plotbz + +NEWSYM FxOpd4C1288bl ; PLOT 8bit + plotlines8bbl plotb +NEWSYM FxOpd4C1288bzl ; PLOT 8bit, zero check + plotlines8bbl plotbz +NEWSYM FxOpd4C1288bdl ; PLOT 8bit, dither + plotlines8bbl plotb +NEWSYM FxOpd4C1288bzdl ; PLOT 8bit, zero check + dither + plotlines8bbl plotbz + +NEWSYM FxOpd4C ; PLOT plot pixel with R1,R2 as x,y and the color register as the color + jmp FxOpd4C1284b + + FETCHPIPE + inc ebp + CLRFLAGS + mov ebx,[SfxR2] + mov bh,[SfxR1] + mov eax,[sfxclineloc] + mov ebx,[eax+ebx*4] + cmp ebx,0FFFFFFFFh + je near .nodraw + xor eax,eax + ; bits 5/2 : 00 = 128 pixels, 01 = 160 pixels, 10 = 192 pixels, 11 = obj + ; bits 1/0 : 00 = 4 color, 01 = 16-color, 10 = not used, 11 = 256 color + ; 192 pixels = 24 tiles, 160 pixels = 20 tiles, 128 pixels = 16 tiles + ; 16+8(4/3) 16+4(4/2) 16(4/0) + push ecx + mov al,[SfxSCMR] + and al,00000011b ; 4 + 32 + cmp al,0 + je near .colors4 + cmp al,3 + je near .colors256 + + shl ebx,5 ; x32 (16 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + test byte[SfxPOR],01h + jnz .nozerocheck_16 + test byte[SfxCOLR],0Fh + jz .nodraw +.nozerocheck_16 + mov dl,[SfxCOLR] + test byte[SfxPOR],02h + jz .nodither4b + mov dh,[SfxR1] + xor dh,[SfxR2] + test dh,01h + jz .nodither4b + shr dh,4 +.nodither4b + and byte[eax],bh + and byte[eax+1],bh + and byte[eax+16],bh + and byte[eax+17],bh + test dl,01h + jz .nodraw_16 + or byte[eax], bl +.nodraw_16 + test dl,02h + jz .nodraw2_16 + or byte[eax+1], bl +.nodraw2_16 + test dl,04h + jz .nodraw3_16 + or byte[eax+16],bl +.nodraw3_16 + test dl,08h + jz .nodraw4_16 + or byte[eax+17],bl +.nodraw4_16 +.nodraw + inc word [SfxR1] + FXReturn + +.colors4 + shl ebx,4 ; x16 (4 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + test byte[SfxPOR],01h + jnz .nozerocheck_4 + test byte[SfxCOLR],03h + jz .noplot_4 +.nozerocheck_4 + mov dl,[SfxCOLR] + test byte[SfxPOR],02h + jz .nodither2b + mov dh,[SfxR1] + xor dh,[SfxR2] + test dh,01h + jz .nodither2b + shr dh,4 +.nodither2b + and byte[eax],bh + and byte[eax+1],bh + test dl,01h + jz .nodraw_4 + or byte[eax], bl +.nodraw_4 + test dl,02h + jz .nodraw2_4 + or byte[eax+1], bl +.nodraw2_4 +.noplot_4 + inc word [SfxR1] + FXReturn + +.colors256 + shl ebx,6 ; x64 (256 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + test byte[SfxPOR],01h + jnz .nozerocheck_256 + mov dl,0FFh + test byte[SfxPOR],08h + jz .nozerocheckb_256 + mov dl,0Fh +.nozerocheckb_256 + test byte[SfxCOLR],dl + jz .noplot_256 +.nozerocheck_256 + mov dl,[SfxCOLR] + and byte[eax],bh + and byte[eax+1],bh + and byte[eax+16],bh + and byte[eax+17],bh + and byte[eax+32],bh + and byte[eax+33],bh + and byte[eax+48],bh + and byte[eax+49],bh + test dl,01h + jz .nodraw_256 + or byte[eax], bl +.nodraw_256 + test dl,02h + jz .nodraw2_256 + or byte[eax+1], bl +.nodraw2_256 + test dl,04h + jz .nodraw3_256 + or byte[eax+16],bl +.nodraw3_256 + test dl,08h + jz .nodraw4_256 + or byte[eax+17],bl +.nodraw4_256 + test dl,10h + jz .nodraw5_256 + or byte[eax+32], bl +.nodraw5_256 + test dl,20h + jz .nodraw6_256 + or byte[eax+33], bl +.nodraw6_256 + test dl,40h + jz .nodraw7_256 + or byte[eax+48],bl +.nodraw7_256 + test dl,80h + jz .nodraw8_256 + or byte[eax+49],bl +.nodraw8_256 +.noplot_256 + inc word [SfxR1] + FXReturn + +.prevx dw 0 +.prevy dw 0 + +NEWSYM FxOpd4CA1 ; RPIX read color of the pixel with R1,R2 as x,y + FETCHPIPE + mov ebx,[SfxR2] + mov bh,[SfxR1] + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov ebx,[eax+ebx*4] + cmp ebx,0FFFFFFFFh + je near .nodraw + xor eax,eax + ; bits 5/2 : 00 = 128 pixels, 01 = 160 pixels, 10 = 192 pixels, 11 = obj + ; bits 1/0 : 00 = 4 color, 01 = 16-color, 10 = not used, 11 = 256 color + ; 192 pixels = 24 tiles, 160 pixels = 20 tiles, 128 pixels = 16 tiles + ; 16+8(4/3) 16+4(4/2) 16(4/0) + push ecx + mov al,[SfxSCMR] + and al,00000011b ; 4 + 32 + + cmp al,0 + je near .colors4 + cmp al,3 + je near .colors256 + + shl ebx,5 ; x32 (16 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + pop ecx + xor bh,bh + test byte[eax],bl + jz .nodraw_16 + or bh,01h +.nodraw_16 + test byte[eax+1],bl + jz .nodraw2_16 + or bh,02h +.nodraw2_16 + test byte[eax+16],bl + jz .nodraw3_16 + or bh,04h +.nodraw3_16 + test byte[eax+17],bl + jz .nodraw4_16 + or bh,08h +.nodraw4_16 +.nodraw + mov bl,bh + and ebx,0FFh + inc ebp +; UpdateR14 + CLRFLAGS + mov [edi],ebx ; Write Destination + mov [flagnz],ebx + FXReturn + +.colors4 + shl ebx,4 ; x16 (4 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + xor bh,bh + test byte[eax],bl + jz .nodraw_4 + or bh,01h +.nodraw_4 + test byte[eax+1],bl + jz .nodraw2_4 + or bh,02h +.nodraw2_4 + mov bl,bh + and ebx,0FFh + inc ebp +; UpdateR14 + CLRFLAGS + mov [edi],ebx ; Write Destination + mov [flagnz],ebx + FXReturn + +.colors256 + shl ebx,6 ; x64 (256 colors) + mov al,[SfxSCBR] + shl eax,10 ; Get SFX address + add eax,ebx + add eax,[sfxramdata] + mov ebx,[SfxR2] + and ebx,07h + shl ebx,1 + add eax,ebx + mov cl,[SfxR1] + and cl,07h + xor cl,07h + mov bl,1 + shl bl,cl + mov bh,bl + xor bh,0FFh + pop ecx + xor bh,bh + test byte[eax],bl + jz .nodraw_256 + or bh,01h +.nodraw_256 + test byte[eax+1],bl + jz .nodraw2_256 + or bh,02h +.nodraw2_256 + test byte[eax+16],bl + jz .nodraw3_256 + or bh,04h +.nodraw3_256 + test byte[eax+17],bl + jz .nodraw4_256 + or bh,08h +.nodraw4_256 + test byte[eax+32],bl + jz .nodraw5_256 + or bh,10h +.nodraw5_256 + test byte[eax+33],bl + jz .nodraw6_256 + or bh,20h +.nodraw6_256 + test byte[eax+48],bl + jz .nodraw7_256 + or bh,40h +.nodraw7_256 + test byte[eax+49],bl + jz .nodraw8_256 + or bh,80h +.nodraw8_256 + mov bl,bh + and ebx,0FFh + inc ebp +; UpdateR14 + CLRFLAGS + mov [edi],ebx ; Write Destination + mov [flagnz],ebx + FXReturn + +NEWSYM FxOpd4D ; SWAP swap upper and lower byte of a register ; V + mov eax,[esi] ; Read Source + FETCHPIPE + ror ax,8 + inc ebp ; Increase program counter + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd4E ; COLOR copy source register to color register ; V + FETCHPIPE + mov eax,[esi] ; Read Source + ; if bit 3 of SfxPOR is set, then don't modify the upper 4 bits + test byte[SfxPOR],04h + jz .nohighnibble + mov bl,al + shr bl,4 + and al,0F0h + or al,bl +.nohighnibble + test byte[SfxPOR],08h + jnz .preserveupper + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx +.nocolchange + CLRFLAGS + inc ebp ; Increase program counter + FXReturn +.preserveupper + mov bl,[SfxCOLR] + and al,0Fh + and bl,0F0h + or al,bl + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + CLRFLAGS + inc ebp ; Increase program counter + FXReturn + +NEWSYM FxOpd4EA1 ; CMODE set plot option register ; V + FETCHPIPE + mov eax,[esi] ; Read Source + inc ebp ; Increase program counter + mov dword [SfxPOR],eax + + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + + + push ebx + mov al,[SfxSCMR] + and eax,00000011b + mov bl,[SfxPOR] + and bl,0Fh + shl bl,2 + or al,bl + mov ebx,[PLOTJmpb+eax*4] + mov eax,[PLOTJmpa+eax*4] + + mov dword [FxTable+4Ch*4],eax + mov dword [FxTableb+4Ch*4],eax + mov dword [FxTablec+4Ch*4],eax + mov dword [FxTabled+4Ch*4],ebx + pop ebx + + CLRFLAGS + FXReturn + +NEWSYM FxOpd4F ; NOT perform exclusive exor with 1 on all bits ; V + mov eax,[esi] ; Read Source + FETCHPIPE + xor eax,0FFFFh + inc ebp ; Increase program counter + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd50 ; ADD RN add, register + register + ADDRNc 0 +NEWSYM FxOpd51 ; ADD RN add, register + register + ADDRNc 1 +NEWSYM FxOpd52 ; ADD RN add, register + register + ADDRNc 2 +NEWSYM FxOpd53 ; ADD RN add, register + register + ADDRNc 3 +NEWSYM FxOpd54 ; ADD RN add, register + register + ADDRNc 4 +NEWSYM FxOpd55 ; ADD RN add, register + register + ADDRNc 5 +NEWSYM FxOpd56 ; ADD RN add, register + register + ADDRNc 6 +NEWSYM FxOpd57 ; ADD RN add, register + register + ADDRNc 7 +NEWSYM FxOpd58 ; ADD RN add, register + register + ADDRNc 8 +NEWSYM FxOpd59 ; ADD RN add, register + register + ADDRNc 9 +NEWSYM FxOpd5A ; ADD RN add, register + register + ADDRNc 10 +NEWSYM FxOpd5B ; ADD RN add, register + register + ADDRNc 11 +NEWSYM FxOpd5C ; ADD RN add, register + register + ADDRNc 12 +NEWSYM FxOpd5D ; ADD RN add, register + register + ADDRNc 13 +NEWSYM FxOpd5E ; ADD RN add, register + register + ADDRNc 14 +NEWSYM FxOpd5F ; ADD RN add, register + register + FETCHPIPE + mov eax, [esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + add ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd50A1 ; ADC RN add with carry, register + register + ADCRNc 0 +NEWSYM FxOpd51A1 ; ADC RN add with carry, register + register + ADCRNc 1 +NEWSYM FxOpd52A1 ; ADC RN add with carry, register + register + ADCRNc 2 +NEWSYM FxOpd53A1 ; ADC RN add with carry, register + register + ADCRNc 3 +NEWSYM FxOpd54A1 ; ADC RN add with carry, register + register + ADCRNc 4 +NEWSYM FxOpd55A1 ; ADC RN add with carry, register + register + ADCRNc 5 +NEWSYM FxOpd56A1 ; ADC RN add with carry, register + register + ADCRNc 6 +NEWSYM FxOpd57A1 ; ADC RN add with carry, register + register + ADCRNc 7 +NEWSYM FxOpd58A1 ; ADC RN add with carry, register + register + ADCRNc 8 +NEWSYM FxOpd59A1 ; ADC RN add with carry, register + register + ADCRNc 9 +NEWSYM FxOpd5AA1 ; ADC RN add with carry, register + register + ADCRNc 10 +NEWSYM FxOpd5BA1 ; ADC RN add with carry, register + register + ADCRNc 11 +NEWSYM FxOpd5CA1 ; ADC RN add with carry, register + register + ADCRNc 12 +NEWSYM FxOpd5DA1 ; ADC RN add with carry, register + register + ADCRNc 13 +NEWSYM FxOpd5EA1 ; ADC RN add with carry, register + register + ADCRNc 14 +NEWSYM FxOpd5FA1 ; ADC RN add with carry, register + register + FETCHPIPE + mov eax, [esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + shr byte[SfxCarry],1 + adc ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +; Weird Opdode (FxOpd50A2, add 0, wow!) +NEWSYM FxOpd50A2 ; ADI RN add, register + immediate + ADIRNc 0 +NEWSYM FxOpd51A2 ; ADI RN add, register + immediate + ADIRNc 1 +NEWSYM FxOpd52A2 ; ADI RN add, register + immediate + ADIRNc 2 +NEWSYM FxOpd53A2 ; ADI RN add, register + immediate + ADIRNc 3 +NEWSYM FxOpd54A2 ; ADI RN add, register + immediate + ADIRNc 4 +NEWSYM FxOpd55A2 ; ADI RN add, register + immediate + ADIRNc 5 +NEWSYM FxOpd56A2 ; ADI RN add, register + immediate + ADIRNc 6 +NEWSYM FxOpd57A2 ; ADI RN add, register + immediate + ADIRNc 7 +NEWSYM FxOpd58A2 ; ADI RN add, register + immediate + ADIRNc 8 +NEWSYM FxOpd59A2 ; ADI RN add, register + immediate + ADIRNc 9 +NEWSYM FxOpd5AA2 ; ADI RN add, register + immediate + ADIRNc 10 +NEWSYM FxOpd5BA2 ; ADI RN add, register + immediate + ADIRNc 11 +NEWSYM FxOpd5CA2 ; ADI RN add, register + immediate + ADIRNc 12 +NEWSYM FxOpd5DA2 ; ADI RN add, register + immediate + ADIRNc 13 +NEWSYM FxOpd5EA2 ; ADI RN add, register + immediate + ADIRNc 14 +NEWSYM FxOpd5FA2 ; ADI RN add, register + immediate + ADIRNc 15 + +; Another very useful Opdode +NEWSYM FxOpd50A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 0 +NEWSYM FxOpd51A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 1 +NEWSYM FxOpd52A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 2 +NEWSYM FxOpd53A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 3 +NEWSYM FxOpd54A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 4 +NEWSYM FxOpd55A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 5 +NEWSYM FxOpd56A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 6 +NEWSYM FxOpd57A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 7 +NEWSYM FxOpd58A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 8 +NEWSYM FxOpd59A3 ; ADCIRN add with carry, register + immediate + ADCIRNc 9 +NEWSYM FxOpd5AA3 ; ADCIRN add with carry, register + immediate + ADCIRNc 10 +NEWSYM FxOpd5BA3 ; ADCIRN add with carry, register + immediate + ADCIRNc 11 +NEWSYM FxOpd5CA3 ; ADCIRN add with carry, register + immediate + ADCIRNc 12 +NEWSYM FxOpd5DA3 ; ADCIRN add with carry, register + immediate + ADCIRNc 13 +NEWSYM FxOpd5EA3 ; ADCIRN add with carry, register + immediate + ADCIRNc 14 +NEWSYM FxOpd5FA3 ; ADCIRN add with carry, register + immediate + ADCIRNc 15 + +NEWSYM FxOpd60 ; SUBRN subtract, register - register + SUBRNc 0 +NEWSYM FxOpd61 ; SUBRN subtract, register - register + SUBRNc 1 +NEWSYM FxOpd62 ; SUBRN subtract, register - register + SUBRNc 2 +NEWSYM FxOpd63 ; SUBRN subtract, register - register + SUBRNc 3 +NEWSYM FxOpd64 ; SUBRN subtract, register - register + SUBRNc 4 +NEWSYM FxOpd65 ; SUBRN subtract, register - register + SUBRNc 5 +NEWSYM FxOpd66 ; SUBRN subtract, register - register + SUBRNc 6 +NEWSYM FxOpd67 ; SUBRN subtract, register - register + SUBRNc 7 +NEWSYM FxOpd68 ; SUBRN subtract, register - register + SUBRNc 8 +NEWSYM FxOpd69 ; SUBRN subtract, register - register + SUBRNc 9 +NEWSYM FxOpd6A ; SUBRN subtract, register - register + SUBRNc 10 +NEWSYM FxOpd6B ; SUBRN subtract, register - register + SUBRNc 11 +NEWSYM FxOpd6C ; SUBRN subtract, register - register + SUBRNc 12 +NEWSYM FxOpd6D ; SUBRN subtract, register - register + SUBRNc 13 +NEWSYM FxOpd6E ; SUBRN subtract, register - register + SUBRNc 14 +NEWSYM FxOpd6F ; SUBRN subtract, register - register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd60A1 ; SBCRN subtract with carry, register - register + SBCRNc 0 +NEWSYM FxOpd61A1 ; SBCRN subtract with carry, register - register + SBCRNc 1 +NEWSYM FxOpd62A1 ; SBCRN subtract with carry, register - register + SBCRNc 2 +NEWSYM FxOpd63A1 ; SBCRN subtract with carry, register - register + SBCRNc 3 +NEWSYM FxOpd64A1 ; SBCRN subtract with carry, register - register + SBCRNc 4 +NEWSYM FxOpd65A1 ; SBCRN subtract with carry, register - register + SBCRNc 5 +NEWSYM FxOpd66A1 ; SBCRN subtract with carry, register - register + SBCRNc 6 +NEWSYM FxOpd67A1 ; SBCRN subtract with carry, register - register + SBCRNc 7 +NEWSYM FxOpd68A1 ; SBCRN subtract with carry, register - register + SBCRNc 8 +NEWSYM FxOpd69A1 ; SBCRN subtract with carry, register - register + SBCRNc 9 +NEWSYM FxOpd6AA1 ; SBCRN subtract with carry, register - register + SBCRNc 10 +NEWSYM FxOpd6BA1 ; SBCRN subtract with carry, register - register + SBCRNc 11 +NEWSYM FxOpd6CA1 ; SBCRN subtract with carry, register - register + SBCRNc 12 +NEWSYM FxOpd6DA1 ; SBCRN subtract with carry, register - register + SBCRNc 13 +NEWSYM FxOpd6EA1 ; SBCRN subtract with carry, register - register + SBCRNc 14 +NEWSYM FxOpd6FA1 ; SBCRN subtract with carry, register - register + mov eax,[esi] ; Read Source + mov ebx,ebp + FETCHPIPE + sub ebx,[SfxCPB] + cmp byte[SfxCarry],1 + sbb ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd60A2 ; SUBIRN subtract, register - immediate + SUBIRNc 0 +NEWSYM FxOpd61A2 ; SUBIRN subtract, register - immediate + SUBIRNc 1 +NEWSYM FxOpd62A2 ; SUBIRN subtract, register - immediate + SUBIRNc 2 +NEWSYM FxOpd63A2 ; SUBIRN subtract, register - immediate + SUBIRNc 3 +NEWSYM FxOpd64A2 ; SUBIRN subtract, register - immediate + SUBIRNc 4 +NEWSYM FxOpd65A2 ; SUBIRN subtract, register - immediate + SUBIRNc 5 +NEWSYM FxOpd66A2 ; SUBIRN subtract, register - immediate + SUBIRNc 6 +NEWSYM FxOpd67A2 ; SUBIRN subtract, register - immediate + SUBIRNc 7 +NEWSYM FxOpd68A2 ; SUBIRN subtract, register - immediate + SUBIRNc 8 +NEWSYM FxOpd69A2 ; SUBIRN subtract, register - immediate + SUBIRNc 9 +NEWSYM FxOpd6AA2 ; SUBIRN subtract, register - immediate + SUBIRNc 10 +NEWSYM FxOpd6BA2 ; SUBIRN subtract, register - immediate + SUBIRNc 11 +NEWSYM FxOpd6CA2 ; SUBIRN subtract, register - immediate + SUBIRNc 12 +NEWSYM FxOpd6DA2 ; SUBIRN subtract, register - immediate + SUBIRNc 13 +NEWSYM FxOpd6EA2 ; SUBIRN subtract, register - immediate + SUBIRNc 14 +NEWSYM FxOpd6FA2 ; SUBIRN subtract, register - immediate + SUBIRNc 15 + +NEWSYM FxOpd60A3 ; CMPRN compare, register, register + CMPRNc 0 +NEWSYM FxOpd61A3 ; CMPRN compare, register, register + CMPRNc 1 +NEWSYM FxOpd62A3 ; CMPRN compare, register, register + CMPRNc 2 +NEWSYM FxOpd63A3 ; CMPRN compare, register, register + CMPRNc 3 +NEWSYM FxOpd64A3 ; CMPRN compare, register, register + CMPRNc 4 +NEWSYM FxOpd65A3 ; CMPRN compare, register, register + CMPRNc 5 +NEWSYM FxOpd66A3 ; CMPRN compare, register, register + CMPRNc 6 +NEWSYM FxOpd67A3 ; CMPRN compare, register, register + CMPRNc 7 +NEWSYM FxOpd68A3 ; CMPRN compare, register, register + CMPRNc 8 +NEWSYM FxOpd69A3 ; CMPRN compare, register, register + CMPRNc 9 +NEWSYM FxOpd6AA3 ; CMPRN compare, register, register + CMPRNc 10 +NEWSYM FxOpd6BA3 ; CMPRN compare, register, register + CMPRNc 11 +NEWSYM FxOpd6CA3 ; CMPRN compare, register, register + CMPRNc 12 +NEWSYM FxOpd6DA3 ; CMPRN compare, register, register + CMPRNc 13 +NEWSYM FxOpd6EA3 ; CMPRN compare, register, register + CMPRNc 14 +NEWSYM FxOpd6FA3 ; CMPRN compare, register, register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + mov [SfxSignZero],eax + CLRFLAGS + inc ebp ; Increase program counter + FXReturn + +NEWSYM FxOpd70 ; MERGE R7 as upper byte, R8 as lower byte (used for texture-mapping) */ + ; V + xor eax,eax + FETCHPIPE + mov ah,byte [SfxR7+1] + mov al,byte [SfxR8+1] + inc ebp + mov [edi],eax ; Write Destination + mov dword[SfxSignZero],0001h + test eax,0F0F0h + jz .nozero + mov dword[SfxSignZero],0000h +.nozero + test eax,08080h + jz .nosign + or dword [SfxSignZero],80000h +.nosign + mov dword [SfxOverflow],1 + test ax,0c0c0h + jnz .Overflow + mov dword [SfxOverflow],0 +.Overflow + mov dword [SfxCarry],1 + test ax,0e0e0h + jnz .Carry + mov dword [SfxCarry],0 +.Carry + CLRFLAGS + FXReturn + +NEWSYM FxOpd71 ; AND RN register & register + ANDRNc 1 +NEWSYM FxOpd72 ; AND RN register & register + ANDRNc 2 +NEWSYM FxOpd73 ; AND RN register & register + ANDRNc 3 +NEWSYM FxOpd74 ; AND RN register & register + ANDRNc 4 +NEWSYM FxOpd75 ; AND RN register & register + ANDRNc 5 +NEWSYM FxOpd76 ; AND RN register & register + ANDRNc 6 +NEWSYM FxOpd77 ; AND RN register & register + ANDRNc 7 +NEWSYM FxOpd78 ; AND RN register & register + ANDRNc 8 +NEWSYM FxOpd79 ; AND RN register & register + ANDRNc 9 +NEWSYM FxOpd7A ; AND RN register & register + ANDRNc 10 +NEWSYM FxOpd7B ; AND RN register & register + ANDRNc 11 +NEWSYM FxOpd7C ; AND RN register & register + ANDRNc 12 +NEWSYM FxOpd7D ; AND RN register & register + ANDRNc 13 +NEWSYM FxOpd7E ; AND RN register & register + ANDRNc 14 +NEWSYM FxOpd7F ; AND RN register & register + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd71A1 ; BIC RN register & ~register + BICRNc 1 +NEWSYM FxOpd72A1 ; BIC RN register & ~register + BICRNc 2 +NEWSYM FxOpd73A1 ; BIC RN register & ~register + BICRNc 3 +NEWSYM FxOpd74A1 ; BIC RN register & ~register + BICRNc 4 +NEWSYM FxOpd75A1 ; BIC RN register & ~register + BICRNc 5 +NEWSYM FxOpd76A1 ; BIC RN register & ~register + BICRNc 6 +NEWSYM FxOpd77A1 ; BIC RN register & ~register + BICRNc 7 +NEWSYM FxOpd78A1 ; BIC RN register & ~register + BICRNc 8 +NEWSYM FxOpd79A1 ; BIC RN register & ~register + BICRNc 9 +NEWSYM FxOpd7AA1 ; BIC RN register & ~register + BICRNc 10 +NEWSYM FxOpd7BA1 ; BIC RN register & ~register + BICRNc 11 +NEWSYM FxOpd7CA1 ; BIC RN register & ~register + BICRNc 12 +NEWSYM FxOpd7DA1 ; BIC RN register & ~register + BICRNc 13 +NEWSYM FxOpd7EA1 ; BIC RN register & ~register + BICRNc 14 +NEWSYM FxOpd7FA1 ; BIC RN register & ~register + FETCHPIPE + mov ebx,ebp + sub ebx,[SfxCPB] + mov eax,[esi] ; Read Source + xor ebx,0FFFFh + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd71A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 1 +NEWSYM FxOpd72A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 2 +NEWSYM FxOpd73A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 3 +NEWSYM FxOpd74A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 4 +NEWSYM FxOpd75A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 5 +NEWSYM FxOpd76A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 6 +NEWSYM FxOpd77A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 7 +NEWSYM FxOpd78A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 8 +NEWSYM FxOpd79A2 ; ANDIRNc and #n - register & immediate + ANDIRNc 9 +NEWSYM FxOpd7AA2 ; ANDIRNc and #n - register & immediate + ANDIRNc 10 +NEWSYM FxOpd7BA2 ; ANDIRNc and #n - register & immediate + ANDIRNc 11 +NEWSYM FxOpd7CA2 ; ANDIRNc and #n - register & immediate + ANDIRNc 12 +NEWSYM FxOpd7DA2 ; ANDIRNc and #n - register & immediate + ANDIRNc 13 +NEWSYM FxOpd7EA2 ; ANDIRNc and #n - register & immediate + ANDIRNc 14 +NEWSYM FxOpd7FA2 ; ANDIRNc and #n - register & immediate + ANDIRNc 15 + +NEWSYM FxOpd71A3 ; BICIRNc register & ~immediate + BICIRNc 1 ^ 0FFFFh +NEWSYM FxOpd72A3 ; BICIRNc register & ~immediate + BICIRNc 2 ^ 0FFFFh +NEWSYM FxOpd73A3 ; BICIRNc register & ~immediate + BICIRNc 3 ^ 0FFFFh +NEWSYM FxOpd74A3 ; BICIRNc register & ~immediate + BICIRNc 4 ^ 0FFFFh +NEWSYM FxOpd75A3 ; BICIRNc register & ~immediate + BICIRNc 5 ^ 0FFFFh +NEWSYM FxOpd76A3 ; BICIRNc register & ~immediate + BICIRNc 6 ^ 0FFFFh +NEWSYM FxOpd77A3 ; BICIRNc register & ~immediate + BICIRNc 7 ^ 0FFFFh +NEWSYM FxOpd78A3 ; BICIRNc register & ~immediate + BICIRNc 8 ^ 0FFFFh +NEWSYM FxOpd79A3 ; BICIRNc register & ~immediate + BICIRNc 9 ^ 0FFFFh +NEWSYM FxOpd7AA3 ; BICIRNc register & ~immediate + BICIRNc 10 ^ 0FFFFh +NEWSYM FxOpd7BA3 ; BICIRNc register & ~immediate + BICIRNc 11 ^ 0FFFFh +NEWSYM FxOpd7CA3 ; BICIRNc register & ~immediate + BICIRNc 12 ^ 0FFFFh +NEWSYM FxOpd7DA3 ; BICIRNc register & ~immediate + BICIRNc 13 ^ 0FFFFh +NEWSYM FxOpd7EA3 ; BICIRNc register & ~immediate + BICIRNc 14 ^ 0FFFFh +NEWSYM FxOpd7FA3 ; BICIRNc register & ~immediate + BICIRNc 15 ^ 0FFFFh + +NEWSYM FxOpd80 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 0 +NEWSYM FxOpd81 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 1 +NEWSYM FxOpd82 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 2 +NEWSYM FxOpd83 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 3 +NEWSYM FxOpd84 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 4 +NEWSYM FxOpd85 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 5 +NEWSYM FxOpd86 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 6 +NEWSYM FxOpd87 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 7 +NEWSYM FxOpd88 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 8 +NEWSYM FxOpd89 ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 9 +NEWSYM FxOpd8A ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 10 +NEWSYM FxOpd8B ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 11 +NEWSYM FxOpd8C ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 12 +NEWSYM FxOpd8D ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 13 +NEWSYM FxOpd8E ; MULTRNc 8 bit to 16 bit signed multiply, register * register + MULTRNc 14 +NEWSYM FxOpd8F ; MULTRNc 8 bit to 16 bit signed multiply, register * register + FETCHPIPE + mov ebx,ebp + mov al,byte [esi] ; Read Source + sub ebx,[SfxCPB] + imul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd80A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 0 +NEWSYM FxOpd81A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 1 +NEWSYM FxOpd82A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 2 +NEWSYM FxOpd83A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 3 +NEWSYM FxOpd84A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 4 +NEWSYM FxOpd85A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 5 +NEWSYM FxOpd86A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 6 +NEWSYM FxOpd87A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 7 +NEWSYM FxOpd88A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 8 +NEWSYM FxOpd89A1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 9 +NEWSYM FxOpd8AA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 10 +NEWSYM FxOpd8BA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 11 +NEWSYM FxOpd8CA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 12 +NEWSYM FxOpd8DA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 13 +NEWSYM FxOpd8EA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + UMULTRNc 14 +NEWSYM FxOpd8FA1 ; UMULRN 8 bit to 16 bit unsigned multiply, register * register + FETCHPIPE + mov ebx,ebp + mov al,byte [esi] ; Read Source + sub ebx,[SfxCPB] + mul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn + +NEWSYM FxOpd80A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 0 +NEWSYM FxOpd81A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 1 +NEWSYM FxOpd82A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 2 +NEWSYM FxOpd83A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 3 +NEWSYM FxOpd84A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 4 +NEWSYM FxOpd85A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 5 +NEWSYM FxOpd86A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 6 +NEWSYM FxOpd87A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 7 +NEWSYM FxOpd88A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 8 +NEWSYM FxOpd89A2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 9 +NEWSYM FxOpd8AA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 10 +NEWSYM FxOpd8BA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 11 +NEWSYM FxOpd8CA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 12 +NEWSYM FxOpd8DA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 13 +NEWSYM FxOpd8EA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 14 +NEWSYM FxOpd8FA2 ; MULIRN 8 bit to 16 bit signed multiply, register * immediate + MULTIRNc 15 + +NEWSYM FxOpd80A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 0 +NEWSYM FxOpd81A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 1 +NEWSYM FxOpd82A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 2 +NEWSYM FxOpd83A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 3 +NEWSYM FxOpd84A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 4 +NEWSYM FxOpd85A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 5 +NEWSYM FxOpd86A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 6 +NEWSYM FxOpd87A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 7 +NEWSYM FxOpd88A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 8 +NEWSYM FxOpd89A3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 9 +NEWSYM FxOpd8AA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 10 +NEWSYM FxOpd8BA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 11 +NEWSYM FxOpd8CA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 12 +NEWSYM FxOpd8DA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 13 +NEWSYM FxOpd8EA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 14 +NEWSYM FxOpd8FA3 ;UMULIRN 8 bit to 16 bit unsigned multiply, register * immediate + UMULTIRNc 15 + +NEWSYM FxOpd90 ; SBK store word to last accessed RAM address ; V + mov ebx,[SfxLastRamAdr] ; Load last ram address + mov eax,[esi] ; Read Source + FETCHPIPE + mov [ebx],al ; Store Word + sub ebx,[SfxRAMMem] + xor ebx,1 + add ebx,[SfxRAMMem] + inc ebp ; Increase program counter + mov [ebx],ah ; Store Word + CLRFLAGS + FXReturn + +NEWSYM FxOpd91 ; LINKc#n R11 = R15 + immediate + LINKc 1 +NEWSYM FxOpd92 ; LINKc#n R11 = R15 + immediate + LINKc 2 +NEWSYM FxOpd93 ; LINKc#n R11 = R15 + immediate + LINKc 3 +NEWSYM FxOpd94 ; LINKc#n R11 = R15 + immediate + LINKc 4 + +NEWSYM FxOpd95 ; SEX sign extend 8 bit to 16 bit ; V + movsx eax, byte [esi] ; Read Source + FETCHPIPE + and eax,0FFFFh + inc ebp + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd96 ; ASR aritmethic shift right by one ; V + mov eax,[esi] ; Read Source + FETCHPIPE + mov [SfxCarry],al + and byte[SfxCarry],1 + sar ax,1 ; logic shift right + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd96A1 ; DIV2 aritmethic shift right by one ; V + mov eax,[esi] ; Read Source + FETCHPIPE + cmp ax,-1 + je .minusone + mov [SfxCarry],al + and byte[SfxCarry],1 + sar ax,1 ; logic shift right + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + FXReturn +.minusone + mov byte[SfxCarry],1 + xor eax,eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov dword [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd97 ; ROR rotate right by one ; V + FETCHPIPE + mov eax,[esi] ; Read Source + shr byte[SfxCarry],1 + rcr ax,1 + setc byte[SfxCarry] + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd98 ; JMPRNc jump to address of register + JMPRNc 8 +NEWSYM FxOpd99 ; JMPRNc jump to address of register + JMPRNc 9 +NEWSYM FxOpd9A ; JMPRNc jump to address of register + JMPRNc 10 +NEWSYM FxOpd9B ; JMPRNc jump to address of register + JMPRNc 11 +NEWSYM FxOpd9C ; JMPRNc jump to address of register + JMPRNc 12 +NEWSYM FxOpd9D ; JMPRNc jump to address of register + JMPRNc 13 + +NEWSYM FxOpd98A1 ; LJMPRNc set program bank to source register and jump to address of register + LJMPRNc 8 +NEWSYM FxOpd99A1 ; LJMPRNc set program bank to source register and jump to address of register + LJMPRNc 9 +NEWSYM FxOpd9AA1 ; LJMPRNc set program bank to source register and jump to address of register + LJMPRNc 10 +NEWSYM FxOpd9BA1 ; LJMPRNc set program bank to source register and jump to address of register + LJMPRNc 11 +NEWSYM FxOpd9CA1 ; LJMPRNc set program bank to source register and jump to address of register + LJMPRNc 12 +NEWSYM FxOpd9DA1 ; LJMPRNc set program bank to source register and jump to address of register + LJMPRNc 13 + +NEWSYM FxOpd9E ; LOB set upper byte to zero (keep low byte) ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,0FFh + inc ebp + mov [edi],eax ; Write Destination + shl eax,8 + mov dword [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpd9F ; FMULT 16 bit to 32 bit signed multiplication, upper 16 bits only + ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR6] + FETCHPIPE + imul bx + inc ebp + and edx,0FFFFh + mov [SfxSignZero],edx + mov [edi],edx ; Write Destination + shr ax,15 + mov [SfxCarry],al + CLRFLAGS + FXReturn + +NEWSYM FxOpd9FA1 ; LMULT 16 bit to 32 bit signed multiplication ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR6] + FETCHPIPE + imul bx + and edx,0FFFFh + inc ebp + mov [edi],edx ; Write Destination + mov [SfxR4],ax + mov [SfxSignZero],edx + shr ax,15 + mov [SfxCarry],al + CLRFLAGS + FXReturn + +NEWSYM FxOpdA0 ; IBTRNc,#PP immediate byte transfer + IBTRNc 0 +NEWSYM FxOpdA1 ; IBTRNc,#PP immediate byte transfer + IBTRNc 1 +NEWSYM FxOpdA2 ; IBTRNc,#PP immediate byte transfer + IBTRNc 2 +NEWSYM FxOpdA3 ; IBTRNc,#PP immediate byte transfer + IBTRNc 3 +NEWSYM FxOpdA4 ; IBTRNc,#PP immediate byte transfer + IBTRNc 4 +NEWSYM FxOpdA5 ; IBTRNc,#PP immediate byte transfer + IBTRNc 5 +NEWSYM FxOpdA6 ; IBTRNc,#PP immediate byte transfer + IBTRNc 6 +NEWSYM FxOpdA7 ; IBTRNc,#PP immediate byte transfer + IBTRNc 7 +NEWSYM FxOpdA8 ; IBTRNc,#PP immediate byte transfer + IBTRNc 8 +NEWSYM FxOpdA9 ; IBTRNc,#PP immediate byte transfer + IBTRNc 9 +NEWSYM FxOpdAA ; IBTRNc,#PP immediate byte transfer + IBTRNc 10 +NEWSYM FxOpdAB ; IBTRNc,#PP immediate byte transfer + IBTRNc 11 +NEWSYM FxOpdAC ; IBTRNc,#PP immediate byte transfer + IBTRNc 12 +NEWSYM FxOpdAD ; IBTRNc,#PP immediate byte transfer + IBTRNc 13 +NEWSYM FxOpdAE ; IBTRNc,#PP immediate byte transfer + movsx eax,byte[ebp] + mov cl,[ebp+1] + add ebp,2 + mov [SfxR0+14*4],ax + UpdateR14 + CLRFLAGS + FXReturn +NEWSYM FxOpdAF ; IBTRNc,#PP immediate byte transfer + movsx eax,byte[ebp] + mov cl,[ebp+1] + and eax,0FFFFh + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + FXReturn + +NEWSYM FxOpdA0A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 0 +NEWSYM FxOpdA1A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 1 +NEWSYM FxOpdA2A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 2 +NEWSYM FxOpdA3A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 3 +NEWSYM FxOpdA4A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 4 +NEWSYM FxOpdA5A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 5 +NEWSYM FxOpdA6A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 6 +NEWSYM FxOpdA7A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 7 +NEWSYM FxOpdA8A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 8 +NEWSYM FxOpdA9A1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 9 +NEWSYM FxOpdAAA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 10 +NEWSYM FxOpdABA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 11 +NEWSYM FxOpdACA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 12 +NEWSYM FxOpdADA1 ; LMS rn,(yy) load word from RAM (short address) + LMSRNc 13 +NEWSYM FxOpdAEA1 ; LMS rn,(yy) load word from RAM (short address) + xor eax,eax + mov al,[ebp] + add eax,eax + inc ebp + add eax,[SfxRAMMem] + mov cl,[ebp] + mov dword [SfxLastRamAdr],eax + mov ebx,[eax] ; Read word from ram + inc ebp + mov [SfxR0+14*4],bx ; Write data + UpdateR14 + CLRFLAGS + FXReturn +NEWSYM FxOpdAFA1 ; LMS rn,(yy) load word from RAM (short address) + xor eax,eax + mov al,[ebp] + add eax,eax + inc ebp + add eax,[SfxRAMMem] + mov cl,[ebp] + mov dword [SfxLastRamAdr],eax + mov ebx,[eax] ; Read word from ram + and ebx,0FFFFh + mov ebp,[SfxCPB] + add ebp,ebx + CLRFLAGS + FXReturn + +NEWSYM FxOpdA0A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 0 +NEWSYM FxOpdA1A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 1 +NEWSYM FxOpdA2A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 2 +NEWSYM FxOpdA3A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 3 +NEWSYM FxOpdA4A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 4 +NEWSYM FxOpdA5A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 5 +NEWSYM FxOpdA6A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 6 +NEWSYM FxOpdA7A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 7 +NEWSYM FxOpdA8A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 8 +NEWSYM FxOpdA9A2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 9 +NEWSYM FxOpdAAA2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 10 +NEWSYM FxOpdABA2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 11 +NEWSYM FxOpdACA2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 12 +NEWSYM FxOpdADA2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 13 +NEWSYM FxOpdAEA2 ; SMS (yy),rn store word in RAM (short address) + SMSRNc 14 +NEWSYM FxOpdAFA2 ; SMS (yy),rn store word in RAM (short address) + xor eax,eax + mov ebx,ebp + sub ebx,[SfxCPB] + mov al,[ebp] + inc ebp + add eax,eax + FETCHPIPE + add eax,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax + inc ebp + mov [eax],bx ; Write word to ram + CLRFLAGS + FXReturn + +NEWSYM FxOpdB0 ; FROM rn set source register + FROMRNd 0 +NEWSYM FxOpdB1 ; FROM rn set source register + FROMRNd 1 +NEWSYM FxOpdB2 ; FROM rn set source register + FROMRNd 2 +NEWSYM FxOpdB3 ; FROM rn set source register + FROMRNd 3 +NEWSYM FxOpdB4 ; FROM rn set source register + FROMRNd 4 +NEWSYM FxOpdB5 ; FROM rn set source register + FROMRNd 5 +NEWSYM FxOpdB6 ; FROM rn set source register + FROMRNd 6 +NEWSYM FxOpdB7 ; FROM rn set source register + FROMRNd 7 +NEWSYM FxOpdB8 ; FROM rn set source register + FROMRNd 8 +NEWSYM FxOpdB9 ; FROM rn set source register + FROMRNd 9 +NEWSYM FxOpdBA ; FROM rn set source register + FROMRNd 10 +NEWSYM FxOpdBB ; FROM rn set source register + FROMRNd 11 +NEWSYM FxOpdBC ; FROM rn set source register + FROMRNd 12 +NEWSYM FxOpdBD ; FROM rn set source register + FROMRNd 13 +NEWSYM FxOpdBE ; FROM rn set source register + FROMRNd 14 +NEWSYM FxOpdBF ; FROM rn set source register + FETCHPIPE + mov esi,SfxR0+15*4 + inc ebp ; Increase program counter + mov eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + call [FxTableb+ecx*4] + mov esi,SfxR0 + FXReturn + +NEWSYM FxOpdC0 ; HIB move high-byte to low-byte ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,0FF00h + mov dword [SfxSignZero],eax + shr eax,8 + inc ebp + mov [edi],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpdC1 ; OR rn or rn + ORRNc 1 +NEWSYM FxOpdC2 ; OR rn or rn + ORRNc 2 +NEWSYM FxOpdC3 ; OR rn or rn + ORRNc 3 +NEWSYM FxOpdC4 ; OR rn or rn + ORRNc 4 +NEWSYM FxOpdC5 ; OR rn or rn + ORRNc 5 +NEWSYM FxOpdC6 ; OR rn or rn + ORRNc 6 +NEWSYM FxOpdC7 ; OR rn or rn + ORRNc 7 +NEWSYM FxOpdC8 ; OR rn or rn + ORRNc 8 +NEWSYM FxOpdC9 ; OR rn or rn + ORRNc 9 +NEWSYM FxOpdCA ; OR rn or rn + ORRNc 10 +NEWSYM FxOpdCB ; OR rn or rn + ORRNc 11 +NEWSYM FxOpdCC ; OR rn or rn + ORRNc 12 +NEWSYM FxOpdCD ; OR rn or rn + ORRNc 13 +NEWSYM FxOpdCE ; OR rn or rn + ORRNc 14 +NEWSYM FxOpdCF ; OR rn or rn + mov eax,[esi] ; Read Source + mov ebx,ebp + FETCHPIPE + sub ebx,[SfxCPB] + or eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpdC1A1 ; XOR rn xor rn + XORRNc 1 +NEWSYM FxOpdC2A1 ; XOR rn xor rn + XORRNc 2 +NEWSYM FxOpdC3A1 ; XOR rn xor rn + XORRNc 3 +NEWSYM FxOpdC4A1 ; XOR rn xor rn + XORRNc 4 +NEWSYM FxOpdC5A1 ; XOR rn xor rn + XORRNc 5 +NEWSYM FxOpdC6A1 ; XOR rn xor rn + XORRNc 6 +NEWSYM FxOpdC7A1 ; XOR rn xor rn + XORRNc 7 +NEWSYM FxOpdC8A1 ; XOR rn xor rn + XORRNc 8 +NEWSYM FxOpdC9A1 ; XOR rn xor rn + XORRNc 9 +NEWSYM FxOpdCAA1 ; XOR rn xor rn + XORRNc 10 +NEWSYM FxOpdCBA1 ; XOR rn xor rn + XORRNc 11 +NEWSYM FxOpdCCA1 ; XOR rn xor rn + XORRNc 12 +NEWSYM FxOpdCDA1 ; XOR rn xor rn + XORRNc 13 +NEWSYM FxOpdCEA1 ; XOR rn xor rn + XORRNc 14 +NEWSYM FxOpdCFA1 ; XOR rn xor rn + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,ebp + sub ebx,[SfxCPB] + xor eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpdC1A2 ; OR #n OR #n + ORIc 1 +NEWSYM FxOpdC2A2 ; OR #n OR #n + ORIc 2 +NEWSYM FxOpdC3A2 ; OR #n OR #n + ORIc 3 +NEWSYM FxOpdC4A2 ; OR #n OR #n + ORIc 4 +NEWSYM FxOpdC5A2 ; OR #n OR #n + ORIc 5 +NEWSYM FxOpdC6A2 ; OR #n OR #n + ORIc 6 +NEWSYM FxOpdC7A2 ; OR #n OR #n + ORIc 7 +NEWSYM FxOpdC8A2 ; OR #n OR #n + ORIc 8 +NEWSYM FxOpdC9A2 ; OR #n OR #n + ORIc 9 +NEWSYM FxOpdCAA2 ; OR #n OR #n + ORIc 10 +NEWSYM FxOpdCBA2 ; OR #n OR #n + ORIc 11 +NEWSYM FxOpdCCA2 ; OR #n OR #n + ORIc 12 +NEWSYM FxOpdCDA2 ; OR #n OR #n + ORIc 13 +NEWSYM FxOpdCEA2 ; OR #n OR #n + ORIc 14 +NEWSYM FxOpdCFA2 ; OR #n OR #n + ORIc 15 + +NEWSYM FxOpdC1A3 ; XOR #n xor #n + XORIc 1 +NEWSYM FxOpdC2A3 ; XOR #n xor #n + XORIc 2 +NEWSYM FxOpdC3A3 ; XOR #n xor #n + XORIc 3 +NEWSYM FxOpdC4A3 ; XOR #n xor #n + XORIc 4 +NEWSYM FxOpdC5A3 ; XOR #n xor #n + XORIc 5 +NEWSYM FxOpdC6A3 ; XOR #n xor #n + XORIc 6 +NEWSYM FxOpdC7A3 ; XOR #n xor #n + XORIc 7 +NEWSYM FxOpdC8A3 ; XOR #n xor #n + XORIc 8 +NEWSYM FxOpdC9A3 ; XOR #n xor #n + XORIc 9 +NEWSYM FxOpdCAA3 ; XOR #n xor #n + XORIc 10 +NEWSYM FxOpdCBA3 ; XOR #n xor #n + XORIc 11 +NEWSYM FxOpdCCA3 ; XOR #n xor #n + XORIc 12 +NEWSYM FxOpdCDA3 ; XOR #n xor #n + XORIc 13 +NEWSYM FxOpdCEA3 ; XOR #n xor #n + XORIc 14 +NEWSYM FxOpdCFA3 ; XOR #n xor #n + XORIc 15 + +NEWSYM FxOpdD0 ; INC rn increase by one + INCRNc 0 +NEWSYM FxOpdD1 ; INC rn increase by one + INCRNc 1 +NEWSYM FxOpdD2 ; INC rn increase by one + INCRNc 2 +NEWSYM FxOpdD3 ; INC rn increase by one + INCRNc 3 +NEWSYM FxOpdD4 ; INC rn increase by one + INCRNc 4 +NEWSYM FxOpdD5 ; INC rn increase by one + INCRNc 5 +NEWSYM FxOpdD6 ; INC rn increase by one + INCRNc 6 +NEWSYM FxOpdD7 ; INC rn increase by one + INCRNc 7 +NEWSYM FxOpdD8 ; INC rn increase by one + INCRNc 8 +NEWSYM FxOpdD9 ; INC rn increase by one + INCRNc 9 +NEWSYM FxOpdDA ; INC rn increase by one + INCRNc 10 +NEWSYM FxOpdDB ; INC rn increase by one + INCRNc 11 +NEWSYM FxOpdDC ; INC rn increase by one + INCRNc 12 +NEWSYM FxOpdDD ; INC rn increase by one + INCRNc 13 +NEWSYM FxOpdDE ; INC rn increase by one + FETCHPIPE + mov eax,[SfxR0+14*4] ; Read Source + inc ax + mov [SfxR0+14*4],eax + mov [SfxSignZero],eax + CLRFLAGS + inc ebp + UpdateR14 + FXReturn + +NEWSYM FxOpdDF ; GETC transfer ROM buffer to color register + mov eax,[SfxRomBuffer] + FETCHPIPE + mov eax,[eax] + test byte[SfxPOR],04h + jz .nohighnibble + mov bl,al + shr bl,4 + and al,0F0h + or al,bl +.nohighnibble + test byte[SfxPOR],08h + jnz .preserveupper + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx +.nocolchange + CLRFLAGS + inc ebp ; Increase program counter + FXReturn +.preserveupper + mov bl,[SfxCOLR] + and al,0Fh + and bl,0F0h + or al,bl + cmp [SfxCOLR],al + je .nocolchange + mov [SfxCOLR],al + and eax,0FFh + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + CLRFLAGS + inc ebp ; Increase program counter + FXReturn + +NEWSYM FxOpdDFA2 ; RAMB set current RAM bank ; Verified + mov eax,[esi] ; Read Source + mov ebx,[SfxnRamBanks] + FETCHPIPE + dec ebx + and eax,ebx + mov dword [SfxRAMBR],eax + shl eax,16 + add eax,[sfxramdata] + mov dword [SfxRAMMem],eax + CLRFLAGS + inc ebp + FXReturn + +NEWSYM FxOpdDFA3 ; ROMB set current ROM bank ; Verified + mov eax,[esi] ; Read Source + and eax,07Fh + FETCHPIPE + mov dword [SfxROMBR],eax + mov eax,[SfxMemTable+eax*4] + mov [SfxCROM],eax + CLRFLAGS + inc ebp + FXReturn + +NEWSYM FxOpdE0 ; DEC rn decrement by one + DECRNc 0 +NEWSYM FxOpdE1 ; DEC rn decrement by one + DECRNc 1 +NEWSYM FxOpdE2 ; DEC rn decrement by one + DECRNc 2 +NEWSYM FxOpdE3 ; DEC rn decrement by one + DECRNc 3 +NEWSYM FxOpdE4 ; DEC rn decrement by one + DECRNc 4 +NEWSYM FxOpdE5 ; DEC rn decrement by one + DECRNc 5 +NEWSYM FxOpdE6 ; DEC rn decrement by one + DECRNc 6 +NEWSYM FxOpdE7 ; DEC rn decrement by one + DECRNc 7 +NEWSYM FxOpdE8 ; DEC rn decrement by one + DECRNc 8 +NEWSYM FxOpdE9 ; DEC rn decrement by one + DECRNc 9 +NEWSYM FxOpdEA ; DEC rn decrement by one + DECRNc 10 +NEWSYM FxOpdEB ; DEC rn decrement by one + DECRNc 11 +NEWSYM FxOpdEC ; DEC rn decrement by one + DECRNc 12 +NEWSYM FxOpdED ; DEC rn decrement by one + DECRNc 13 +NEWSYM FxOpdEE ; DEC rn decrement by one + dec word[SfxR0+14*4] + FETCHPIPE + mov eax,[SfxR0+14*4] ; Read Source + mov [SfxSignZero],eax + UpdateR14 + CLRFLAGS + inc ebp + FXReturn + +NEWSYM FxOpdEF ; getb get byte from ROM at address R14 ; V + FETCHPIPE + mov eax,[SfxRomBuffer] + inc ebp + mov eax,[eax] + and eax,0FFh +; cmp edi,SfxR15 +; je .nor15 + mov [edi],eax ; Write DREG + CLRFLAGS + FXReturn +.nor15 + or eax,8000h + mov [edi],eax ; Write DREG + CLRFLAGS + FXReturn + + add eax,ebp + sub eax,[SfxCPB] + mov [SfxR15],eax + CLRFLAGS + FXReturn + +NEWSYM FxOpdEFA1 ; getbh get high-byte from ROM at address R14 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxRomBuffer] + and eax,0FFh + FETCHPIPE + mov ah,[ebx] + inc ebp + mov [edi],eax ; Write DREG + CLRFLAGS + FXReturn + +NEWSYM FxOpdEFA2 ; getbl get low-byte from ROM at address R14 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxRomBuffer] + and eax,0FF00h + FETCHPIPE + mov al,[ebx] + inc ebp + mov [edi],eax ; Write DREG + CLRFLAGS + FXReturn + +NEWSYM FxOpdEFA3 ; getbs get sign extended byte from ROM at address R14 ; V + mov ebx,[SfxRomBuffer] + FETCHPIPE + movsx eax,byte[ebx] + inc ebp + mov [edi],ax ; Write DREG + CLRFLAGS + FXReturn + +NEWSYM FxOpdF0 ; IWT RN,#xx immediate word transfer to register + IWTRNc 0 +NEWSYM FxOpdF1 ; IWT RN,#xx immediate word transfer to register + IWTRNc 1 +NEWSYM FxOpdF2 ; IWT RN,#xx immediate word transfer to register + IWTRNc 2 +NEWSYM FxOpdF3 ; IWT RN,#xx immediate word transfer to register + IWTRNc 3 +NEWSYM FxOpdF4 ; IWT RN,#xx immediate word transfer to register + IWTRNc 4 +NEWSYM FxOpdF5 ; IWT RN,#xx immediate word transfer to register + IWTRNc 5 +NEWSYM FxOpdF6 ; IWT RN,#xx immediate word transfer to register + IWTRNc 6 +NEWSYM FxOpdF7 ; IWT RN,#xx immediate word transfer to register + IWTRNc 7 +NEWSYM FxOpdF8 ; IWT RN,#xx immediate word transfer to register + IWTRNc 8 +NEWSYM FxOpdF9 ; IWT RN,#xx immediate word transfer to register + IWTRNc 9 +NEWSYM FxOpdFA ; IWT RN,#xx immediate word transfer to register + IWTRNc 10 +NEWSYM FxOpdFB ; IWT RN,#xx immediate word transfer to register + IWTRNc 11 +NEWSYM FxOpdFC ; IWT RN,#xx immediate word transfer to register + IWTRNc 12 +NEWSYM FxOpdFD ; IWT RN,#xx immediate word transfer to register + IWTRNc 13 +NEWSYM FxOpdFE ; IWT RN,#xx immediate word transfer to register + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + add ebp,3 + mov [SfxR0+14*4],eax + UpdateR14 + CLRFLAGS + FXReturn +NEWSYM FxOpdFF ; IWT RN,#xx immediate word transfer to register + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + FXReturn + +NEWSYM FxOpdF0A1 ; LM RN,(XX) load word from RAM + LMRNc 0 +NEWSYM FxOpdF1A1 ; LM RN,(XX) load word from RAM + LMRNc 1 +NEWSYM FxOpdF2A1 ; LM RN,(XX) load word from RAM + LMRNc 2 +NEWSYM FxOpdF3A1 ; LM RN,(XX) load word from RAM + LMRNc 3 +NEWSYM FxOpdF4A1 ; LM RN,(XX) load word from RAM + LMRNc 4 +NEWSYM FxOpdF5A1 ; LM RN,(XX) load word from RAM + LMRNc 5 +NEWSYM FxOpdF6A1 ; LM RN,(XX) load word from RAM + LMRNc 6 +NEWSYM FxOpdF7A1 ; LM RN,(XX) load word from RAM + LMRNc 7 +NEWSYM FxOpdF8A1 ; LM RN,(XX) load word from RAM + LMRNc 8 +NEWSYM FxOpdF9A1 ; LM RN,(XX) load word from RAM + LMRNc 9 +NEWSYM FxOpdFAA1 ; LM RN,(XX) load word from RAM + LMRNc 10 +NEWSYM FxOpdFBA1 ; LM RN,(XX) load word from RAM + LMRNc 11 +NEWSYM FxOpdFCA1 ; LM RN,(XX) load word from RAM + LMRNc 12 +NEWSYM FxOpdFDA1 ; LM RN,(XX) load word from RAM + LMRNc 13 +NEWSYM FxOpdFEA1 ; LM RN,(XX) load word from RAM + xor eax,eax + mov cl,[ebp+2] + mov ax,[ebp] + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov dl,[eax+ebx] + xor eax,1 + add ebp,3 + mov dh,[eax+ebx] + mov word [SfxR0+14*4],dx ; Store Word + UpdateR14 + CLRFLAGS + FXReturn +NEWSYM FxOpdFFA1 ; LM RN,(XX) load word from RAM + FETCHPIPE + mov eax,ecx + inc ebp + FETCHPIPE + inc ebp + mov ah,cl + FETCHPIPE + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov dl,[eax+ebx] + xor eax,1 + mov dh,[eax+ebx] + and edx,0FFFFh + mov ebp,[SfxCPB] + add ebp,edx + CLRFLAGS + FXReturn + +NEWSYM FxOpdF0A2 ; SM (XX),RN store word in RAM + SMRNc 0 +NEWSYM FxOpdF1A2 ; SM (XX),RN store word in RAM + SMRNc 1 +NEWSYM FxOpdF2A2 ; SM (XX),RN store word in RAM + SMRNc 2 +NEWSYM FxOpdF3A2 ; SM (XX),RN store word in RAM + SMRNc 3 +NEWSYM FxOpdF4A2 ; SM (XX),RN store word in RAM + SMRNc 4 +NEWSYM FxOpdF5A2 ; SM (XX),RN store word in RAM + SMRNc 5 +NEWSYM FxOpdF6A2 ; SM (XX),RN store word in RAM + SMRNc 6 +NEWSYM FxOpdF7A2 ; SM (XX),RN store word in RAM + SMRNc 7 +NEWSYM FxOpdF8A2 ; SM (XX),RN store word in RAM + SMRNc 8 +NEWSYM FxOpdF9A2 ; SM (XX),RN store word in RAM + SMRNc 9 +NEWSYM FxOpdFAA2 ; SM (XX),RN store word in RAM + SMRNc 10 +NEWSYM FxOpdFBA2 ; SM (XX),RN store word in RAM + SMRNc 11 +NEWSYM FxOpdFCA2 ; SM (XX),RN store word in RAM + SMRNc 12 +NEWSYM FxOpdFDA2 ; SM (XX),RN store word in RAM + SMRNc 13 +NEWSYM FxOpdFEA2 ; SM (XX),RN store word in RAM + SMRNc 14 +NEWSYM FxOpdFFA2 ; SM (XX),RN store word in RAM + FETCHPIPE + mov ebx,ebp + sub ebx,[SfxCPB] + mov eax,ecx + inc ebp + FETCHPIPE + inc ebp + mov ah,cl + FETCHPIPE + mov dx,bx + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov [eax+ebx],dl + xor eax,1 + inc ebp + mov [eax+ebx],dh + CLRFLAGS + FXReturn + \ No newline at end of file diff --git a/zsnes/src/chips/fxemu2c.mac b/zsnes/src/chips/fxemu2c.mac new file mode 100644 index 00000000..fda7f5f7 --- /dev/null +++ b/zsnes/src/chips/fxemu2c.mac @@ -0,0 +1,529 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + + +%macro FXReturn 0 + dec dword [NumberOfOpcodes] + jmp [FxTabled+ecx*4] + ALIGN32 +%endmacro + +%macro FXReturn2 0 + dec dword [NumberOfOpcodes] + js %%endloop + jmp [FxTabled+ecx*4] +%%endloop + jmp FXEndLoop +; jmp [FxTabled+ecx*4] + ALIGN32 +%endmacro + +%macro TORNd 1 ; V + FETCHPIPE + mov edi, SfxR0+%1*4 + inc ebp ; Increase program counter + call [FxTable+ecx*4] + mov edi,SfxR0 + FXReturn +%endmacro + +%macro WITHc 1 ; Verified. + FETCHPIPE + mov esi,SfxR0+%1*4 + mov edi,SfxR0+%1*4 + mov dword [SfxB],1 + inc ebp ; Increase program counter + call [FxTablec+ecx*4] + mov esi,SfxR0 + mov edi,SfxR0 + mov dword [SfxB],0 ; Clear B Flag + FXReturn +%endmacro + +%macro STWRNc 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + mov ebx,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax ; Save last ram address + add dword [SfxLastRamAdr],ebx ; Save last ram address + mov edx,[esi] ; Read Source + FETCHPIPE + mov [ebx+eax],dl ; Store Word + xor eax,1 + inc ebp ; Increase program counter + mov [ebx+eax],dh ; Store Word + CLRFLAGS + FXReturn +%endmacro + +%macro STBRNc 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + FETCHPIPE + add eax,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax ; Save last ram address + mov ebx,[esi] ; Read Source + mov byte [eax],bl ; Store Byte + CLRFLAGS + inc ebp ; Increase program counter + FXReturn +%endmacro + +%macro LDWRNc 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + mov ebx,[SfxRAMMem] + mov dword [SfxLastRamAdr],eax ; Save last ram address + FETCHPIPE + mov dl,[ebx+eax] ; Store Word + add dword [SfxLastRamAdr],ebx ; Save last ram address + xor eax,1 + and edx,0FFFFh + inc ebp ; Increase program counter + mov dh,[ebx+eax] ; Store Word + mov [edi],edx ; Read Source + CLRFLAGS + FXReturn +%endmacro + +%macro LDBRNc 1 ; V + mov eax,[SfxR0+%1*4] ; Read register + FETCHPIPE + add eax,[SfxRAMMem] + xor ebx,ebx + mov dword [SfxLastRamAdr],eax ; Save last ram address + mov bl,[eax] ; Read Byte + inc ebp ; Increase program counter + mov [edi],ebx ; Store Result + CLRFLAGS + FXReturn +%endmacro + +%macro ADDRNc 1 ; V + mov eax, [esi] ; Read Source + mov ebx, [SfxR0+%1*4] + FETCHPIPE + add ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro ADCRNc 1 ; V + FETCHPIPE + mov eax, [esi] ; Read Source + mov ebx, [SfxR0+%1*4] + shr byte[SfxCarry],1 + adc ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro ADIRNc 1 ; V + mov eax, [esi] ; Read Source + FETCHPIPE + add ax,%1 + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro ADCIRNc 1 ; V + FETCHPIPE + mov eax, [esi] ; Read Source + shr byte[SfxCarry],1 + adc ax,%1 + seto byte[SfxOverflow] + setc byte[SfxCarry] + mov [SfxSignZero],eax + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro SUBRNc 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] + FETCHPIPE + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro SBCRNc 1 ; V + FETCHPIPE + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] + cmp byte[SfxCarry],1 + sbb ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro SUBIRNc 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + sub ax,%1 + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + inc ebp ; Increase program counter + mov [edi],eax ; Write Destination + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro CMPRNc 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] + FETCHPIPE + sub ax,bx + seto byte[SfxOverflow] + setc byte[SfxCarry] + xor byte[SfxCarry],1 + mov [SfxSignZero],eax + CLRFLAGS + inc ebp ; Increase program counter + FXReturn +%endmacro + +%macro ANDRNc 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] ; Read RN + FETCHPIPE + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro BICRNc 1 ; V + mov ebx,[SfxR0+%1*4] ; Read RN + mov eax,[esi] ; Read Source + xor ebx,0FFFFh + FETCHPIPE + and eax,ebx + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro ANDIRNc 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,%1 + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro BICIRNc 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + and eax,%1 + inc ebp + mov dword [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro MULTRNc 1 ; V + mov al,byte [esi] ; Read Source + mov bl,byte [SfxR0+%1*4] ; Read RN + FETCHPIPE + imul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro UMULTRNc 1 ; V + mov al,byte [esi] ; Read Source + mov bl,byte [SfxR0+%1*4] ; Read RN + FETCHPIPE + mul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro MULTIRNc 1 ; V + mov al,byte [esi] ; Read Source + mov bl,%1 ; Read RN + FETCHPIPE + imul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro UMULTIRNc 1 ; V + mov al,byte [esi] ; Read Source + mov bl,%1 ; Read RN + FETCHPIPE + mul bl + inc ebp + and eax,0FFFFh + mov [SfxSignZero],eax + mov [edi],eax ; Write Destination + CLRFLAGS + FXReturn +%endmacro + +%macro LINKc 1 ; Verified. + mov eax,ebp + sub eax,[SfxCPB] + add eax,%1 + FETCHPIPE + mov word [SfxR11],ax + CLRFLAGS + inc ebp + FXReturn +%endmacro + +%macro JMPRNc 1 ; V + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read RN + mov ebp,[SfxCPB] + add ebp,eax + CLRFLAGS + FXReturn +%endmacro + +%macro LJMPRNc 1 ; V + FETCHPIPE + mov eax,[SfxR0+%1*4] + and eax,07Fh + mov byte[SfxPBR],al +; mov byte[fxtrace+eax],1 + mov eax,[SfxMemTable+eax*4] + mov [SfxCPB],eax + mov ebp,eax + add ebp,[esi] ; Read RN + mov dword [SfxCacheActive],0 + push ecx + call FxOp02 + pop ecx + dec ebp + FXReturn +%endmacro + +%macro IBTRNc 1 ; V + movsx eax,byte[ebp] + mov cl,[ebp+1] + add ebp,2 + mov [SfxR0+%1*4],ax + CLRFLAGS + FXReturn +%endmacro + +%macro LMSRNc 1 ; Verified. + xor eax,eax + mov al,[ebp] + add eax,eax + inc ebp + add eax,[SfxRAMMem] + mov cl,[ebp] + mov dword [SfxLastRamAdr],eax + mov ebx,[eax] ; Read word from ram + inc ebp + mov [SfxR0+%1*4],bx ; Write data + CLRFLAGS + FXReturn +%endmacro + +%macro SMSRNc 1 ; Verified. + xor eax,eax + mov al,[ebp] + inc ebp + add eax,eax + mov cl,[ebp] + add eax,[SfxRAMMem] + mov ebx,[SfxR0+%1*4] ; Read data + mov dword [SfxLastRamAdr],eax + inc ebp + mov [eax],bx ; Write word to ram + CLRFLAGS + FXReturn +%endmacro + +%macro FROMRNd 1 ; V + FETCHPIPE + mov esi,SfxR0+%1*4 + inc ebp ; Increase program counter + call [FxTable+ecx*4] + mov esi,SfxR0 + FXReturn +%endmacro + +%macro ORRNc 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] ; Read + FETCHPIPE + or eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro XORRNc 1 ; V + mov eax,[esi] ; Read Source + mov ebx,[SfxR0+%1*4] ; Read + FETCHPIPE + xor eax,ebx + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro ORIc 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + or eax,%1 + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro XORIc 1 ; V + mov eax,[esi] ; Read Source + FETCHPIPE + xor eax,%1 + inc ebp + mov [edi],eax ; Write DREG + mov [SfxSignZero],eax + CLRFLAGS + FXReturn +%endmacro + +%macro INCRNc 1 ; Verified + inc word[SfxR0+%1*4] + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read Source + mov [SfxSignZero],eax + CLRFLAGS + inc ebp + FXReturn +%endmacro + +%macro DECRNc 1 ; Verified + dec word[SfxR0+%1*4] + FETCHPIPE + mov eax,[SfxR0+%1*4] ; Read Source + mov [SfxR0+%1*4],eax + mov [SfxSignZero],eax + CLRFLAGS + inc ebp + FXReturn +%endmacro + +%macro IWTRNc 1 ; aka LEA ; Verified. + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + add ebp,3 + mov [SfxR0+%1*4],eax + CLRFLAGS + FXReturn +%endmacro + +%macro LMRNc 1 ; Verified! + xor eax,eax + mov cl,[ebp+2] + mov ax,[ebp] + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov dl,[eax+ebx] + xor eax,1 + add ebp,3 + mov dh,[eax+ebx] + mov word [SfxR0+%1*4],dx ; Store Word + CLRFLAGS + FXReturn +%endmacro + +%macro SMRNc 1 ; Verified + mov ebx,[SfxR0+%1*4] + mov eax,[ebp] + mov cl,[ebp+2] + and eax,0FFFFh + mov dx,bx + mov ebx,[SfxRAMMem] + mov [SfxLastRamAdr],eax + add [SfxLastRamAdr],ebx + mov [eax+ebx],dl + xor eax,1 + add ebp,3 + mov [eax+ebx],dh + CLRFLAGS + FXReturn +%endmacro + \ No newline at end of file diff --git a/zsnes/src/chips/fxtable.asm b/zsnes/src/chips/fxtable.asm new file mode 100644 index 00000000..835c2abf --- /dev/null +++ b/zsnes/src/chips/fxtable.asm @@ -0,0 +1,3546 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM FxTable,FxTableA1,FxTableA2,FxTableA3,FxTableb,FxTablebA1,FxTablebA2 +EXTSYM FxTablebA3,FxTablec,FxTablecA1,FxTablecA2,FxTablecA3,FxTabled +EXTSYM FxTabledA1,FxTabledA2,FxTabledA3,SfxMemTable,romdata,sfxramdata +EXTSYM FxOp00,FxOp01,FxOp02,FxOp03,FxOp04,FxOp05,FxOp06,FxOp07,FxOp08 +EXTSYM FxOp09,FxOp0A,FxOp0B,FxOp0C,FxOp0D,FxOp0E,FxOp0F,FxOp10,FxOp11 +EXTSYM FxOp12,FxOp13,FxOp14,FxOp15,FxOp16,FxOp17,FxOp18,FxOp19,FxOp1A +EXTSYM FxOp1B,FxOp1C,FxOp1D,FxOp1E,FxOp1F,FxOp20,FxOp21,FxOp22,FxOp23 +EXTSYM FxOp24,FxOp25,FxOp26,FxOp27,FxOp28,FxOp29,FxOp2A,FxOp2B,FxOp2C +EXTSYM FxOp2D,FxOp2E,FxOp2F,FxOp30,FxOp30A1,FxOp31,FxOp31A1,FxOp32 +EXTSYM FxOp32A1,FxOp33,FxOp33A1,FxOp34,FxOp34A1,FxOp35,FxOp35A1,FxOp36 +EXTSYM FxOp36A1,FxOp37,FxOp37A1,FxOp38,FxOp38A1,FxOp39,FxOp39A1,FxOp3A +EXTSYM FxOp3AA1,FxOp3B,FxOp3BA1,FxOp3C,FxOp3D,FxOp3E,FxOp3F,FxOp40 +EXTSYM FxOp40A1,FxOp41,FxOp41A1,FxOp42,FxOp42A1,FxOp43,FxOp43A1,FxOp44 +EXTSYM FxOp44A1,FxOp45,FxOp45A1,FxOp46,FxOp46A1,FxOp47,FxOp47A1,FxOp48 +EXTSYM FxOp48A1,FxOp49,FxOp49A1,FxOp4A,FxOp4AA1,FxOp4B,FxOp4BA1,FxOp4C +EXTSYM FxOp4CA1,FxOp4D,FxOp4E,FxOp4EA1,FxOp4F,FxOp50,FxOp50A1,FxOp50A2 +EXTSYM FxOp50A3,FxOp51,FxOp51A1,FxOp51A2,FxOp51A3,FxOp52,FxOp52A1,FxOp52A2 +EXTSYM FxOp52A3,FxOp53,FxOp53A1,FxOp53A2,FxOp53A3,FxOp54,FxOp54A1,FxOp54A2 +EXTSYM FxOp54A3,FxOp55,FxOp55A1,FxOp55A2,FxOp55A3,FxOp56,FxOp56A1,FxOp56A2 +EXTSYM FxOp56A3,FxOp57,FxOp57A1,FxOp57A2,FxOp57A3,FxOp58,FxOp58A1,FxOp58A2 +EXTSYM FxOp58A3,FxOp59,FxOp59A1,FxOp59A2,FxOp59A3,FxOp5A,FxOp5AA1,FxOp5AA2 +EXTSYM FxOp5AA3,FxOp5B,FxOp5BA1,FxOp5BA2,FxOp5BA3,FxOp5C,FxOp5CA1,FxOp5CA2 +EXTSYM FxOp5CA3,FxOp5D,FxOp5DA1,FxOp5DA2,FxOp5DA3,FxOp5E,FxOp5EA1,FxOp5EA2 +EXTSYM FxOp5EA3,FxOp5F,FxOp5FA1,FxOp5FA2,FxOp5FA3,FxOp60,FxOp60A1,FxOp60A2 +EXTSYM FxOp60A3,FxOp61,FxOp61A1,FxOp61A2,FxOp61A3,FxOp62,FxOp62A1,FxOp62A2 +EXTSYM FxOp62A3,FxOp63,FxOp63A1,FxOp63A2,FxOp63A3,FxOp64,FxOp64A1,FxOp64A2 +EXTSYM FxOp64A3,FxOp65,FxOp65A1,FxOp65A2,FxOp65A3,FxOp66,FxOp66A1,FxOp66A2 +EXTSYM FxOp66A3,FxOp67,FxOp67A1,FxOp67A2,FxOp67A3,FxOp68,FxOp68A1,FxOp68A2 +EXTSYM FxOp68A3,FxOp69,FxOp69A1,FxOp69A2,FxOp69A3,FxOp6A,FxOp6AA1,FxOp6AA2 +EXTSYM FxOp6AA3,FxOp6B,FxOp6BA1,FxOp6BA2,FxOp6BA3,FxOp6C,FxOp6CA1,FxOp6CA2 +EXTSYM FxOp6CA3,FxOp6D,FxOp6DA1,FxOp6DA2,FxOp6DA3,FxOp6E,FxOp6EA1,FxOp6EA2 +EXTSYM FxOp6EA3,FxOp6F,FxOp6FA1,FxOp6FA2,FxOp6FA3,FxOp70,FxOp71,FxOp71A1 +EXTSYM FxOp71A2,FxOp71A3,FxOp72,FxOp72A1,FxOp72A2,FxOp72A3,FxOp73,FxOp73A1 +EXTSYM FxOp73A2,FxOp73A3,FxOp74,FxOp74A1,FxOp74A2,FxOp74A3,FxOp75,FxOp75A1 +EXTSYM FxOp75A2,FxOp75A3,FxOp76,FxOp76A1,FxOp76A2,FxOp76A3,FxOp77,FxOp77A1 +EXTSYM FxOp77A2,FxOp77A3,FxOp78,FxOp78A1,FxOp78A2,FxOp78A3,FxOp79,FxOp79A1 +EXTSYM FxOp79A2,FxOp79A3,FxOp7A,FxOp7AA1,FxOp7AA2,FxOp7AA3,FxOp7B,FxOp7BA1 +EXTSYM FxOp7BA2,FxOp7BA3,FxOp7C,FxOp7CA1,FxOp7CA2,FxOp7CA3,FxOp7D,FxOp7DA1 +EXTSYM FxOp7DA2,FxOp7DA3,FxOp7E,FxOp7EA1,FxOp7EA2,FxOp7EA3,FxOp7F,FxOp7FA1 +EXTSYM FxOp7FA2,FxOp7FA3,FxOp80,FxOp80A1,FxOp80A2,FxOp80A3,FxOp81,FxOp81A1 +EXTSYM FxOp81A2,FxOp81A3,FxOp82,FxOp82A1,FxOp82A2,FxOp82A3,FxOp83,FxOp83A1 +EXTSYM FxOp83A2,FxOp83A3,FxOp84,FxOp84A1,FxOp84A2,FxOp84A3,FxOp85,FxOp85A1 +EXTSYM FxOp85A2,FxOp85A3,FxOp86,FxOp86A1,FxOp86A2,FxOp86A3,FxOp87,FxOp87A1 +EXTSYM FxOp87A2,FxOp87A3,FxOp88,FxOp88A1,FxOp88A2,FxOp88A3,FxOp89,FxOp89A1 +EXTSYM FxOp89A2,FxOp89A3,FxOp8A,FxOp8AA1,FxOp8AA2,FxOp8AA3,FxOp8B,FxOp8BA1 +EXTSYM FxOp8BA2,FxOp8BA3,FxOp8C,FxOp8CA1,FxOp8CA2,FxOp8CA3,FxOp8D,FxOp8DA1 +EXTSYM FxOp8DA2,FxOp8DA3,FxOp8E,FxOp8EA1,FxOp8EA2,FxOp8EA3,FxOp8F,FxOp8FA1 +EXTSYM FxOp8FA2,FxOp8FA3,FxOp90,FxOp91,FxOp92,FxOp93,FxOp94,FxOp95,FxOp96 +EXTSYM FxOp96A1,FxOp97,FxOp98,FxOp98A1,FxOp99,FxOp99A1,FxOp9A,FxOp9AA1,FxOp9B +EXTSYM FxOp9BA1,FxOp9C,FxOp9CA1,FxOp9D,FxOp9DA1,FxOp9E,FxOp9F,FxOp9FA1,FxOpA0 +EXTSYM FxOpA0A1,FxOpA0A2,FxOpA1,FxOpA1A1,FxOpA1A2,FxOpA2,FxOpA2A1,FxOpA2A2 +EXTSYM FxOpA3,FxOpA3A1,FxOpA3A2,FxOpA4,FxOpA4A1,FxOpA4A2,FxOpA5,FxOpA5A1 +EXTSYM FxOpA5A2,FxOpA6,FxOpA6A1,FxOpA6A2,FxOpA7,FxOpA7A1,FxOpA7A2,FxOpA8 +EXTSYM FxOpA8A1,FxOpA8A2,FxOpA9,FxOpA9A1,FxOpA9A2,FxOpAA,FxOpAAA1,FxOpAAA2 +EXTSYM FxOpAB,FxOpABA1,FxOpABA2,FxOpAC,FxOpACA1,FxOpACA2,FxOpAD,FxOpADA1 +EXTSYM FxOpADA2,FxOpAE,FxOpAEA1,FxOpAEA2,FxOpAF,FxOpAFA1,FxOpAFA2,FxOpB0 +EXTSYM FxOpB1,FxOpB2,FxOpB3,FxOpB4,FxOpB5,FxOpB6,FxOpB7,FxOpB8,FxOpB9,FxOpBA +EXTSYM FxOpBB,FxOpBC,FxOpBD,FxOpBE,FxOpBF,FxOpC0,FxOpC1,FxOpC1A1,FxOpC1A2 +EXTSYM FxOpC1A3,FxOpC2,FxOpC2A1,FxOpC2A2,FxOpC2A3,FxOpC3,FxOpC3A1,FxOpC3A2 +EXTSYM FxOpC3A3,FxOpC4,FxOpC4A1,FxOpC4A2,FxOpC4A3,FxOpC5,FxOpC5A1,FxOpC5A2 +EXTSYM FxOpC5A3,FxOpC6,FxOpC6A1,FxOpC6A2,FxOpC6A3,FxOpC7,FxOpC7A1,FxOpC7A2 +EXTSYM FxOpC7A3,FxOpC8,FxOpC8A1,FxOpC8A2,FxOpC8A3,FxOpC9,FxOpC9A1,FxOpC9A2 +EXTSYM FxOpC9A3,FxOpCA,FxOpCAA1,FxOpCAA2,FxOpCAA3,FxOpCB,FxOpCBA1,FxOpCBA2 +EXTSYM FxOpCBA3,FxOpCC,FxOpCCA1,FxOpCCA2,FxOpCCA3,FxOpCD,FxOpCDA1,FxOpCDA2 +EXTSYM FxOpCDA3,FxOpCE,FxOpCEA1,FxOpCEA2,FxOpCEA3,FxOpCF,FxOpCFA1,FxOpCFA2 +EXTSYM FxOpCFA3,FxOpD0,FxOpD1,FxOpD2,FxOpD3,FxOpD4,FxOpD5,FxOpD6,FxOpD7 +EXTSYM FxOpD8,FxOpD9,FxOpDA,FxOpDB,FxOpDC,FxOpDD,FxOpDE,FxOpDF,FxOpDFA2 +EXTSYM FxOpDFA3,FxOpE0,FxOpE1,FxOpE2,FxOpE3,FxOpE4,FxOpE5,FxOpE6,FxOpE7 +EXTSYM FxOpE8,FxOpE9,FxOpEA,FxOpEB,FxOpEC,FxOpED,FxOpEE,FxOpEF,FxOpEFA1 +EXTSYM FxOpEFA2,FxOpEFA3,FxOpF0,FxOpF0A1,FxOpF0A2,FxOpF1,FxOpF1A1,FxOpF1A2 +EXTSYM FxOpF2,FxOpF2A1,FxOpF2A2,FxOpF3,FxOpF3A1,FxOpF3A2,FxOpF4,FxOpF4A1 +EXTSYM FxOpF4A2,FxOpF5,FxOpF5A1,FxOpF5A2,FxOpF6,FxOpF6A1,FxOpF6A2,FxOpF7 +EXTSYM FxOpF7A1,FxOpF7A2,FxOpF8,FxOpF8A1,FxOpF8A2,FxOpF9,FxOpF9A1,FxOpF9A2 +EXTSYM FxOpFA,FxOpFAA1,FxOpFAA2,FxOpFB,FxOpFBA1,FxOpFBA2,FxOpFC,FxOpFCA1 +EXTSYM FxOpFCA2,FxOpFD,FxOpFDA1,FxOpFDA2,FxOpFE,FxOpFEA1,FxOpFEA2,FxOpFF +EXTSYM FxOpFFA1,FxOpFFA2,FxOpb05,FxOpb06,FxOpb07,FxOpb08,FxOpb09,FxOpb0A +EXTSYM FxOpb0B,FxOpb0C,FxOpb0D,FxOpb0E,FxOpb0F,FxOpb10,FxOpb11,FxOpb12 +EXTSYM FxOpb13,FxOpb14,FxOpb15,FxOpb16,FxOpb17,FxOpb18,FxOpb19,FxOpb1A,FxOpb1B +EXTSYM FxOpb1C,FxOpb1D,FxOpb1E,FxOpb1F,FxOpb3D,FxOpb3E,FxOpb3F,FxOpbB0,FxOpbB1 +EXTSYM FxOpbB2,FxOpbB3,FxOpbB4,FxOpbB5,FxOpbB6,FxOpbB7,FxOpbB8,FxOpbB9,FxOpbBA +EXTSYM FxOpbBB,FxOpbBC,FxOpbBD,FxOpbBE,FxOpbBF,FxOpc05,FxOpc06,FxOpc07,FxOpc08 +EXTSYM FxOpc09,FxOpc0A,FxOpc0B,FxOpc0C,FxOpc0D,FxOpc0E,FxOpc0F,FxOpc10,FxOpc11 +EXTSYM FxOpc12,FxOpc13,FxOpc14,FxOpc15,FxOpc16,FxOpc17,FxOpc18,FxOpc19,FxOpc1A +EXTSYM FxOpc1B,FxOpc1C,FxOpc1D,FxOpc1E,FxOpc1F,FxOpc3D,FxOpc3E,FxOpc3F,FxOpcB0 +EXTSYM FxOpcB1,FxOpcB2,FxOpcB3,FxOpcB4,FxOpcB5,FxOpcB6,FxOpcB7,FxOpcB8,FxOpcB9 +EXTSYM FxOpcBA,FxOpcBB,FxOpcBC,FxOpcBD,FxOpcBE,FxOpcBF,FxOpd00,FxOpd01,FxOpd02 +EXTSYM FxOpd03,FxOpd04,FxOpd05,FxOpd06,FxOpd07,FxOpd08,FxOpd09,FxOpd0A,FxOpd0B +EXTSYM FxOpd0C,FxOpd0D,FxOpd0E,FxOpd0F,FxOpd10,FxOpd11,FxOpd12,FxOpd13,FxOpd14 +EXTSYM FxOpd15,FxOpd16,FxOpd17,FxOpd18,FxOpd19,FxOpd1A,FxOpd1B,FxOpd1C,FxOpd1D +EXTSYM FxOpd1E,FxOpd1F,FxOpd20,FxOpd21,FxOpd22,FxOpd23,FxOpd24,FxOpd25,FxOpd26 +EXTSYM FxOpd27,FxOpd28,FxOpd29,FxOpd2A,FxOpd2B,FxOpd2C,FxOpd2D,FxOpd2E,FxOpd2F +EXTSYM FxOpd30,FxOpd30A1,FxOpd31,FxOpd31A1,FxOpd32,FxOpd32A1,FxOpd33,FxOpd33A1 +EXTSYM FxOpd34,FxOpd34A1,FxOpd35,FxOpd35A1,FxOpd36,FxOpd36A1,FxOpd37,FxOpd37A1 +EXTSYM FxOpd38,FxOpd38A1,FxOpd39,FxOpd39A1,FxOpd3A,FxOpd3AA1,FxOpd3B,FxOpd3BA1 +EXTSYM FxOpd3C,FxOpd3D,FxOpd3E,FxOpd3F,FxOpd40,FxOpd40A1,FxOpd41,FxOpd41A1 +EXTSYM FxOpd42,FxOpd42A1,FxOpd43,FxOpd43A1,FxOpd44,FxOpd44A1,FxOpd45,FxOpd45A1 +EXTSYM FxOpd46,FxOpd46A1,FxOpd47,FxOpd47A1,FxOpd48,FxOpd48A1,FxOpd49,FxOpd49A1 +EXTSYM FxOpd4A,FxOpd4AA1,FxOpd4B,FxOpd4BA1,FxOpd4C,FxOpd4CA1,FxOpd4D,FxOpd4E +EXTSYM FxOpd4EA1,FxOpd4F,FxOpd50,FxOpd50A1,FxOpd50A2,FxOpd50A3,FxOpd51,FxOpd51A1 +EXTSYM FxOpd51A2,FxOpd51A3,FxOpd52,FxOpd52A1,FxOpd52A2,FxOpd52A3,FxOpd53 +EXTSYM FxOpd53A1,FxOpd53A2,FxOpd53A3,FxOpd54,FxOpd54A1,FxOpd54A2,FxOpd54A3 +EXTSYM FxOpd55,FxOpd55A1,FxOpd55A2,FxOpd55A3,FxOpd56,FxOpd56A1,FxOpd56A2 +EXTSYM FxOpd56A3,FxOpd57,FxOpd57A1,FxOpd57A2,FxOpd57A3,FxOpd58,FxOpd58A1 +EXTSYM FxOpd58A2,FxOpd58A3,FxOpd59,FxOpd59A1,FxOpd59A2,FxOpd59A3,FxOpd5A +EXTSYM FxOpd5AA1,FxOpd5AA2,FxOpd5AA3,FxOpd5B,FxOpd5BA1,FxOpd5BA2,FxOpd5BA3 +EXTSYM FxOpd5C,FxOpd5CA1,FxOpd5CA2,FxOpd5CA3,FxOpd5D,FxOpd5DA1,FxOpd5DA2 +EXTSYM FxOpd5DA3,FxOpd5E,FxOpd5EA1,FxOpd5EA2,FxOpd5EA3,FxOpd5F,FxOpd5FA1 +EXTSYM FxOpd5FA2,FxOpd5FA3,FxOpd60,FxOpd60A1,FxOpd60A2,FxOpd60A3,FxOpd61 +EXTSYM FxOpd61A1,FxOpd61A2,FxOpd61A3,FxOpd62,FxOpd62A1,FxOpd62A2,FxOpd62A3 +EXTSYM FxOpd63,FxOpd63A1,FxOpd63A2,FxOpd63A3,FxOpd64,FxOpd64A1,FxOpd64A2 +EXTSYM FxOpd64A3,FxOpd65,FxOpd65A1,FxOpd65A2,FxOpd65A3,FxOpd66,FxOpd66A1 +EXTSYM FxOpd66A2,FxOpd66A3,FxOpd67,FxOpd67A1,FxOpd67A2,FxOpd67A3,FxOpd68 +EXTSYM FxOpd68A1,FxOpd68A2,FxOpd68A3,FxOpd69,FxOpd69A1,FxOpd69A2,FxOpd69A3 +EXTSYM FxOpd6A,FxOpd6AA1,FxOpd6AA2,FxOpd6AA3,FxOpd6B,FxOpd6BA1,FxOpd6BA2 +EXTSYM FxOpd6BA3,FxOpd6C,FxOpd6CA1,FxOpd6CA2,FxOpd6CA3,FxOpd6D,FxOpd6DA1 +EXTSYM FxOpd6DA2,FxOpd6DA3,FxOpd6E,FxOpd6EA1,FxOpd6EA2,FxOpd6EA3,FxOpd6F +EXTSYM FxOpd6FA1,FxOpd6FA2,FxOpd6FA3,FxOpd70,FxOpd71,FxOpd71A1,FxOpd71A2 +EXTSYM FxOpd71A3,FxOpd72,FxOpd72A1,FxOpd72A2,FxOpd72A3,FxOpd73,FxOpd73A1 +EXTSYM FxOpd73A2,FxOpd73A3,FxOpd74,FxOpd74A1,FxOpd74A2,FxOpd74A3,FxOpd75 +EXTSYM FxOpd75A1,FxOpd75A2,FxOpd75A3,FxOpd76,FxOpd76A1,FxOpd76A2,FxOpd76A3 +EXTSYM FxOpd77,FxOpd77A1,FxOpd77A2,FxOpd77A3,FxOpd78,FxOpd78A1,FxOpd78A2 +EXTSYM FxOpd78A3,FxOpd79,FxOpd79A1,FxOpd79A2,FxOpd79A3,FxOpd7A,FxOpd7AA1 +EXTSYM FxOpd7AA2,FxOpd7AA3,FxOpd7B,FxOpd7BA1,FxOpd7BA2,FxOpd7BA3,FxOpd7C +EXTSYM FxOpd7CA1,FxOpd7CA2,FxOpd7CA3,FxOpd7D,FxOpd7DA1,FxOpd7DA2,FxOpd7DA3 +EXTSYM FxOpd7E,FxOpd7EA1,FxOpd7EA2,FxOpd7EA3,FxOpd7F,FxOpd7FA1,FxOpd7FA2 +EXTSYM FxOpd7FA3,FxOpd80,FxOpd80A1,FxOpd80A2,FxOpd80A3,FxOpd81,FxOpd81A1 +EXTSYM FxOpd81A2,FxOpd81A3,FxOpd82,FxOpd82A1,FxOpd82A2,FxOpd82A3,FxOpd83 +EXTSYM FxOpd83A1,FxOpd83A2,FxOpd83A3,FxOpd84,FxOpd84A1,FxOpd84A2,FxOpd84A3 +EXTSYM FxOpd85,FxOpd85A1,FxOpd85A2,FxOpd85A3,FxOpd86,FxOpd86A1,FxOpd86A2 +EXTSYM FxOpd86A3,FxOpd87,FxOpd87A1,FxOpd87A2,FxOpd87A3,FxOpd88,FxOpd88A1 +EXTSYM FxOpd88A2,FxOpd88A3,FxOpd89,FxOpd89A1,FxOpd89A2,FxOpd89A3,FxOpd8A +EXTSYM FxOpd8AA1,FxOpd8AA2,FxOpd8AA3,FxOpd8B,FxOpd8BA1,FxOpd8BA2,FxOpd8BA3 +EXTSYM FxOpd8C,FxOpd8CA1,FxOpd8CA2,FxOpd8CA3,FxOpd8D,FxOpd8DA1,FxOpd8DA2 +EXTSYM FxOpd8DA3,FxOpd8E,FxOpd8EA1,FxOpd8EA2,FxOpd8EA3,FxOpd8F,FxOpd8FA1 +EXTSYM FxOpd8FA2,FxOpd8FA3,FxOpd90,FxOpd91,FxOpd92,FxOpd93,FxOpd94,FxOpd95 +EXTSYM FxOpd96,FxOpd96A1,FxOpd97,FxOpd98,FxOpd98A1,FxOpd99,FxOpd99A1,FxOpd9A +EXTSYM FxOpd9AA1,FxOpd9B,FxOpd9BA1,FxOpd9C,FxOpd9CA1,FxOpd9D,FxOpd9DA1,FxOpd9E +EXTSYM FxOpd9F,FxOpd9FA1,FxOpdA0,FxOpdA0A1,FxOpdA0A2,FxOpdA1,FxOpdA1A1,FxOpdA1A2 +EXTSYM FxOpdA2,FxOpdA2A1,FxOpdA2A2,FxOpdA3,FxOpdA3A1,FxOpdA3A2,FxOpdA4,FxOpdA4A1 +EXTSYM FxOpdA4A2,FxOpdA5,FxOpdA5A1,FxOpdA5A2,FxOpdA6,FxOpdA6A1,FxOpdA6A2,FxOpdA7 +EXTSYM FxOpdA7A1,FxOpdA7A2,FxOpdA8,FxOpdA8A1,FxOpdA8A2,FxOpdA9,FxOpdA9A1 +EXTSYM FxOpdA9A2,FxOpdAA,FxOpdAAA1,FxOpdAAA2,FxOpdAB,FxOpdABA1,FxOpdABA2 +EXTSYM FxOpdAC,FxOpdACA1,FxOpdACA2,FxOpdAD,FxOpdADA1,FxOpdADA2,FxOpdAE +EXTSYM FxOpdAEA1,FxOpdAEA2,FxOpdAF,FxOpdAFA1,FxOpdAFA2,FxOpdB0,FxOpdB1,FxOpdB2 +EXTSYM FxOpdB3,FxOpdB4,FxOpdB5,FxOpdB6,FxOpdB7,FxOpdB8,FxOpdB9,FxOpdBA,FxOpdBB +EXTSYM FxOpdBC,FxOpdBD,FxOpdBE,FxOpdBF,FxOpdC0,FxOpdC1,FxOpdC1A1,FxOpdC1A2 +EXTSYM FxOpdC1A3,FxOpdC2,FxOpdC2A1,FxOpdC2A2,FxOpdC2A3,FxOpdC3,FxOpdC3A1 +EXTSYM FxOpdC3A2,FxOpdC3A3,FxOpdC4,FxOpdC4A1,FxOpdC4A2,FxOpdC4A3,FxOpdC5 +EXTSYM FxOpdC5A1,FxOpdC5A2,FxOpdC5A3,FxOpdC6,FxOpdC6A1,FxOpdC6A2,FxOpdC6A3 +EXTSYM FxOpdC7,FxOpdC7A1,FxOpdC7A2,FxOpdC7A3,FxOpdC8,FxOpdC8A1,FxOpdC8A2 +EXTSYM FxOpdC8A3,FxOpdC9,FxOpdC9A1,FxOpdC9A2,FxOpdC9A3,FxOpdCA,FxOpdCAA1 +EXTSYM FxOpdCAA2,FxOpdCAA3,FxOpdCB,FxOpdCBA1,FxOpdCBA2,FxOpdCBA3,FxOpdCC +EXTSYM FxOpdCCA1,FxOpdCCA2,FxOpdCCA3,FxOpdCD,FxOpdCDA1,FxOpdCDA2,FxOpdCDA3 +EXTSYM FxOpdCE,FxOpdCEA1,FxOpdCEA2,FxOpdCEA3,FxOpdCF,FxOpdCFA1,FxOpdCFA2 +EXTSYM FxOpdCFA3,FxOpdD0,FxOpdD1,FxOpdD2,FxOpdD3,FxOpdD4,FxOpdD5,FxOpdD6 +EXTSYM FxOpdD7,FxOpdD8,FxOpdD9,FxOpdDA,FxOpdDB,FxOpdDC,FxOpdDD,FxOpdDE,FxOpdDF +EXTSYM FxOpdDFA2,FxOpdDFA3,FxOpdE0,FxOpdE1,FxOpdE2,FxOpdE3,FxOpdE4,FxOpdE5 +EXTSYM FxOpdE6,FxOpdE7,FxOpdE8,FxOpdE9,FxOpdEA,FxOpdEB,FxOpdEC,FxOpdED,FxOpdEE +EXTSYM FxOpdEF,FxOpdEFA1,FxOpdEFA2,FxOpdEFA3,FxOpdF0,FxOpdF0A1,FxOpdF0A2,FxOpdF1 +EXTSYM FxOpdF1A1,FxOpdF1A2,FxOpdF2,FxOpdF2A1,FxOpdF2A2,FxOpdF3,FxOpdF3A1,FxOpdF3A2 +EXTSYM FxOpdF4,FxOpdF4A1,FxOpdF4A2,FxOpdF5,FxOpdF5A1,FxOpdF5A2,FxOpdF6,FxOpdF6A1 +EXTSYM FxOpdF6A2,FxOpdF7,FxOpdF7A1,FxOpdF7A2,FxOpdF8,FxOpdF8A1,FxOpdF8A2,FxOpdF9 +EXTSYM FxOpdF9A1,FxOpdF9A2,FxOpdFA,FxOpdFAA1,FxOpdFAA2,FxOpdFB,FxOpdFBA1,FxOpdFBA2 +EXTSYM FxOpdFC,FxOpdFCA1,FxOpdFCA2,FxOpdFD,FxOpdFDA1,FxOpdFDA2,FxOpdFE,FxOpdFEA1 +EXTSYM FxOpdFEA2,FxOpdFF,FxOpdFFA1,FxOpdFFA2,PLOTJmpa,PLOTJmpb +EXTSYM FxOp4C1284b,FxOp4C1284bz,FxOp4C1284bd,FxOp4C1284bzd +EXTSYM FxOp4C1282b,FxOp4C1282bz,FxOp4C1282bd,FxOp4C1282bzd +EXTSYM FxOp4C1288b,FxOp4C1288bz,FxOp4C1288bd,FxOp4C1288bzd +EXTSYM FxOp4C1288bl,FxOp4C1288bzl,FxOp4C1288bdl,FxOp4C1288bzdl +EXTSYM FxOpd4C1284b,FxOpd4C1284bz,FxOpd4C1284bd,FxOpd4C1284bzd +EXTSYM FxOpd4C1282b,FxOpd4C1282bz,FxOpd4C1282bd,FxOpd4C1282bzd +EXTSYM FxOpd4C1288b,FxOpd4C1288bz,FxOpd4C1288bd,FxOpd4C1288bzd +EXTSYM FxOpd4C1288bl,FxOpd4C1288bzl,FxOpd4C1288bdl,FxOpd4C1288bzdl +EXTSYM fxxand,fxbit01,fxbit23,fxbit45,fxbit67 + + + + + + + + + +NEWSYM sfx128lineloc, dd 0 +NEWSYM sfx160lineloc, dd 0 +NEWSYM sfx192lineloc, dd 0 +NEWSYM sfxobjlineloc, dd 0 + + +NEWSYM InitFxTables + +; cmp al,0 +; je near .colors4 +; cmp al,3 +; je near .colors256 +; test byte[SfxPOR],01h +; jz .zerocheck +; test byte[SfxPOR],02h +; jz .nodither4b + ; Initiate PLOT jump tables + xor ebx,ebx + mov ecx,64 + mov eax,PLOTJmpa +.ploop + mov edx,ebx + push ebx + and edx,03h + test bl,04h + jz near .zerocheck + test bl,08h + jnz .dither + cmp dl,0 + je .colors4 + cmp dl,3 + je .colors256 + mov ebx,FxOp4C1284b + jmp .end +.colors4 + mov ebx,FxOp4C1282b + jmp .end +.colors256 + test bl,20h + jnz .lowercheck + mov ebx,FxOp4C1288b + jmp .end +.lowercheck + mov ebx,FxOp4C1288bl + jmp .end +.dither + cmp dl,0 + je .colors4d + cmp dl,3 + je .colors256d + mov ebx,FxOp4C1284bd + jmp .end +.colors4d + mov ebx,FxOp4C1282bd + jmp .end +.colors256d + test bl,20h + jnz .lowercheckd + mov ebx,FxOp4C1288bd + jmp .end +.lowercheckd + mov ebx,FxOp4C1288bdl + jmp .end +.zerocheck + test bl,08h + jnz .ditherz + cmp dl,0 + je .colors4z + cmp dl,3 + je .colors256z + mov ebx,FxOp4C1284bz + jmp .end +.colors4z + mov ebx,FxOp4C1282bz + jmp .end +.colors256z + test bl,20h + jnz .lowercheckz + mov ebx,FxOp4C1288bz + jmp .end +.lowercheckz + mov ebx,FxOp4C1288bzl + jmp .end +.ditherz + cmp dl,0 + je .colors4dz + cmp dl,3 + je .colors256dz + mov ebx,FxOp4C1284bzd + jmp .end +.colors4dz + mov ebx,FxOp4C1282bzd + jmp .end +.colors256dz + test bl,20h + jnz .lowercheckdz + mov ebx,FxOp4C1288bzd + jmp .end +.lowercheckdz + mov ebx,FxOp4C1288bzdl +.end + mov [eax],ebx + pop ebx + inc ebx + add eax,4 + dec ecx + jnz near .ploop + + xor ebx,ebx + mov ecx,64 + mov eax,PLOTJmpb +.ploop2 + mov edx,ebx + push ebx + and edx,03h + test bl,04h + jz near .zerocheck2 + test bl,08h + jnz .dither2 + cmp dl,0 + je .colors42 + cmp dl,3 + je .colors2562 + mov ebx,FxOpd4C1284b + jmp .end2 +.colors42 + mov ebx,FxOpd4C1282b + jmp .end2 +.colors2562 + test bl,20h + jnz .lowercheck2 + mov ebx,FxOpd4C1288b + jmp .end2 +.lowercheck2 + mov ebx,FxOpd4C1288bl + jmp .end2 +.dither2 + cmp dl,0 + je .colors4d2 + cmp dl,3 + je .colors256d2 + mov ebx,FxOpd4C1284bd + jmp .end2 +.colors4d2 + mov ebx,FxOpd4C1282bd + jmp .end2 +.colors256d2 + test bl,20h + jnz .lowercheckd2 + mov ebx,FxOpd4C1288bd + jmp .end2 +.lowercheckd2 + mov ebx,FxOpd4C1288bdl + jmp .end2 +.zerocheck2 + test bl,08h + jnz .ditherz2 + cmp dl,0 + je .colors4z2 + cmp dl,3 + je .colors256z2 + mov ebx,FxOpd4C1284bz + jmp .end2 +.colors4z2 + mov ebx,FxOpd4C1282bz + jmp .end2 +.colors256z2 + test bl,20h + jnz .lowercheckz2 + mov ebx,FxOpd4C1288bz + jmp .end2 +.lowercheckz2 + mov ebx,FxOpd4C1288bzl + jmp .end2 +.ditherz2 + cmp dl,0 + je .colors4dz2 + cmp dl,3 + je .colors256dz2 + mov ebx,FxOpd4C1284bzd + jmp .end2 +.colors4dz2 + mov ebx,FxOpd4C1282bzd + jmp .end2 +.colors256dz2 + test bl,20h + jnz .lowercheckdz2 + mov ebx,FxOpd4C1288bzd + jmp .end2 +.lowercheckdz2 + mov ebx,FxOpd4C1288bzdl +.end2 + mov [eax],ebx + pop ebx + inc ebx + add eax,4 + dec ecx + jnz near .ploop2 + + ; Initiate AND and bit tables + mov eax,fxxand + mov ecx,256 + xor ebx,ebx +.loopat + push ecx + mov ecx,ebx + and ecx,07h + xor ecx,07h + mov edx,0101h + shl edx,cl + xor edx,0FFFFFFFFh + pop ecx + mov [eax],edx + inc ebx + add eax,4 + loop .loopat + ; bit tables + mov eax,fxbit01 + mov ecx,256 + xor ebx,ebx +.loopb01 + xor edx,edx + test ebx,01h + jz .nob0 + or edx,0FFh +.nob0 + test ebx,02h + jz .nob1 + or edx,0FF00h +.nob1 + mov [eax],edx + xor edx,edx + test ebx,04h + jz .nob2 + or edx,0FFh +.nob2 + test ebx,08h + jz .nob3 + or edx,0FF00h +.nob3 + mov [eax+256*4],edx + xor edx,edx + test ebx,10h + jz .nob4 + or edx,0FFh +.nob4 + test ebx,20h + jz .nob5 + or edx,0FF00h +.nob5 + mov [eax+256*8],edx + xor edx,edx + test ebx,40h + jz .nob6 + or edx,0FFh +.nob6 + test ebx,80h + jz .nob7 + or edx,0FF00h +.nob7 + mov [eax+256*12],edx + add eax,4 + inc ebx + dec ecx + jnz near .loopb01 + + ; Initialize PLOT tables + mov esi,[sfxramdata] + add esi,1024*1024 + ; Create 4 * 256k plot tables + ; 128 line mode + mov [sfx128lineloc],esi + xor eax,eax + xor ebx,ebx +.nexty +.nextx + cmp eax,128 + jae .over + push eax + push ebx + shr eax,3 + shr ebx,3 + shl ebx,4 + add ebx,eax + mov [esi],ebx + add esi,4 + pop ebx + pop eax + jmp .notover +.over + mov dword[esi],0FFFFFFFFh + add esi,4 +.notover + inc al + jnz .nextx + inc bl + jnz .nexty + ; 160 line mode + mov [sfx160lineloc],esi +.nexty2 +.nextx2 + cmp eax,160 + jae .over2 + push eax + push ebx + shr eax,3 + shr ebx,3 + mov edx,ebx + shl ebx,4 + shl edx,2 + add ebx,eax + add ebx,edx + mov [esi],ebx + add esi,4 + pop ebx + pop eax + jmp .notover2 +.over2 + mov dword[esi],0FFFFFFFFh + add esi,4 +.notover2 + inc al + jnz .nextx2 + inc bl + jnz .nexty2 + ; 192 line mode + mov [sfx192lineloc],esi +.nexty3 +.nextx3 + cmp eax,192 + jae .over3 + push eax + push ebx + shr eax,3 + shr ebx,3 + mov edx,ebx + shl ebx,4 + shl edx,3 + add ebx,eax + add ebx,edx + mov [esi],ebx + add esi,4 + pop ebx + pop eax + jmp .notover3 +.over3 + mov dword[esi],0FFFFFFFFh + add esi,4 +.notover3 + inc al + jnz .nextx3 + inc bl + jnz .nexty3 + ; obj mode + mov [sfxobjlineloc],esi +.nexty4 +.nextx4 + push eax + push ebx + and ebx,80h + and eax,80h + shl ebx,1 + shl eax,2 + add ebx,eax + mov edx,ebx + pop ebx + pop eax + push eax + push ebx + and ebx,78h + and eax,78h + shr ebx,3 + shl eax,1 + add ebx,eax + add edx,ebx + pop ebx + pop eax + mov [esi],edx + add esi,4 + inc al + jnz .nextx4 + inc bl + jnz .nexty4 + + mov eax,[romdata] + xor ebx,ebx + mov ecx,256 +.loopc + mov [SfxMemTable+ebx*4],eax + inc ebx + dec ecx + jnz .loopc + + mov eax,[romdata] +; sub eax,32768 + xor ebx,ebx + mov ecx,64 +.loop + mov [SfxMemTable+ebx*4],eax + add eax,65536 + inc ebx + dec ecx + jnz .loop + + mov eax,[romdata] + add eax,32768 + mov ecx,32 +.loop2 + mov [SfxMemTable+ebx*4],eax + add eax,65536*2 + inc ebx + dec ecx + jnz .loop2 + + mov eax,[sfxramdata] + mov [SfxMemTable+70h*4],eax + add eax,65536 + mov [SfxMemTable+71h*4],eax + add eax,65536 + mov [SfxMemTable+72h*4],eax + add eax,65536 + mov [SfxMemTable+73h*4],eax + + mov eax,[romdata] +; sub eax,32768 + xor ebx,ebx + mov ebx,80h + mov ecx,64 +.loops + mov [SfxMemTable+ebx*4],eax + add eax,65536 + inc ebx + dec ecx + jnz .loops + + mov eax,[romdata] + add eax,32768 + mov ecx,32 +.loop2s + mov [SfxMemTable+ebx*4],eax + add eax,65536*2 + inc ebx + dec ecx + jnz .loop2s + mov eax,[sfxramdata] + mov [SfxMemTable+0F0h*4],eax + add eax,65536 + mov [SfxMemTable+0F1h*4],eax + add eax,65536 + mov [SfxMemTable+0F2h*4],eax + add eax,65536 + mov [SfxMemTable+0F3h*4],eax + + mov dword [FxTable+00h*4],FxOp00 + mov dword [FxTable+01h*4],FxOp01 + mov dword [FxTable+02h*4],FxOp02 + mov dword [FxTable+03h*4],FxOp03 + mov dword [FxTable+04h*4],FxOp04 + mov dword [FxTable+05h*4],FxOp05 + mov dword [FxTable+06h*4],FxOp06 + mov dword [FxTable+07h*4],FxOp07 + mov dword [FxTable+08h*4],FxOp08 + mov dword [FxTable+09h*4],FxOp09 + mov dword [FxTable+0Ah*4],FxOp0A + mov dword [FxTable+0Bh*4],FxOp0B + mov dword [FxTable+0Ch*4],FxOp0C + mov dword [FxTable+0Dh*4],FxOp0D + mov dword [FxTable+0Eh*4],FxOp0E + mov dword [FxTable+0Fh*4],FxOp0F + + mov dword [FxTable+10h*4],FxOp10 + mov dword [FxTable+11h*4],FxOp11 + mov dword [FxTable+12h*4],FxOp12 + mov dword [FxTable+13h*4],FxOp13 + mov dword [FxTable+14h*4],FxOp14 + mov dword [FxTable+15h*4],FxOp15 + mov dword [FxTable+16h*4],FxOp16 + mov dword [FxTable+17h*4],FxOp17 + mov dword [FxTable+18h*4],FxOp18 + mov dword [FxTable+19h*4],FxOp19 + mov dword [FxTable+1Ah*4],FxOp1A + mov dword [FxTable+1Bh*4],FxOp1B + mov dword [FxTable+1Ch*4],FxOp1C + mov dword [FxTable+1Dh*4],FxOp1D + mov dword [FxTable+1Eh*4],FxOp1E + mov dword [FxTable+1Fh*4],FxOp1F + + mov dword [FxTable+20h*4],FxOp20 + mov dword [FxTable+21h*4],FxOp21 + mov dword [FxTable+22h*4],FxOp22 + mov dword [FxTable+23h*4],FxOp23 + mov dword [FxTable+24h*4],FxOp24 + mov dword [FxTable+25h*4],FxOp25 + mov dword [FxTable+26h*4],FxOp26 + mov dword [FxTable+27h*4],FxOp27 + mov dword [FxTable+28h*4],FxOp28 + mov dword [FxTable+29h*4],FxOp29 + mov dword [FxTable+2Ah*4],FxOp2A + mov dword [FxTable+2Bh*4],FxOp2B + mov dword [FxTable+2Ch*4],FxOp2C + mov dword [FxTable+2Dh*4],FxOp2D + mov dword [FxTable+2Eh*4],FxOp2E + mov dword [FxTable+2Fh*4],FxOp2F + + mov dword [FxTable+30h*4],FxOp30 + mov dword [FxTable+31h*4],FxOp31 + mov dword [FxTable+32h*4],FxOp32 + mov dword [FxTable+33h*4],FxOp33 + mov dword [FxTable+34h*4],FxOp34 + mov dword [FxTable+35h*4],FxOp35 + mov dword [FxTable+36h*4],FxOp36 + mov dword [FxTable+37h*4],FxOp37 + mov dword [FxTable+38h*4],FxOp38 + mov dword [FxTable+39h*4],FxOp39 + mov dword [FxTable+3Ah*4],FxOp3A + mov dword [FxTable+3Bh*4],FxOp3B + mov dword [FxTable+3Ch*4],FxOp3C + mov dword [FxTable+3Dh*4],FxOp3D + mov dword [FxTable+3Eh*4],FxOp3E + mov dword [FxTable+3Fh*4],FxOp3F + + mov dword [FxTable+40h*4],FxOp40 + mov dword [FxTable+41h*4],FxOp41 + mov dword [FxTable+42h*4],FxOp42 + mov dword [FxTable+43h*4],FxOp43 + mov dword [FxTable+44h*4],FxOp44 + mov dword [FxTable+45h*4],FxOp45 + mov dword [FxTable+46h*4],FxOp46 + mov dword [FxTable+47h*4],FxOp47 + mov dword [FxTable+48h*4],FxOp48 + mov dword [FxTable+49h*4],FxOp49 + mov dword [FxTable+4Ah*4],FxOp4A + mov dword [FxTable+4Bh*4],FxOp4B + mov dword [FxTable+4Ch*4],FxOp4C + mov dword [FxTable+4Dh*4],FxOp4D + mov dword [FxTable+4Eh*4],FxOp4E + mov dword [FxTable+4Fh*4],FxOp4F + + mov dword [FxTable+50h*4],FxOp50 + mov dword [FxTable+51h*4],FxOp51 + mov dword [FxTable+52h*4],FxOp52 + mov dword [FxTable+53h*4],FxOp53 + mov dword [FxTable+54h*4],FxOp54 + mov dword [FxTable+55h*4],FxOp55 + mov dword [FxTable+56h*4],FxOp56 + mov dword [FxTable+57h*4],FxOp57 + mov dword [FxTable+58h*4],FxOp58 + mov dword [FxTable+59h*4],FxOp59 + mov dword [FxTable+5Ah*4],FxOp5A + mov dword [FxTable+5Bh*4],FxOp5B + mov dword [FxTable+5Ch*4],FxOp5C + mov dword [FxTable+5Dh*4],FxOp5D + mov dword [FxTable+5Eh*4],FxOp5E + mov dword [FxTable+5Fh*4],FxOp5F + + mov dword [FxTable+60h*4],FxOp60 + mov dword [FxTable+61h*4],FxOp61 + mov dword [FxTable+62h*4],FxOp62 + mov dword [FxTable+63h*4],FxOp63 + mov dword [FxTable+64h*4],FxOp64 + mov dword [FxTable+65h*4],FxOp65 + mov dword [FxTable+66h*4],FxOp66 + mov dword [FxTable+67h*4],FxOp67 + mov dword [FxTable+68h*4],FxOp68 + mov dword [FxTable+69h*4],FxOp69 + mov dword [FxTable+6Ah*4],FxOp6A + mov dword [FxTable+6Bh*4],FxOp6B + mov dword [FxTable+6Ch*4],FxOp6C + mov dword [FxTable+6Dh*4],FxOp6D + mov dword [FxTable+6Eh*4],FxOp6E + mov dword [FxTable+6Fh*4],FxOp6F + + mov dword [FxTable+70h*4],FxOp70 + mov dword [FxTable+71h*4],FxOp71 + mov dword [FxTable+72h*4],FxOp72 + mov dword [FxTable+73h*4],FxOp73 + mov dword [FxTable+74h*4],FxOp74 + mov dword [FxTable+75h*4],FxOp75 + mov dword [FxTable+76h*4],FxOp76 + mov dword [FxTable+77h*4],FxOp77 + mov dword [FxTable+78h*4],FxOp78 + mov dword [FxTable+79h*4],FxOp79 + mov dword [FxTable+7Ah*4],FxOp7A + mov dword [FxTable+7Bh*4],FxOp7B + mov dword [FxTable+7Ch*4],FxOp7C + mov dword [FxTable+7Dh*4],FxOp7D + mov dword [FxTable+7Eh*4],FxOp7E + mov dword [FxTable+7Fh*4],FxOp7F + + mov dword [FxTable+80h*4],FxOp80 + mov dword [FxTable+81h*4],FxOp81 + mov dword [FxTable+82h*4],FxOp82 + mov dword [FxTable+83h*4],FxOp83 + mov dword [FxTable+84h*4],FxOp84 + mov dword [FxTable+85h*4],FxOp85 + mov dword [FxTable+86h*4],FxOp86 + mov dword [FxTable+87h*4],FxOp87 + mov dword [FxTable+88h*4],FxOp88 + mov dword [FxTable+89h*4],FxOp89 + mov dword [FxTable+8Ah*4],FxOp8A + mov dword [FxTable+8Bh*4],FxOp8B + mov dword [FxTable+8Ch*4],FxOp8C + mov dword [FxTable+8Dh*4],FxOp8D + mov dword [FxTable+8Eh*4],FxOp8E + mov dword [FxTable+8Fh*4],FxOp8F + + mov dword [FxTable+90h*4],FxOp90 + mov dword [FxTable+91h*4],FxOp91 + mov dword [FxTable+92h*4],FxOp92 + mov dword [FxTable+93h*4],FxOp93 + mov dword [FxTable+94h*4],FxOp94 + mov dword [FxTable+95h*4],FxOp95 + mov dword [FxTable+96h*4],FxOp96 + mov dword [FxTable+97h*4],FxOp97 + mov dword [FxTable+98h*4],FxOp98 + mov dword [FxTable+99h*4],FxOp99 + mov dword [FxTable+9Ah*4],FxOp9A + mov dword [FxTable+9Bh*4],FxOp9B + mov dword [FxTable+9Ch*4],FxOp9C + mov dword [FxTable+9Dh*4],FxOp9D + mov dword [FxTable+9Eh*4],FxOp9E + mov dword [FxTable+9Fh*4],FxOp9F + + mov dword [FxTable+0A0h*4],FxOpA0 + mov dword [FxTable+0A1h*4],FxOpA1 + mov dword [FxTable+0A2h*4],FxOpA2 + mov dword [FxTable+0A3h*4],FxOpA3 + mov dword [FxTable+0A4h*4],FxOpA4 + mov dword [FxTable+0A5h*4],FxOpA5 + mov dword [FxTable+0A6h*4],FxOpA6 + mov dword [FxTable+0A7h*4],FxOpA7 + mov dword [FxTable+0A8h*4],FxOpA8 + mov dword [FxTable+0A9h*4],FxOpA9 + mov dword [FxTable+0AAh*4],FxOpAA + mov dword [FxTable+0ABh*4],FxOpAB + mov dword [FxTable+0ACh*4],FxOpAC + mov dword [FxTable+0ADh*4],FxOpAD + mov dword [FxTable+0AEh*4],FxOpAE + mov dword [FxTable+0AFh*4],FxOpAF + + mov dword [FxTable+0B0h*4],FxOpB0 + mov dword [FxTable+0B1h*4],FxOpB1 + mov dword [FxTable+0B2h*4],FxOpB2 + mov dword [FxTable+0B3h*4],FxOpB3 + mov dword [FxTable+0B4h*4],FxOpB4 + mov dword [FxTable+0B5h*4],FxOpB5 + mov dword [FxTable+0B6h*4],FxOpB6 + mov dword [FxTable+0B7h*4],FxOpB7 + mov dword [FxTable+0B8h*4],FxOpB8 + mov dword [FxTable+0B9h*4],FxOpB9 + mov dword [FxTable+0BAh*4],FxOpBA + mov dword [FxTable+0BBh*4],FxOpBB + mov dword [FxTable+0BCh*4],FxOpBC + mov dword [FxTable+0BDh*4],FxOpBD + mov dword [FxTable+0BEh*4],FxOpBE + mov dword [FxTable+0BFh*4],FxOpBF + + mov dword [FxTable+0C0h*4],FxOpC0 + mov dword [FxTable+0C1h*4],FxOpC1 + mov dword [FxTable+0C2h*4],FxOpC2 + mov dword [FxTable+0C3h*4],FxOpC3 + mov dword [FxTable+0C4h*4],FxOpC4 + mov dword [FxTable+0C5h*4],FxOpC5 + mov dword [FxTable+0C6h*4],FxOpC6 + mov dword [FxTable+0C7h*4],FxOpC7 + mov dword [FxTable+0C8h*4],FxOpC8 + mov dword [FxTable+0C9h*4],FxOpC9 + mov dword [FxTable+0CAh*4],FxOpCA + mov dword [FxTable+0CBh*4],FxOpCB + mov dword [FxTable+0CCh*4],FxOpCC + mov dword [FxTable+0CDh*4],FxOpCD + mov dword [FxTable+0CEh*4],FxOpCE + mov dword [FxTable+0CFh*4],FxOpCF + + mov dword [FxTable+0D0h*4],FxOpD0 + mov dword [FxTable+0D1h*4],FxOpD1 + mov dword [FxTable+0D2h*4],FxOpD2 + mov dword [FxTable+0D3h*4],FxOpD3 + mov dword [FxTable+0D4h*4],FxOpD4 + mov dword [FxTable+0D5h*4],FxOpD5 + mov dword [FxTable+0D6h*4],FxOpD6 + mov dword [FxTable+0D7h*4],FxOpD7 + mov dword [FxTable+0D8h*4],FxOpD8 + mov dword [FxTable+0D9h*4],FxOpD9 + mov dword [FxTable+0DAh*4],FxOpDA + mov dword [FxTable+0DBh*4],FxOpDB + mov dword [FxTable+0DCh*4],FxOpDC + mov dword [FxTable+0DDh*4],FxOpDD + mov dword [FxTable+0DEh*4],FxOpDE + mov dword [FxTable+0DFh*4],FxOpDF + + mov dword [FxTable+0E0h*4],FxOpE0 + mov dword [FxTable+0E1h*4],FxOpE1 + mov dword [FxTable+0E2h*4],FxOpE2 + mov dword [FxTable+0E3h*4],FxOpE3 + mov dword [FxTable+0E4h*4],FxOpE4 + mov dword [FxTable+0E5h*4],FxOpE5 + mov dword [FxTable+0E6h*4],FxOpE6 + mov dword [FxTable+0E7h*4],FxOpE7 + mov dword [FxTable+0E8h*4],FxOpE8 + mov dword [FxTable+0E9h*4],FxOpE9 + mov dword [FxTable+0EAh*4],FxOpEA + mov dword [FxTable+0EBh*4],FxOpEB + mov dword [FxTable+0ECh*4],FxOpEC + mov dword [FxTable+0EDh*4],FxOpED + mov dword [FxTable+0EEh*4],FxOpEE + mov dword [FxTable+0EFh*4],FxOpEF + + mov dword [FxTable+0F0h*4],FxOpF0 + mov dword [FxTable+0F1h*4],FxOpF1 + mov dword [FxTable+0F2h*4],FxOpF2 + mov dword [FxTable+0F3h*4],FxOpF3 + mov dword [FxTable+0F4h*4],FxOpF4 + mov dword [FxTable+0F5h*4],FxOpF5 + mov dword [FxTable+0F6h*4],FxOpF6 + mov dword [FxTable+0F7h*4],FxOpF7 + mov dword [FxTable+0F8h*4],FxOpF8 + mov dword [FxTable+0F9h*4],FxOpF9 + mov dword [FxTable+0FAh*4],FxOpFA + mov dword [FxTable+0FBh*4],FxOpFB + mov dword [FxTable+0FCh*4],FxOpFC + mov dword [FxTable+0FDh*4],FxOpFD + mov dword [FxTable+0FEh*4],FxOpFE + mov dword [FxTable+0FFh*4],FxOpFF + + + mov dword [FxTableA1+00h*4],FxOp00 + mov dword [FxTableA1+01h*4],FxOp01 + mov dword [FxTableA1+02h*4],FxOp02 + mov dword [FxTableA1+03h*4],FxOp03 + mov dword [FxTableA1+04h*4],FxOp04 + mov dword [FxTableA1+05h*4],FxOp05 + mov dword [FxTableA1+06h*4],FxOp06 + mov dword [FxTableA1+07h*4],FxOp07 + mov dword [FxTableA1+08h*4],FxOp08 + mov dword [FxTableA1+09h*4],FxOp09 + mov dword [FxTableA1+0Ah*4],FxOp0A + mov dword [FxTableA1+0Bh*4],FxOp0B + mov dword [FxTableA1+0Ch*4],FxOp0C + mov dword [FxTableA1+0Dh*4],FxOp0D + mov dword [FxTableA1+0Eh*4],FxOp0E + mov dword [FxTableA1+0Fh*4],FxOp0F + + mov dword [FxTableA1+10h*4],FxOp10 + mov dword [FxTableA1+11h*4],FxOp11 + mov dword [FxTableA1+12h*4],FxOp12 + mov dword [FxTableA1+13h*4],FxOp13 + mov dword [FxTableA1+14h*4],FxOp14 + mov dword [FxTableA1+15h*4],FxOp15 + mov dword [FxTableA1+16h*4],FxOp16 + mov dword [FxTableA1+17h*4],FxOp17 + mov dword [FxTableA1+18h*4],FxOp18 + mov dword [FxTableA1+19h*4],FxOp19 + mov dword [FxTableA1+1Ah*4],FxOp1A + mov dword [FxTableA1+1Bh*4],FxOp1B + mov dword [FxTableA1+1Ch*4],FxOp1C + mov dword [FxTableA1+1Dh*4],FxOp1D + mov dword [FxTableA1+1Eh*4],FxOp1E + mov dword [FxTableA1+1Fh*4],FxOp1F + + mov dword [FxTableA1+20h*4],FxOp20 + mov dword [FxTableA1+21h*4],FxOp21 + mov dword [FxTableA1+22h*4],FxOp22 + mov dword [FxTableA1+23h*4],FxOp23 + mov dword [FxTableA1+24h*4],FxOp24 + mov dword [FxTableA1+25h*4],FxOp25 + mov dword [FxTableA1+26h*4],FxOp26 + mov dword [FxTableA1+27h*4],FxOp27 + mov dword [FxTableA1+28h*4],FxOp28 + mov dword [FxTableA1+29h*4],FxOp29 + mov dword [FxTableA1+2Ah*4],FxOp2A + mov dword [FxTableA1+2Bh*4],FxOp2B + mov dword [FxTableA1+2Ch*4],FxOp2C + mov dword [FxTableA1+2Dh*4],FxOp2D + mov dword [FxTableA1+2Eh*4],FxOp2E + mov dword [FxTableA1+2Fh*4],FxOp2F + + mov dword [FxTableA1+30h*4],FxOp30A1 + mov dword [FxTableA1+31h*4],FxOp31A1 + mov dword [FxTableA1+32h*4],FxOp32A1 + mov dword [FxTableA1+33h*4],FxOp33A1 + mov dword [FxTableA1+34h*4],FxOp34A1 + mov dword [FxTableA1+35h*4],FxOp35A1 + mov dword [FxTableA1+36h*4],FxOp36A1 + mov dword [FxTableA1+37h*4],FxOp37A1 + mov dword [FxTableA1+38h*4],FxOp38A1 + mov dword [FxTableA1+39h*4],FxOp39A1 + mov dword [FxTableA1+3Ah*4],FxOp3AA1 + mov dword [FxTableA1+3Bh*4],FxOp3BA1 + mov dword [FxTableA1+3Ch*4],FxOp3C + mov dword [FxTableA1+3Dh*4],FxOp3D + mov dword [FxTableA1+3Eh*4],FxOp3E + mov dword [FxTableA1+3Fh*4],FxOp3F + + mov dword [FxTableA1+40h*4],FxOp40A1 + mov dword [FxTableA1+41h*4],FxOp41A1 + mov dword [FxTableA1+42h*4],FxOp42A1 + mov dword [FxTableA1+43h*4],FxOp43A1 + mov dword [FxTableA1+44h*4],FxOp44A1 + mov dword [FxTableA1+45h*4],FxOp45A1 + mov dword [FxTableA1+46h*4],FxOp46A1 + mov dword [FxTableA1+47h*4],FxOp47A1 + mov dword [FxTableA1+48h*4],FxOp48A1 + mov dword [FxTableA1+49h*4],FxOp49A1 + mov dword [FxTableA1+4Ah*4],FxOp4AA1 + mov dword [FxTableA1+4Bh*4],FxOp4BA1 + mov dword [FxTableA1+4Ch*4],FxOp4CA1 + mov dword [FxTableA1+4Dh*4],FxOp4D + mov dword [FxTableA1+4Eh*4],FxOp4EA1 + mov dword [FxTableA1+4Fh*4],FxOp4F + + mov dword [FxTableA1+50h*4],FxOp50A1 + mov dword [FxTableA1+51h*4],FxOp51A1 + mov dword [FxTableA1+52h*4],FxOp52A1 + mov dword [FxTableA1+53h*4],FxOp53A1 + mov dword [FxTableA1+54h*4],FxOp54A1 + mov dword [FxTableA1+55h*4],FxOp55A1 + mov dword [FxTableA1+56h*4],FxOp56A1 + mov dword [FxTableA1+57h*4],FxOp57A1 + mov dword [FxTableA1+58h*4],FxOp58A1 + mov dword [FxTableA1+59h*4],FxOp59A1 + mov dword [FxTableA1+5Ah*4],FxOp5AA1 + mov dword [FxTableA1+5Bh*4],FxOp5BA1 + mov dword [FxTableA1+5Ch*4],FxOp5CA1 + mov dword [FxTableA1+5Dh*4],FxOp5DA1 + mov dword [FxTableA1+5Eh*4],FxOp5EA1 + mov dword [FxTableA1+5Fh*4],FxOp5FA1 + + mov dword [FxTableA1+60h*4],FxOp60A1 + mov dword [FxTableA1+61h*4],FxOp61A1 + mov dword [FxTableA1+62h*4],FxOp62A1 + mov dword [FxTableA1+63h*4],FxOp63A1 + mov dword [FxTableA1+64h*4],FxOp64A1 + mov dword [FxTableA1+65h*4],FxOp65A1 + mov dword [FxTableA1+66h*4],FxOp66A1 + mov dword [FxTableA1+67h*4],FxOp67A1 + mov dword [FxTableA1+68h*4],FxOp68A1 + mov dword [FxTableA1+69h*4],FxOp69A1 + mov dword [FxTableA1+6Ah*4],FxOp6AA1 + mov dword [FxTableA1+6Bh*4],FxOp6BA1 + mov dword [FxTableA1+6Ch*4],FxOp6CA1 + mov dword [FxTableA1+6Dh*4],FxOp6DA1 + mov dword [FxTableA1+6Eh*4],FxOp6EA1 + mov dword [FxTableA1+6Fh*4],FxOp6FA1 + + mov dword [FxTableA1+70h*4],FxOp70 + mov dword [FxTableA1+71h*4],FxOp71A1 + mov dword [FxTableA1+72h*4],FxOp72A1 + mov dword [FxTableA1+73h*4],FxOp73A1 + mov dword [FxTableA1+74h*4],FxOp74A1 + mov dword [FxTableA1+75h*4],FxOp75A1 + mov dword [FxTableA1+76h*4],FxOp76A1 + mov dword [FxTableA1+77h*4],FxOp77A1 + mov dword [FxTableA1+78h*4],FxOp78A1 + mov dword [FxTableA1+79h*4],FxOp79A1 + mov dword [FxTableA1+7Ah*4],FxOp7AA1 + mov dword [FxTableA1+7Bh*4],FxOp7BA1 + mov dword [FxTableA1+7Ch*4],FxOp7CA1 + mov dword [FxTableA1+7Dh*4],FxOp7DA1 + mov dword [FxTableA1+7Eh*4],FxOp7EA1 + mov dword [FxTableA1+7Fh*4],FxOp7FA1 + + mov dword [FxTableA1+80h*4],FxOp80A1 + mov dword [FxTableA1+81h*4],FxOp81A1 + mov dword [FxTableA1+82h*4],FxOp82A1 + mov dword [FxTableA1+83h*4],FxOp83A1 + mov dword [FxTableA1+84h*4],FxOp84A1 + mov dword [FxTableA1+85h*4],FxOp85A1 + mov dword [FxTableA1+86h*4],FxOp86A1 + mov dword [FxTableA1+87h*4],FxOp87A1 + mov dword [FxTableA1+88h*4],FxOp88A1 + mov dword [FxTableA1+89h*4],FxOp89A1 + mov dword [FxTableA1+8Ah*4],FxOp8AA1 + mov dword [FxTableA1+8Bh*4],FxOp8BA1 + mov dword [FxTableA1+8Ch*4],FxOp8CA1 + mov dword [FxTableA1+8Dh*4],FxOp8DA1 + mov dword [FxTableA1+8Eh*4],FxOp8EA1 + mov dword [FxTableA1+8Fh*4],FxOp8FA1 + + mov dword [FxTableA1+90h*4],FxOp90 + mov dword [FxTableA1+91h*4],FxOp91 + mov dword [FxTableA1+92h*4],FxOp92 + mov dword [FxTableA1+93h*4],FxOp93 + mov dword [FxTableA1+94h*4],FxOp94 + mov dword [FxTableA1+95h*4],FxOp95 + mov dword [FxTableA1+96h*4],FxOp96A1 + mov dword [FxTableA1+97h*4],FxOp97 + mov dword [FxTableA1+98h*4],FxOp98A1 + mov dword [FxTableA1+99h*4],FxOp99A1 + mov dword [FxTableA1+9Ah*4],FxOp9AA1 + mov dword [FxTableA1+9Bh*4],FxOp9BA1 + mov dword [FxTableA1+9Ch*4],FxOp9CA1 + mov dword [FxTableA1+9Dh*4],FxOp9DA1 + mov dword [FxTableA1+9Eh*4],FxOp9E + mov dword [FxTableA1+9Fh*4],FxOp9FA1 + + mov dword [FxTableA1+0A0h*4],FxOpA0A1 + mov dword [FxTableA1+0A1h*4],FxOpA1A1 + mov dword [FxTableA1+0A2h*4],FxOpA2A1 + mov dword [FxTableA1+0A3h*4],FxOpA3A1 + mov dword [FxTableA1+0A4h*4],FxOpA4A1 + mov dword [FxTableA1+0A5h*4],FxOpA5A1 + mov dword [FxTableA1+0A6h*4],FxOpA6A1 + mov dword [FxTableA1+0A7h*4],FxOpA7A1 + mov dword [FxTableA1+0A8h*4],FxOpA8A1 + mov dword [FxTableA1+0A9h*4],FxOpA9A1 + mov dword [FxTableA1+0AAh*4],FxOpAAA1 + mov dword [FxTableA1+0ABh*4],FxOpABA1 + mov dword [FxTableA1+0ACh*4],FxOpACA1 + mov dword [FxTableA1+0ADh*4],FxOpADA1 + mov dword [FxTableA1+0AEh*4],FxOpAEA1 + mov dword [FxTableA1+0AFh*4],FxOpAFA1 + + mov dword [FxTableA1+0B0h*4],FxOpB0 + mov dword [FxTableA1+0B1h*4],FxOpB1 + mov dword [FxTableA1+0B2h*4],FxOpB2 + mov dword [FxTableA1+0B3h*4],FxOpB3 + mov dword [FxTableA1+0B4h*4],FxOpB4 + mov dword [FxTableA1+0B5h*4],FxOpB5 + mov dword [FxTableA1+0B6h*4],FxOpB6 + mov dword [FxTableA1+0B7h*4],FxOpB7 + mov dword [FxTableA1+0B8h*4],FxOpB8 + mov dword [FxTableA1+0B9h*4],FxOpB9 + mov dword [FxTableA1+0BAh*4],FxOpBA + mov dword [FxTableA1+0BBh*4],FxOpBB + mov dword [FxTableA1+0BCh*4],FxOpBC + mov dword [FxTableA1+0BDh*4],FxOpBD + mov dword [FxTableA1+0BEh*4],FxOpBE + mov dword [FxTableA1+0BFh*4],FxOpBF + + mov dword [FxTableA1+0C0h*4],FxOpC0 + mov dword [FxTableA1+0C1h*4],FxOpC1A1 + mov dword [FxTableA1+0C2h*4],FxOpC2A1 + mov dword [FxTableA1+0C3h*4],FxOpC3A1 + mov dword [FxTableA1+0C4h*4],FxOpC4A1 + mov dword [FxTableA1+0C5h*4],FxOpC5A1 + mov dword [FxTableA1+0C6h*4],FxOpC6A1 + mov dword [FxTableA1+0C7h*4],FxOpC7A1 + mov dword [FxTableA1+0C8h*4],FxOpC8A1 + mov dword [FxTableA1+0C9h*4],FxOpC9A1 + mov dword [FxTableA1+0CAh*4],FxOpCAA1 + mov dword [FxTableA1+0CBh*4],FxOpCBA1 + mov dword [FxTableA1+0CCh*4],FxOpCCA1 + mov dword [FxTableA1+0CDh*4],FxOpCDA1 + mov dword [FxTableA1+0CEh*4],FxOpCEA1 + mov dword [FxTableA1+0CFh*4],FxOpCFA1 + + mov dword [FxTableA1+0D0h*4],FxOpD0 + mov dword [FxTableA1+0D1h*4],FxOpD1 + mov dword [FxTableA1+0D2h*4],FxOpD2 + mov dword [FxTableA1+0D3h*4],FxOpD3 + mov dword [FxTableA1+0D4h*4],FxOpD4 + mov dword [FxTableA1+0D5h*4],FxOpD5 + mov dword [FxTableA1+0D6h*4],FxOpD6 + mov dword [FxTableA1+0D7h*4],FxOpD7 + mov dword [FxTableA1+0D8h*4],FxOpD8 + mov dword [FxTableA1+0D9h*4],FxOpD9 + mov dword [FxTableA1+0DAh*4],FxOpDA + mov dword [FxTableA1+0DBh*4],FxOpDB + mov dword [FxTableA1+0DCh*4],FxOpDC + mov dword [FxTableA1+0DDh*4],FxOpDD + mov dword [FxTableA1+0DEh*4],FxOpDE + mov dword [FxTableA1+0DFh*4],FxOpDF + + mov dword [FxTableA1+0E0h*4],FxOpE0 + mov dword [FxTableA1+0E1h*4],FxOpE1 + mov dword [FxTableA1+0E2h*4],FxOpE2 + mov dword [FxTableA1+0E3h*4],FxOpE3 + mov dword [FxTableA1+0E4h*4],FxOpE4 + mov dword [FxTableA1+0E5h*4],FxOpE5 + mov dword [FxTableA1+0E6h*4],FxOpE6 + mov dword [FxTableA1+0E7h*4],FxOpE7 + mov dword [FxTableA1+0E8h*4],FxOpE8 + mov dword [FxTableA1+0E9h*4],FxOpE9 + mov dword [FxTableA1+0EAh*4],FxOpEA + mov dword [FxTableA1+0EBh*4],FxOpEB + mov dword [FxTableA1+0ECh*4],FxOpEC + mov dword [FxTableA1+0EDh*4],FxOpED + mov dword [FxTableA1+0EEh*4],FxOpEE + mov dword [FxTableA1+0EFh*4],FxOpEFA1 + + mov dword [FxTableA1+0F0h*4],FxOpF0A1 + mov dword [FxTableA1+0F1h*4],FxOpF1A1 + mov dword [FxTableA1+0F2h*4],FxOpF2A1 + mov dword [FxTableA1+0F3h*4],FxOpF3A1 + mov dword [FxTableA1+0F4h*4],FxOpF4A1 + mov dword [FxTableA1+0F5h*4],FxOpF5A1 + mov dword [FxTableA1+0F6h*4],FxOpF6A1 + mov dword [FxTableA1+0F7h*4],FxOpF7A1 + mov dword [FxTableA1+0F8h*4],FxOpF8A1 + mov dword [FxTableA1+0F9h*4],FxOpF9A1 + mov dword [FxTableA1+0FAh*4],FxOpFAA1 + mov dword [FxTableA1+0FBh*4],FxOpFBA1 + mov dword [FxTableA1+0FCh*4],FxOpFCA1 + mov dword [FxTableA1+0FDh*4],FxOpFDA1 + mov dword [FxTableA1+0FEh*4],FxOpFEA1 + mov dword [FxTableA1+0FFh*4],FxOpFFA1 + + + mov dword [FxTableA2+00h*4],FxOp00 + mov dword [FxTableA2+01h*4],FxOp01 + mov dword [FxTableA2+02h*4],FxOp02 + mov dword [FxTableA2+03h*4],FxOp03 + mov dword [FxTableA2+04h*4],FxOp04 + mov dword [FxTableA2+05h*4],FxOp05 + mov dword [FxTableA2+06h*4],FxOp06 + mov dword [FxTableA2+07h*4],FxOp07 + mov dword [FxTableA2+08h*4],FxOp08 + mov dword [FxTableA2+09h*4],FxOp09 + mov dword [FxTableA2+0Ah*4],FxOp0A + mov dword [FxTableA2+0Bh*4],FxOp0B + mov dword [FxTableA2+0Ch*4],FxOp0C + mov dword [FxTableA2+0Dh*4],FxOp0D + mov dword [FxTableA2+0Eh*4],FxOp0E + mov dword [FxTableA2+0Fh*4],FxOp0F + + mov dword [FxTableA2+10h*4],FxOp10 + mov dword [FxTableA2+11h*4],FxOp11 + mov dword [FxTableA2+12h*4],FxOp12 + mov dword [FxTableA2+13h*4],FxOp13 + mov dword [FxTableA2+14h*4],FxOp14 + mov dword [FxTableA2+15h*4],FxOp15 + mov dword [FxTableA2+16h*4],FxOp16 + mov dword [FxTableA2+17h*4],FxOp17 + mov dword [FxTableA2+18h*4],FxOp18 + mov dword [FxTableA2+19h*4],FxOp19 + mov dword [FxTableA2+1Ah*4],FxOp1A + mov dword [FxTableA2+1Bh*4],FxOp1B + mov dword [FxTableA2+1Ch*4],FxOp1C + mov dword [FxTableA2+1Dh*4],FxOp1D + mov dword [FxTableA2+1Eh*4],FxOp1E + mov dword [FxTableA2+1Fh*4],FxOp1F + + mov dword [FxTableA2+20h*4],FxOp20 + mov dword [FxTableA2+21h*4],FxOp21 + mov dword [FxTableA2+22h*4],FxOp22 + mov dword [FxTableA2+23h*4],FxOp23 + mov dword [FxTableA2+24h*4],FxOp24 + mov dword [FxTableA2+25h*4],FxOp25 + mov dword [FxTableA2+26h*4],FxOp26 + mov dword [FxTableA2+27h*4],FxOp27 + mov dword [FxTableA2+28h*4],FxOp28 + mov dword [FxTableA2+29h*4],FxOp29 + mov dword [FxTableA2+2Ah*4],FxOp2A + mov dword [FxTableA2+2Bh*4],FxOp2B + mov dword [FxTableA2+2Ch*4],FxOp2C + mov dword [FxTableA2+2Dh*4],FxOp2D + mov dword [FxTableA2+2Eh*4],FxOp2E + mov dword [FxTableA2+2Fh*4],FxOp2F + + mov dword [FxTableA2+30h*4],FxOp30 + mov dword [FxTableA2+31h*4],FxOp31 + mov dword [FxTableA2+32h*4],FxOp32 + mov dword [FxTableA2+33h*4],FxOp33 + mov dword [FxTableA2+34h*4],FxOp34 + mov dword [FxTableA2+35h*4],FxOp35 + mov dword [FxTableA2+36h*4],FxOp36 + mov dword [FxTableA2+37h*4],FxOp37 + mov dword [FxTableA2+38h*4],FxOp38 + mov dword [FxTableA2+39h*4],FxOp39 + mov dword [FxTableA2+3Ah*4],FxOp3A + mov dword [FxTableA2+3Bh*4],FxOp3B + mov dword [FxTableA2+3Ch*4],FxOp3C + mov dword [FxTableA2+3Dh*4],FxOp3D + mov dword [FxTableA2+3Eh*4],FxOp3E + mov dword [FxTableA2+3Fh*4],FxOp3F + + mov dword [FxTableA2+40h*4],FxOp40 + mov dword [FxTableA2+41h*4],FxOp41 + mov dword [FxTableA2+42h*4],FxOp42 + mov dword [FxTableA2+43h*4],FxOp43 + mov dword [FxTableA2+44h*4],FxOp44 + mov dword [FxTableA2+45h*4],FxOp45 + mov dword [FxTableA2+46h*4],FxOp46 + mov dword [FxTableA2+47h*4],FxOp47 + mov dword [FxTableA2+48h*4],FxOp48 + mov dword [FxTableA2+49h*4],FxOp49 + mov dword [FxTableA2+4Ah*4],FxOp4A + mov dword [FxTableA2+4Bh*4],FxOp4B + mov dword [FxTableA2+4Ch*4],FxOp4C + mov dword [FxTableA2+4Dh*4],FxOp4D + mov dword [FxTableA2+4Eh*4],FxOp4E + mov dword [FxTableA2+4Fh*4],FxOp4F + + mov dword [FxTableA2+50h*4],FxOp50A2 + mov dword [FxTableA2+51h*4],FxOp51A2 + mov dword [FxTableA2+52h*4],FxOp52A2 + mov dword [FxTableA2+53h*4],FxOp53A2 + mov dword [FxTableA2+54h*4],FxOp54A2 + mov dword [FxTableA2+55h*4],FxOp55A2 + mov dword [FxTableA2+56h*4],FxOp56A2 + mov dword [FxTableA2+57h*4],FxOp57A2 + mov dword [FxTableA2+58h*4],FxOp58A2 + mov dword [FxTableA2+59h*4],FxOp59A2 + mov dword [FxTableA2+5Ah*4],FxOp5AA2 + mov dword [FxTableA2+5Bh*4],FxOp5BA2 + mov dword [FxTableA2+5Ch*4],FxOp5CA2 + mov dword [FxTableA2+5Dh*4],FxOp5DA2 + mov dword [FxTableA2+5Eh*4],FxOp5EA2 + mov dword [FxTableA2+5Fh*4],FxOp5FA2 + + mov dword [FxTableA2+60h*4],FxOp60A2 + mov dword [FxTableA2+61h*4],FxOp61A2 + mov dword [FxTableA2+62h*4],FxOp62A2 + mov dword [FxTableA2+63h*4],FxOp63A2 + mov dword [FxTableA2+64h*4],FxOp64A2 + mov dword [FxTableA2+65h*4],FxOp65A2 + mov dword [FxTableA2+66h*4],FxOp66A2 + mov dword [FxTableA2+67h*4],FxOp67A2 + mov dword [FxTableA2+68h*4],FxOp68A2 + mov dword [FxTableA2+69h*4],FxOp69A2 + mov dword [FxTableA2+6Ah*4],FxOp6AA2 + mov dword [FxTableA2+6Bh*4],FxOp6BA2 + mov dword [FxTableA2+6Ch*4],FxOp6CA2 + mov dword [FxTableA2+6Dh*4],FxOp6DA2 + mov dword [FxTableA2+6Eh*4],FxOp6EA2 + mov dword [FxTableA2+6Fh*4],FxOp6FA2 + + mov dword [FxTableA2+70h*4],FxOp70 + mov dword [FxTableA2+71h*4],FxOp71A2 + mov dword [FxTableA2+72h*4],FxOp72A2 + mov dword [FxTableA2+73h*4],FxOp73A2 + mov dword [FxTableA2+74h*4],FxOp74A2 + mov dword [FxTableA2+75h*4],FxOp75A2 + mov dword [FxTableA2+76h*4],FxOp76A2 + mov dword [FxTableA2+77h*4],FxOp77A2 + mov dword [FxTableA2+78h*4],FxOp78A2 + mov dword [FxTableA2+79h*4],FxOp79A2 + mov dword [FxTableA2+7Ah*4],FxOp7AA2 + mov dword [FxTableA2+7Bh*4],FxOp7BA2 + mov dword [FxTableA2+7Ch*4],FxOp7CA2 + mov dword [FxTableA2+7Dh*4],FxOp7DA2 + mov dword [FxTableA2+7Eh*4],FxOp7EA2 + mov dword [FxTableA2+7Fh*4],FxOp7FA2 + + mov dword [FxTableA2+80h*4],FxOp80A2 + mov dword [FxTableA2+81h*4],FxOp81A2 + mov dword [FxTableA2+82h*4],FxOp82A2 + mov dword [FxTableA2+83h*4],FxOp83A2 + mov dword [FxTableA2+84h*4],FxOp84A2 + mov dword [FxTableA2+85h*4],FxOp85A2 + mov dword [FxTableA2+86h*4],FxOp86A2 + mov dword [FxTableA2+87h*4],FxOp87A2 + mov dword [FxTableA2+88h*4],FxOp88A2 + mov dword [FxTableA2+89h*4],FxOp89A2 + mov dword [FxTableA2+8Ah*4],FxOp8AA2 + mov dword [FxTableA2+8Bh*4],FxOp8BA2 + mov dword [FxTableA2+8Ch*4],FxOp8CA2 + mov dword [FxTableA2+8Dh*4],FxOp8DA2 + mov dword [FxTableA2+8Eh*4],FxOp8EA2 + mov dword [FxTableA2+8Fh*4],FxOp8FA2 + + mov dword [FxTableA2+90h*4],FxOp90 + mov dword [FxTableA2+91h*4],FxOp91 + mov dword [FxTableA2+92h*4],FxOp92 + mov dword [FxTableA2+93h*4],FxOp93 + mov dword [FxTableA2+94h*4],FxOp94 + mov dword [FxTableA2+95h*4],FxOp95 + mov dword [FxTableA2+96h*4],FxOp96 + mov dword [FxTableA2+97h*4],FxOp97 + mov dword [FxTableA2+98h*4],FxOp98 + mov dword [FxTableA2+99h*4],FxOp99 + mov dword [FxTableA2+9Ah*4],FxOp9A + mov dword [FxTableA2+9Bh*4],FxOp9B + mov dword [FxTableA2+9Ch*4],FxOp9C + mov dword [FxTableA2+9Dh*4],FxOp9D + mov dword [FxTableA2+9Eh*4],FxOp9E + mov dword [FxTableA2+9Fh*4],FxOp9F + + mov dword [FxTableA2+0A0h*4],FxOpA0A2 + mov dword [FxTableA2+0A1h*4],FxOpA1A2 + mov dword [FxTableA2+0A2h*4],FxOpA2A2 + mov dword [FxTableA2+0A3h*4],FxOpA3A2 + mov dword [FxTableA2+0A4h*4],FxOpA4A2 + mov dword [FxTableA2+0A5h*4],FxOpA5A2 + mov dword [FxTableA2+0A6h*4],FxOpA6A2 + mov dword [FxTableA2+0A7h*4],FxOpA7A2 + mov dword [FxTableA2+0A8h*4],FxOpA8A2 + mov dword [FxTableA2+0A9h*4],FxOpA9A2 + mov dword [FxTableA2+0AAh*4],FxOpAAA2 + mov dword [FxTableA2+0ABh*4],FxOpABA2 + mov dword [FxTableA2+0ACh*4],FxOpACA2 + mov dword [FxTableA2+0ADh*4],FxOpADA2 + mov dword [FxTableA2+0AEh*4],FxOpAEA2 + mov dword [FxTableA2+0AFh*4],FxOpAFA2 + + mov dword [FxTableA2+0B0h*4],FxOpB0 + mov dword [FxTableA2+0B1h*4],FxOpB1 + mov dword [FxTableA2+0B2h*4],FxOpB2 + mov dword [FxTableA2+0B3h*4],FxOpB3 + mov dword [FxTableA2+0B4h*4],FxOpB4 + mov dword [FxTableA2+0B5h*4],FxOpB5 + mov dword [FxTableA2+0B6h*4],FxOpB6 + mov dword [FxTableA2+0B7h*4],FxOpB7 + mov dword [FxTableA2+0B8h*4],FxOpB8 + mov dword [FxTableA2+0B9h*4],FxOpB9 + mov dword [FxTableA2+0BAh*4],FxOpBA + mov dword [FxTableA2+0BBh*4],FxOpBB + mov dword [FxTableA2+0BCh*4],FxOpBC + mov dword [FxTableA2+0BDh*4],FxOpBD + mov dword [FxTableA2+0BEh*4],FxOpBE + mov dword [FxTableA2+0BFh*4],FxOpBF + + mov dword [FxTableA2+0C0h*4],FxOpC0 + mov dword [FxTableA2+0C1h*4],FxOpC1A2 + mov dword [FxTableA2+0C2h*4],FxOpC2A2 + mov dword [FxTableA2+0C3h*4],FxOpC3A2 + mov dword [FxTableA2+0C4h*4],FxOpC4A2 + mov dword [FxTableA2+0C5h*4],FxOpC5A2 + mov dword [FxTableA2+0C6h*4],FxOpC6A2 + mov dword [FxTableA2+0C7h*4],FxOpC7A2 + mov dword [FxTableA2+0C8h*4],FxOpC8A2 + mov dword [FxTableA2+0C9h*4],FxOpC9A2 + mov dword [FxTableA2+0CAh*4],FxOpCAA2 + mov dword [FxTableA2+0CBh*4],FxOpCBA2 + mov dword [FxTableA2+0CCh*4],FxOpCCA2 + mov dword [FxTableA2+0CDh*4],FxOpCDA2 + mov dword [FxTableA2+0CEh*4],FxOpCEA2 + mov dword [FxTableA2+0CFh*4],FxOpCFA2 + + mov dword [FxTableA2+0D0h*4],FxOpD0 + mov dword [FxTableA2+0D1h*4],FxOpD1 + mov dword [FxTableA2+0D2h*4],FxOpD2 + mov dword [FxTableA2+0D3h*4],FxOpD3 + mov dword [FxTableA2+0D4h*4],FxOpD4 + mov dword [FxTableA2+0D5h*4],FxOpD5 + mov dword [FxTableA2+0D6h*4],FxOpD6 + mov dword [FxTableA2+0D7h*4],FxOpD7 + mov dword [FxTableA2+0D8h*4],FxOpD8 + mov dword [FxTableA2+0D9h*4],FxOpD9 + mov dword [FxTableA2+0DAh*4],FxOpDA + mov dword [FxTableA2+0DBh*4],FxOpDB + mov dword [FxTableA2+0DCh*4],FxOpDC + mov dword [FxTableA2+0DDh*4],FxOpDD + mov dword [FxTableA2+0DEh*4],FxOpDE + mov dword [FxTableA2+0DFh*4],FxOpDFA2 + + mov dword [FxTableA2+0E0h*4],FxOpE0 + mov dword [FxTableA2+0E1h*4],FxOpE1 + mov dword [FxTableA2+0E2h*4],FxOpE2 + mov dword [FxTableA2+0E3h*4],FxOpE3 + mov dword [FxTableA2+0E4h*4],FxOpE4 + mov dword [FxTableA2+0E5h*4],FxOpE5 + mov dword [FxTableA2+0E6h*4],FxOpE6 + mov dword [FxTableA2+0E7h*4],FxOpE7 + mov dword [FxTableA2+0E8h*4],FxOpE8 + mov dword [FxTableA2+0E9h*4],FxOpE9 + mov dword [FxTableA2+0EAh*4],FxOpEA + mov dword [FxTableA2+0EBh*4],FxOpEB + mov dword [FxTableA2+0ECh*4],FxOpEC + mov dword [FxTableA2+0EDh*4],FxOpED + mov dword [FxTableA2+0EEh*4],FxOpEE + mov dword [FxTableA2+0EFh*4],FxOpEFA2 + + mov dword [FxTableA2+0F0h*4],FxOpF0A2 + mov dword [FxTableA2+0F1h*4],FxOpF1A2 + mov dword [FxTableA2+0F2h*4],FxOpF2A2 + mov dword [FxTableA2+0F3h*4],FxOpF3A2 + mov dword [FxTableA2+0F4h*4],FxOpF4A2 + mov dword [FxTableA2+0F5h*4],FxOpF5A2 + mov dword [FxTableA2+0F6h*4],FxOpF6A2 + mov dword [FxTableA2+0F7h*4],FxOpF7A2 + mov dword [FxTableA2+0F8h*4],FxOpF8A2 + mov dword [FxTableA2+0F9h*4],FxOpF9A2 + mov dword [FxTableA2+0FAh*4],FxOpFAA2 + mov dword [FxTableA2+0FBh*4],FxOpFBA2 + mov dword [FxTableA2+0FCh*4],FxOpFCA2 + mov dword [FxTableA2+0FDh*4],FxOpFDA2 + mov dword [FxTableA2+0FEh*4],FxOpFEA2 + mov dword [FxTableA2+0FFh*4],FxOpFFA2 + + mov dword [FxTableA3+00h*4],FxOp00 + mov dword [FxTableA3+01h*4],FxOp01 + mov dword [FxTableA3+02h*4],FxOp02 + mov dword [FxTableA3+03h*4],FxOp03 + mov dword [FxTableA3+04h*4],FxOp04 + mov dword [FxTableA3+05h*4],FxOp05 + mov dword [FxTableA3+06h*4],FxOp06 + mov dword [FxTableA3+07h*4],FxOp07 + mov dword [FxTableA3+08h*4],FxOp08 + mov dword [FxTableA3+09h*4],FxOp09 + mov dword [FxTableA3+0Ah*4],FxOp0A + mov dword [FxTableA3+0Bh*4],FxOp0B + mov dword [FxTableA3+0Ch*4],FxOp0C + mov dword [FxTableA3+0Dh*4],FxOp0D + mov dword [FxTableA3+0Eh*4],FxOp0E + mov dword [FxTableA3+0Fh*4],FxOp0F + + mov dword [FxTableA3+10h*4],FxOp10 + mov dword [FxTableA3+11h*4],FxOp11 + mov dword [FxTableA3+12h*4],FxOp12 + mov dword [FxTableA3+13h*4],FxOp13 + mov dword [FxTableA3+14h*4],FxOp14 + mov dword [FxTableA3+15h*4],FxOp15 + mov dword [FxTableA3+16h*4],FxOp16 + mov dword [FxTableA3+17h*4],FxOp17 + mov dword [FxTableA3+18h*4],FxOp18 + mov dword [FxTableA3+19h*4],FxOp19 + mov dword [FxTableA3+1Ah*4],FxOp1A + mov dword [FxTableA3+1Bh*4],FxOp1B + mov dword [FxTableA3+1Ch*4],FxOp1C + mov dword [FxTableA3+1Dh*4],FxOp1D + mov dword [FxTableA3+1Eh*4],FxOp1E + mov dword [FxTableA3+1Fh*4],FxOp1F + + mov dword [FxTableA3+20h*4],FxOp20 + mov dword [FxTableA3+21h*4],FxOp21 + mov dword [FxTableA3+22h*4],FxOp22 + mov dword [FxTableA3+23h*4],FxOp23 + mov dword [FxTableA3+24h*4],FxOp24 + mov dword [FxTableA3+25h*4],FxOp25 + mov dword [FxTableA3+26h*4],FxOp26 + mov dword [FxTableA3+27h*4],FxOp27 + mov dword [FxTableA3+28h*4],FxOp28 + mov dword [FxTableA3+29h*4],FxOp29 + mov dword [FxTableA3+2Ah*4],FxOp2A + mov dword [FxTableA3+2Bh*4],FxOp2B + mov dword [FxTableA3+2Ch*4],FxOp2C + mov dword [FxTableA3+2Dh*4],FxOp2D + mov dword [FxTableA3+2Eh*4],FxOp2E + mov dword [FxTableA3+2Fh*4],FxOp2F + + mov dword [FxTableA3+30h*4],FxOp30 + mov dword [FxTableA3+31h*4],FxOp31 + mov dword [FxTableA3+32h*4],FxOp32 + mov dword [FxTableA3+33h*4],FxOp33 + mov dword [FxTableA3+34h*4],FxOp34 + mov dword [FxTableA3+35h*4],FxOp35 + mov dword [FxTableA3+36h*4],FxOp36 + mov dword [FxTableA3+37h*4],FxOp37 + mov dword [FxTableA3+38h*4],FxOp38 + mov dword [FxTableA3+39h*4],FxOp39 + mov dword [FxTableA3+3Ah*4],FxOp3A + mov dword [FxTableA3+3Bh*4],FxOp3B + mov dword [FxTableA3+3Ch*4],FxOp3C + mov dword [FxTableA3+3Dh*4],FxOp3D + mov dword [FxTableA3+3Eh*4],FxOp3E + mov dword [FxTableA3+3Fh*4],FxOp3F + + mov dword [FxTableA3+40h*4],FxOp40 + mov dword [FxTableA3+41h*4],FxOp41 + mov dword [FxTableA3+42h*4],FxOp42 + mov dword [FxTableA3+43h*4],FxOp43 + mov dword [FxTableA3+44h*4],FxOp44 + mov dword [FxTableA3+45h*4],FxOp45 + mov dword [FxTableA3+46h*4],FxOp46 + mov dword [FxTableA3+47h*4],FxOp47 + mov dword [FxTableA3+48h*4],FxOp48 + mov dword [FxTableA3+49h*4],FxOp49 + mov dword [FxTableA3+4Ah*4],FxOp4A + mov dword [FxTableA3+4Bh*4],FxOp4B + mov dword [FxTableA3+4Ch*4],FxOp4C + mov dword [FxTableA3+4Dh*4],FxOp4D + mov dword [FxTableA3+4Eh*4],FxOp4E + mov dword [FxTableA3+4Fh*4],FxOp4F + + mov dword [FxTableA3+50h*4],FxOp50A3 + mov dword [FxTableA3+51h*4],FxOp51A3 + mov dword [FxTableA3+52h*4],FxOp52A3 + mov dword [FxTableA3+53h*4],FxOp53A3 + mov dword [FxTableA3+54h*4],FxOp54A3 + mov dword [FxTableA3+55h*4],FxOp55A3 + mov dword [FxTableA3+56h*4],FxOp56A3 + mov dword [FxTableA3+57h*4],FxOp57A3 + mov dword [FxTableA3+58h*4],FxOp58A3 + mov dword [FxTableA3+59h*4],FxOp59A3 + mov dword [FxTableA3+5Ah*4],FxOp5AA3 + mov dword [FxTableA3+5Bh*4],FxOp5BA3 + mov dword [FxTableA3+5Ch*4],FxOp5CA3 + mov dword [FxTableA3+5Dh*4],FxOp5DA3 + mov dword [FxTableA3+5Eh*4],FxOp5EA3 + mov dword [FxTableA3+5Fh*4],FxOp5FA3 + + mov dword [FxTableA3+60h*4],FxOp60A3 + mov dword [FxTableA3+61h*4],FxOp61A3 + mov dword [FxTableA3+62h*4],FxOp62A3 + mov dword [FxTableA3+63h*4],FxOp63A3 + mov dword [FxTableA3+64h*4],FxOp64A3 + mov dword [FxTableA3+65h*4],FxOp65A3 + mov dword [FxTableA3+66h*4],FxOp66A3 + mov dword [FxTableA3+67h*4],FxOp67A3 + mov dword [FxTableA3+68h*4],FxOp68A3 + mov dword [FxTableA3+69h*4],FxOp69A3 + mov dword [FxTableA3+6Ah*4],FxOp6AA3 + mov dword [FxTableA3+6Bh*4],FxOp6BA3 + mov dword [FxTableA3+6Ch*4],FxOp6CA3 + mov dword [FxTableA3+6Dh*4],FxOp6DA3 + mov dword [FxTableA3+6Eh*4],FxOp6EA3 + mov dword [FxTableA3+6Fh*4],FxOp6FA3 + + mov dword [FxTableA3+70h*4],FxOp70 + mov dword [FxTableA3+71h*4],FxOp71A3 + mov dword [FxTableA3+72h*4],FxOp72A3 + mov dword [FxTableA3+73h*4],FxOp73A3 + mov dword [FxTableA3+74h*4],FxOp74A3 + mov dword [FxTableA3+75h*4],FxOp75A3 + mov dword [FxTableA3+76h*4],FxOp76A3 + mov dword [FxTableA3+77h*4],FxOp77A3 + mov dword [FxTableA3+78h*4],FxOp78A3 + mov dword [FxTableA3+79h*4],FxOp79A3 + mov dword [FxTableA3+7Ah*4],FxOp7AA3 + mov dword [FxTableA3+7Bh*4],FxOp7BA3 + mov dword [FxTableA3+7Ch*4],FxOp7CA3 + mov dword [FxTableA3+7Dh*4],FxOp7DA3 + mov dword [FxTableA3+7Eh*4],FxOp7EA3 + mov dword [FxTableA3+7Fh*4],FxOp7FA3 + + mov dword [FxTableA3+80h*4],FxOp80A3 + mov dword [FxTableA3+81h*4],FxOp81A3 + mov dword [FxTableA3+82h*4],FxOp82A3 + mov dword [FxTableA3+83h*4],FxOp83A3 + mov dword [FxTableA3+84h*4],FxOp84A3 + mov dword [FxTableA3+85h*4],FxOp85A3 + mov dword [FxTableA3+86h*4],FxOp86A3 + mov dword [FxTableA3+87h*4],FxOp87A3 + mov dword [FxTableA3+88h*4],FxOp88A3 + mov dword [FxTableA3+89h*4],FxOp89A3 + mov dword [FxTableA3+8Ah*4],FxOp8AA3 + mov dword [FxTableA3+8Bh*4],FxOp8BA3 + mov dword [FxTableA3+8Ch*4],FxOp8CA3 + mov dword [FxTableA3+8Dh*4],FxOp8DA3 + mov dword [FxTableA3+8Eh*4],FxOp8EA3 + mov dword [FxTableA3+8Fh*4],FxOp8FA3 + + mov dword [FxTableA3+90h*4],FxOp90 + mov dword [FxTableA3+91h*4],FxOp91 + mov dword [FxTableA3+92h*4],FxOp92 + mov dword [FxTableA3+93h*4],FxOp93 + mov dword [FxTableA3+94h*4],FxOp94 + mov dword [FxTableA3+95h*4],FxOp95 + mov dword [FxTableA3+96h*4],FxOp96 + mov dword [FxTableA3+97h*4],FxOp97 + mov dword [FxTableA3+98h*4],FxOp98 + mov dword [FxTableA3+99h*4],FxOp99 + mov dword [FxTableA3+9Ah*4],FxOp9A + mov dword [FxTableA3+9Bh*4],FxOp9B + mov dword [FxTableA3+9Ch*4],FxOp9C + mov dword [FxTableA3+9Dh*4],FxOp9D + mov dword [FxTableA3+9Eh*4],FxOp9E + mov dword [FxTableA3+9Fh*4],FxOp9F + + mov dword [FxTableA3+0A0h*4],FxOpA0 + mov dword [FxTableA3+0A1h*4],FxOpA1 + mov dword [FxTableA3+0A2h*4],FxOpA2 + mov dword [FxTableA3+0A3h*4],FxOpA3 + mov dword [FxTableA3+0A4h*4],FxOpA4 + mov dword [FxTableA3+0A5h*4],FxOpA5 + mov dword [FxTableA3+0A6h*4],FxOpA6 + mov dword [FxTableA3+0A7h*4],FxOpA7 + mov dword [FxTableA3+0A8h*4],FxOpA8 + mov dword [FxTableA3+0A9h*4],FxOpA9 + mov dword [FxTableA3+0AAh*4],FxOpAA + mov dword [FxTableA3+0ABh*4],FxOpAB + mov dword [FxTableA3+0ACh*4],FxOpAC + mov dword [FxTableA3+0ADh*4],FxOpAD + mov dword [FxTableA3+0AEh*4],FxOpAE + mov dword [FxTableA3+0AFh*4],FxOpAF + + mov dword [FxTableA3+0B0h*4],FxOpB0 + mov dword [FxTableA3+0B1h*4],FxOpB1 + mov dword [FxTableA3+0B2h*4],FxOpB2 + mov dword [FxTableA3+0B3h*4],FxOpB3 + mov dword [FxTableA3+0B4h*4],FxOpB4 + mov dword [FxTableA3+0B5h*4],FxOpB5 + mov dword [FxTableA3+0B6h*4],FxOpB6 + mov dword [FxTableA3+0B7h*4],FxOpB7 + mov dword [FxTableA3+0B8h*4],FxOpB8 + mov dword [FxTableA3+0B9h*4],FxOpB9 + mov dword [FxTableA3+0BAh*4],FxOpBA + mov dword [FxTableA3+0BBh*4],FxOpBB + mov dword [FxTableA3+0BCh*4],FxOpBC + mov dword [FxTableA3+0BDh*4],FxOpBD + mov dword [FxTableA3+0BEh*4],FxOpBE + mov dword [FxTableA3+0BFh*4],FxOpBF + + mov dword [FxTableA3+0C0h*4],FxOpC0 + mov dword [FxTableA3+0C1h*4],FxOpC1A3 + mov dword [FxTableA3+0C2h*4],FxOpC2A3 + mov dword [FxTableA3+0C3h*4],FxOpC3A3 + mov dword [FxTableA3+0C4h*4],FxOpC4A3 + mov dword [FxTableA3+0C5h*4],FxOpC5A3 + mov dword [FxTableA3+0C6h*4],FxOpC6A3 + mov dword [FxTableA3+0C7h*4],FxOpC7A3 + mov dword [FxTableA3+0C8h*4],FxOpC8A3 + mov dword [FxTableA3+0C9h*4],FxOpC9A3 + mov dword [FxTableA3+0CAh*4],FxOpCAA3 + mov dword [FxTableA3+0CBh*4],FxOpCBA3 + mov dword [FxTableA3+0CCh*4],FxOpCCA3 + mov dword [FxTableA3+0CDh*4],FxOpCDA3 + mov dword [FxTableA3+0CEh*4],FxOpCEA3 + mov dword [FxTableA3+0CFh*4],FxOpCFA3 + + mov dword [FxTableA3+0D0h*4],FxOpD0 + mov dword [FxTableA3+0D1h*4],FxOpD1 + mov dword [FxTableA3+0D2h*4],FxOpD2 + mov dword [FxTableA3+0D3h*4],FxOpD3 + mov dword [FxTableA3+0D4h*4],FxOpD4 + mov dword [FxTableA3+0D5h*4],FxOpD5 + mov dword [FxTableA3+0D6h*4],FxOpD6 + mov dword [FxTableA3+0D7h*4],FxOpD7 + mov dword [FxTableA3+0D8h*4],FxOpD8 + mov dword [FxTableA3+0D9h*4],FxOpD9 + mov dword [FxTableA3+0DAh*4],FxOpDA + mov dword [FxTableA3+0DBh*4],FxOpDB + mov dword [FxTableA3+0DCh*4],FxOpDC + mov dword [FxTableA3+0DDh*4],FxOpDD + mov dword [FxTableA3+0DEh*4],FxOpDE + mov dword [FxTableA3+0DFh*4],FxOpDFA3 + + mov dword [FxTableA3+0E0h*4],FxOpE0 + mov dword [FxTableA3+0E1h*4],FxOpE1 + mov dword [FxTableA3+0E2h*4],FxOpE2 + mov dword [FxTableA3+0E3h*4],FxOpE3 + mov dword [FxTableA3+0E4h*4],FxOpE4 + mov dword [FxTableA3+0E5h*4],FxOpE5 + mov dword [FxTableA3+0E6h*4],FxOpE6 + mov dword [FxTableA3+0E7h*4],FxOpE7 + mov dword [FxTableA3+0E8h*4],FxOpE8 + mov dword [FxTableA3+0E9h*4],FxOpE9 + mov dword [FxTableA3+0EAh*4],FxOpEA + mov dword [FxTableA3+0EBh*4],FxOpEB + mov dword [FxTableA3+0ECh*4],FxOpEC + mov dword [FxTableA3+0EDh*4],FxOpED + mov dword [FxTableA3+0EEh*4],FxOpEE + mov dword [FxTableA3+0EFh*4],FxOpEFA3 + + mov dword [FxTableA3+0F0h*4],FxOpF0 + mov dword [FxTableA3+0F1h*4],FxOpF1 + mov dword [FxTableA3+0F2h*4],FxOpF2 + mov dword [FxTableA3+0F3h*4],FxOpF3 + mov dword [FxTableA3+0F4h*4],FxOpF4 + mov dword [FxTableA3+0F5h*4],FxOpF5 + mov dword [FxTableA3+0F6h*4],FxOpF6 + mov dword [FxTableA3+0F7h*4],FxOpF7 + mov dword [FxTableA3+0F8h*4],FxOpF8 + mov dword [FxTableA3+0F9h*4],FxOpF9 + mov dword [FxTableA3+0FAh*4],FxOpFA + mov dword [FxTableA3+0FBh*4],FxOpFB + mov dword [FxTableA3+0FCh*4],FxOpFC + mov dword [FxTableA3+0FDh*4],FxOpFD + mov dword [FxTableA3+0FEh*4],FxOpFE + mov dword [FxTableA3+0FFh*4],FxOpFF + + ; Transfer FxTable to FxTableb and FxTablec + mov esi,FxTable + mov edi,FxTableb + mov ecx,256*4 + rep movsd + mov esi,FxTable + mov edi,FxTablec + mov ecx,256*4 + rep movsd + + mov dword [FxTableb+05h*4],FxOpb05 + mov dword [FxTableb+06h*4],FxOpb06 + mov dword [FxTableb+07h*4],FxOpb07 + mov dword [FxTableb+08h*4],FxOpb08 + mov dword [FxTableb+09h*4],FxOpb09 + mov dword [FxTableb+0Ah*4],FxOpb0A + mov dword [FxTableb+0Bh*4],FxOpb0B + mov dword [FxTableb+0Ch*4],FxOpb0C + mov dword [FxTableb+0Dh*4],FxOpb0D + mov dword [FxTableb+0Eh*4],FxOpb0E + mov dword [FxTableb+0Fh*4],FxOpb0F + mov dword [FxTableb+10h*4],FxOpb10 + mov dword [FxTableb+11h*4],FxOpb11 + mov dword [FxTableb+12h*4],FxOpb12 + mov dword [FxTableb+13h*4],FxOpb13 + mov dword [FxTableb+14h*4],FxOpb14 + mov dword [FxTableb+15h*4],FxOpb15 + mov dword [FxTableb+16h*4],FxOpb16 + mov dword [FxTableb+17h*4],FxOpb17 + mov dword [FxTableb+18h*4],FxOpb18 + mov dword [FxTableb+19h*4],FxOpb19 + mov dword [FxTableb+1Ah*4],FxOpb1A + mov dword [FxTableb+1Bh*4],FxOpb1B + mov dword [FxTableb+1Ch*4],FxOpb1C + mov dword [FxTableb+1Dh*4],FxOpb1D + mov dword [FxTableb+1Eh*4],FxOpb1E + mov dword [FxTableb+1Fh*4],FxOpb1F + mov dword [FxTableb+3Dh*4],FxOpb3D + mov dword [FxTableb+3Eh*4],FxOpb3E + mov dword [FxTableb+3Fh*4],FxOpb3F + mov dword [FxTableb+0B0h*4],FxOpbB0 + mov dword [FxTableb+0B1h*4],FxOpbB1 + mov dword [FxTableb+0B2h*4],FxOpbB2 + mov dword [FxTableb+0B3h*4],FxOpbB3 + mov dword [FxTableb+0B4h*4],FxOpbB4 + mov dword [FxTableb+0B5h*4],FxOpbB5 + mov dword [FxTableb+0B6h*4],FxOpbB6 + mov dword [FxTableb+0B7h*4],FxOpbB7 + mov dword [FxTableb+0B8h*4],FxOpbB8 + mov dword [FxTableb+0B9h*4],FxOpbB9 + mov dword [FxTableb+0BAh*4],FxOpbBA + mov dword [FxTableb+0BBh*4],FxOpbBB + mov dword [FxTableb+0BCh*4],FxOpbBC + mov dword [FxTableb+0BDh*4],FxOpbBD + mov dword [FxTableb+0BEh*4],FxOpbBE + mov dword [FxTableb+0BFh*4],FxOpbBF + + mov dword [FxTablebA1+05h*4],FxOpb05 + mov dword [FxTablebA1+06h*4],FxOpb06 + mov dword [FxTablebA1+07h*4],FxOpb07 + mov dword [FxTablebA1+08h*4],FxOpb08 + mov dword [FxTablebA1+09h*4],FxOpb09 + mov dword [FxTablebA1+0Ah*4],FxOpb0A + mov dword [FxTablebA1+0Bh*4],FxOpb0B + mov dword [FxTablebA1+0Ch*4],FxOpb0C + mov dword [FxTablebA1+0Dh*4],FxOpb0D + mov dword [FxTablebA1+0Eh*4],FxOpb0E + mov dword [FxTablebA1+0Fh*4],FxOpb0F + mov dword [FxTablebA1+10h*4],FxOpb10 + mov dword [FxTablebA1+11h*4],FxOpb11 + mov dword [FxTablebA1+12h*4],FxOpb12 + mov dword [FxTablebA1+13h*4],FxOpb13 + mov dword [FxTablebA1+14h*4],FxOpb14 + mov dword [FxTablebA1+15h*4],FxOpb15 + mov dword [FxTablebA1+16h*4],FxOpb16 + mov dword [FxTablebA1+17h*4],FxOpb17 + mov dword [FxTablebA1+18h*4],FxOpb18 + mov dword [FxTablebA1+19h*4],FxOpb19 + mov dword [FxTablebA1+1Ah*4],FxOpb1A + mov dword [FxTablebA1+1Bh*4],FxOpb1B + mov dword [FxTablebA1+1Ch*4],FxOpb1C + mov dword [FxTablebA1+1Dh*4],FxOpb1D + mov dword [FxTablebA1+1Eh*4],FxOpb1E + mov dword [FxTablebA1+1Fh*4],FxOpb1F + mov dword [FxTablebA1+3Dh*4],FxOpb3D + mov dword [FxTablebA1+3Eh*4],FxOpb3E + mov dword [FxTablebA1+3Fh*4],FxOpb3F + mov dword [FxTablebA1+0B0h*4],FxOpbB0 + mov dword [FxTablebA1+0B1h*4],FxOpbB1 + mov dword [FxTablebA1+0B2h*4],FxOpbB2 + mov dword [FxTablebA1+0B3h*4],FxOpbB3 + mov dword [FxTablebA1+0B4h*4],FxOpbB4 + mov dword [FxTablebA1+0B5h*4],FxOpbB5 + mov dword [FxTablebA1+0B6h*4],FxOpbB6 + mov dword [FxTablebA1+0B7h*4],FxOpbB7 + mov dword [FxTablebA1+0B8h*4],FxOpbB8 + mov dword [FxTablebA1+0B9h*4],FxOpbB9 + mov dword [FxTablebA1+0BAh*4],FxOpbBA + mov dword [FxTablebA1+0BBh*4],FxOpbBB + mov dword [FxTablebA1+0BCh*4],FxOpbBC + mov dword [FxTablebA1+0BDh*4],FxOpbBD + mov dword [FxTablebA1+0BEh*4],FxOpbBE + mov dword [FxTablebA1+0BFh*4],FxOpbBF + + mov dword [FxTablebA2+05h*4],FxOpb05 + mov dword [FxTablebA2+06h*4],FxOpb06 + mov dword [FxTablebA2+07h*4],FxOpb07 + mov dword [FxTablebA2+08h*4],FxOpb08 + mov dword [FxTablebA2+09h*4],FxOpb09 + mov dword [FxTablebA2+0Ah*4],FxOpb0A + mov dword [FxTablebA2+0Bh*4],FxOpb0B + mov dword [FxTablebA2+0Ch*4],FxOpb0C + mov dword [FxTablebA2+0Dh*4],FxOpb0D + mov dword [FxTablebA2+0Eh*4],FxOpb0E + mov dword [FxTablebA2+0Fh*4],FxOpb0F + mov dword [FxTablebA2+10h*4],FxOpb10 + mov dword [FxTablebA2+11h*4],FxOpb11 + mov dword [FxTablebA2+12h*4],FxOpb12 + mov dword [FxTablebA2+13h*4],FxOpb13 + mov dword [FxTablebA2+14h*4],FxOpb14 + mov dword [FxTablebA2+15h*4],FxOpb15 + mov dword [FxTablebA2+16h*4],FxOpb16 + mov dword [FxTablebA2+17h*4],FxOpb17 + mov dword [FxTablebA2+18h*4],FxOpb18 + mov dword [FxTablebA2+19h*4],FxOpb19 + mov dword [FxTablebA2+1Ah*4],FxOpb1A + mov dword [FxTablebA2+1Bh*4],FxOpb1B + mov dword [FxTablebA2+1Ch*4],FxOpb1C + mov dword [FxTablebA2+1Dh*4],FxOpb1D + mov dword [FxTablebA2+1Eh*4],FxOpb1E + mov dword [FxTablebA2+1Fh*4],FxOpb1F + mov dword [FxTablebA2+3Dh*4],FxOpb3D + mov dword [FxTablebA2+3Eh*4],FxOpb3E + mov dword [FxTablebA2+3Fh*4],FxOpb3F + mov dword [FxTablebA2+0B0h*4],FxOpbB0 + mov dword [FxTablebA2+0B1h*4],FxOpbB1 + mov dword [FxTablebA2+0B2h*4],FxOpbB2 + mov dword [FxTablebA2+0B3h*4],FxOpbB3 + mov dword [FxTablebA2+0B4h*4],FxOpbB4 + mov dword [FxTablebA2+0B5h*4],FxOpbB5 + mov dword [FxTablebA2+0B6h*4],FxOpbB6 + mov dword [FxTablebA2+0B7h*4],FxOpbB7 + mov dword [FxTablebA2+0B8h*4],FxOpbB8 + mov dword [FxTablebA2+0B9h*4],FxOpbB9 + mov dword [FxTablebA2+0BAh*4],FxOpbBA + mov dword [FxTablebA2+0BBh*4],FxOpbBB + mov dword [FxTablebA2+0BCh*4],FxOpbBC + mov dword [FxTablebA2+0BDh*4],FxOpbBD + mov dword [FxTablebA2+0BEh*4],FxOpbBE + mov dword [FxTablebA2+0BFh*4],FxOpbBF + + mov dword [FxTablebA3+05h*4],FxOpb05 + mov dword [FxTablebA3+06h*4],FxOpb06 + mov dword [FxTablebA3+07h*4],FxOpb07 + mov dword [FxTablebA3+08h*4],FxOpb08 + mov dword [FxTablebA3+09h*4],FxOpb09 + mov dword [FxTablebA3+0Ah*4],FxOpb0A + mov dword [FxTablebA3+0Bh*4],FxOpb0B + mov dword [FxTablebA3+0Ch*4],FxOpb0C + mov dword [FxTablebA3+0Dh*4],FxOpb0D + mov dword [FxTablebA3+0Eh*4],FxOpb0E + mov dword [FxTablebA3+0Fh*4],FxOpb0F + mov dword [FxTablebA3+10h*4],FxOpb10 + mov dword [FxTablebA3+11h*4],FxOpb11 + mov dword [FxTablebA3+12h*4],FxOpb12 + mov dword [FxTablebA3+13h*4],FxOpb13 + mov dword [FxTablebA3+14h*4],FxOpb14 + mov dword [FxTablebA3+15h*4],FxOpb15 + mov dword [FxTablebA3+16h*4],FxOpb16 + mov dword [FxTablebA3+17h*4],FxOpb17 + mov dword [FxTablebA3+18h*4],FxOpb18 + mov dword [FxTablebA3+19h*4],FxOpb19 + mov dword [FxTablebA3+1Ah*4],FxOpb1A + mov dword [FxTablebA3+1Bh*4],FxOpb1B + mov dword [FxTablebA3+1Ch*4],FxOpb1C + mov dword [FxTablebA3+1Dh*4],FxOpb1D + mov dword [FxTablebA3+1Eh*4],FxOpb1E + mov dword [FxTablebA3+1Fh*4],FxOpb1F + mov dword [FxTablebA3+3Dh*4],FxOpb3D + mov dword [FxTablebA3+3Eh*4],FxOpb3E + mov dword [FxTablebA3+3Fh*4],FxOpb3F + mov dword [FxTablebA3+0B0h*4],FxOpbB0 + mov dword [FxTablebA3+0B1h*4],FxOpbB1 + mov dword [FxTablebA3+0B2h*4],FxOpbB2 + mov dword [FxTablebA3+0B3h*4],FxOpbB3 + mov dword [FxTablebA3+0B4h*4],FxOpbB4 + mov dword [FxTablebA3+0B5h*4],FxOpbB5 + mov dword [FxTablebA3+0B6h*4],FxOpbB6 + mov dword [FxTablebA3+0B7h*4],FxOpbB7 + mov dword [FxTablebA3+0B8h*4],FxOpbB8 + mov dword [FxTablebA3+0B9h*4],FxOpbB9 + mov dword [FxTablebA3+0BAh*4],FxOpbBA + mov dword [FxTablebA3+0BBh*4],FxOpbBB + mov dword [FxTablebA3+0BCh*4],FxOpbBC + mov dword [FxTablebA3+0BDh*4],FxOpbBD + mov dword [FxTablebA3+0BEh*4],FxOpbBE + mov dword [FxTablebA3+0BFh*4],FxOpbBF + + mov dword [FxTablec+05h*4],FxOpc05 + mov dword [FxTablec+06h*4],FxOpc06 + mov dword [FxTablec+07h*4],FxOpc07 + mov dword [FxTablec+08h*4],FxOpc08 + mov dword [FxTablec+09h*4],FxOpc09 + mov dword [FxTablec+0Ah*4],FxOpc0A + mov dword [FxTablec+0Bh*4],FxOpc0B + mov dword [FxTablec+0Ch*4],FxOpc0C + mov dword [FxTablec+0Dh*4],FxOpc0D + mov dword [FxTablec+0Eh*4],FxOpc0E + mov dword [FxTablec+0Fh*4],FxOpc0F + mov dword [FxTablec+10h*4],FxOpc10 + mov dword [FxTablec+11h*4],FxOpc11 + mov dword [FxTablec+12h*4],FxOpc12 + mov dword [FxTablec+13h*4],FxOpc13 + mov dword [FxTablec+14h*4],FxOpc14 + mov dword [FxTablec+15h*4],FxOpc15 + mov dword [FxTablec+16h*4],FxOpc16 + mov dword [FxTablec+17h*4],FxOpc17 + mov dword [FxTablec+18h*4],FxOpc18 + mov dword [FxTablec+19h*4],FxOpc19 + mov dword [FxTablec+1Ah*4],FxOpc1A + mov dword [FxTablec+1Bh*4],FxOpc1B + mov dword [FxTablec+1Ch*4],FxOpc1C + mov dword [FxTablec+1Dh*4],FxOpc1D + mov dword [FxTablec+1Eh*4],FxOpc1E + mov dword [FxTablec+1Fh*4],FxOpc1F + mov dword [FxTablec+3Dh*4],FxOpc3D + mov dword [FxTablec+3Eh*4],FxOpc3E + mov dword [FxTablec+3Fh*4],FxOpc3F + mov dword [FxTablec+0B0h*4],FxOpcB0 + mov dword [FxTablec+0B1h*4],FxOpcB1 + mov dword [FxTablec+0B2h*4],FxOpcB2 + mov dword [FxTablec+0B3h*4],FxOpcB3 + mov dword [FxTablec+0B4h*4],FxOpcB4 + mov dword [FxTablec+0B5h*4],FxOpcB5 + mov dword [FxTablec+0B6h*4],FxOpcB6 + mov dword [FxTablec+0B7h*4],FxOpcB7 + mov dword [FxTablec+0B8h*4],FxOpcB8 + mov dword [FxTablec+0B9h*4],FxOpcB9 + mov dword [FxTablec+0BAh*4],FxOpcBA + mov dword [FxTablec+0BBh*4],FxOpcBB + mov dword [FxTablec+0BCh*4],FxOpcBC + mov dword [FxTablec+0BDh*4],FxOpcBD + mov dword [FxTablec+0BEh*4],FxOpcBE + mov dword [FxTablec+0BFh*4],FxOpcBF + + mov dword [FxTablecA1+05h*4],FxOpc05 + mov dword [FxTablecA1+06h*4],FxOpc06 + mov dword [FxTablecA1+07h*4],FxOpc07 + mov dword [FxTablecA1+08h*4],FxOpc08 + mov dword [FxTablecA1+09h*4],FxOpc09 + mov dword [FxTablecA1+0Ah*4],FxOpc0A + mov dword [FxTablecA1+0Bh*4],FxOpc0B + mov dword [FxTablecA1+0Ch*4],FxOpc0C + mov dword [FxTablecA1+0Dh*4],FxOpc0D + mov dword [FxTablecA1+0Eh*4],FxOpc0E + mov dword [FxTablecA1+0Fh*4],FxOpc0F + mov dword [FxTablecA1+10h*4],FxOpc10 + mov dword [FxTablecA1+11h*4],FxOpc11 + mov dword [FxTablecA1+12h*4],FxOpc12 + mov dword [FxTablecA1+13h*4],FxOpc13 + mov dword [FxTablecA1+14h*4],FxOpc14 + mov dword [FxTablecA1+15h*4],FxOpc15 + mov dword [FxTablecA1+16h*4],FxOpc16 + mov dword [FxTablecA1+17h*4],FxOpc17 + mov dword [FxTablecA1+18h*4],FxOpc18 + mov dword [FxTablecA1+19h*4],FxOpc19 + mov dword [FxTablecA1+1Ah*4],FxOpc1A + mov dword [FxTablecA1+1Bh*4],FxOpc1B + mov dword [FxTablecA1+1Ch*4],FxOpc1C + mov dword [FxTablecA1+1Dh*4],FxOpc1D + mov dword [FxTablecA1+1Eh*4],FxOpc1E + mov dword [FxTablecA1+1Fh*4],FxOpc1F + mov dword [FxTablecA1+3Dh*4],FxOpc3D + mov dword [FxTablecA1+3Eh*4],FxOpc3E + mov dword [FxTablecA1+3Fh*4],FxOpc3F + mov dword [FxTablecA1+0B0h*4],FxOpcB0 + mov dword [FxTablecA1+0B1h*4],FxOpcB1 + mov dword [FxTablecA1+0B2h*4],FxOpcB2 + mov dword [FxTablecA1+0B3h*4],FxOpcB3 + mov dword [FxTablecA1+0B4h*4],FxOpcB4 + mov dword [FxTablecA1+0B5h*4],FxOpcB5 + mov dword [FxTablecA1+0B6h*4],FxOpcB6 + mov dword [FxTablecA1+0B7h*4],FxOpcB7 + mov dword [FxTablecA1+0B8h*4],FxOpcB8 + mov dword [FxTablecA1+0B9h*4],FxOpcB9 + mov dword [FxTablecA1+0BAh*4],FxOpcBA + mov dword [FxTablecA1+0BBh*4],FxOpcBB + mov dword [FxTablecA1+0BCh*4],FxOpcBC + mov dword [FxTablecA1+0BDh*4],FxOpcBD + mov dword [FxTablecA1+0BEh*4],FxOpcBE + mov dword [FxTablecA1+0BFh*4],FxOpcBF + + mov dword [FxTablecA2+05h*4],FxOpc05 + mov dword [FxTablecA2+06h*4],FxOpc06 + mov dword [FxTablecA2+07h*4],FxOpc07 + mov dword [FxTablecA2+08h*4],FxOpc08 + mov dword [FxTablecA2+09h*4],FxOpc09 + mov dword [FxTablecA2+0Ah*4],FxOpc0A + mov dword [FxTablecA2+0Bh*4],FxOpc0B + mov dword [FxTablecA2+0Ch*4],FxOpc0C + mov dword [FxTablecA2+0Dh*4],FxOpc0D + mov dword [FxTablecA2+0Eh*4],FxOpc0E + mov dword [FxTablecA2+0Fh*4],FxOpc0F + mov dword [FxTablecA2+10h*4],FxOpc10 + mov dword [FxTablecA2+11h*4],FxOpc11 + mov dword [FxTablecA2+12h*4],FxOpc12 + mov dword [FxTablecA2+13h*4],FxOpc13 + mov dword [FxTablecA2+14h*4],FxOpc14 + mov dword [FxTablecA2+15h*4],FxOpc15 + mov dword [FxTablecA2+16h*4],FxOpc16 + mov dword [FxTablecA2+17h*4],FxOpc17 + mov dword [FxTablecA2+18h*4],FxOpc18 + mov dword [FxTablecA2+19h*4],FxOpc19 + mov dword [FxTablecA2+1Ah*4],FxOpc1A + mov dword [FxTablecA2+1Bh*4],FxOpc1B + mov dword [FxTablecA2+1Ch*4],FxOpc1C + mov dword [FxTablecA2+1Dh*4],FxOpc1D + mov dword [FxTablecA2+1Eh*4],FxOpc1E + mov dword [FxTablecA2+1Fh*4],FxOpc1F + mov dword [FxTablecA2+3Dh*4],FxOpc3D + mov dword [FxTablecA2+3Eh*4],FxOpc3E + mov dword [FxTablecA2+3Fh*4],FxOpc3F + mov dword [FxTablecA2+0B0h*4],FxOpcB0 + mov dword [FxTablecA2+0B1h*4],FxOpcB1 + mov dword [FxTablecA2+0B2h*4],FxOpcB2 + mov dword [FxTablecA2+0B3h*4],FxOpcB3 + mov dword [FxTablecA2+0B4h*4],FxOpcB4 + mov dword [FxTablecA2+0B5h*4],FxOpcB5 + mov dword [FxTablecA2+0B6h*4],FxOpcB6 + mov dword [FxTablecA2+0B7h*4],FxOpcB7 + mov dword [FxTablecA2+0B8h*4],FxOpcB8 + mov dword [FxTablecA2+0B9h*4],FxOpcB9 + mov dword [FxTablecA2+0BAh*4],FxOpcBA + mov dword [FxTablecA2+0BBh*4],FxOpcBB + mov dword [FxTablecA2+0BCh*4],FxOpcBC + mov dword [FxTablecA2+0BDh*4],FxOpcBD + mov dword [FxTablecA2+0BEh*4],FxOpcBE + mov dword [FxTablecA2+0BFh*4],FxOpcBF + + mov dword [FxTablecA3+05h*4],FxOpc05 + mov dword [FxTablecA3+06h*4],FxOpc06 + mov dword [FxTablecA3+07h*4],FxOpc07 + mov dword [FxTablecA3+08h*4],FxOpc08 + mov dword [FxTablecA3+09h*4],FxOpc09 + mov dword [FxTablecA3+0Ah*4],FxOpc0A + mov dword [FxTablecA3+0Bh*4],FxOpc0B + mov dword [FxTablecA3+0Ch*4],FxOpc0C + mov dword [FxTablecA3+0Dh*4],FxOpc0D + mov dword [FxTablecA3+0Eh*4],FxOpc0E + mov dword [FxTablecA3+0Fh*4],FxOpc0F + mov dword [FxTablecA3+10h*4],FxOpc10 + mov dword [FxTablecA3+11h*4],FxOpc11 + mov dword [FxTablecA3+12h*4],FxOpc12 + mov dword [FxTablecA3+13h*4],FxOpc13 + mov dword [FxTablecA3+14h*4],FxOpc14 + mov dword [FxTablecA3+15h*4],FxOpc15 + mov dword [FxTablecA3+16h*4],FxOpc16 + mov dword [FxTablecA3+17h*4],FxOpc17 + mov dword [FxTablecA3+18h*4],FxOpc18 + mov dword [FxTablecA3+19h*4],FxOpc19 + mov dword [FxTablecA3+1Ah*4],FxOpc1A + mov dword [FxTablecA3+1Bh*4],FxOpc1B + mov dword [FxTablecA3+1Ch*4],FxOpc1C + mov dword [FxTablecA3+1Dh*4],FxOpc1D + mov dword [FxTablecA3+1Eh*4],FxOpc1E + mov dword [FxTablecA3+1Fh*4],FxOpc1F + mov dword [FxTablecA3+3Dh*4],FxOpc3D + mov dword [FxTablecA3+3Eh*4],FxOpc3E + mov dword [FxTablecA3+3Fh*4],FxOpc3F + mov dword [FxTablecA3+0B0h*4],FxOpcB0 + mov dword [FxTablecA3+0B1h*4],FxOpcB1 + mov dword [FxTablecA3+0B2h*4],FxOpcB2 + mov dword [FxTablecA3+0B3h*4],FxOpcB3 + mov dword [FxTablecA3+0B4h*4],FxOpcB4 + mov dword [FxTablecA3+0B5h*4],FxOpcB5 + mov dword [FxTablecA3+0B6h*4],FxOpcB6 + mov dword [FxTablecA3+0B7h*4],FxOpcB7 + mov dword [FxTablecA3+0B8h*4],FxOpcB8 + mov dword [FxTablecA3+0B9h*4],FxOpcB9 + mov dword [FxTablecA3+0BAh*4],FxOpcBA + mov dword [FxTablecA3+0BBh*4],FxOpcBB + mov dword [FxTablecA3+0BCh*4],FxOpcBC + mov dword [FxTablecA3+0BDh*4],FxOpcBD + mov dword [FxTablecA3+0BEh*4],FxOpcBE + mov dword [FxTablecA3+0BFh*4],FxOpcBF + + mov dword [FxTabled+00h*4],FxOpd00 + mov dword [FxTabled+01h*4],FxOpd01 + mov dword [FxTabled+02h*4],FxOpd02 + mov dword [FxTabled+03h*4],FxOpd03 + mov dword [FxTabled+04h*4],FxOpd04 + mov dword [FxTabled+05h*4],FxOpd05 + mov dword [FxTabled+06h*4],FxOpd06 + mov dword [FxTabled+07h*4],FxOpd07 + mov dword [FxTabled+08h*4],FxOpd08 + mov dword [FxTabled+09h*4],FxOpd09 + mov dword [FxTabled+0Ah*4],FxOpd0A + mov dword [FxTabled+0Bh*4],FxOpd0B + mov dword [FxTabled+0Ch*4],FxOpd0C + mov dword [FxTabled+0Dh*4],FxOpd0D + mov dword [FxTabled+0Eh*4],FxOpd0E + mov dword [FxTabled+0Fh*4],FxOpd0F + + mov dword [FxTabled+10h*4],FxOpd10 + mov dword [FxTabled+11h*4],FxOpd11 + mov dword [FxTabled+12h*4],FxOpd12 + mov dword [FxTabled+13h*4],FxOpd13 + mov dword [FxTabled+14h*4],FxOpd14 + mov dword [FxTabled+15h*4],FxOpd15 + mov dword [FxTabled+16h*4],FxOpd16 + mov dword [FxTabled+17h*4],FxOpd17 + mov dword [FxTabled+18h*4],FxOpd18 + mov dword [FxTabled+19h*4],FxOpd19 + mov dword [FxTabled+1Ah*4],FxOpd1A + mov dword [FxTabled+1Bh*4],FxOpd1B + mov dword [FxTabled+1Ch*4],FxOpd1C + mov dword [FxTabled+1Dh*4],FxOpd1D + mov dword [FxTabled+1Eh*4],FxOpd1E + mov dword [FxTabled+1Fh*4],FxOpd1F + + mov dword [FxTabled+20h*4],FxOpd20 + mov dword [FxTabled+21h*4],FxOpd21 + mov dword [FxTabled+22h*4],FxOpd22 + mov dword [FxTabled+23h*4],FxOpd23 + mov dword [FxTabled+24h*4],FxOpd24 + mov dword [FxTabled+25h*4],FxOpd25 + mov dword [FxTabled+26h*4],FxOpd26 + mov dword [FxTabled+27h*4],FxOpd27 + mov dword [FxTabled+28h*4],FxOpd28 + mov dword [FxTabled+29h*4],FxOpd29 + mov dword [FxTabled+2Ah*4],FxOpd2A + mov dword [FxTabled+2Bh*4],FxOpd2B + mov dword [FxTabled+2Ch*4],FxOpd2C + mov dword [FxTabled+2Dh*4],FxOpd2D + mov dword [FxTabled+2Eh*4],FxOpd2E + mov dword [FxTabled+2Fh*4],FxOpd2F + + mov dword [FxTabled+30h*4],FxOpd30 + mov dword [FxTabled+31h*4],FxOpd31 + mov dword [FxTabled+32h*4],FxOpd32 + mov dword [FxTabled+33h*4],FxOpd33 + mov dword [FxTabled+34h*4],FxOpd34 + mov dword [FxTabled+35h*4],FxOpd35 + mov dword [FxTabled+36h*4],FxOpd36 + mov dword [FxTabled+37h*4],FxOpd37 + mov dword [FxTabled+38h*4],FxOpd38 + mov dword [FxTabled+39h*4],FxOpd39 + mov dword [FxTabled+3Ah*4],FxOpd3A + mov dword [FxTabled+3Bh*4],FxOpd3B + mov dword [FxTabled+3Ch*4],FxOpd3C + mov dword [FxTabled+3Dh*4],FxOpd3D + mov dword [FxTabled+3Eh*4],FxOpd3E + mov dword [FxTabled+3Fh*4],FxOpd3F + + mov dword [FxTabled+40h*4],FxOpd40 + mov dword [FxTabled+41h*4],FxOpd41 + mov dword [FxTabled+42h*4],FxOpd42 + mov dword [FxTabled+43h*4],FxOpd43 + mov dword [FxTabled+44h*4],FxOpd44 + mov dword [FxTabled+45h*4],FxOpd45 + mov dword [FxTabled+46h*4],FxOpd46 + mov dword [FxTabled+47h*4],FxOpd47 + mov dword [FxTabled+48h*4],FxOpd48 + mov dword [FxTabled+49h*4],FxOpd49 + mov dword [FxTabled+4Ah*4],FxOpd4A + mov dword [FxTabled+4Bh*4],FxOpd4B + mov dword [FxTabled+4Ch*4],FxOpd4C + mov dword [FxTabled+4Dh*4],FxOpd4D + mov dword [FxTabled+4Eh*4],FxOpd4E + mov dword [FxTabled+4Fh*4],FxOpd4F + + mov dword [FxTabled+50h*4],FxOpd50 + mov dword [FxTabled+51h*4],FxOpd51 + mov dword [FxTabled+52h*4],FxOpd52 + mov dword [FxTabled+53h*4],FxOpd53 + mov dword [FxTabled+54h*4],FxOpd54 + mov dword [FxTabled+55h*4],FxOpd55 + mov dword [FxTabled+56h*4],FxOpd56 + mov dword [FxTabled+57h*4],FxOpd57 + mov dword [FxTabled+58h*4],FxOpd58 + mov dword [FxTabled+59h*4],FxOpd59 + mov dword [FxTabled+5Ah*4],FxOpd5A + mov dword [FxTabled+5Bh*4],FxOpd5B + mov dword [FxTabled+5Ch*4],FxOpd5C + mov dword [FxTabled+5Dh*4],FxOpd5D + mov dword [FxTabled+5Eh*4],FxOpd5E + mov dword [FxTabled+5Fh*4],FxOpd5F + + mov dword [FxTabled+60h*4],FxOpd60 + mov dword [FxTabled+61h*4],FxOpd61 + mov dword [FxTabled+62h*4],FxOpd62 + mov dword [FxTabled+63h*4],FxOpd63 + mov dword [FxTabled+64h*4],FxOpd64 + mov dword [FxTabled+65h*4],FxOpd65 + mov dword [FxTabled+66h*4],FxOpd66 + mov dword [FxTabled+67h*4],FxOpd67 + mov dword [FxTabled+68h*4],FxOpd68 + mov dword [FxTabled+69h*4],FxOpd69 + mov dword [FxTabled+6Ah*4],FxOpd6A + mov dword [FxTabled+6Bh*4],FxOpd6B + mov dword [FxTabled+6Ch*4],FxOpd6C + mov dword [FxTabled+6Dh*4],FxOpd6D + mov dword [FxTabled+6Eh*4],FxOpd6E + mov dword [FxTabled+6Fh*4],FxOpd6F + + mov dword [FxTabled+70h*4],FxOpd70 + mov dword [FxTabled+71h*4],FxOpd71 + mov dword [FxTabled+72h*4],FxOpd72 + mov dword [FxTabled+73h*4],FxOpd73 + mov dword [FxTabled+74h*4],FxOpd74 + mov dword [FxTabled+75h*4],FxOpd75 + mov dword [FxTabled+76h*4],FxOpd76 + mov dword [FxTabled+77h*4],FxOpd77 + mov dword [FxTabled+78h*4],FxOpd78 + mov dword [FxTabled+79h*4],FxOpd79 + mov dword [FxTabled+7Ah*4],FxOpd7A + mov dword [FxTabled+7Bh*4],FxOpd7B + mov dword [FxTabled+7Ch*4],FxOpd7C + mov dword [FxTabled+7Dh*4],FxOpd7D + mov dword [FxTabled+7Eh*4],FxOpd7E + mov dword [FxTabled+7Fh*4],FxOpd7F + + mov dword [FxTabled+80h*4],FxOpd80 + mov dword [FxTabled+81h*4],FxOpd81 + mov dword [FxTabled+82h*4],FxOpd82 + mov dword [FxTabled+83h*4],FxOpd83 + mov dword [FxTabled+84h*4],FxOpd84 + mov dword [FxTabled+85h*4],FxOpd85 + mov dword [FxTabled+86h*4],FxOpd86 + mov dword [FxTabled+87h*4],FxOpd87 + mov dword [FxTabled+88h*4],FxOpd88 + mov dword [FxTabled+89h*4],FxOpd89 + mov dword [FxTabled+8Ah*4],FxOpd8A + mov dword [FxTabled+8Bh*4],FxOpd8B + mov dword [FxTabled+8Ch*4],FxOpd8C + mov dword [FxTabled+8Dh*4],FxOpd8D + mov dword [FxTabled+8Eh*4],FxOpd8E + mov dword [FxTabled+8Fh*4],FxOpd8F + + mov dword [FxTabled+90h*4],FxOpd90 + mov dword [FxTabled+91h*4],FxOpd91 + mov dword [FxTabled+92h*4],FxOpd92 + mov dword [FxTabled+93h*4],FxOpd93 + mov dword [FxTabled+94h*4],FxOpd94 + mov dword [FxTabled+95h*4],FxOpd95 + mov dword [FxTabled+96h*4],FxOpd96 + mov dword [FxTabled+97h*4],FxOpd97 + mov dword [FxTabled+98h*4],FxOpd98 + mov dword [FxTabled+99h*4],FxOpd99 + mov dword [FxTabled+9Ah*4],FxOpd9A + mov dword [FxTabled+9Bh*4],FxOpd9B + mov dword [FxTabled+9Ch*4],FxOpd9C + mov dword [FxTabled+9Dh*4],FxOpd9D + mov dword [FxTabled+9Eh*4],FxOpd9E + mov dword [FxTabled+9Fh*4],FxOpd9F + + mov dword [FxTabled+0A0h*4],FxOpdA0 + mov dword [FxTabled+0A1h*4],FxOpdA1 + mov dword [FxTabled+0A2h*4],FxOpdA2 + mov dword [FxTabled+0A3h*4],FxOpdA3 + mov dword [FxTabled+0A4h*4],FxOpdA4 + mov dword [FxTabled+0A5h*4],FxOpdA5 + mov dword [FxTabled+0A6h*4],FxOpdA6 + mov dword [FxTabled+0A7h*4],FxOpdA7 + mov dword [FxTabled+0A8h*4],FxOpdA8 + mov dword [FxTabled+0A9h*4],FxOpdA9 + mov dword [FxTabled+0AAh*4],FxOpdAA + mov dword [FxTabled+0ABh*4],FxOpdAB + mov dword [FxTabled+0ACh*4],FxOpdAC + mov dword [FxTabled+0ADh*4],FxOpdAD + mov dword [FxTabled+0AEh*4],FxOpdAE + mov dword [FxTabled+0AFh*4],FxOpdAF + + mov dword [FxTabled+0B0h*4],FxOpdB0 + mov dword [FxTabled+0B1h*4],FxOpdB1 + mov dword [FxTabled+0B2h*4],FxOpdB2 + mov dword [FxTabled+0B3h*4],FxOpdB3 + mov dword [FxTabled+0B4h*4],FxOpdB4 + mov dword [FxTabled+0B5h*4],FxOpdB5 + mov dword [FxTabled+0B6h*4],FxOpdB6 + mov dword [FxTabled+0B7h*4],FxOpdB7 + mov dword [FxTabled+0B8h*4],FxOpdB8 + mov dword [FxTabled+0B9h*4],FxOpdB9 + mov dword [FxTabled+0BAh*4],FxOpdBA + mov dword [FxTabled+0BBh*4],FxOpdBB + mov dword [FxTabled+0BCh*4],FxOpdBC + mov dword [FxTabled+0BDh*4],FxOpdBD + mov dword [FxTabled+0BEh*4],FxOpdBE + mov dword [FxTabled+0BFh*4],FxOpdBF + + mov dword [FxTabled+0C0h*4],FxOpdC0 + mov dword [FxTabled+0C1h*4],FxOpdC1 + mov dword [FxTabled+0C2h*4],FxOpdC2 + mov dword [FxTabled+0C3h*4],FxOpdC3 + mov dword [FxTabled+0C4h*4],FxOpdC4 + mov dword [FxTabled+0C5h*4],FxOpdC5 + mov dword [FxTabled+0C6h*4],FxOpdC6 + mov dword [FxTabled+0C7h*4],FxOpdC7 + mov dword [FxTabled+0C8h*4],FxOpdC8 + mov dword [FxTabled+0C9h*4],FxOpdC9 + mov dword [FxTabled+0CAh*4],FxOpdCA + mov dword [FxTabled+0CBh*4],FxOpdCB + mov dword [FxTabled+0CCh*4],FxOpdCC + mov dword [FxTabled+0CDh*4],FxOpdCD + mov dword [FxTabled+0CEh*4],FxOpdCE + mov dword [FxTabled+0CFh*4],FxOpdCF + + mov dword [FxTabled+0D0h*4],FxOpdD0 + mov dword [FxTabled+0D1h*4],FxOpdD1 + mov dword [FxTabled+0D2h*4],FxOpdD2 + mov dword [FxTabled+0D3h*4],FxOpdD3 + mov dword [FxTabled+0D4h*4],FxOpdD4 + mov dword [FxTabled+0D5h*4],FxOpdD5 + mov dword [FxTabled+0D6h*4],FxOpdD6 + mov dword [FxTabled+0D7h*4],FxOpdD7 + mov dword [FxTabled+0D8h*4],FxOpdD8 + mov dword [FxTabled+0D9h*4],FxOpdD9 + mov dword [FxTabled+0DAh*4],FxOpdDA + mov dword [FxTabled+0DBh*4],FxOpdDB + mov dword [FxTabled+0DCh*4],FxOpdDC + mov dword [FxTabled+0DDh*4],FxOpdDD + mov dword [FxTabled+0DEh*4],FxOpdDE + mov dword [FxTabled+0DFh*4],FxOpdDF + + mov dword [FxTabled+0E0h*4],FxOpdE0 + mov dword [FxTabled+0E1h*4],FxOpdE1 + mov dword [FxTabled+0E2h*4],FxOpdE2 + mov dword [FxTabled+0E3h*4],FxOpdE3 + mov dword [FxTabled+0E4h*4],FxOpdE4 + mov dword [FxTabled+0E5h*4],FxOpdE5 + mov dword [FxTabled+0E6h*4],FxOpdE6 + mov dword [FxTabled+0E7h*4],FxOpdE7 + mov dword [FxTabled+0E8h*4],FxOpdE8 + mov dword [FxTabled+0E9h*4],FxOpdE9 + mov dword [FxTabled+0EAh*4],FxOpdEA + mov dword [FxTabled+0EBh*4],FxOpdEB + mov dword [FxTabled+0ECh*4],FxOpdEC + mov dword [FxTabled+0EDh*4],FxOpdED + mov dword [FxTabled+0EEh*4],FxOpdEE + mov dword [FxTabled+0EFh*4],FxOpdEF + + mov dword [FxTabled+0F0h*4],FxOpdF0 + mov dword [FxTabled+0F1h*4],FxOpdF1 + mov dword [FxTabled+0F2h*4],FxOpdF2 + mov dword [FxTabled+0F3h*4],FxOpdF3 + mov dword [FxTabled+0F4h*4],FxOpdF4 + mov dword [FxTabled+0F5h*4],FxOpdF5 + mov dword [FxTabled+0F6h*4],FxOpdF6 + mov dword [FxTabled+0F7h*4],FxOpdF7 + mov dword [FxTabled+0F8h*4],FxOpdF8 + mov dword [FxTabled+0F9h*4],FxOpdF9 + mov dword [FxTabled+0FAh*4],FxOpdFA + mov dword [FxTabled+0FBh*4],FxOpdFB + mov dword [FxTabled+0FCh*4],FxOpdFC + mov dword [FxTabled+0FDh*4],FxOpdFD + mov dword [FxTabled+0FEh*4],FxOpdFE + mov dword [FxTabled+0FFh*4],FxOpdFF + + + mov dword [FxTabledA1+00h*4],FxOpd00 + mov dword [FxTabledA1+01h*4],FxOpd01 + mov dword [FxTabledA1+02h*4],FxOpd02 + mov dword [FxTabledA1+03h*4],FxOpd03 + mov dword [FxTabledA1+04h*4],FxOpd04 + mov dword [FxTabledA1+05h*4],FxOpd05 + mov dword [FxTabledA1+06h*4],FxOpd06 + mov dword [FxTabledA1+07h*4],FxOpd07 + mov dword [FxTabledA1+08h*4],FxOpd08 + mov dword [FxTabledA1+09h*4],FxOpd09 + mov dword [FxTabledA1+0Ah*4],FxOpd0A + mov dword [FxTabledA1+0Bh*4],FxOpd0B + mov dword [FxTabledA1+0Ch*4],FxOpd0C + mov dword [FxTabledA1+0Dh*4],FxOpd0D + mov dword [FxTabledA1+0Eh*4],FxOpd0E + mov dword [FxTabledA1+0Fh*4],FxOpd0F + + mov dword [FxTabledA1+10h*4],FxOpd10 + mov dword [FxTabledA1+11h*4],FxOpd11 + mov dword [FxTabledA1+12h*4],FxOpd12 + mov dword [FxTabledA1+13h*4],FxOpd13 + mov dword [FxTabledA1+14h*4],FxOpd14 + mov dword [FxTabledA1+15h*4],FxOpd15 + mov dword [FxTabledA1+16h*4],FxOpd16 + mov dword [FxTabledA1+17h*4],FxOpd17 + mov dword [FxTabledA1+18h*4],FxOpd18 + mov dword [FxTabledA1+19h*4],FxOpd19 + mov dword [FxTabledA1+1Ah*4],FxOpd1A + mov dword [FxTabledA1+1Bh*4],FxOpd1B + mov dword [FxTabledA1+1Ch*4],FxOpd1C + mov dword [FxTabledA1+1Dh*4],FxOpd1D + mov dword [FxTabledA1+1Eh*4],FxOpd1E + mov dword [FxTabledA1+1Fh*4],FxOpd1F + + mov dword [FxTabledA1+20h*4],FxOpd20 + mov dword [FxTabledA1+21h*4],FxOpd21 + mov dword [FxTabledA1+22h*4],FxOpd22 + mov dword [FxTabledA1+23h*4],FxOpd23 + mov dword [FxTabledA1+24h*4],FxOpd24 + mov dword [FxTabledA1+25h*4],FxOpd25 + mov dword [FxTabledA1+26h*4],FxOpd26 + mov dword [FxTabledA1+27h*4],FxOpd27 + mov dword [FxTabledA1+28h*4],FxOpd28 + mov dword [FxTabledA1+29h*4],FxOpd29 + mov dword [FxTabledA1+2Ah*4],FxOpd2A + mov dword [FxTabledA1+2Bh*4],FxOpd2B + mov dword [FxTabledA1+2Ch*4],FxOpd2C + mov dword [FxTabledA1+2Dh*4],FxOpd2D + mov dword [FxTabledA1+2Eh*4],FxOpd2E + mov dword [FxTabledA1+2Fh*4],FxOpd2F + + mov dword [FxTabledA1+30h*4],FxOpd30A1 + mov dword [FxTabledA1+31h*4],FxOpd31A1 + mov dword [FxTabledA1+32h*4],FxOpd32A1 + mov dword [FxTabledA1+33h*4],FxOpd33A1 + mov dword [FxTabledA1+34h*4],FxOpd34A1 + mov dword [FxTabledA1+35h*4],FxOpd35A1 + mov dword [FxTabledA1+36h*4],FxOpd36A1 + mov dword [FxTabledA1+37h*4],FxOpd37A1 + mov dword [FxTabledA1+38h*4],FxOpd38A1 + mov dword [FxTabledA1+39h*4],FxOpd39A1 + mov dword [FxTabledA1+3Ah*4],FxOpd3AA1 + mov dword [FxTabledA1+3Bh*4],FxOpd3BA1 + mov dword [FxTabledA1+3Ch*4],FxOpd3C + mov dword [FxTabledA1+3Dh*4],FxOpd3D + mov dword [FxTabledA1+3Eh*4],FxOpd3E + mov dword [FxTabledA1+3Fh*4],FxOpd3F + + mov dword [FxTabledA1+40h*4],FxOpd40A1 + mov dword [FxTabledA1+41h*4],FxOpd41A1 + mov dword [FxTabledA1+42h*4],FxOpd42A1 + mov dword [FxTabledA1+43h*4],FxOpd43A1 + mov dword [FxTabledA1+44h*4],FxOpd44A1 + mov dword [FxTabledA1+45h*4],FxOpd45A1 + mov dword [FxTabledA1+46h*4],FxOpd46A1 + mov dword [FxTabledA1+47h*4],FxOpd47A1 + mov dword [FxTabledA1+48h*4],FxOpd48A1 + mov dword [FxTabledA1+49h*4],FxOpd49A1 + mov dword [FxTabledA1+4Ah*4],FxOpd4AA1 + mov dword [FxTabledA1+4Bh*4],FxOpd4BA1 + mov dword [FxTabledA1+4Ch*4],FxOpd4CA1 + mov dword [FxTabledA1+4Dh*4],FxOpd4D + mov dword [FxTabledA1+4Eh*4],FxOpd4EA1 + mov dword [FxTabledA1+4Fh*4],FxOpd4F + + mov dword [FxTabledA1+50h*4],FxOpd50A1 + mov dword [FxTabledA1+51h*4],FxOpd51A1 + mov dword [FxTabledA1+52h*4],FxOpd52A1 + mov dword [FxTabledA1+53h*4],FxOpd53A1 + mov dword [FxTabledA1+54h*4],FxOpd54A1 + mov dword [FxTabledA1+55h*4],FxOpd55A1 + mov dword [FxTabledA1+56h*4],FxOpd56A1 + mov dword [FxTabledA1+57h*4],FxOpd57A1 + mov dword [FxTabledA1+58h*4],FxOpd58A1 + mov dword [FxTabledA1+59h*4],FxOpd59A1 + mov dword [FxTabledA1+5Ah*4],FxOpd5AA1 + mov dword [FxTabledA1+5Bh*4],FxOpd5BA1 + mov dword [FxTabledA1+5Ch*4],FxOpd5CA1 + mov dword [FxTabledA1+5Dh*4],FxOpd5DA1 + mov dword [FxTabledA1+5Eh*4],FxOpd5EA1 + mov dword [FxTabledA1+5Fh*4],FxOpd5FA1 + + mov dword [FxTabledA1+60h*4],FxOpd60A1 + mov dword [FxTabledA1+61h*4],FxOpd61A1 + mov dword [FxTabledA1+62h*4],FxOpd62A1 + mov dword [FxTabledA1+63h*4],FxOpd63A1 + mov dword [FxTabledA1+64h*4],FxOpd64A1 + mov dword [FxTabledA1+65h*4],FxOpd65A1 + mov dword [FxTabledA1+66h*4],FxOpd66A1 + mov dword [FxTabledA1+67h*4],FxOpd67A1 + mov dword [FxTabledA1+68h*4],FxOpd68A1 + mov dword [FxTabledA1+69h*4],FxOpd69A1 + mov dword [FxTabledA1+6Ah*4],FxOpd6AA1 + mov dword [FxTabledA1+6Bh*4],FxOpd6BA1 + mov dword [FxTabledA1+6Ch*4],FxOpd6CA1 + mov dword [FxTabledA1+6Dh*4],FxOpd6DA1 + mov dword [FxTabledA1+6Eh*4],FxOpd6EA1 + mov dword [FxTabledA1+6Fh*4],FxOpd6FA1 + + mov dword [FxTabledA1+70h*4],FxOpd70 + mov dword [FxTabledA1+71h*4],FxOpd71A1 + mov dword [FxTabledA1+72h*4],FxOpd72A1 + mov dword [FxTabledA1+73h*4],FxOpd73A1 + mov dword [FxTabledA1+74h*4],FxOpd74A1 + mov dword [FxTabledA1+75h*4],FxOpd75A1 + mov dword [FxTabledA1+76h*4],FxOpd76A1 + mov dword [FxTabledA1+77h*4],FxOpd77A1 + mov dword [FxTabledA1+78h*4],FxOpd78A1 + mov dword [FxTabledA1+79h*4],FxOpd79A1 + mov dword [FxTabledA1+7Ah*4],FxOpd7AA1 + mov dword [FxTabledA1+7Bh*4],FxOpd7BA1 + mov dword [FxTabledA1+7Ch*4],FxOpd7CA1 + mov dword [FxTabledA1+7Dh*4],FxOpd7DA1 + mov dword [FxTabledA1+7Eh*4],FxOpd7EA1 + mov dword [FxTabledA1+7Fh*4],FxOpd7FA1 + + mov dword [FxTabledA1+80h*4],FxOpd80A1 + mov dword [FxTabledA1+81h*4],FxOpd81A1 + mov dword [FxTabledA1+82h*4],FxOpd82A1 + mov dword [FxTabledA1+83h*4],FxOpd83A1 + mov dword [FxTabledA1+84h*4],FxOpd84A1 + mov dword [FxTabledA1+85h*4],FxOpd85A1 + mov dword [FxTabledA1+86h*4],FxOpd86A1 + mov dword [FxTabledA1+87h*4],FxOpd87A1 + mov dword [FxTabledA1+88h*4],FxOpd88A1 + mov dword [FxTabledA1+89h*4],FxOpd89A1 + mov dword [FxTabledA1+8Ah*4],FxOpd8AA1 + mov dword [FxTabledA1+8Bh*4],FxOpd8BA1 + mov dword [FxTabledA1+8Ch*4],FxOpd8CA1 + mov dword [FxTabledA1+8Dh*4],FxOpd8DA1 + mov dword [FxTabledA1+8Eh*4],FxOpd8EA1 + mov dword [FxTabledA1+8Fh*4],FxOpd8FA1 + + mov dword [FxTabledA1+90h*4],FxOpd90 + mov dword [FxTabledA1+91h*4],FxOpd91 + mov dword [FxTabledA1+92h*4],FxOpd92 + mov dword [FxTabledA1+93h*4],FxOpd93 + mov dword [FxTabledA1+94h*4],FxOpd94 + mov dword [FxTabledA1+95h*4],FxOpd95 + mov dword [FxTabledA1+96h*4],FxOpd96A1 + mov dword [FxTabledA1+97h*4],FxOpd97 + mov dword [FxTabledA1+98h*4],FxOpd98A1 + mov dword [FxTabledA1+99h*4],FxOpd99A1 + mov dword [FxTabledA1+9Ah*4],FxOpd9AA1 + mov dword [FxTabledA1+9Bh*4],FxOpd9BA1 + mov dword [FxTabledA1+9Ch*4],FxOpd9CA1 + mov dword [FxTabledA1+9Dh*4],FxOpd9DA1 + mov dword [FxTabledA1+9Eh*4],FxOpd9E + mov dword [FxTabledA1+9Fh*4],FxOpd9FA1 + + mov dword [FxTabledA1+0A0h*4],FxOpdA0A1 + mov dword [FxTabledA1+0A1h*4],FxOpdA1A1 + mov dword [FxTabledA1+0A2h*4],FxOpdA2A1 + mov dword [FxTabledA1+0A3h*4],FxOpdA3A1 + mov dword [FxTabledA1+0A4h*4],FxOpdA4A1 + mov dword [FxTabledA1+0A5h*4],FxOpdA5A1 + mov dword [FxTabledA1+0A6h*4],FxOpdA6A1 + mov dword [FxTabledA1+0A7h*4],FxOpdA7A1 + mov dword [FxTabledA1+0A8h*4],FxOpdA8A1 + mov dword [FxTabledA1+0A9h*4],FxOpdA9A1 + mov dword [FxTabledA1+0AAh*4],FxOpdAAA1 + mov dword [FxTabledA1+0ABh*4],FxOpdABA1 + mov dword [FxTabledA1+0ACh*4],FxOpdACA1 + mov dword [FxTabledA1+0ADh*4],FxOpdADA1 + mov dword [FxTabledA1+0AEh*4],FxOpdAEA1 + mov dword [FxTabledA1+0AFh*4],FxOpdAFA1 + + mov dword [FxTabledA1+0B0h*4],FxOpdB0 + mov dword [FxTabledA1+0B1h*4],FxOpdB1 + mov dword [FxTabledA1+0B2h*4],FxOpdB2 + mov dword [FxTabledA1+0B3h*4],FxOpdB3 + mov dword [FxTabledA1+0B4h*4],FxOpdB4 + mov dword [FxTabledA1+0B5h*4],FxOpdB5 + mov dword [FxTabledA1+0B6h*4],FxOpdB6 + mov dword [FxTabledA1+0B7h*4],FxOpdB7 + mov dword [FxTabledA1+0B8h*4],FxOpdB8 + mov dword [FxTabledA1+0B9h*4],FxOpdB9 + mov dword [FxTabledA1+0BAh*4],FxOpdBA + mov dword [FxTabledA1+0BBh*4],FxOpdBB + mov dword [FxTabledA1+0BCh*4],FxOpdBC + mov dword [FxTabledA1+0BDh*4],FxOpdBD + mov dword [FxTabledA1+0BEh*4],FxOpdBE + mov dword [FxTabledA1+0BFh*4],FxOpdBF + + mov dword [FxTabledA1+0C0h*4],FxOpdC0 + mov dword [FxTabledA1+0C1h*4],FxOpdC1A1 + mov dword [FxTabledA1+0C2h*4],FxOpdC2A1 + mov dword [FxTabledA1+0C3h*4],FxOpdC3A1 + mov dword [FxTabledA1+0C4h*4],FxOpdC4A1 + mov dword [FxTabledA1+0C5h*4],FxOpdC5A1 + mov dword [FxTabledA1+0C6h*4],FxOpdC6A1 + mov dword [FxTabledA1+0C7h*4],FxOpdC7A1 + mov dword [FxTabledA1+0C8h*4],FxOpdC8A1 + mov dword [FxTabledA1+0C9h*4],FxOpdC9A1 + mov dword [FxTabledA1+0CAh*4],FxOpdCAA1 + mov dword [FxTabledA1+0CBh*4],FxOpdCBA1 + mov dword [FxTabledA1+0CCh*4],FxOpdCCA1 + mov dword [FxTabledA1+0CDh*4],FxOpdCDA1 + mov dword [FxTabledA1+0CEh*4],FxOpdCEA1 + mov dword [FxTabledA1+0CFh*4],FxOpdCFA1 + + mov dword [FxTabledA1+0D0h*4],FxOpdD0 + mov dword [FxTabledA1+0D1h*4],FxOpdD1 + mov dword [FxTabledA1+0D2h*4],FxOpdD2 + mov dword [FxTabledA1+0D3h*4],FxOpdD3 + mov dword [FxTabledA1+0D4h*4],FxOpdD4 + mov dword [FxTabledA1+0D5h*4],FxOpdD5 + mov dword [FxTabledA1+0D6h*4],FxOpdD6 + mov dword [FxTabledA1+0D7h*4],FxOpdD7 + mov dword [FxTabledA1+0D8h*4],FxOpdD8 + mov dword [FxTabledA1+0D9h*4],FxOpdD9 + mov dword [FxTabledA1+0DAh*4],FxOpdDA + mov dword [FxTabledA1+0DBh*4],FxOpdDB + mov dword [FxTabledA1+0DCh*4],FxOpdDC + mov dword [FxTabledA1+0DDh*4],FxOpdDD + mov dword [FxTabledA1+0DEh*4],FxOpdDE + mov dword [FxTabledA1+0DFh*4],FxOpdDF + + mov dword [FxTabledA1+0E0h*4],FxOpdE0 + mov dword [FxTabledA1+0E1h*4],FxOpdE1 + mov dword [FxTabledA1+0E2h*4],FxOpdE2 + mov dword [FxTabledA1+0E3h*4],FxOpdE3 + mov dword [FxTabledA1+0E4h*4],FxOpdE4 + mov dword [FxTabledA1+0E5h*4],FxOpdE5 + mov dword [FxTabledA1+0E6h*4],FxOpdE6 + mov dword [FxTabledA1+0E7h*4],FxOpdE7 + mov dword [FxTabledA1+0E8h*4],FxOpdE8 + mov dword [FxTabledA1+0E9h*4],FxOpdE9 + mov dword [FxTabledA1+0EAh*4],FxOpdEA + mov dword [FxTabledA1+0EBh*4],FxOpdEB + mov dword [FxTabledA1+0ECh*4],FxOpdEC + mov dword [FxTabledA1+0EDh*4],FxOpdED + mov dword [FxTabledA1+0EEh*4],FxOpdEE + mov dword [FxTabledA1+0EFh*4],FxOpdEFA1 + + mov dword [FxTabledA1+0F0h*4],FxOpdF0A1 + mov dword [FxTabledA1+0F1h*4],FxOpdF1A1 + mov dword [FxTabledA1+0F2h*4],FxOpdF2A1 + mov dword [FxTabledA1+0F3h*4],FxOpdF3A1 + mov dword [FxTabledA1+0F4h*4],FxOpdF4A1 + mov dword [FxTabledA1+0F5h*4],FxOpdF5A1 + mov dword [FxTabledA1+0F6h*4],FxOpdF6A1 + mov dword [FxTabledA1+0F7h*4],FxOpdF7A1 + mov dword [FxTabledA1+0F8h*4],FxOpdF8A1 + mov dword [FxTabledA1+0F9h*4],FxOpdF9A1 + mov dword [FxTabledA1+0FAh*4],FxOpdFAA1 + mov dword [FxTabledA1+0FBh*4],FxOpdFBA1 + mov dword [FxTabledA1+0FCh*4],FxOpdFCA1 + mov dword [FxTabledA1+0FDh*4],FxOpdFDA1 + mov dword [FxTabledA1+0FEh*4],FxOpdFEA1 + mov dword [FxTabledA1+0FFh*4],FxOpdFFA1 + + + mov dword [FxTabledA2+00h*4],FxOpd00 + mov dword [FxTabledA2+01h*4],FxOpd01 + mov dword [FxTabledA2+02h*4],FxOpd02 + mov dword [FxTabledA2+03h*4],FxOpd03 + mov dword [FxTabledA2+04h*4],FxOpd04 + mov dword [FxTabledA2+05h*4],FxOpd05 + mov dword [FxTabledA2+06h*4],FxOpd06 + mov dword [FxTabledA2+07h*4],FxOpd07 + mov dword [FxTabledA2+08h*4],FxOpd08 + mov dword [FxTabledA2+09h*4],FxOpd09 + mov dword [FxTabledA2+0Ah*4],FxOpd0A + mov dword [FxTabledA2+0Bh*4],FxOpd0B + mov dword [FxTabledA2+0Ch*4],FxOpd0C + mov dword [FxTabledA2+0Dh*4],FxOpd0D + mov dword [FxTabledA2+0Eh*4],FxOpd0E + mov dword [FxTabledA2+0Fh*4],FxOpd0F + + mov dword [FxTabledA2+10h*4],FxOpd10 + mov dword [FxTabledA2+11h*4],FxOpd11 + mov dword [FxTabledA2+12h*4],FxOpd12 + mov dword [FxTabledA2+13h*4],FxOpd13 + mov dword [FxTabledA2+14h*4],FxOpd14 + mov dword [FxTabledA2+15h*4],FxOpd15 + mov dword [FxTabledA2+16h*4],FxOpd16 + mov dword [FxTabledA2+17h*4],FxOpd17 + mov dword [FxTabledA2+18h*4],FxOpd18 + mov dword [FxTabledA2+19h*4],FxOpd19 + mov dword [FxTabledA2+1Ah*4],FxOpd1A + mov dword [FxTabledA2+1Bh*4],FxOpd1B + mov dword [FxTabledA2+1Ch*4],FxOpd1C + mov dword [FxTabledA2+1Dh*4],FxOpd1D + mov dword [FxTabledA2+1Eh*4],FxOpd1E + mov dword [FxTabledA2+1Fh*4],FxOpd1F + + mov dword [FxTabledA2+20h*4],FxOpd20 + mov dword [FxTabledA2+21h*4],FxOpd21 + mov dword [FxTabledA2+22h*4],FxOpd22 + mov dword [FxTabledA2+23h*4],FxOpd23 + mov dword [FxTabledA2+24h*4],FxOpd24 + mov dword [FxTabledA2+25h*4],FxOpd25 + mov dword [FxTabledA2+26h*4],FxOpd26 + mov dword [FxTabledA2+27h*4],FxOpd27 + mov dword [FxTabledA2+28h*4],FxOpd28 + mov dword [FxTabledA2+29h*4],FxOpd29 + mov dword [FxTabledA2+2Ah*4],FxOpd2A + mov dword [FxTabledA2+2Bh*4],FxOpd2B + mov dword [FxTabledA2+2Ch*4],FxOpd2C + mov dword [FxTabledA2+2Dh*4],FxOpd2D + mov dword [FxTabledA2+2Eh*4],FxOpd2E + mov dword [FxTabledA2+2Fh*4],FxOpd2F + + mov dword [FxTabledA2+30h*4],FxOpd30 + mov dword [FxTabledA2+31h*4],FxOpd31 + mov dword [FxTabledA2+32h*4],FxOpd32 + mov dword [FxTabledA2+33h*4],FxOpd33 + mov dword [FxTabledA2+34h*4],FxOpd34 + mov dword [FxTabledA2+35h*4],FxOpd35 + mov dword [FxTabledA2+36h*4],FxOpd36 + mov dword [FxTabledA2+37h*4],FxOpd37 + mov dword [FxTabledA2+38h*4],FxOpd38 + mov dword [FxTabledA2+39h*4],FxOpd39 + mov dword [FxTabledA2+3Ah*4],FxOpd3A + mov dword [FxTabledA2+3Bh*4],FxOpd3B + mov dword [FxTabledA2+3Ch*4],FxOpd3C + mov dword [FxTabledA2+3Dh*4],FxOpd3D + mov dword [FxTabledA2+3Eh*4],FxOpd3E + mov dword [FxTabledA2+3Fh*4],FxOpd3F + + mov dword [FxTabledA2+40h*4],FxOpd40 + mov dword [FxTabledA2+41h*4],FxOpd41 + mov dword [FxTabledA2+42h*4],FxOpd42 + mov dword [FxTabledA2+43h*4],FxOpd43 + mov dword [FxTabledA2+44h*4],FxOpd44 + mov dword [FxTabledA2+45h*4],FxOpd45 + mov dword [FxTabledA2+46h*4],FxOpd46 + mov dword [FxTabledA2+47h*4],FxOpd47 + mov dword [FxTabledA2+48h*4],FxOpd48 + mov dword [FxTabledA2+49h*4],FxOpd49 + mov dword [FxTabledA2+4Ah*4],FxOpd4A + mov dword [FxTabledA2+4Bh*4],FxOpd4B + mov dword [FxTabledA2+4Ch*4],FxOpd4C + mov dword [FxTabledA2+4Dh*4],FxOpd4D + mov dword [FxTabledA2+4Eh*4],FxOpd4E + mov dword [FxTabledA2+4Fh*4],FxOpd4F + + mov dword [FxTabledA2+50h*4],FxOpd50A2 + mov dword [FxTabledA2+51h*4],FxOpd51A2 + mov dword [FxTabledA2+52h*4],FxOpd52A2 + mov dword [FxTabledA2+53h*4],FxOpd53A2 + mov dword [FxTabledA2+54h*4],FxOpd54A2 + mov dword [FxTabledA2+55h*4],FxOpd55A2 + mov dword [FxTabledA2+56h*4],FxOpd56A2 + mov dword [FxTabledA2+57h*4],FxOpd57A2 + mov dword [FxTabledA2+58h*4],FxOpd58A2 + mov dword [FxTabledA2+59h*4],FxOpd59A2 + mov dword [FxTabledA2+5Ah*4],FxOpd5AA2 + mov dword [FxTabledA2+5Bh*4],FxOpd5BA2 + mov dword [FxTabledA2+5Ch*4],FxOpd5CA2 + mov dword [FxTabledA2+5Dh*4],FxOpd5DA2 + mov dword [FxTabledA2+5Eh*4],FxOpd5EA2 + mov dword [FxTabledA2+5Fh*4],FxOpd5FA2 + + mov dword [FxTabledA2+60h*4],FxOpd60A2 + mov dword [FxTabledA2+61h*4],FxOpd61A2 + mov dword [FxTabledA2+62h*4],FxOpd62A2 + mov dword [FxTabledA2+63h*4],FxOpd63A2 + mov dword [FxTabledA2+64h*4],FxOpd64A2 + mov dword [FxTabledA2+65h*4],FxOpd65A2 + mov dword [FxTabledA2+66h*4],FxOpd66A2 + mov dword [FxTabledA2+67h*4],FxOpd67A2 + mov dword [FxTabledA2+68h*4],FxOpd68A2 + mov dword [FxTabledA2+69h*4],FxOpd69A2 + mov dword [FxTabledA2+6Ah*4],FxOpd6AA2 + mov dword [FxTabledA2+6Bh*4],FxOpd6BA2 + mov dword [FxTabledA2+6Ch*4],FxOpd6CA2 + mov dword [FxTabledA2+6Dh*4],FxOpd6DA2 + mov dword [FxTabledA2+6Eh*4],FxOpd6EA2 + mov dword [FxTabledA2+6Fh*4],FxOpd6FA2 + + mov dword [FxTabledA2+70h*4],FxOpd70 + mov dword [FxTabledA2+71h*4],FxOpd71A2 + mov dword [FxTabledA2+72h*4],FxOpd72A2 + mov dword [FxTabledA2+73h*4],FxOpd73A2 + mov dword [FxTabledA2+74h*4],FxOpd74A2 + mov dword [FxTabledA2+75h*4],FxOpd75A2 + mov dword [FxTabledA2+76h*4],FxOpd76A2 + mov dword [FxTabledA2+77h*4],FxOpd77A2 + mov dword [FxTabledA2+78h*4],FxOpd78A2 + mov dword [FxTabledA2+79h*4],FxOpd79A2 + mov dword [FxTabledA2+7Ah*4],FxOpd7AA2 + mov dword [FxTabledA2+7Bh*4],FxOpd7BA2 + mov dword [FxTabledA2+7Ch*4],FxOpd7CA2 + mov dword [FxTabledA2+7Dh*4],FxOpd7DA2 + mov dword [FxTabledA2+7Eh*4],FxOpd7EA2 + mov dword [FxTabledA2+7Fh*4],FxOpd7FA2 + + mov dword [FxTabledA2+80h*4],FxOpd80A2 + mov dword [FxTabledA2+81h*4],FxOpd81A2 + mov dword [FxTabledA2+82h*4],FxOpd82A2 + mov dword [FxTabledA2+83h*4],FxOpd83A2 + mov dword [FxTabledA2+84h*4],FxOpd84A2 + mov dword [FxTabledA2+85h*4],FxOpd85A2 + mov dword [FxTabledA2+86h*4],FxOpd86A2 + mov dword [FxTabledA2+87h*4],FxOpd87A2 + mov dword [FxTabledA2+88h*4],FxOpd88A2 + mov dword [FxTabledA2+89h*4],FxOpd89A2 + mov dword [FxTabledA2+8Ah*4],FxOpd8AA2 + mov dword [FxTabledA2+8Bh*4],FxOpd8BA2 + mov dword [FxTabledA2+8Ch*4],FxOpd8CA2 + mov dword [FxTabledA2+8Dh*4],FxOpd8DA2 + mov dword [FxTabledA2+8Eh*4],FxOpd8EA2 + mov dword [FxTabledA2+8Fh*4],FxOpd8FA2 + + mov dword [FxTabledA2+90h*4],FxOpd90 + mov dword [FxTabledA2+91h*4],FxOpd91 + mov dword [FxTabledA2+92h*4],FxOpd92 + mov dword [FxTabledA2+93h*4],FxOpd93 + mov dword [FxTabledA2+94h*4],FxOpd94 + mov dword [FxTabledA2+95h*4],FxOpd95 + mov dword [FxTabledA2+96h*4],FxOpd96 + mov dword [FxTabledA2+97h*4],FxOpd97 + mov dword [FxTabledA2+98h*4],FxOpd98 + mov dword [FxTabledA2+99h*4],FxOpd99 + mov dword [FxTabledA2+9Ah*4],FxOpd9A + mov dword [FxTabledA2+9Bh*4],FxOpd9B + mov dword [FxTabledA2+9Ch*4],FxOpd9C + mov dword [FxTabledA2+9Dh*4],FxOpd9D + mov dword [FxTabledA2+9Eh*4],FxOpd9E + mov dword [FxTabledA2+9Fh*4],FxOpd9F + + mov dword [FxTabledA2+0A0h*4],FxOpdA0A2 + mov dword [FxTabledA2+0A1h*4],FxOpdA1A2 + mov dword [FxTabledA2+0A2h*4],FxOpdA2A2 + mov dword [FxTabledA2+0A3h*4],FxOpdA3A2 + mov dword [FxTabledA2+0A4h*4],FxOpdA4A2 + mov dword [FxTabledA2+0A5h*4],FxOpdA5A2 + mov dword [FxTabledA2+0A6h*4],FxOpdA6A2 + mov dword [FxTabledA2+0A7h*4],FxOpdA7A2 + mov dword [FxTabledA2+0A8h*4],FxOpdA8A2 + mov dword [FxTabledA2+0A9h*4],FxOpdA9A2 + mov dword [FxTabledA2+0AAh*4],FxOpdAAA2 + mov dword [FxTabledA2+0ABh*4],FxOpdABA2 + mov dword [FxTabledA2+0ACh*4],FxOpdACA2 + mov dword [FxTabledA2+0ADh*4],FxOpdADA2 + mov dword [FxTabledA2+0AEh*4],FxOpdAEA2 + mov dword [FxTabledA2+0AFh*4],FxOpdAFA2 + + mov dword [FxTabledA2+0B0h*4],FxOpdB0 + mov dword [FxTabledA2+0B1h*4],FxOpdB1 + mov dword [FxTabledA2+0B2h*4],FxOpdB2 + mov dword [FxTabledA2+0B3h*4],FxOpdB3 + mov dword [FxTabledA2+0B4h*4],FxOpdB4 + mov dword [FxTabledA2+0B5h*4],FxOpdB5 + mov dword [FxTabledA2+0B6h*4],FxOpdB6 + mov dword [FxTabledA2+0B7h*4],FxOpdB7 + mov dword [FxTabledA2+0B8h*4],FxOpdB8 + mov dword [FxTabledA2+0B9h*4],FxOpdB9 + mov dword [FxTabledA2+0BAh*4],FxOpdBA + mov dword [FxTabledA2+0BBh*4],FxOpdBB + mov dword [FxTabledA2+0BCh*4],FxOpdBC + mov dword [FxTabledA2+0BDh*4],FxOpdBD + mov dword [FxTabledA2+0BEh*4],FxOpdBE + mov dword [FxTabledA2+0BFh*4],FxOpdBF + + mov dword [FxTabledA2+0C0h*4],FxOpdC0 + mov dword [FxTabledA2+0C1h*4],FxOpdC1A2 + mov dword [FxTabledA2+0C2h*4],FxOpdC2A2 + mov dword [FxTabledA2+0C3h*4],FxOpdC3A2 + mov dword [FxTabledA2+0C4h*4],FxOpdC4A2 + mov dword [FxTabledA2+0C5h*4],FxOpdC5A2 + mov dword [FxTabledA2+0C6h*4],FxOpdC6A2 + mov dword [FxTabledA2+0C7h*4],FxOpdC7A2 + mov dword [FxTabledA2+0C8h*4],FxOpdC8A2 + mov dword [FxTabledA2+0C9h*4],FxOpdC9A2 + mov dword [FxTabledA2+0CAh*4],FxOpdCAA2 + mov dword [FxTabledA2+0CBh*4],FxOpdCBA2 + mov dword [FxTabledA2+0CCh*4],FxOpdCCA2 + mov dword [FxTabledA2+0CDh*4],FxOpdCDA2 + mov dword [FxTabledA2+0CEh*4],FxOpdCEA2 + mov dword [FxTabledA2+0CFh*4],FxOpdCFA2 + + mov dword [FxTabledA2+0D0h*4],FxOpdD0 + mov dword [FxTabledA2+0D1h*4],FxOpdD1 + mov dword [FxTabledA2+0D2h*4],FxOpdD2 + mov dword [FxTabledA2+0D3h*4],FxOpdD3 + mov dword [FxTabledA2+0D4h*4],FxOpdD4 + mov dword [FxTabledA2+0D5h*4],FxOpdD5 + mov dword [FxTabledA2+0D6h*4],FxOpdD6 + mov dword [FxTabledA2+0D7h*4],FxOpdD7 + mov dword [FxTabledA2+0D8h*4],FxOpdD8 + mov dword [FxTabledA2+0D9h*4],FxOpdD9 + mov dword [FxTabledA2+0DAh*4],FxOpdDA + mov dword [FxTabledA2+0DBh*4],FxOpdDB + mov dword [FxTabledA2+0DCh*4],FxOpdDC + mov dword [FxTabledA2+0DDh*4],FxOpdDD + mov dword [FxTabledA2+0DEh*4],FxOpdDE + mov dword [FxTabledA2+0DFh*4],FxOpdDFA2 + + mov dword [FxTabledA2+0E0h*4],FxOpdE0 + mov dword [FxTabledA2+0E1h*4],FxOpdE1 + mov dword [FxTabledA2+0E2h*4],FxOpdE2 + mov dword [FxTabledA2+0E3h*4],FxOpdE3 + mov dword [FxTabledA2+0E4h*4],FxOpdE4 + mov dword [FxTabledA2+0E5h*4],FxOpdE5 + mov dword [FxTabledA2+0E6h*4],FxOpdE6 + mov dword [FxTabledA2+0E7h*4],FxOpdE7 + mov dword [FxTabledA2+0E8h*4],FxOpdE8 + mov dword [FxTabledA2+0E9h*4],FxOpdE9 + mov dword [FxTabledA2+0EAh*4],FxOpdEA + mov dword [FxTabledA2+0EBh*4],FxOpdEB + mov dword [FxTabledA2+0ECh*4],FxOpdEC + mov dword [FxTabledA2+0EDh*4],FxOpdED + mov dword [FxTabledA2+0EEh*4],FxOpdEE + mov dword [FxTabledA2+0EFh*4],FxOpdEFA2 + + mov dword [FxTabledA2+0F0h*4],FxOpdF0A2 + mov dword [FxTabledA2+0F1h*4],FxOpdF1A2 + mov dword [FxTabledA2+0F2h*4],FxOpdF2A2 + mov dword [FxTabledA2+0F3h*4],FxOpdF3A2 + mov dword [FxTabledA2+0F4h*4],FxOpdF4A2 + mov dword [FxTabledA2+0F5h*4],FxOpdF5A2 + mov dword [FxTabledA2+0F6h*4],FxOpdF6A2 + mov dword [FxTabledA2+0F7h*4],FxOpdF7A2 + mov dword [FxTabledA2+0F8h*4],FxOpdF8A2 + mov dword [FxTabledA2+0F9h*4],FxOpdF9A2 + mov dword [FxTabledA2+0FAh*4],FxOpdFAA2 + mov dword [FxTabledA2+0FBh*4],FxOpdFBA2 + mov dword [FxTabledA2+0FCh*4],FxOpdFCA2 + mov dword [FxTabledA2+0FDh*4],FxOpdFDA2 + mov dword [FxTabledA2+0FEh*4],FxOpdFEA2 + mov dword [FxTabledA2+0FFh*4],FxOpdFFA2 + + mov dword [FxTabledA3+00h*4],FxOpd00 + mov dword [FxTabledA3+01h*4],FxOpd01 + mov dword [FxTabledA3+02h*4],FxOpd02 + mov dword [FxTabledA3+03h*4],FxOpd03 + mov dword [FxTabledA3+04h*4],FxOpd04 + mov dword [FxTabledA3+05h*4],FxOpd05 + mov dword [FxTabledA3+06h*4],FxOpd06 + mov dword [FxTabledA3+07h*4],FxOpd07 + mov dword [FxTabledA3+08h*4],FxOpd08 + mov dword [FxTabledA3+09h*4],FxOpd09 + mov dword [FxTabledA3+0Ah*4],FxOpd0A + mov dword [FxTabledA3+0Bh*4],FxOpd0B + mov dword [FxTabledA3+0Ch*4],FxOpd0C + mov dword [FxTabledA3+0Dh*4],FxOpd0D + mov dword [FxTabledA3+0Eh*4],FxOpd0E + mov dword [FxTabledA3+0Fh*4],FxOpd0F + + mov dword [FxTabledA3+10h*4],FxOpd10 + mov dword [FxTabledA3+11h*4],FxOpd11 + mov dword [FxTabledA3+12h*4],FxOpd12 + mov dword [FxTabledA3+13h*4],FxOpd13 + mov dword [FxTabledA3+14h*4],FxOpd14 + mov dword [FxTabledA3+15h*4],FxOpd15 + mov dword [FxTabledA3+16h*4],FxOpd16 + mov dword [FxTabledA3+17h*4],FxOpd17 + mov dword [FxTabledA3+18h*4],FxOpd18 + mov dword [FxTabledA3+19h*4],FxOpd19 + mov dword [FxTabledA3+1Ah*4],FxOpd1A + mov dword [FxTabledA3+1Bh*4],FxOpd1B + mov dword [FxTabledA3+1Ch*4],FxOpd1C + mov dword [FxTabledA3+1Dh*4],FxOpd1D + mov dword [FxTabledA3+1Eh*4],FxOpd1E + mov dword [FxTabledA3+1Fh*4],FxOpd1F + + mov dword [FxTabledA3+20h*4],FxOpd20 + mov dword [FxTabledA3+21h*4],FxOpd21 + mov dword [FxTabledA3+22h*4],FxOpd22 + mov dword [FxTabledA3+23h*4],FxOpd23 + mov dword [FxTabledA3+24h*4],FxOpd24 + mov dword [FxTabledA3+25h*4],FxOpd25 + mov dword [FxTabledA3+26h*4],FxOpd26 + mov dword [FxTabledA3+27h*4],FxOpd27 + mov dword [FxTabledA3+28h*4],FxOpd28 + mov dword [FxTabledA3+29h*4],FxOpd29 + mov dword [FxTabledA3+2Ah*4],FxOpd2A + mov dword [FxTabledA3+2Bh*4],FxOpd2B + mov dword [FxTabledA3+2Ch*4],FxOpd2C + mov dword [FxTabledA3+2Dh*4],FxOpd2D + mov dword [FxTabledA3+2Eh*4],FxOpd2E + mov dword [FxTabledA3+2Fh*4],FxOpd2F + + mov dword [FxTabledA3+30h*4],FxOpd30 + mov dword [FxTabledA3+31h*4],FxOpd31 + mov dword [FxTabledA3+32h*4],FxOpd32 + mov dword [FxTabledA3+33h*4],FxOpd33 + mov dword [FxTabledA3+34h*4],FxOpd34 + mov dword [FxTabledA3+35h*4],FxOpd35 + mov dword [FxTabledA3+36h*4],FxOpd36 + mov dword [FxTabledA3+37h*4],FxOpd37 + mov dword [FxTabledA3+38h*4],FxOpd38 + mov dword [FxTabledA3+39h*4],FxOpd39 + mov dword [FxTabledA3+3Ah*4],FxOpd3A + mov dword [FxTabledA3+3Bh*4],FxOpd3B + mov dword [FxTabledA3+3Ch*4],FxOpd3C + mov dword [FxTabledA3+3Dh*4],FxOpd3D + mov dword [FxTabledA3+3Eh*4],FxOpd3E + mov dword [FxTabledA3+3Fh*4],FxOpd3F + + mov dword [FxTabledA3+40h*4],FxOpd40 + mov dword [FxTabledA3+41h*4],FxOpd41 + mov dword [FxTabledA3+42h*4],FxOpd42 + mov dword [FxTabledA3+43h*4],FxOpd43 + mov dword [FxTabledA3+44h*4],FxOpd44 + mov dword [FxTabledA3+45h*4],FxOpd45 + mov dword [FxTabledA3+46h*4],FxOpd46 + mov dword [FxTabledA3+47h*4],FxOpd47 + mov dword [FxTabledA3+48h*4],FxOpd48 + mov dword [FxTabledA3+49h*4],FxOpd49 + mov dword [FxTabledA3+4Ah*4],FxOpd4A + mov dword [FxTabledA3+4Bh*4],FxOpd4B + mov dword [FxTabledA3+4Ch*4],FxOpd4C + mov dword [FxTabledA3+4Dh*4],FxOpd4D + mov dword [FxTabledA3+4Eh*4],FxOpd4E + mov dword [FxTabledA3+4Fh*4],FxOpd4F + + mov dword [FxTabledA3+50h*4],FxOpd50A3 + mov dword [FxTabledA3+51h*4],FxOpd51A3 + mov dword [FxTabledA3+52h*4],FxOpd52A3 + mov dword [FxTabledA3+53h*4],FxOpd53A3 + mov dword [FxTabledA3+54h*4],FxOpd54A3 + mov dword [FxTabledA3+55h*4],FxOpd55A3 + mov dword [FxTabledA3+56h*4],FxOpd56A3 + mov dword [FxTabledA3+57h*4],FxOpd57A3 + mov dword [FxTabledA3+58h*4],FxOpd58A3 + mov dword [FxTabledA3+59h*4],FxOpd59A3 + mov dword [FxTabledA3+5Ah*4],FxOpd5AA3 + mov dword [FxTabledA3+5Bh*4],FxOpd5BA3 + mov dword [FxTabledA3+5Ch*4],FxOpd5CA3 + mov dword [FxTabledA3+5Dh*4],FxOpd5DA3 + mov dword [FxTabledA3+5Eh*4],FxOpd5EA3 + mov dword [FxTabledA3+5Fh*4],FxOpd5FA3 + + mov dword [FxTabledA3+60h*4],FxOpd60A3 + mov dword [FxTabledA3+61h*4],FxOpd61A3 + mov dword [FxTabledA3+62h*4],FxOpd62A3 + mov dword [FxTabledA3+63h*4],FxOpd63A3 + mov dword [FxTabledA3+64h*4],FxOpd64A3 + mov dword [FxTabledA3+65h*4],FxOpd65A3 + mov dword [FxTabledA3+66h*4],FxOpd66A3 + mov dword [FxTabledA3+67h*4],FxOpd67A3 + mov dword [FxTabledA3+68h*4],FxOpd68A3 + mov dword [FxTabledA3+69h*4],FxOpd69A3 + mov dword [FxTabledA3+6Ah*4],FxOpd6AA3 + mov dword [FxTabledA3+6Bh*4],FxOpd6BA3 + mov dword [FxTabledA3+6Ch*4],FxOpd6CA3 + mov dword [FxTabledA3+6Dh*4],FxOpd6DA3 + mov dword [FxTabledA3+6Eh*4],FxOpd6EA3 + mov dword [FxTabledA3+6Fh*4],FxOpd6FA3 + + mov dword [FxTabledA3+70h*4],FxOpd70 + mov dword [FxTabledA3+71h*4],FxOpd71A3 + mov dword [FxTabledA3+72h*4],FxOpd72A3 + mov dword [FxTabledA3+73h*4],FxOpd73A3 + mov dword [FxTabledA3+74h*4],FxOpd74A3 + mov dword [FxTabledA3+75h*4],FxOpd75A3 + mov dword [FxTabledA3+76h*4],FxOpd76A3 + mov dword [FxTabledA3+77h*4],FxOpd77A3 + mov dword [FxTabledA3+78h*4],FxOpd78A3 + mov dword [FxTabledA3+79h*4],FxOpd79A3 + mov dword [FxTabledA3+7Ah*4],FxOpd7AA3 + mov dword [FxTabledA3+7Bh*4],FxOpd7BA3 + mov dword [FxTabledA3+7Ch*4],FxOpd7CA3 + mov dword [FxTabledA3+7Dh*4],FxOpd7DA3 + mov dword [FxTabledA3+7Eh*4],FxOpd7EA3 + mov dword [FxTabledA3+7Fh*4],FxOpd7FA3 + + mov dword [FxTabledA3+80h*4],FxOpd80A3 + mov dword [FxTabledA3+81h*4],FxOpd81A3 + mov dword [FxTabledA3+82h*4],FxOpd82A3 + mov dword [FxTabledA3+83h*4],FxOpd83A3 + mov dword [FxTabledA3+84h*4],FxOpd84A3 + mov dword [FxTabledA3+85h*4],FxOpd85A3 + mov dword [FxTabledA3+86h*4],FxOpd86A3 + mov dword [FxTabledA3+87h*4],FxOpd87A3 + mov dword [FxTabledA3+88h*4],FxOpd88A3 + mov dword [FxTabledA3+89h*4],FxOpd89A3 + mov dword [FxTabledA3+8Ah*4],FxOpd8AA3 + mov dword [FxTabledA3+8Bh*4],FxOpd8BA3 + mov dword [FxTabledA3+8Ch*4],FxOpd8CA3 + mov dword [FxTabledA3+8Dh*4],FxOpd8DA3 + mov dword [FxTabledA3+8Eh*4],FxOpd8EA3 + mov dword [FxTabledA3+8Fh*4],FxOpd8FA3 + + mov dword [FxTabledA3+90h*4],FxOpd90 + mov dword [FxTabledA3+91h*4],FxOpd91 + mov dword [FxTabledA3+92h*4],FxOpd92 + mov dword [FxTabledA3+93h*4],FxOpd93 + mov dword [FxTabledA3+94h*4],FxOpd94 + mov dword [FxTabledA3+95h*4],FxOpd95 + mov dword [FxTabledA3+96h*4],FxOpd96 + mov dword [FxTabledA3+97h*4],FxOpd97 + mov dword [FxTabledA3+98h*4],FxOpd98 + mov dword [FxTabledA3+99h*4],FxOpd99 + mov dword [FxTabledA3+9Ah*4],FxOpd9A + mov dword [FxTabledA3+9Bh*4],FxOpd9B + mov dword [FxTabledA3+9Ch*4],FxOpd9C + mov dword [FxTabledA3+9Dh*4],FxOpd9D + mov dword [FxTabledA3+9Eh*4],FxOpd9E + mov dword [FxTabledA3+9Fh*4],FxOpd9F + + mov dword [FxTabledA3+0A0h*4],FxOpdA0 + mov dword [FxTabledA3+0A1h*4],FxOpdA1 + mov dword [FxTabledA3+0A2h*4],FxOpdA2 + mov dword [FxTabledA3+0A3h*4],FxOpdA3 + mov dword [FxTabledA3+0A4h*4],FxOpdA4 + mov dword [FxTabledA3+0A5h*4],FxOpdA5 + mov dword [FxTabledA3+0A6h*4],FxOpdA6 + mov dword [FxTabledA3+0A7h*4],FxOpdA7 + mov dword [FxTabledA3+0A8h*4],FxOpdA8 + mov dword [FxTabledA3+0A9h*4],FxOpdA9 + mov dword [FxTabledA3+0AAh*4],FxOpdAA + mov dword [FxTabledA3+0ABh*4],FxOpdAB + mov dword [FxTabledA3+0ACh*4],FxOpdAC + mov dword [FxTabledA3+0ADh*4],FxOpdAD + mov dword [FxTabledA3+0AEh*4],FxOpdAE + mov dword [FxTabledA3+0AFh*4],FxOpdAF + + mov dword [FxTabledA3+0B0h*4],FxOpdB0 + mov dword [FxTabledA3+0B1h*4],FxOpdB1 + mov dword [FxTabledA3+0B2h*4],FxOpdB2 + mov dword [FxTabledA3+0B3h*4],FxOpdB3 + mov dword [FxTabledA3+0B4h*4],FxOpdB4 + mov dword [FxTabledA3+0B5h*4],FxOpdB5 + mov dword [FxTabledA3+0B6h*4],FxOpdB6 + mov dword [FxTabledA3+0B7h*4],FxOpdB7 + mov dword [FxTabledA3+0B8h*4],FxOpdB8 + mov dword [FxTabledA3+0B9h*4],FxOpdB9 + mov dword [FxTabledA3+0BAh*4],FxOpdBA + mov dword [FxTabledA3+0BBh*4],FxOpdBB + mov dword [FxTabledA3+0BCh*4],FxOpdBC + mov dword [FxTabledA3+0BDh*4],FxOpdBD + mov dword [FxTabledA3+0BEh*4],FxOpdBE + mov dword [FxTabledA3+0BFh*4],FxOpdBF + + mov dword [FxTabledA3+0C0h*4],FxOpdC0 + mov dword [FxTabledA3+0C1h*4],FxOpdC1A3 + mov dword [FxTabledA3+0C2h*4],FxOpdC2A3 + mov dword [FxTabledA3+0C3h*4],FxOpdC3A3 + mov dword [FxTabledA3+0C4h*4],FxOpdC4A3 + mov dword [FxTabledA3+0C5h*4],FxOpdC5A3 + mov dword [FxTabledA3+0C6h*4],FxOpdC6A3 + mov dword [FxTabledA3+0C7h*4],FxOpdC7A3 + mov dword [FxTabledA3+0C8h*4],FxOpdC8A3 + mov dword [FxTabledA3+0C9h*4],FxOpdC9A3 + mov dword [FxTabledA3+0CAh*4],FxOpdCAA3 + mov dword [FxTabledA3+0CBh*4],FxOpdCBA3 + mov dword [FxTabledA3+0CCh*4],FxOpdCCA3 + mov dword [FxTabledA3+0CDh*4],FxOpdCDA3 + mov dword [FxTabledA3+0CEh*4],FxOpdCEA3 + mov dword [FxTabledA3+0CFh*4],FxOpdCFA3 + + mov dword [FxTabledA3+0D0h*4],FxOpdD0 + mov dword [FxTabledA3+0D1h*4],FxOpdD1 + mov dword [FxTabledA3+0D2h*4],FxOpdD2 + mov dword [FxTabledA3+0D3h*4],FxOpdD3 + mov dword [FxTabledA3+0D4h*4],FxOpdD4 + mov dword [FxTabledA3+0D5h*4],FxOpdD5 + mov dword [FxTabledA3+0D6h*4],FxOpdD6 + mov dword [FxTabledA3+0D7h*4],FxOpdD7 + mov dword [FxTabledA3+0D8h*4],FxOpdD8 + mov dword [FxTabledA3+0D9h*4],FxOpdD9 + mov dword [FxTabledA3+0DAh*4],FxOpdDA + mov dword [FxTabledA3+0DBh*4],FxOpdDB + mov dword [FxTabledA3+0DCh*4],FxOpdDC + mov dword [FxTabledA3+0DDh*4],FxOpdDD + mov dword [FxTabledA3+0DEh*4],FxOpdDE + mov dword [FxTabledA3+0DFh*4],FxOpdDFA3 + + mov dword [FxTabledA3+0E0h*4],FxOpdE0 + mov dword [FxTabledA3+0E1h*4],FxOpdE1 + mov dword [FxTabledA3+0E2h*4],FxOpdE2 + mov dword [FxTabledA3+0E3h*4],FxOpdE3 + mov dword [FxTabledA3+0E4h*4],FxOpdE4 + mov dword [FxTabledA3+0E5h*4],FxOpdE5 + mov dword [FxTabledA3+0E6h*4],FxOpdE6 + mov dword [FxTabledA3+0E7h*4],FxOpdE7 + mov dword [FxTabledA3+0E8h*4],FxOpdE8 + mov dword [FxTabledA3+0E9h*4],FxOpdE9 + mov dword [FxTabledA3+0EAh*4],FxOpdEA + mov dword [FxTabledA3+0EBh*4],FxOpdEB + mov dword [FxTabledA3+0ECh*4],FxOpdEC + mov dword [FxTabledA3+0EDh*4],FxOpdED + mov dword [FxTabledA3+0EEh*4],FxOpdEE + mov dword [FxTabledA3+0EFh*4],FxOpdEFA3 + + mov dword [FxTabledA3+0F0h*4],FxOpdF0 + mov dword [FxTabledA3+0F1h*4],FxOpdF1 + mov dword [FxTabledA3+0F2h*4],FxOpdF2 + mov dword [FxTabledA3+0F3h*4],FxOpdF3 + mov dword [FxTabledA3+0F4h*4],FxOpdF4 + mov dword [FxTabledA3+0F5h*4],FxOpdF5 + mov dword [FxTabledA3+0F6h*4],FxOpdF6 + mov dword [FxTabledA3+0F7h*4],FxOpdF7 + mov dword [FxTabledA3+0F8h*4],FxOpdF8 + mov dword [FxTabledA3+0F9h*4],FxOpdF9 + mov dword [FxTabledA3+0FAh*4],FxOpdFA + mov dword [FxTabledA3+0FBh*4],FxOpdFB + mov dword [FxTabledA3+0FCh*4],FxOpdFC + mov dword [FxTabledA3+0FDh*4],FxOpdFD + mov dword [FxTabledA3+0FEh*4],FxOpdFE + mov dword [FxTabledA3+0FFh*4],FxOpdFF + ret + +; normal +NEWSYM sfxnametab + db 'STOP NOP CACHE LSR ' + db 'ROL BRA BLT BGE ' + db 'BNE BEQ BPL BMI ' + db 'BCC BCS BVC BVS ' + + db 'TO R0 TO R1 TO R2 TO R3 ' ; MOVE when B=1 + db 'TO R4 TO R5 TO R6 TO R7 ' + db 'TO R8 TO R9 TO R10 TO R11 ' + db 'TO R12 TO R13 TO R14 TO R15 ' + + db 'WITH R0 WITH R1 WITH R2 WITH R3 ' + db 'WITH R4 WITH R5 WITH R6 WITH R7 ' + db 'WITH R8 WITH R9 WITH R10WITH R11' + db 'WITH R12WITH R13WITH R14WITH R15' + + db 'STW(R0) STW(R1) STW(R2) STW(R3) ' + db 'STW(R4) STW(R5) STW(R6) STW(R7) ' + db 'STW(R8) STW(R9) STW(R10)STW(R11)' + db 'LOOP ALT1 ALT2 ALT3 ' + + db 'LDW(R0) LDW(R1) LDW(R2) LDW(R3) ' + db 'LDW(R4) LDW(R5) LDW(R6) LDW(R7) ' + db 'LDW(R8) LDW(R9) LDW(R10)LDW(R11)' + db 'PLOT SWAP COLOR NOT ' + + db 'ADD R0 ADD R1 ADD R2 ADD R3 ' + db 'ADD R4 ADD R5 ADD R6 ADD R7 ' + db 'ADD R8 ADD R9 ADD R10 ADD R11 ' + db 'ADD R12 ADD R13 ADD R14 ADD R15 ' + + db 'SUB R0 SUB R1 SUB R2 SUB R3 ' + db 'SUB R4 SUB R5 SUB R6 SUB R7 ' + db 'SUB R8 SUB R9 SUB R10 SUB R11 ' + db 'SUB R12 SUB R13 SUB R14 SUB R15 ' + + db 'MERGE AND R1 AND R2 AND R3 ' + db 'AND R4 AND R5 AND R6 AND R7 ' + db 'AND R8 AND R9 AND R10 AND R11 ' + db 'AND R12 AND R13 AND R14 AND R15 ' + + db 'MULT R0 MULT R1 MULT R2 MULT R3 ' + db 'MULT R4 MULT R5 MULT R6 MULT R7 ' + db 'MULT R8 MULT R9 MULT R10MULT R11' + db 'MULT R12MULT R13MULT R14MULT R15' + + db 'SBK LINK #$1LINK #$2LINK #$3' + db 'LINK #$4SEX ASR ROR ' + db 'JMP R8 JMP R9 JMP R10 JMP R11 ' + db 'JMP R12 JMP R13 LOB FMULT ' + + db 'IBT R0 IBT R1 IBT R2 IBT R3 ' + db 'IBT R4 IBT R5 IBT R6 IBT R7 ' + db 'IBT R8 IBT R9 IBT R10 IBT R11 ' + db 'IBT R12 IBT R13 IBT R14 IBT R15 ' + + db 'FROM R0 FROM R1 FROM R2 FROM R3 ' ; MOVES if B=1 + db 'FROM R4 FROM R5 FROM R6 FROM R7 ' + db 'FROM R8 FROM R9 FROM R10FROM R11' + db 'FROM R12FROM R13FROM R14FROM R15' + + db 'HIB OR R1 OR R2 OR R3 ' + db 'OR R4 OR R5 OR R6 OR R7 ' + db 'OR R8 OR R9 OR R10 OR R11 ' + db 'OR R12 OR R13 OR R14 OR R15 ' + + db 'INC R0 INC R1 INC R2 INC R3 ' + db 'INC R4 INC R5 INC R6 INC R7 ' + db 'INC R8 INC R9 INC R10 INC R11 ' + db 'INC R12 INC R13 INC R14 GETC ' + + db 'DEC R0 DEC R1 DEC R2 DEC R3 ' + db 'DEC R4 DEC R5 DEC R6 DEC R7 ' + db 'DEC R8 DEC R9 DEC R10 DEC R11 ' + db 'DEC R12 DEC R13 DEC R14 GETB ' + + db 'IWT R0 IWT R1 IWT R2 IWT R3 ' + db 'IWT R4 IWT R5 IWT R6 IWT R7 ' + db 'IWT R8 IWT R9 IWT R10 IWT R11 ' + db 'IWT R12 IWT R13 IWT R14 IWT R15 ' + +;A1 + db 'STOP NOP CACHE LSR ' + db 'ROL BRA BLT BGE ' + db 'BNE BEQ BPL BMI ' + db 'BCC BCS BVC BVS ' + + db 'TO R0 TO R1 TO R2 TO R3 ' ; MOVE when B=1 + db 'TO R4 TO R5 TO R6 TO R7 ' + db 'TO R8 TO R9 TO R10 TO R11 ' + db 'TO R12 TO R13 TO R14 TO R15 ' + + db 'WITH R0 WITH R1 WITH R2 WITH R3 ' + db 'WITH R4 WITH R5 WITH R6 WITH R7 ' + db 'WITH R8 WITH R9 WITH R10WITH R11' + db 'WITH R12WITH R13WITH R14WITH R15' + + db 'STB(R0) STB(R1) STB(R2) STB(R3) ' + db 'STB(R4) STB(R5) STB(R6) STB(R7) ' + db 'STB(R8) STB(R9) STB(R10)STB(R11)' + db 'LOOP ALT1 ALT2 ALT3 ' + + db 'LDB(R0) LDB(R1) LDB(R2) LDB(R3) ' + db 'LDB(R4) LDB(R5) LDB(R6) LDB(R7) ' + db 'LDB(R8) LDB(R9) LDB(R10)LDB(R11)' + db 'PLOT SWAP CMODE NOT ' + + db 'ADC R0 ADC R1 ADC R2 ADC R3 ' + db 'ADC R4 ADC R5 ADC R6 ADC R7 ' + db 'ADC R8 ADC R9 ADC R10 ADC R11 ' + db 'ADC R12 ADC R13 ADC R14 ADC R15 ' + + db 'SBC R0 SBC R1 SBC R2 SBC R3 ' + db 'SBC R4 SBC R5 SBC R6 SBC R7 ' + db 'SBC R8 SBC R9 SBC R10 SBC R11 ' + db 'SBC R12 SBC R13 SBC R14 SBC R15 ' + + db 'MERGE BIC R1 BIC R2 BIC R3 ' + db 'BIC R4 BIC R5 BIC R6 BIC R7 ' + db 'BIC R8 BIC R9 BIC R10 BIC R11 ' + db 'BIC R12 BIC R13 BIC R14 BIC R15 ' + + db 'UMULTR0 UMULTR1 UMULTR2 UMULTR3 ' + db 'UMULTR4 UMULTR5 UMULTR6 UMULTR7 ' + db 'UMULTR8 UMULTR9 UMULTR10UMULTR11' + db 'UMULTR12UMULTR13UMULTR14UMULTR15' + + db 'SBK LINK #$1LINK #$2LINK #$3' + db 'LINK #$4SEX DIV2 ROR ' + db 'LJMP R8 LJMP R9 LJMP R10LJMP R11' + db 'LJMP R12LJMP R13LOB LMULT ' + + db 'LMS R0 LMS R1 LMS R2 LMS R3 ' + db 'LMS R4 LMS R5 LMS R6 LMS R7 ' + db 'LMS R8 LMS R9 LMS R10 LMS R11 ' + db 'LMS R12 LMS R13 LMS R14 LMS R15 ' + + db 'FROM R0 FROM R1 FROM R2 FROM R3 ' ; MOVES if B=1 + db 'FROM R4 FROM R5 FROM R6 FROM R7 ' + db 'FROM R8 FROM R9 FROM R10FROM R11' + db 'FROM R12FROM R13FROM R14FROM R15' + + db 'HIB XOR R1 XOR R2 XOR R3 ' + db 'XOR R4 XOR R5 XOR R6 XOR R7 ' + db 'XOR R8 XOR R9 XOR R10 XOR R11 ' + db 'XOR R12 XOR R13 XOR R14 XOR R15 ' + + db 'INC R0 INC R1 INC R2 INC R3 ' + db 'INC R4 INC R5 INC R6 INC R7 ' + db 'INC R8 INC R9 INC R10 INC R11 ' + db 'INC R12 INC R13 INC R14 GETC ' + + db 'DEC R0 DEC R1 DEC R2 DEC R3 ' + db 'DEC R4 DEC R5 DEC R6 DEC R7 ' + db 'DEC R8 DEC R9 DEC R10 DEC R11 ' + db 'DEC R12 DEC R13 DEC R14 GETBH ' + + db 'LM R0 LM R1 LM R2 LM R3 ' + db 'LM R4 LM R5 LM R6 LM R7 ' + db 'LM R8 LM R9 LM R10 LM R11 ' + db 'LM R12 LM R13 LM R14 LM R15 ' +;A2 + db 'STOP NOP CACHE LSR ' + db 'ROL BRA BLT BGE ' + db 'BNE BEQ BPL BMI ' + db 'BCC BCS BVC BVS ' + + db 'TO R0 TO R1 TO R2 TO R3 ' ; MOVE when B=1 + db 'TO R4 TO R5 TO R6 TO R7 ' + db 'TO R8 TO R9 TO R10 TO R11 ' + db 'TO R12 TO R13 TO R14 TO R15 ' + + db 'WITH R0 WITH R1 WITH R2 WITH R3 ' + db 'WITH R4 WITH R5 WITH R6 WITH R7 ' + db 'WITH R8 WITH R9 WITH R10WITH R11' + db 'WITH R12WITH R13WITH R14WITH R15' + + db 'STW(R0) STW(R1) STW(R2) STW(R3) ' + db 'STW(R4) STW(R5) STW(R6) STW(R7) ' + db 'STW(R8) STW(R9) STW(R10)STW(R11)' + db 'LOOP ALT1 ALT2 ALT3 ' + + db 'LDW(R0) LDW(R1) LDW(R2) LDW(R3) ' + db 'LDW(R4) LDW(R5) LDW(R6) LDW(R7) ' + db 'LDW(R8) LDW(R9) LDW(R10)LDW(R11)' + db 'PLOT SWAP COLOR NOT ' + + db 'ADD #$0 ADD #$1 ADD #$2 ADD #$3 ' + db 'ADD #$4 ADD #$5 ADD #$6 ADD #$7 ' + db 'ADD #$8 ADD #$9 ADD #$A ADD #$B ' + db 'ADD #$C ADD #$D ADD #$E ADD #$F ' + + db 'SUB #$0 SUB #$1 SUB #$2 SUB #$3 ' + db 'SUB #$4 SUB #$5 SUB #$6 SUB #$7 ' + db 'SUB #$8 SUB #$9 SUB #$A SUB #$B ' + db 'SUB #$C SUB #$D SUB #$E SUB #$F ' + + db 'MERGE AND #$1 AND #$2 AND #$3 ' + db 'AND #$4 AND #$5 AND #$6 AND #$7 ' + db 'AND #$8 AND #$9 AND #$A AND #$B ' + db 'AND #$C AND #$D AND #$E AND #$F ' + + db 'MULTIR0 MULTIR1 MULTIR2 MULTIR3 ' + db 'MULTIR4 MULTIR5 MULTIR6 MULTIR7 ' + db 'MULTIR8 MULTIR9 MULTIR10MULTIR11' + db 'MULTIR12MULTIR13MULTIR14MULTIR15' + + db 'SBK LINK #$1LINK #$2LINK #$3' + db 'LINK #$4SEX ASR ROR ' + db 'JMP R8 JMP R9 JMP R10 JMP R11 ' + db 'JMP R12 JMP R13 LOB FMULT ' + + db 'SMS R0 SMS R1 SMS R2 SMS R3 ' + db 'SMS R4 SMS R5 SMS R6 SMS R7 ' + db 'SMS R8 SMS R9 SMS R10 SMS R11 ' + db 'SMS R12 SMS R13 SMS R14 SMS R15 ' + + db 'FROM R0 FROM R1 FROM R2 FROM R3 ' ; MOVES if B=1 + db 'FROM R4 FROM R5 FROM R6 FROM R7 ' + db 'FROM R8 FROM R9 FROM R10FROM R11' + db 'FROM R12FROM R13FROM R14FROM R15' + + db 'HIB OR #$1 OR #$2 OR #$3 ' + db 'OR #$4 OR #$5 OR #$6 OR #$7 ' + db 'OR #$8 OR #$9 OR #$A OR #$B ' + db 'OR #$C OR #$D OR #$E OR #$F ' + + db 'INC R0 INC R1 INC R2 INC R3 ' + db 'INC R4 INC R5 INC R6 INC R7 ' + db 'INC R8 INC R9 INC R10 INC R11 ' + db 'INC R12 INC R13 INC R14 RAMB ' + + db 'DEC R0 DEC R1 DEC R2 DEC R3 ' + db 'DEC R4 DEC R5 DEC R6 DEC R7 ' + db 'DEC R8 DEC R9 DEC R10 DEC R11 ' + db 'DEC R12 DEC R13 DEC R14 GETBL ' + + db 'SM R0 SM R1 SM R2 SM R3 ' + db 'SM R4 SM R5 SM R6 SM R7 ' + db 'SM R8 SM R9 SM R10 SM R11 ' + db 'SM R12 SM R13 SM R14 SM R15 ' +;A3 + db 'STOP NOP CACHE LSR ' + db 'ROL BRA BLT BGE ' + db 'BNE BEQ BPL BMI ' + db 'BCC BCS BVC BVS ' + + db 'TO R0 TO R1 TO R2 TO R3 ' ; MOVE when B=1 + db 'TO R4 TO R5 TO R6 TO R7 ' + db 'TO R8 TO R9 TO R10 TO R11 ' + db 'TO R12 TO R13 TO R14 TO R15 ' + + db 'WITH R0 WITH R1 WITH R2 WITH R3 ' + db 'WITH R4 WITH R5 WITH R6 WITH R7 ' + db 'WITH R8 WITH R9 WITH R10WITH R11' + db 'WITH R12WITH R13WITH R14WITH R15' + + db 'STW(R0) STW(R1) STW(R2) STW(R3) ' + db 'STW(R4) STW(R5) STW(R6) STW(R7) ' + db 'STW(R8) STW(R9) STW(R10)STW(R11)' + db 'LOOP ALT1 ALT2 ALT3 ' + + db 'LDW(R0) LDW(R1) LDW(R2) LDW(R3) ' + db 'LDW(R4) LDW(R5) LDW(R6) LDW(R7) ' + db 'LDW(R8) LDW(R9) LDW(R10)LDW(R11)' + db 'PLOT SWAP COLOR NOT ' + + db 'ADC #$0 ADC #$1 ADC #$2 ADC #$3 ' + db 'ADC #$4 ADC #$5 ADC #$6 ADC #$7 ' + db 'ADC #$8 ADC #$9 ADC #$A ADC #$B ' + db 'ADC #$C ADC #$D ADC #$E ADC #$F ' + + db 'CMP R0 CMP R1 CMP R2 CMP R3 ' + db 'CMP R4 CMP R5 CMP R6 CMP R7 ' + db 'CMP R8 CMP R9 CMP R10 CMP R11 ' + db 'CMP R12 CMP R13 CMP R14 CMP R15 ' + + db 'MERGE BIC #$1 BIC #$2 BIC #$3 ' + db 'BIC #$4 BIC #$5 BIC #$6 BIC #$7 ' + db 'BIC #$8 BIC #$9 BIC #$A BIC #$B ' + db 'BIC #$C BIC #$D BIC #$E BIC #$F ' + + db 'UMULIR0 UMULIR1 UMULIR2 UMULIR3 ' + db 'UMULIR4 UMULIR5 UMULIR6 UMULIR7 ' + db 'UMULIR8 UMULIR9 UMULIR10UMULIR11' + db 'UMULIR12UMULIR13UMULIR14UMULIR15' + + db 'SBK LINK #$1LINK #$2LINK #$3' + db 'LINK #$4SEX ASR ROR ' + db 'JMP R8 JMP R9 JMP R10 JMP R11 ' + db 'JMP R12 JMP R13 LOB FMULT ' + + db 'IBT R0 IBT R1 IBT R2 IBT R3 ' + db 'IBT R4 IBT R5 IBT R6 IBT R7 ' + db 'IBT R8 IBT R9 IBT R10 IBT R11 ' + db 'IBT R12 IBT R13 IBT R14 IBT R15 ' + + db 'FROM R0 FROM R1 FROM R2 FROM R3 ' ; MOVES if B=1 + db 'FROM R4 FROM R5 FROM R6 FROM R7 ' + db 'FROM R8 FROM R9 FROM R10FROM R11' + db 'FROM R12FROM R13FROM R14FROM R15' + + db 'HIB XOR #$1 XOR #$2 XOR #$3 ' + db 'XOR #$4 XOR #$5 XOR #$6 XOR #$7 ' + db 'XOR #$8 XOR #$9 XOR #$A XOR #$B ' + db 'XOR #$C XOR #$D XOR #$E XOR #$F ' + + db 'INC R0 INC R1 INC R2 INC R3 ' + db 'INC R4 INC R5 INC R6 INC R7 ' + db 'INC R8 INC R9 INC R10 INC R11 ' + db 'INC R12 INC R13 INC R14 ROMB ' + + db 'DEC R0 DEC R1 DEC R2 DEC R3 ' + db 'DEC R4 DEC R5 DEC R6 DEC R7 ' + db 'DEC R8 DEC R9 DEC R10 DEC R11 ' + db 'DEC R12 DEC R13 DEC R14 GETBS ' + + db 'IWT R0 IWT R1 IWT R2 IWT R3 ' + db 'IWT R4 IWT R5 IWT R6 IWT R7 ' + db 'IWT R8 IWT R9 IWT R10 IWT R11 ' + db 'IWT R12 IWT R13 IWT R14 IWT R15 ' + + \ No newline at end of file diff --git a/zsnes/src/chips/sa1proc.asm b/zsnes/src/chips/sa1proc.asm new file mode 100644 index 00000000..6c55d6f2 --- /dev/null +++ b/zsnes/src/chips/sa1proc.asm @@ -0,0 +1,365 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM xa,xx,xy,xd,xdb,xpb,xs,xe,initaddrl,UpdateDPage,wramdata,IRAM,cycpbl,SA1DoIRQ +EXTSYM spcnumread,SA1IRQEn,nextopcodesa1,debugds +EXTSYM SNSRegP,SNSRegE,SNSRegPCS,SA1Ptr,SNSPtr,nmiv,irqv,nmiv2,irqv2,snesmap2,SA1tablead +EXTSYM SA1xpb,SA1RegP,wramdataa,SA1TimerVal,debuggeron +EXTSYM SA1RegE,SA1RegPCS,SA1BWPtr,SNSBWPtr,CurBWPtr,SA1NMIV,SA1IRQV,debstop,tablead +EXTSYM membank0w8,romdata,SA1LBound,SA1UBound,SA1SH,SA1SHb +EXTSYM stackor,stackand,snesmmap,SA1xs,SA1IRQExec +EXTSYM SA1Message,Sflagnz,Sflagc,Sflago + + + + + + +; In exec loop, jump to execloop if SA1Status != 0 +; *** Disable spc700 if possible *** + + + +NEWSYM SA1Status, db 0 ; 0 = 65816, 1 = SA1A, 2 = SA1B + +NEWSYM CurrentExecSA1, db 0 +NEWSYM CurrentCPU, db 0 + +ALIGN32 +NEWSYM prevedi, dd 0 + +%macro SA1Debugb 0 + pushad + sub esi,[initaddrl] + mov [SA1xpc],esi + call nextopcodesa1 + popad + mov bl,[esi] + xor dh,dh + inc esi + call dword near [edi+ebx*4] + dec esi +%endmacro + +%macro SA1Debug 0 + ; debug version + test byte[debugds],01h + jz near .nodebug + cmp byte[debuggeron],0 + je near .nodebug + SA1Debugb + SA1Debugb + SA1Debugb + SA1Debugb + SA1Debugb + SA1Debugb + SA1Debugb + SA1Debugb + jmp .debug +.nodebug +%endmacro + + +NEWSYM SA1Swap + mov ecx,[SA1BWPtr] + mov eax,[SA1Ptr] ; small speed hack + test byte[SA1DoIRQ],1 + jnz near .sa1exec3 + cmp byte[IRAM],0 + jne .sa1exec2 + cmp dword[eax],0FCF000A5h + je near .nosa1exec + cmp dword[eax-2],0FCF000A5h + je near .nosa1exec +.sa1exec2 + cmp byte[SA1SHb],1 + je near .nosa1execb + + cmp word[ecx+72A4h],0 + jnz .sa1exec + cmp dword[eax],0F072A4ADh + je near .nosa1execb +.sa1exec + cmp byte[IRAM+72h],0 + jne .sa1exec3 + cmp dword[eax],0F03072ADh + je near .nosa1execb +.sa1exec3 +.yesdebugr + xor ecx,ecx + ; store all snes 65816 stuff + mov [SNSRegP],dl + mov eax,[initaddrl] + mov [prevedi],edi + mov [SNSRegPCS],eax + mov [SNSPtr],esi + ; restore all sa1 65816 stuff + mov dl,[SA1RegP] + mov eax,[SA1RegPCS] + mov [initaddrl],eax + mov eax,[SA1BWPtr] + mov [CurBWPtr],eax + mov esi,[SA1Ptr] + mov dword[snesmap2],IRAM + mov dword[wramdata],IRAM + ; Check if IRQ is executed on SA-1 + xor eax,eax + mov al,dl + add dh,25 + mov edi,[SA1tablead+eax*4] + mov byte[SA1Status],1 + test dword[SA1DoIRQ],0FF000003h + jnz near .switchirq +.returnirq + +; SA1Debug + + cmp byte[SA1SH],1 + je near .speedhack + + ; non debug version + mov bl,[esi] + inc esi + call dword near [edi+ebx*4] + dec esi +.debug + + ; store all sa1 65816 stuff + mov [SA1RegP],dl + mov eax,[initaddrl] + mov [SA1RegPCS],eax + mov [SA1Ptr],esi + ; restore all snes 65816 stuff + mov dl,[SNSRegP] + mov eax,[SNSRegPCS] + mov [initaddrl],eax + mov eax,[SNSBWPtr] + mov [CurBWPtr],eax + mov dword[wramdata],wramdataa + mov esi,[SNSPtr] + mov eax,[wramdata] + mov dword[snesmap2],eax + mov edi,[prevedi] + xor eax,eax + add dh,11 + inc byte[CurrentExecSA1] + mov byte[SA1Status],0 + add dword[SA1TimerVal],23 + ret + +.speedhack + add dh,100 + + mov bl,[esi] + inc esi + call dword near [edi+ebx*4] + dec esi + ; store all sa1 65816 stuff + mov [SA1RegP],dl + mov eax,[initaddrl] + mov [SA1RegPCS],eax + mov [SA1Ptr],esi + ; restore all snes 65816 stuff + mov dl,[SNSRegP] + mov eax,[SNSRegPCS] + mov [initaddrl],eax + mov eax,[SNSBWPtr] + mov [CurBWPtr],eax + mov dword[wramdata],wramdataa + mov esi,[SNSPtr] + mov eax,[wramdata] + mov dword[snesmap2],eax + mov edi,[prevedi] + xor eax,eax + add byte[CurrentExecSA1],4 + mov byte[SA1Status],0 + add dword[SA1TimerVal],23 +; xor dh,dh + mov dh,18 + cmp esi,dword[SA1LBound] + jb .stoph + cmp esi,dword[SA1UBound] + ja .stoph + ret +.stoph + mov byte[SA1SH],0 + ret +.nosa1execb + xor ecx,ecx + add dh,15 + add byte[CurrentExecSA1],2 + mov byte[SA1Status],0 + ret +.nosa1exec + xor ecx,ecx + add dh,22 + add byte[CurrentExecSA1],2 + mov byte[SA1Status],0 + ret +.switchirq + test dword[SA1DoIRQ],3 + jz .notirq + test dword[SA1DoIRQ],1 + jz .nmi + and byte[SA1DoIRQ],0FEh + call SA1switchtovirq + jmp .returnirq +.nmi + and byte[SA1DoIRQ],0FDh + call SA1switchtonmi + jmp .returnirq +.notirq + dec byte[SA1DoIRQ+3] + jz .hack + jmp .returnirq +.hack + or byte[SA1DoIRQ],8 + jmp .returnirq + +NEWSYM SA1xpc, dd 0 + +%macro makedl 0 + and dl,00111100b + test dword[Sflagnz],18000h + jz %%noneg + or dl,80h +%%noneg + test dword[Sflagnz],0FFFFh + jnz %%nozero + or dl,02h +%%nozero + test dword[Sflagc],0FFh + jz %%nocarry + or dl,01h +%%nocarry + test dword[Sflago],0FFh + jz %%nov + or dl,40h +%%nov +%endmacro + +NEWSYM SA1switchtonmi + mov al,byte[SA1Message] + mov byte[SA1Message+2],al + mov byte[SA1IRQExec+2],1 + mov ebx,esi + sub ebx,[initaddrl] + mov [SA1xpc],bx + + xor ecx,ecx + mov cx,[SA1xs] + mov al,[SA1xpb] + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + mov al,[SA1xpc+1] + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + mov al,[SA1xpc] + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + makedl + mov al,dl + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + mov [SA1xs],cx + + xor ebx,ebx + mov [SA1xpb],bl + xor eax,eax + mov ax,[SA1NMIV] + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + ret +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + ret + +NEWSYM SA1switchtovirq + mov al,byte[SA1Message] + mov byte[SA1Message+2],al + mov byte[SA1IRQExec+1],1 + mov ebx,esi + sub ebx,[initaddrl] + mov [SA1xpc],bx + + xor ecx,ecx + mov cx,[SA1xs] + mov al,[SA1xpb] + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + mov al,[SA1xpc+1] + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + mov al,[SA1xpc] + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + makedl + mov al,dl + call membank0w8 + + dec cx + and cx,word[stackand] + or cx,word[stackor] + mov [SA1xs],cx + xor ebx,ebx + mov [SA1xpb],bl + xor eax,eax + mov ax,[SA1IRQV] + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + ret +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + ret + \ No newline at end of file diff --git a/zsnes/src/chips/sa1regs.asm b/zsnes/src/chips/sa1regs.asm new file mode 100644 index 00000000..f17c0310 --- /dev/null +++ b/zsnes/src/chips/sa1regs.asm @@ -0,0 +1,2577 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +; SPC7110 emulation. Information fully reverse engineered +; by Dark Force and John Weidman, ZSNES code by zsKnight +; SA-1 emulation. Information provided by Ivar of Snes9x. +; coded by zsKnight +; SDD-1 emulation. SDD-1 MMC reverse engineered by zsKnight, +; SDD-1 decompress Dark Force and John Weidman, + + +; - Add MMC support +; - Add end of DMA IRQ support +; - Add Char Conversion #1 +; - Add Char Conversion #2 +; - Add Memory Disables (Guess this isn't needed) +; IRQs - IRQ Clear (also clear 2300), IRQ Disable, and IRQ Enable + +; Mario RPG Level-up not working - it was using one of the IRQ functions +; that no other place in the game is using, which I suppose is the cause +; of the problem, but it's been so long since I worked on SA-1, that +; I forgot which part. + + +%include "macros.mac" + +EXTSYM regptr,regptw,romdata,SA1Status,debstop4,SDD1BankA,curromsize +EXTSYM debuggeron +EXTSYM Get_Time,Get_TimeDate +EXTSYM spc7110romptr,SPC7110Entries +EXTSYM SPC7110IndexSize,SPC7110nfname +EXTSYM Open_File,Close_File,Read_File,File_Seek +; EXTSYM Msgptr,MessageOn +EXTSYM irqv2,irqv,nmiv2,nmiv +EXTSYM snesmmap,snesmap2 +EXTSYM curypos,CurrentExecSA1 +EXTSYM debstop3 +EXTSYM memaccessbankr8sdd1,memtabler8,AddrNoIncr + +%include "cpu\regs.mac" +%include "cpu\regsw.mac" + + + + + + + + +ALIGN32 +NEWSYM SPCMultA, dd 0 +NEWSYM SPCMultB, dd 0 +NEWSYM SPCDivEnd, dd 0 +NEWSYM SPCMulRes, dd 0 +NEWSYM SPCDivRes, dd 0 +NEWSYM SPC7110BankA, dd 020100h +NEWSYM SPC7110RTCStat, dd 0 +NEWSYM SPC7110RTC, db 00,00,00,00,00,00,01,00,01,00,00,00,00,00,0Fh,00 +NEWSYM SPC7110RTCB, db 00,00,00,00,00,00,01,00,01,00,00,00,00,01,0Fh,06 +NEWSYM SPCROMPtr, dd 0 +NEWSYM SPCROMtoI, dd SPCROMPtr +NEWSYM SPCROMAdj, dd 0 +NEWSYM SPCROMInc, dd 0 +NEWSYM SPCROMCom, dd 0 +NEWSYM SPCCompPtr, dd 0 +NEWSYM SPCDecmPtr, dd 0 +NEWSYM SPCCompCounter, dd 0 +NEWSYM SPCCompCommand, dd 0 +NEWSYM SPCCheckFix, dd 0 +NEWSYM SPCSignedVal, dd 0 +num2writespc7110reg equ $-SPCMultA +NEWSYM PHnum2writespc7110reg, dd num2writespc7110reg + +NEWSYM RTCData, db 0Fh,0,0,0,0,0,0,0,0,0,0,0,0,0,0Fh,0 +NEWSYM RTCPtr, dd 0 +NEWSYM RTCPtr2, dd 0 +NEWSYM RTCRest, dd 0 +NEWSYM SPC7110TempPosition, dd 0 +NEWSYM SPC7110TempLength, dd 0 +NEWSYM SPCPrevCompPtr, dd 0 + +RTC2800: + push ebx + cmp dword[RTCRest],100 +; je .go +; inc dword[RTCRest] +; jmp .notfirst +.go + cmp dword[RTCPtr],0 + jne near .notfirst + cmp byte[debuggeron],1 + je near .notfirst + ; fill time/date + push ebx + push eax + call Get_Time + mov bl,al + and bl,0Fh + mov [RTCData+1],bl ; seconds + shr eax,4 + mov bl,al + and bl,0Fh + mov [RTCData+2],bl +; jmp .done + shr eax,4 + cmp word[RTCData+1],0 +; jne .notminch + mov bl,al + and bl,0Fh + mov [RTCData+3],bl ; minutes + shr eax,4 + mov bl,al + and bl,0Fh + mov [RTCData+4],bl +.notminch +; jmp .done + shr eax,4 + mov bl,al + and bl,0Fh + mov [RTCData+5],bl ; hours + shr eax,4 + mov bl,al + and bl,0Fh + mov [RTCData+6],bl + call Get_TimeDate + mov bl,al + and bl,0Fh + mov [RTCData+7],bl ; day + shr eax,4 + mov bl,al + and bl,0Fh + mov bl,al + and bl,0Fh + mov [RTCData+8],bl + shr eax,4 + mov bl,al + and bl,0Fh + mov [RTCData+9],bl ; month + shr eax,8 + mov bl,al + and bl,0Fh + mov [RTCData+10],bl ; year + shr eax,4 + mov bl,al + and bl,01Fh + xor bh,bh +.notokay + cmp bl,9 + jbe .okay + inc bh + sub bl,10 + jmp .notokay +.okay + mov [RTCData+11],bl + add bh,9 + mov [RTCData+12],bh + shr eax,8 + and al,0Fh + mov [RTCData+13],al ; day of week +.done + pop eax + pop ebx +.notfirst + mov ebx,[RTCPtr] + mov al,[RTCData+ebx] + inc dword[RTCPtr] + cmp dword[RTCPtr],0Fh + jne .notclear + mov dword[RTCPtr],0 +.notclear + pop ebx + ret + +RTC2801w: + mov byte[debstop3],1 + mov dword[RTCRest],0 + mov dword[RTCPtr],0 + cmp al,0Eh + jne .notreset + mov dword[RTCPtr2],0 + ret +.notreset + cmp al,0Dh + jne .notstop + mov dword[RTCPtr2],0 + ret +.notstop + push ebx + mov ebx,dword[RTCPtr2] + cmp ebx,0 + je .next + cmp ebx,13 + ja .nomore + mov [RTCData+ebx],al +.next + inc dword[RTCPtr2] +.nomore + pop ebx + ret + +NEWSYM RTCinit + mov dword[RTCPtr],0 + ret +NEWSYM RTCReset + setreg 2800h*4,RTC2800 + ret +NEWSYM RTCReset2 + setregw 2801h*4,RTC2801w + ret + +SPC4850: + mov al,[SPC7110RTC] + ret +SPC4851: + mov al,[SPC7110RTC+01h] + ret +SPC4852: + mov al,[SPC7110RTC+02h] + ret +SPC4853: + mov al,[SPC7110RTC+03h] + ret +SPC4854: + mov al,[SPC7110RTC+04h] + ret +SPC4855: + mov al,[SPC7110RTC+05h] + ret +SPC4856: + mov al,[SPC7110RTC+06h] + ret +SPC4857: + mov al,[SPC7110RTC+07h] + ret +SPC4858: + mov al,[SPC7110RTC+08h] + ret +SPC4859: + mov al,[SPC7110RTC+09h] + ret +SPC485A: + mov al,[SPC7110RTC+0Ah] + ret +SPC485B: + mov al,[SPC7110RTC+0Bh] + ret +SPC485C: + mov al,[SPC7110RTC+0Ch] + ret +SPC485D: + mov al,[SPC7110RTC+0Dh] + ret +SPC485E: + mov al,[SPC7110RTC+0Eh] + ret +SPC485F: + mov al,[SPC7110RTC+0Fh] + ret + +NEWSYM SPCDecompFin, dd 0 + +NEWSYM SPC7110init + mov dword[SPCMultA],0 + mov dword[SPCMultB],0 + mov dword[SPCDivEnd],0 + mov dword[SPCMulRes],0 + mov dword[SPCDivRes],0 + mov dword[SPC7110BankA],020100h + mov dword[SPC7110RTCStat],0 + mov dword[SPC7110RTCStat],0 + mov dword[SPCROMPtr],0 + mov dword[SPCROMtoI],SPCROMPtr + mov dword[SPCROMAdj],0 + mov dword[SPCROMInc],0 + mov dword[SPCROMCom],0 + mov dword[SPCDecompFin],0 + mov dword[SPCCompPtr],0 + mov dword[SPCDecmPtr],0 + mov dword[SPCCompCounter],0 + mov dword[SPCCompCommand],0 + mov dword[SPCCheckFix],0 + mov dword[SPCPrevCompPtr],0 + ret + +NEWSYM SPC7110Reset + setregw 4801h*4,SPC4801w + setregw 4802h*4,SPC4802w + setregw 4803h*4,SPC4803w + setregw 4804h*4,SPC4804w + setregw 4805h*4,SPC4805w + setregw 4806h*4,SPC4806w + setregw 4807h*4,SPC4807w + setregw 4808h*4,SPC4808w + setregw 4809h*4,SPC4809w + setregw 480Ah*4,SPC480Aw + setregw 480Bh*4,SPC480Bw + + setregw 4811h*4,SPC4811w + setregw 4812h*4,SPC4812w + setregw 4813h*4,SPC4813w + setregw 4814h*4,SPC4814w + setregw 4815h*4,SPC4815w + setregw 4816h*4,SPC4816w + setregw 4817h*4,SPC4817w + setregw 4818h*4,SPC4818w + + setregw 4820h*4,SPC4820w + setregw 4821h*4,SPC4821w + setregw 4822h*4,SPC4822w + setregw 4823h*4,SPC4823w + setregw 4824h*4,SPC4824w + setregw 4825h*4,SPC4825w + setregw 4826h*4,SPC4826w + setregw 4827h*4,SPC4827w + setregw 482Eh*4,SPC482Ew + + setregw 4831h*4,SPC4831w + setregw 4832h*4,SPC4832w + setregw 4833h*4,SPC4833w + + setregw 4840h*4,SPC4840w + setregw 4841h*4,SPC4841w + setregw 4842h*4,SPC4842w + ret + +NEWSYM initSPC7110regs + setreg 4800h*4,SPC4800 + setreg 4801h*4,SPC4801 + setreg 4802h*4,SPC4802 + setreg 4803h*4,SPC4803 + setreg 4804h*4,SPC4804 + setreg 4805h*4,SPC4805 + setreg 4806h*4,SPC4806 + setreg 4807h*4,SPC4807 + setreg 4808h*4,SPC4808 + setreg 4809h*4,SPC4809 + setreg 480Ah*4,SPC480A + setreg 480Bh*4,SPC480B + setreg 480Ch*4,SPC480C + + setreg 4810h*4,SPC4810 + setreg 4811h*4,SPC4811 + setreg 4812h*4,SPC4812 + setreg 4813h*4,SPC4813 + setreg 4814h*4,SPC4814 + setreg 4815h*4,SPC4815 + setreg 4816h*4,SPC4816 + setreg 4817h*4,SPC4817 + setreg 4818h*4,SPC4818 + setreg 481Ah*4,SPC481A + + setreg 4820h*4,SPC4820 + setreg 4821h*4,SPC4821 + setreg 4822h*4,SPC4822 + setreg 4823h*4,SPC4823 + setreg 4824h*4,SPC4824 + setreg 4825h*4,SPC4825 + setreg 4826h*4,SPC4826 + setreg 4827h*4,SPC4827 + setreg 4828h*4,SPC4828 + setreg 4829h*4,SPC4829 + setreg 482Ah*4,SPC482A + setreg 482Bh*4,SPC482B + setreg 482Ch*4,SPC482C + setreg 482Dh*4,SPC482D + setreg 482Eh*4,SPC482E + setreg 482Fh*4,SPC482F + + setreg 4831h*4,SPC4831 + setreg 4832h*4,SPC4832 + setreg 4833h*4,SPC4833 + setreg 4834h*4,SPC4834 + + setreg 4840h*4,SPC4840 + setreg 4841h*4,SPC4841 + setreg 4842h*4,SPC4842 + + + setreg 4850h*4,SPC4850 + setreg 4851h*4,SPC4851 + setreg 4852h*4,SPC4852 + setreg 4853h*4,SPC4853 + setreg 4854h*4,SPC4854 + setreg 4855h*4,SPC4855 + setreg 4856h*4,SPC4856 + setreg 4857h*4,SPC4857 + setreg 4858h*4,SPC4858 + setreg 4859h*4,SPC4859 + setreg 485Ah*4,SPC485A + setreg 485Bh*4,SPC485B + setreg 485Ch*4,SPC485C + setreg 485Dh*4,SPC485D + setreg 485Eh*4,SPC485E + setreg 485Fh*4,SPC485F + ret + +%macro BankSwitchSPC7110 2 + push ecx + push edx + push eax + mov [SPC7110BankA+%1],al + inc al + cmp byte[curromsize],13 + jne .mbit24 +.mbit40 + cmp al,5 + jb .okaymbit + sub al,4 + jmp .mbit40 +.mbit24 + cmp al,3 + jb .okaymbit + sub al,2 + jmp .mbit24 +.okaymbit + and eax,07h + shl eax,20 + add eax,[romdata] + mov ecx,10h + mov ebx,snesmap2+%2*4 + mov edx,snesmmap+%2*4 +.mmaploop2 + mov [ebx],eax + mov [edx],eax + add eax,10000h + add ebx,4 + add edx,4 + loop .mmaploop2 + pop eax + pop edx + pop ecx + ret +%endmacro + +NEWSYM LastLog + pushad + cmp byte[CurValUsed],0 + je near .novalue + xor ebx,ebx + mov edx,DecompArray + mov eax,[CurPtrVal] + cmp dword[DecompAPtr],0 + je .noptr +.loop + mov ecx,[edx] + cmp ecx,eax + je .match + add edx,8 + inc ebx + cmp ebx,[DecompAPtr] + jne .loop +.noptr + cmp dword[DecompAPtr],8192 + je .novalue + mov [edx],eax + xor eax,eax + mov ax,[CurDecompSize] + mov [edx+4],ax + mov ax,[CurPtrLen] + mov [edx+6],ax + mov al,[CurPtrLen+2] + mov [edx+3],al + inc dword[DecompAPtr] + jmp .novalue +.match + add edx,4 + mov bx,[CurDecompSize] + xor ebx,ebx + cmp [edx],bx + jae .novalue + mov [edx],bx +.novalue + mov [lastentry],edx + mov byte[CurValUsed],1 + mov eax,[SPCCompPtr] + and eax,0FFFFFFh + mov [CurPtrVal],eax + popad + ret + + +SPC4800: +; mov byte[debstop3],1 +; cmp word[SPCCompCounter],0FFFFh +; jne .notzero +; xor al,al +; ret +;.notzero + cmp byte[SPCCompCommand],0 + je .manual + xor al,al + dec word[SPCCompCounter] + push ebx + xor ebx,ebx +; mov ebx,[SPCCompPtr] +; and ebx,0FFFFFFh +; add ebx,[romdata] +; add ebx,100000h + mov bx,[SPCDecmPtr] + add ebx,[romdata] + add ebx,510000h + mov al,[ebx] + pop ebx +; xor al,al + inc dword[SPCCompPtr] + + push eax + inc word[SPCDecmPtr] + mov ax,[SPCDecmPtr] + mov [CurDecompPtr],ax + sub ax,[PrevDecompPtr] + mov [CurDecompSize],ax + pop eax +; cmp word[SPCCompCounter],0FFFFh +; jne .exit +; mov byte[SPCDecompFin],80h +;.exit + ret +.manual + xor al,al + push ebx + xor ebx,ebx + mov bx,[SPCDecmPtr] + add ebx,[romdata] + add ebx,510000h + mov al,[ebx] + pop ebx + + dec word[SPCCompCounter] + inc dword[SPCCompPtr] + inc word[SPCDecmPtr] + inc word[CurDecompSize] +; cmp word[SPCCompCounter],0FFFFh +; jne .exit2 +; mov byte[SPCDecompFin],80h +;.exit2 + ret +SPC4801: + mov al,[SPCCompPtr] + ret +SPC4802: + mov al,[SPCCompPtr+1] + ret +SPC4803: + mov al,[SPCCompPtr+2] + ret +SPC4804: + mov al,[SPCCompPtr+3] + ret +SPC4805: + mov al,[SPCDecmPtr] + ret +SPC4806: + mov al,[SPCDecmPtr+1] + ret +SPC4807: + xor al,al + ret +SPC4808: + xor al,al + ret +SPC4809: + mov al,[SPCCompCounter] + ret +SPC480A: + mov al,[SPCCompCounter+1] + ret +SPC480B: + mov al,[SPCCompCommand] + mov dword[SPCDecmPtr],0 + ret +SPC480C: ; decompression finished status + mov al,[SPCDecompFin] + mov byte[SPCDecompFin],0 + ret + +NEWSYM CurPtrVal, dd 0 +NEWSYM CurCompCounter2, dd 0 +NEWSYM CurPtrLen, dd 0 +NEWSYM CurValUsed, db 0 +NEWSYM PrevDecompPtr, dw 0 +NEWSYM CurDecompPtr, dw 0 +NEWSYM CurDecompSize, dw 0 +NEWSYM DecompArray, times 65536 db 0 +NEWSYM DecompAPtr, dd 0 +lastentry dd 0 + + +NEWSYM UpdateRTC + test byte[SPC7110RTC+0Dh],02h + jnz .notimer +.notimer + ret + +SPC4801w: + mov [SPCCompPtr],al + ret +SPC4802w: + mov [SPCCompPtr+1],al + ret +SPC4803w: + mov [SPCCompPtr+2],al + ret +SPC4804w: + mov [SPCCompPtr+3],al + ret +SPC4805w: + mov [SPCDecmPtr],al + ret +SPC4806w: + mov [SPCDecmPtr+1],al + cmp dword[SPCCompPtr],0124AD48h + jne .nodata + mov byte[debstop3],1 +.nodata + + pushad + cmp byte[CurValUsed],0 + je near .novalue + xor ebx,ebx + mov edx,DecompArray + mov eax,[CurPtrVal] +; and eax,0FFFFFFh + + cmp dword[DecompAPtr],0 + je .noptr +.loop + mov ecx,[edx] +; and ecx,0FFFFFFh + cmp ecx,eax + je .match + add edx,8 + inc ebx + cmp ebx,[DecompAPtr] + jne .loop +.noptr + cmp dword[DecompAPtr],8192 + je .novalue + mov [edx],eax + xor eax,eax + mov ax,[CurDecompSize] + mov [edx+4],ax + mov ax,[CurPtrLen] + mov [edx+6],ax + mov al,[CurPtrLen+2] + mov [edx+3],al + inc dword[DecompAPtr] + jmp .novalue +.match + add edx,4 + xor ebx,ebx + mov bx,[CurDecompSize] + cmp [edx],bx + jae .novalue + mov [edx],bx +.novalue + mov [lastentry],edx + mov byte[CurValUsed],1 + mov eax,[SPCCompPtr] + and eax,0FFFFFFh + mov [CurPtrVal],eax + popad + mov word[CurDecompSize],0 + + push eax + mov al,[SPCCompPtr+3] + mov [CurPtrLen+2],al + mov ax,[SPCDecmPtr] ;CurCompCounter2] + mov [CurPtrLen],ax + mov eax,[SPCCompPtr] + mov [CurPtrVal],eax + + mov ax,[SPCDecmPtr] + mov [PrevDecompPtr],ax + mov [CurDecompPtr],ax + mov word[CurDecompSize],0 + pop eax + + mov byte[SPCDecompFin],0h + ; Start Decompression + + pushad + mov eax,[SPCCompPtr] + cmp [SPCPrevCompPtr],eax + je near .previousequal + mov [SPCPrevCompPtr],eax + + mov ecx,[SPC7110Entries] + mov ebx,[SPCCompPtr] + and ebx,0FFFFFFh + mov eax,[spc7110romptr] + or ecx,ecx + jz .noentries +.loopc + mov edx,[eax] + cmp dl,[SPCCompPtr+3] + jne .notfound + shr edx,8 + cmp ebx,edx + je .found +.notfound + add eax,12 + loop .loopc + jmp .noentries +.found + xor word[CurPtrLen],0FFFFh + mov ecx,[eax+8] + mov ebx,[eax+4] + xor edx,edx + mov dx,[SPCDecmPtr] + add edx,[romdata] + add edx,510000h + push eax +.loopb + mov al,[ebx] + mov [edx],al + inc ebx + inc edx + loop .loopb + pop eax + mov ebx,[eax+4] + mov edx,[lastentry] +; mov [edx+4],ebx + mov ebx,[eax] +; mov [edx],ebx + jmp .foundentry +.noentries + + mov ecx,[SPC7110IndexSize] + ; Address/index, pointer, length, SPC7110nfname + mov edx,[romdata] + add edx,580000h +.sploop + mov eax,[SPCCompPtr] + shl eax,8 + mov al,[SPCCompPtr+3] + cmp [edx],eax + je .foundsp + add edx,12 + sub ecx,12 + jc .overflow + jnz .sploop +.overflow + jmp .notfoundentry +.foundsp + mov eax,[edx+4] + mov [SPC7110TempPosition],eax + mov eax,[edx+8] + mov [SPC7110TempLength],eax + mov edx,SPC7110nfname + add edx,9 + mov eax,[SPCCompPtr] + and eax,0FFFFFFh + mov ecx,6 +.sploop2 + mov ebx,eax + shr ebx,20 + and ebx,0Fh + cmp bl,9 + jbe .below9 + add bl,55-48 +.below9 + add bl,48 + mov [edx],bl + inc edx + shl eax,4 + loop .sploop2 + + mov edx,SPC7110nfname + call Open_File + jc .error + mov bx,ax + mov dx,[SPC7110TempPosition] + mov cx,[SPC7110TempPosition+2] + call File_Seek + xor edx,edx + mov dx,[SPCDecmPtr] + add edx,[romdata] + add edx,510000h + mov ecx,[SPC7110TempLength] + call Read_File + call Close_File + jmp .foundentry +.error +; mov dword[Msgptr],SPC7110nfname +; mov dword[MessageOn],60*6 +.notfoundentry +.foundentry +.previousequal + popad +.fin +.blah + ; Finished +; mov word[SPCCompCounter],0FFFFh + mov byte[SPCDecompFin],80h + ret +SPC4807w: + ret +SPC4808w: + ret +SPC4809w: + mov [SPCCompCounter],al + mov [CurCompCounter2],al + ret +SPC480Aw: + mov [SPCCompCounter+1],al + mov [CurCompCounter2+1],al + ret +SPC480Bw: + mov [SPCCompCommand],al + ret + +;NEWSYM SPCROMPtr, dd 0 +;NEWSYM SPCROMAdj, dd 0 +;NEWSYM SPCROMInc, dd 0 +;NEWSYM SPCROMCom, dd 0 +; 01, +;$4810 DATA ROM CONTINUOUS READ PORT: returns a byte from data rom at data +; rom pointer location, defval:00 +;$4811 DATA ROM POINTER: ($0000FF) r/w low offset, defval:00 +;$4812 DATA ROM POINTER: ($00FF00) r/w high offset, defval:00 +;$4813 DATA ROM POINTER: ($FF0000) r/w bank offset, defval:00 +; bank offset is zero based from start of data rom: banks $00-$3f +; data rom -> $10-$4f full rom +;$4814 DATA ROM POINTER ADJUST: ($00FF) low byte, defval:00 +;$4815 DATA ROM POINTER ADJUST: ($FF00) high byte, defval:00 +;$4816 DATA ROM POINTER INCREMENT: ($00FF) low byte, defval:00 +;$4817 DATA ROM POINTER INCREMENT: ($FF00) high byte, defval:00 +;$4818 DATA ROM COMMAND MODE: bit field control of data rom pointer (see +; data rom command mode byte), defval:00 +; write: set command mode, +; read: performs action instead of returning value, unknown purpose, +; command mode is loaded to $4818 but only set after writing to both +; $4814 and $4815 in any order +;$481A DATA ROM READ AFTER ADJUST PORT: returns a byte from data rom at +; data rom pointer location + adjust value ($4814/5), defval:00 + + +SPC4810: + cmp dword[SPCCheckFix],0 + jne .okay + xor al,al + ret +.okay + push ebx + push ecx + mov ebx,[SPCROMPtr] + add ebx,[romdata] + add ebx,100000h + mov al,[ebx] + cmp byte[SPCROMCom+1],0 + jne .noincr1 + mov ebx,[SPCROMtoI] + inc dword[ebx] +.noincr1 + cmp byte[SPCROMCom+1],1 ; add 4816 after 4810 read + jne .noincr1b + mov ebx,[SPCROMtoI] + mov ecx,[SPCROMInc] + add dword[ebx],ecx +.noincr1b + pop ecx + pop ebx + ret +SPC4811: + mov al,[SPCROMPtr] + ret +SPC4812: + mov al,[SPCROMPtr+1] + ret +SPC4813: + mov al,[SPCROMPtr+2] + ret +SPC4814: + mov al,[SPCROMAdj] + ret +SPC4815: + mov al,[SPCROMAdj+1] + ret +SPC4816: + mov al,[SPCROMInc] + ret +SPC4817: + mov al,[SPCROMInc+1] + ret +SPC4818: + mov al,[SPCROMCom] + ret +SPC481A: + cmp dword[SPCCheckFix],0 + jne .okay + xor al,al + ret +.okay + push ebx + push ecx + xor ebx,ebx + xor ecx,ecx + mov bx,[SPCROMAdj] + add ebx,[SPCROMPtr] + add ebx,[romdata] + add ebx,100000h + mov al,[ebx] + + cmp byte[SPCROMCom+1],4 ; 16bit 4814 + jne .notincr + mov ecx,[SPCROMtoI] + mov ebx,[SPCROMAdj] + add [ecx],ebx +.notincr + pop ecx + pop ebx + ret + +SPC4811w: + mov [SPCROMPtr],al + mov byte[SPCCheckFix],1 + ret +SPC4812w: + mov [SPCROMPtr+1],al + ret +SPC4813w: + mov [SPCROMPtr+2],al + ret +SPC4814w: + mov [SPCROMAdj],al + cmp byte[SPCROMCom+1],2 ; 8 bit 4814 + jne .notincr + mov ebx,[SPCROMtoI] + xor ecx,ecx + mov cl,[SPCROMAdj] + test byte[SPCROMCom],08h + jz .noneg + movsx ecx,byte[SPCROMAdj] +.noneg + add dword[ebx],ecx +.notincr + ret +SPC4815w: + mov [SPCROMAdj+1],al + mov word[SPCROMAdj+2],0 + test byte[SPCROMCom],08h + jz .noneg + test byte[SPCROMAdj+1],80h + jz .noneg + mov word[SPCROMAdj+2],0FFFFh +.noneg + cmp byte[SPCROMCom+1],3 ; 16bit 4814 + jne .notincr + push ebx + push ecx + mov ecx,[SPCROMtoI] + mov ebx,[SPCROMAdj] + add [ecx],ebx + pop ecx + pop ebx +.notincr + ret +SPC4816w: + mov [SPCROMInc],al + ret +SPC4817w: + mov [SPCROMInc+1],al + mov word[SPCROMInc+2],0 + test byte[SPCROMCom],04h + jz .noneg + test byte[SPCROMInc+1],40h + jz .noneg + mov word[SPCROMInc+2],0FFFFh +.noneg + ret +SPC4818w: + mov [SPCROMCom],al + mov word[SPCROMAdj+2],0 + test byte[SPCROMCom],08h + jz .noneg + test byte[SPCROMAdj+1],80h + jz .noneg + mov word[SPCROMAdj+2],0FFFFh +.noneg + mov word[SPCROMInc+2],0 + test byte[SPCROMCom],04h + jz .noneg2 + test byte[SPCROMInc+1],40h + jz .noneg2 + mov word[SPCROMInc+2],0FFFFh +.noneg2 + mov dword[SPCROMtoI],SPCROMPtr + test byte[SPCROMCom],10h + jz .nouseadjust + mov dword[SPCROMtoI],SPCROMAdj +.nouseadjust + test al,02h + jz .no4814 + test al,40h + jz .no16b + test al,20h + jz .not481A + mov byte[SPCROMCom+1],4 ; 16bit 4814 after 481A + jmp .fin +.not481A + mov byte[SPCROMCom+1],3 ; 16bit 4814 + jmp .fin +.no16b + test al,20h + jz .nooffsetadd + mov byte[SPCROMCom+1],2 ; 8 bit 4814 + jmp .fin +.nooffsetadd + mov byte[SPCROMCom+1],0FFh + jmp .fin +.no4814 + test al,01h + jz .incrval0 + mov byte[SPCROMCom+1],1 ; add 4816 after 4810 read + jmp .fin +.incrval0 + mov byte[SPCROMCom+1],0 ; add 1 after 4810 read +.fin + ret + +;Data Rom Command Mode Byte: +;X6543210 +;|||||||| +;|||||| \__ : 00 - use 1 as the offset increment value, add immediately after reading $4810 +;|||||| : 01 - use $4816 as offset increment, add immediately after reading $4810 +;|||||| : 10 - use $4814 as offset increment, see below for when to add +;|||||| : 11 - unused +;||||||____ : 0 - unsigned calculation for $4816 +;||||| 1 - signed calculation for $4816 +;|||||_____ : 0 - unsigned calculation for $4814 +;|||| 1 - signed calculation for $4814 +;||||______ : 0 - offset increment gets added to $4811/2/3 +;||| 1 - offset increment gets added to $4814/5 +;| \_______ : 00 - disable offset addition +;| : 01 - 8 bit offset addition using $4814, immediately after writing to $4814/5 +;| : 10 - 16 bit offset addition using $4814/5, immediately after writing to $4814/5 +;| : 11 - 16 bit offset addition using $4814/5, only after reading $481A +;|_________ : unused + +SPC4820: + mov al,[SPCMultA] +; mov byte[debstop3],1 + ret +SPC4821: + mov al,[SPCMultA+1] + ret +SPC4822: + mov al,[SPCMultA+2] + ret +SPC4823: + mov al,[SPCMultA+3] + ret +SPC4824: + mov al,[SPCMultB] + ret +SPC4825: + mov al,[SPCMultB+1] + ret +SPC4826: + mov al,[SPCDivEnd] + ret +SPC4827: + mov al,[SPCDivEnd+1] + ret + +SPC4820w: + mov [SPCMultA],al + ret +SPC4821w: + mov [SPCMultA+1],al + ret +SPC4822w: + mov [SPCMultA+2],al + ret +SPC4823w: + mov [SPCMultA+3],al + ret +SPC4824w: + mov [SPCMultB],al + ret +SPC4825w: + mov [SPCMultB+1],al + ; Calculate SPCMultA*SPCMultB -> SPCMulRes + test byte[SPCSignedVal],1 + jnz .signed + push edx + push eax + push ebx + xor eax,eax + xor ebx,ebx + mov ax,[SPCMultA] + mov bx,[SPCMultB] + mul ebx + mov [SPCMulRes],eax + pop ebx + pop eax + pop edx + ret +.signed + push edx + push eax + push ebx + movsx eax,word[SPCMultA] + movsx ebx,word[SPCMultB] + imul ebx + mov [SPCMulRes],eax + pop ebx + pop eax + pop edx + ret +SPC4826w: + mov [SPCDivEnd],al + ret +SPC4827w: + mov [SPCDivEnd+1],al + ; Calculte SPCMultA/SPCDivEnd -> SPCMulRes, rem SPCDivRes + cmp word[SPCDivEnd],0 + je near .nodivide + test byte[SPCSignedVal],1 + jnz .signed + push edx + push eax + push ebx + xor edx,edx + xor ebx,ebx + mov eax,[SPCMultA] + mov bx,[SPCDivEnd] + div ebx + mov [SPCMulRes],eax + mov [SPCDivRes],dx + pop ebx + pop eax + pop edx + ret +.signed + push edx + push eax + push ebx + xor edx,edx + mov eax,[SPCMultA] + test eax,80000000h + jz .nd + mov edx,0FFFFFFFFh +.nd + movsx ebx,word[SPCDivEnd] + idiv ebx + mov [SPCMulRes],eax + mov [SPCDivRes],dx + pop ebx + pop eax + pop edx + ret +.nodivide + mov dword[SPCMulRes],0FFFFFFFFh + mov dword[SPCDivRes],0FFFFh + ret +SPC4828: + mov al,[SPCMulRes] + ret +SPC4829: + mov al,[SPCMulRes+1] + ret +SPC482A: + mov al,[SPCMulRes+2] + ret +SPC482B: + mov al,[SPCMulRes+3] + ret +SPC482C: + mov al,[SPCDivRes] + ret +SPC482D: + mov al,[SPCDivRes+1] + ret +SPC482E: + xor al,al + ret +SPC482Ew: + mov byte[SPCSignedVal],al + mov dword[SPCMultA],0 + mov dword[SPCMultB],0 + mov dword[SPCDivEnd],0 + mov dword[SPCMulRes],0 + mov dword[SPCDivRes],0 + ret +SPC482F: + xor al,al + ret + +SPC4831w: + BankSwitchSPC7110 0,0D0h + ret +SPC4832w: + BankSwitchSPC7110 1,0E0h + ret +SPC4833w: +; mov byte[debstop3],1 + BankSwitchSPC7110 2,0F0h + ret +SPC4831: + mov al,[SPC7110BankA] + ret +SPC4832: + mov al,[SPC7110BankA+1] + ret +SPC4833: + mov al,[SPC7110BankA+2] + ret + +SPC4834: + xor al,al + ret + +;NEWSYM SPC7110RTCStat, dd 0 +;NEWSYM SPC7110RTC, db 00,00,00,00,00,00,01,00,01,00,00,00,00,01,0F,06 +;$4840 RTC CHIP ENABLE/DISABLE: bit 0: on = enable, off = disable, defval:00 +;$4841 RTC INDEX/DATA PORT: +; first write after rtc enable: rtc command mode byte (see rtc command modes) +; subsequent writes: index of rtc register to read/write (00-0f) +; read: returns value of indexed rtc register +; auto-increment of register index occurs after each subsequent read/write +;$4842 RTC READY STATUS: bit 7: on = ready, off = still processing, tested before reading rtc data +; high bit cleared after successful read + +SPC4840w: + test al,1 + jz .notreset + mov byte[SPC7110RTCStat],al + mov byte[SPC7110RTCStat+1],0FEh +.notreset + ret +SPC4841w: + cmp byte[SPC7110RTCStat+1],0FEh + je .commandbyte + cmp byte[SPC7110RTCStat+1],0FFh + je .commandindex + push ebx + xor ebx,ebx + mov bl,[SPC7110RTCStat+1] + mov [SPC7110RTC+ebx],al + cmp ebx,0Fh + jne .notlast + test al,01h + jz .notlast + mov dword[SPC7110RTC],0 + mov dword[SPC7110RTC+4],010000h + mov dword[SPC7110RTC+8],01h + mov byte[SPC7110RTC+12],0 +.notlast + pop ebx + inc byte[SPC7110RTCStat+1] + and byte[SPC7110RTCStat+1],0Fh + ret +.commandbyte + inc byte[SPC7110RTCStat+1] + mov byte[SPC7110RTCStat+2],al + ret +.commandindex + push eax + and al,0Fh + mov byte[SPC7110RTCStat+1],al + pop eax + ret +SPC4842w: + ret +SPC4840: + mov al,[SPC7110RTCStat] + ret +SPC4841: + cmp byte[SPC7110RTCStat+1],0FEh + je near .commandbyte + cmp byte[SPC7110RTCStat+1],0FFh + je near .commandbyte + push ebx + xor ebx,ebx + mov bl,[SPC7110RTCStat+1] + or ebx,ebx + jnz near .dontupdate + test byte[SPC7110RTC+0Fh],03h + jnz near .dontupdate + test byte[SPC7110RTC+0Dh],01h + jnz near .dontupdate +;00 - seconds 1's digit 00 +;01 - seconds 10's digit 00 +;02 - minutes 1's digit 00 +;03 - minutes 10's digit 00 +;04 - hours 1's digit 00 +;05 - hours 10's digit 00 +;06 - day of month 1's digit 01 +;07 - day of month 10's digit 00 +;08 - month 1's digit 01 +;09 - month 10's digit 00 +;0a - year 1's digit 00 +;0b - year 10's digit 00 +;0c - day of week 00 + + cmp byte[debuggeron],1 + je near .dontupdate + ; fill time/date + push ebx + push eax + call Get_Time + mov bl,al + and bl,0Fh + mov [SPC7110RTC],bl ; seconds + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+1],bl + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+2],bl ; minutes + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+3],bl + test byte[SPC7110RTC+0Fh],4 +; jz .not24hrs +; jmp .not24hrs + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+4],bl ; hours + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+5],bl + jmp .24hrs +.not24hrs + shr eax,4 + xor ebx,ebx + mov bl,al + mov al,[SPCTimerVal+ebx] + mov bl,al + and bl,0Fh + mov [SPC7110RTC+4],bl ; hours + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+5],bl +.24hrs + call Get_TimeDate + mov bl,al + and bl,0Fh + mov [SPC7110RTC+6],bl ; day + shr eax,4 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+7],bl + shr eax,4 + mov bl,al + and bl,0Fh + xor bh,bh + cmp bl,9 + jbe .less + sub bl,10 + mov bh,1 +.less + mov [SPC7110RTC+8],bl ; month + mov [SPC7110RTC+9],bh ; month + shr eax,8 + mov bl,al + and bl,0Fh + mov [SPC7110RTC+10],bl ; year + shr eax,4 + mov bl,al + and bl,01Fh + xor bh,bh +.notokay + cmp bl,9 + jbe .okay + inc bh + sub bl,10 + jmp .notokay +.okay + mov [SPC7110RTC+11],bl + shr eax,8 + and al,0Fh + mov [SPC7110RTC+12],al ; day of week +.done + pop eax + pop ebx + +.dontupdate +; test byte[SPC7110RTC+0Fh],1 +; jz .realtime +; cmp ebx,0Dh +; jae .realtime +; mov al,[SPC7110RTCB+ebx] +; jmp .next +;.realtime + mov al,[SPC7110RTC+ebx] +;.next + pop ebx + inc byte[SPC7110RTCStat+1] + and byte[SPC7110RTCStat+1],0Fh + ret +.commandbyte + inc byte[SPC7110RTCStat+1] + mov al,byte[SPC7110RTCStat+2] + ret + +SPCTimerVal + db 12h,01h,02h,03h,04h,05h,06h,07h,08h,09h,0,0,0,0,0,0 + db 10h,11h,32h,21h,22h,23h,24h,25h,26h,27h,0,0,0,0,0,0 + db 28h,29h + +SPC4842: + mov al,80h + ret + + +;$4820 16 BIT MULTIPLICAND: ($00FF) low byte, defval:00 +; 32 BIT DIVIDEND: ($000000FF) low byte of low word, defval:00 +;$4821 16 BIT MULTIPLICAND: ($FF00) high byte, defval:00 +; 32 BIT DIVIDEND: ($0000FF00) high byte of low word, defval:00 +;$4822 32 BIT DIVIDEND: ($00FF0000) low byte of high word, defval:00 +;$4823 32 BIT DIVIDEND: ($FF000000) high byte of high word, defval:00 +;$4824 16 BIT MULTIPLIER: ($00FF) low byte, defval:00 +;$4825 16 BIT MULTIPLIER: ($FF00) high byte, defval:00 +;$4826 16 BIT DIVISOR: ($00FF), defval:00 +;$4827 16 BIT DIVISOR: ($FF00), defval:00 +;$4828 32 BIT PRODUCT: ($000000FF) low byte of low word, defval:00 +; 32 BIT QUOTIENT:($000000FF) low byte of low word, defval:00 +;$4829 32 BIT PRODUCT: ($0000FF00) high byte of low word, defval:00 +; 32 BIT QUOTIENT:($0000FF00) high byte of low word, defval:00 +;$482A 32 BIT PRODUCT: ($00FF0000) low byte of high word, defval:00 +; 32 BIT QUOTIENT:($00FF0000) low byte of high word, defval:00 +;$482B 32 BIT PRODUCT: ($FF000000) high byte of high word, defval:00 +; 32 BIT QUOTIENT:($FF000000) high byte of high word, defval:00 +;$482C 16 BIT REMAINDER: ($00FF) low byte, defval:00 +;$482D 16 BIT REMAINDER: ($FF00) high byte, defval:00 +;$482E MUL/DIV RESET, write = reset $4820 to $482D, defval:00 +;$482F MUL/DIV FINISHED STATUS: bit 7: on = processing, off = finished, +; high bit is set after a write to multiplier or divisor regs $4825/$4827, defval:00 + +ALIGN32 + +; IRQ Stuff +NEWSYM SA1Mode, dd 0 ; 0 = SNES CPU, 1 = SA1 CPU +NEWSYM SA1Control, dd 0 ; don't execute if b5 or 6 are set +NEWSYM SA1BankPtr, dd 0 +NEWSYM SA1ResetV, dd 0 +NEWSYM SA1NMIV, dd 0 +NEWSYM SA1IRQV, dd 0 +NEWSYM SA1RV, dd 0 +NEWSYM CurBWPtr, dd 0 +NEWSYM SA1TempVar, dd 0 +NEWSYM SA1IRQEn, dd 0 +NEWSYM SA1Message, dd 0 +NEWSYM SA1IRQExec, dd 0 +NEWSYM SA1IRQEnable, dd 0 +NEWSYM SA1DoIRQ, dd 0 +; Arithmetic Stuff +NEWSYM SA1ARC, dd 0 +NEWSYM SA1AR1, dd 0 +NEWSYM SA1AR2, dd 0 +NEWSYM SA1ARR1, dd 0 +NEWSYM SA1ARR2,dd 0 +NEWSYM SA1Stat, dd 0 + +NEWSYM SNSNMIV, dd 0 +NEWSYM SNSIRQV, dd 0 +NEWSYM SA1DMACount, dd 0 +NEWSYM SA1DMAInfo, dd 0 +NEWSYM SA1DMAChar, dd 0 +NEWSYM SA1DMASource, dd 0 +NEWSYM SA1DMADest, dd 0 +NEWSYM SA1IRQTemp, dd 0 + +NEWSYM SA1BankSw, dd 1 +NEWSYM SA1BankVal, db 0,1,2,3 + +SA1Reserved times 472 db 0 + +; SA1 Swap Stuff +NEWSYM SA1xa, dd 0 +NEWSYM SA1xx, dd 0 +NEWSYM SA1xy, dd 0 +NEWSYM SA1xd, dd 0 +NEWSYM SA1xdb, dd 0 +NEWSYM SA1xpb, dd 0 +NEWSYM SA1xs, dd 0 +NEWSYM SA1RegP, dd 0 +NEWSYM SA1RegE, dd 0 +NEWSYM SA1RegPCS,dd 0 +NEWSYM SA1BWPtr,dd 0 +NEWSYM SA1Ptr, dd 0 ; Current PC, SA-1 + +NEWSYM SA1Overflow, dd 0 +NEWSYM VarLenAddr, dd 0 +NEWSYM VarLenAddrB, dd 0 +NEWSYM VarLenBarrel, dd 0 +NEWSYM SA1TimerVal, dd 0 +NEWSYM SA1TimerSet, dd 0 +NEWSYM SA1TimerCount, dd 0 +NEWSYM SA1IRQData, dd 0 + +; SNES Swap Stuff +NEWSYM SNSRegP, dd 0 +NEWSYM SNSRegE, dd 0 +NEWSYM SNSRegPCS,dd 0 +NEWSYM SNSBWPtr,dd 0 +NEWSYM SNSPtr, dd 0 ; Current PC, SNES + +NEWSYM IRAM, times 2049 db 0 ;2 kbytes of iram + +num2writesa1reg equ $-SA1Mode +NEWSYM PHnum2writesa1reg, dd num2writesa1reg + +NEWSYM SA1RAMArea, dd 0 +NEWSYM SA1Temp, dd 0 +NEWSYM Sdd1Mode, dd 0 +NEWSYM Sdd1Bank, dd 0 +NEWSYM Sdd1Addr, dd 0 +NEWSYM Sdd1NewAddr, dd 0 + +%macro SA1QuickF 2 +NEWSYM %1 + mov [%2],al + ret +%endmacro + +NEWSYM RestoreSA1 + mov eax,[romdata] + add [SA1RegPCS],eax + add [CurBWPtr],eax + add [SA1BWPtr],eax + add [SNSBWPtr],eax + cmp byte[SA1Stat],1 + jne .notsa1stat + mov dword[SA1RegPCS],IRAM +.notsa1stat + cmp byte[SA1Stat],2 + jne .notsa1stat2 + mov dword[SA1RegPCS],IRAM-3000h +.notsa1stat2 + mov eax,[SA1RegPCS] + add [SA1Ptr],eax + mov eax,[romdata] + add eax,4096*1024 + mov [SA1RAMArea],eax + pushad + call UpdateBanks + popad + ret + +NEWSYM SaveSA1 + mov byte[SA1Stat],0 + mov eax,[SA1RegPCS] + sub [SA1Ptr],eax + cmp dword[SA1RegPCS],IRAM + jne .notiram + mov byte[SA1Stat],1 +.notiram + cmp dword[SA1RegPCS],IRAM-3000h + jne .notiram2 + mov byte[SA1Stat],2 +.notiram2 + mov eax,[romdata] + sub [SA1RegPCS],eax + sub [CurBWPtr],eax + sub [SA1BWPtr],eax + sub [SNSBWPtr],eax + ret + + +NEWSYM SA1Reset + mov byte[SA1IRQData+1],0 + mov byte[SA1Mode],0 + mov byte[SA1Status],0 + mov byte[SA1Control],20h + mov dword[SA1DoIRQ],0 + mov ax,[irqv2] + mov [irqv],ax + mov ax,[nmiv2] + mov [nmiv],ax + mov eax,[romdata] + sub eax,8000h + mov [SA1RegPCS],eax + mov eax,[romdata] + add eax,4096*1024 + mov [SA1RAMArea],eax + mov eax,[romdata] + add eax,4096*1024-6000h + mov dword[CurBWPtr],eax + mov dword[SA1BWPtr],eax + mov dword[SNSBWPtr],eax + mov dword[SA1xa],0 + mov dword[SA1xx],0 + mov dword[SA1xy],0 + mov dword[SA1xd],0 + mov dword[SA1xdb],0 + mov dword[SA1xpb],0 + mov dword[SA1xs],1FFh + mov dword[SA1RegP],0 + mov dword[SA1RegE],0 + mov dword[SA1IRQExec],0 + mov dword[SA1IRQEnable],0 + mov dword[SA1Message],0 + mov byte[SA1Overflow],0 + ret + +NEWSYM UpdateBanks + cmp byte[SA1BankSw],1 + jne .noswap + mov al,[SA1BankVal] + call sa12220w + mov al,[SA1BankVal+1] + call sa12221w + mov al,[SA1BankVal+2] + call sa12222w + mov al,[SA1BankVal+3] + call sa12223w +.noswap + ret + +NEWSYM UpdateBanksSDD1 + pushad + cmp dword[SDD1BankA],0 + je .nobank + mov al,[SDD1BankA] + call sdd14804w + mov al,[SDD1BankA+1] + call sdd14805w + mov al,[SDD1BankA+2] + call sdd14806w + mov al,[SDD1BankA+3] + call sdd14807w +.nobank + popad + ret + +%macro BankSwitch 4 + push ecx + push edx + push eax + mov [SA1BankVal+%1],al + mov ebx,snesmmap+%2*4 + test al,80h + jz .noupper + and eax,07h + shl eax,20 + push eax + jmp .yesupper +.noupper + and eax,07h + shl eax,20 + push eax + mov eax,%4 +.yesupper + mov ecx,20h + add eax,[romdata] + sub eax,8000h +.mmaploop + mov [ebx],eax + add eax,8000h + add ebx,4 + loop .mmaploop + pop eax + add eax,[romdata] + mov ecx,10h + mov ebx,snesmap2+%3*4 + mov edx,snesmmap+%3*4 +.mmaploop2 + mov [ebx],eax + mov [edx],eax + add eax,10000h + add ebx,4 + add edx,4 + loop .mmaploop2 + pop eax + pop edx + pop ecx + ret +%endmacro + +NEWSYM sa12220w + BankSwitch 0,0,0C0h,0 +NEWSYM sa12221w + BankSwitch 1,20h,0D0h,100000h +NEWSYM sa12222w + BankSwitch 2,80h,0E0h,200000h +NEWSYM sa12223w + BankSwitch 3,0A0h,0F0h,300000h + +%macro BankSwitchSDD1 2 + push ecx + push edx + push eax + mov [SDD1BankA+%1],al + and eax,07h + shl eax,20 + add eax,[romdata] + mov ecx,10h + mov ebx,snesmap2+%2*4 + mov edx,snesmmap+%2*4 +.mmaploop2 + mov [ebx],eax + mov [edx],eax + add eax,10000h + add ebx,4 + add edx,4 + loop .mmaploop2 + pop eax + pop edx + pop ecx + ret +%endmacro + +sdd14804: + mov al,[SDD1BankA] + ret +sdd14805: + mov al,[SDD1BankA+1] + ret +sdd14806: + mov al,[SDD1BankA+2] + ret +sdd14807: + mov al,[SDD1BankA+3] + ret + +NEWSYM sdd14804w + BankSwitchSDD1 0,0C0h +NEWSYM sdd14805w + BankSwitchSDD1 1,0D0h +NEWSYM sdd14806w + BankSwitchSDD1 2,0E0h +NEWSYM sdd14807w + BankSwitchSDD1 3,0F0h + +NEWSYM sa12200w + mov bl,al + and bl,0Fh + mov byte[SA1Message],bl + test al,80h + jz .noirq + or byte[SA1DoIRQ],1 +.noirq + test al,10h + jz .nonmi + or byte[SA1DoIRQ],2 +.nonmi + test byte[SA1Control],20h + jz .noreset + test al,20h + jnz .noreset + mov [SA1Control],al + mov ebx,[romdata] + mov [SA1BankPtr],ebx + xor ebx,ebx + mov bx,[SA1ResetV] + add ebx,[romdata] + sub ebx,8000h + mov [SA1Ptr],ebx + mov byte[SA1xpb],0 + mov word[SA1xs],1FFh + mov ebx,[romdata] + sub ebx,8000h + mov [SA1RegPCS],ebx + xor ebx,ebx + ret +.noreset + mov [SA1Control],al + ret + +NEWSYM sa12201w ; IRQ Enable + mov byte[SA1IRQEnable],al + ret +NEWSYM sa12202w ; IRQ Clear + test al,80h + jz .noirqclear + and byte[SA1IRQExec],0FEh + and byte[SA1DoIRQ],0FBh +.noirqclear + test al,20h + jz .nocdmairqclear + and byte[SA1IRQExec],0FDh + and byte[SA1DoIRQ],0F7h +.nocdmairqclear + ret + +SA1QuickF sa12203w, SA1ResetV +SA1QuickF sa12204w, SA1ResetV+1 +SA1QuickF sa12205w, SA1NMIV +SA1QuickF sa12206w, SA1NMIV+1 +SA1QuickF sa12207w, SA1IRQV +SA1QuickF sa12208w, SA1IRQV+1 +NEWSYM sa12209w ; IRQ Stuff + mov [SA1IRQData+1],al + test al,80h + jz .noirq + ; execute IRQ on the SNES + or byte[SA1DoIRQ],4 +.noirq + mov bl,al + and bl,0Fh + mov byte[SA1Message+1],bl + mov bx,[irqv2] + test al,40h + jz .noirqchange + mov bx,[SNSIRQV] +.noirqchange + mov [irqv],bx + mov bx,[nmiv2] + test al,10h + jz .nonmichange + mov bx,[SNSNMIV] +.nonmichange + mov [nmiv],bx + ret + +SA1QuickF sa1220Aw, SA1IRQEn + +NEWSYM sa1220Bw ; SA-1 IRQ Clear + test al,80h + jz .noirqclear + mov byte[SA1IRQExec+1],0 + and byte[SA1DoIRQ],0FEh +.noirqclear + test al,20h + jz .nocdmairqclear +.nocdmairqclear + test al,10h + jz .nonmiclear + mov byte[SA1IRQExec+2],0 + and byte[SA1DoIRQ],0FDh +.nonmiclear + ret + +SA1QuickF sa1220Cw, SNSNMIV +SA1QuickF sa1220Dw, SNSNMIV+1 +SA1QuickF sa1220Ew, SNSIRQV +SA1QuickF sa1220Fw, SNSIRQV+1 + +NEWSYM sa12224w ; BWRAM + mov bl,al + and ebx,1Fh + shl ebx,13 + add ebx,[romdata] + add ebx,1024*4096-6000h + mov dword[SNSBWPtr],ebx + cmp byte[SA1Status],0 + jne .nosnes + mov dword[CurBWPtr],ebx +.nosnes + ret +NEWSYM sa12225w ; BWRAM + mov bl,al + and ebx,1Fh + shl ebx,13 + add ebx,[romdata] + add ebx,1024*4096-6000h + mov dword[SA1BWPtr],ebx + cmp byte[SA1Status],0 + je .nosa1 + mov dword[CurBWPtr],ebx +.nosa1 + ret +NEWSYM sa12250w + mov byte[SA1ARC],al + mov byte[SA1ARC+1],1 + test al,2 + jz .notcumul + mov word[SA1ARR1],0 + mov word[SA1ARR1+2],0 + mov word[SA1ARR1+4],0 +.notcumul + ret +NEWSYM sa12251w + mov byte[SA1AR1],al + mov byte[SA1ARC+1],1 + ret +NEWSYM sa12252w + mov byte[SA1AR1+1],al + mov byte[SA1ARC+1],1 + ret +NEWSYM sa12253w + mov byte[SA1AR2],al + mov byte[SA1ARC+1],1 + ret +NEWSYM sa12254w + mov byte[SA1AR2+1],al + mov byte[SA1ARC+1],1 + test byte[SA1ARC],2 + jnz .cumul + call UpdateArithStuff + ret + ; set overflow bit if exceeds 40bits +.cumul + pushad + xor edx,edx + mov ax,[SA1AR1] + mov bx,[SA1AR2] + imul bx + shl edx,16 + mov dx,ax + mov byte[SA1Overflow],0 + add [SA1ARR1],edx + adc byte[SA1ARR2],0 + jnc .notoverflow + mov byte[SA1Overflow],80h +.notoverflow + popad + ret + +UpdateArithStuff: + cmp byte[SA1ARC+1],1 + jne .noarith + pushad + mov byte[SA1ARC+1],0 + test byte[SA1ARC],3 + jz .multiply + test byte[SA1ARC],2 + jnz near .cumulativesum + test byte[SA1ARC],1 + jnz .division +.multiply + xor edx,edx + mov ax,[SA1AR1] + mov bx,[SA1AR2] + imul bx + mov [SA1ARR1],ax + mov [SA1ARR1+2],dx + popad +.noarith + ret +.division + movsx eax,word[SA1AR1] + xor edx,edx + test eax,80000000h + jz .notneg + mov edx,0FFFFFFFFh +.notneg + xor ebx,ebx + mov bx,[SA1AR2] + or ebx,ebx + jz .invalid + idiv ebx + mov [SA1ARR1],ax + mov [SA1ARR1+2],dx +; mov word[SA1AR1],0 +; mov word[SA1AR2],0 + popad + ret +.invalid + mov word[SA1ARR1],0 + mov word[SA1ARR1+2],0 + popad + ret +.cumulativesum + popad + ret + +sa12300r: + mov al,[SA1Message+1] + test byte[SA1IRQExec],1 + jz .notexecuted + or al,80h +.notexecuted + test byte[SA1IRQExec],2 + jz .notexecutedi + or al,20h +.notexecutedi + mov bl,[SA1IRQData+1] + and bl,50h + or al,bl + ret +sa12301r: + mov al,[SA1Message] + test byte[SA1IRQExec+1],1 + jz .notexecuted + or al,80h +.notexecuted + ret +sa12306r: +; call UpdateArithStuff + mov al,[SA1ARR1] + ret +sa12307r: +; call UpdateArithStuff + mov al,[SA1ARR1+1] + ret +sa12308r: +; call UpdateArithStuff + mov al,[SA1ARR1+2] + ret +sa12309r: +; call UpdateArithStuff + mov al,[SA1ARR1+3] + ret +sa1230Ar: +; call UpdateArithStuff + mov al,[SA1ARR2] + ret +sa1230Br: + mov al,[SA1Overflow] + ret + +NEWSYM IRamRead + mov al,[IRAM+ecx-3000h] + ret + +NEWSYM IRamWrite + mov [IRAM+ecx-3000h],al + ret +NEWSYM IRamWrite2 + mov [IRAM+ecx-3000h],al + xor dh,dh + ret + +NEWSYM sa1223Fw + mov [SA1Overflow+1],al + ret + +; Variable Length Data +NEWSYM sa12258w + mov [VarLenBarrel+2],al + mov bl,al + and bl,0Fh + cmp bl,0 + jne .not0 + mov bl,16 +.not0 + mov [VarLenBarrel+3],bl + test al,80h + jz .notchange + mov [VarLenBarrel],bl + mov [VarLenBarrel+1],bl +.notchange + ret +NEWSYM sa12259w + mov [VarLenAddr],al + mov [VarLenAddrB],al + mov byte[VarLenBarrel],0 + mov byte[VarLenBarrel+1],0 + ret +NEWSYM sa1225Aw + mov [VarLenAddr+1],al + mov [VarLenAddrB+1],al + mov byte[VarLenBarrel],0 + mov byte[VarLenBarrel+1],0 + ret +NEWSYM sa1225Bw + mov [VarLenAddr+2],al + mov [VarLenAddrB+2],al + mov byte[VarLenBarrel],0 + mov byte[VarLenBarrel+1],0 + ret + +; Variable Length Read +NEWSYM sa1230Cr + push ecx + xor ebx,ebx + xor ecx,ecx + mov bl,[VarLenAddr+2] + mov cx,[VarLenAddr] + test ecx,8000h + jz .loweraddr + add ecx,[snesmmap+ebx*4] + jmp .upperaddr +.loweraddr + add ecx,[snesmap2+ebx*4] +.upperaddr + mov ebx,[ecx] + mov cl,[VarLenBarrel+1] + shr ebx,cl + mov al,bl + pop ecx + test byte[VarLenBarrel+2],80h + jnz .autoinc + ret +.autoinc + mov bl,[VarLenBarrel+3] + add [VarLenBarrel],bl + mov bl,[VarLenBarrel] + cmp bl,16 + jbe .notover + sub byte[VarLenBarrel],16 + add dword[VarLenAddr],2 + mov byte[VarLenAddr+3],0 +.notover + ret + +NEWSYM sa1230Dr + push ecx + xor ebx,ebx + xor ecx,ecx + mov bl,[VarLenAddrB+2] + mov cx,[VarLenAddrB] + test ecx,8000h + jz .loweraddr + add ecx,[snesmmap+ebx*4] + jmp .upperaddr +.loweraddr + add ecx,[snesmap2+ebx*4] +.upperaddr + mov ebx,[ecx] + mov cl,[VarLenBarrel+1] + shr ebx,cl + mov al,bh + pop ecx + test byte[VarLenBarrel+2],80h + jnz .autoinc + ret +.autoinc + mov bl,[VarLenBarrel+3] + add [VarLenBarrel+1],bl + mov bl,[VarLenBarrel+1] + cmp bl,16 + jbe .notover + sub byte[VarLenBarrel+1],16 + add dword[VarLenAddrB],2 + mov byte[VarLenAddrB+3],0 +.notover + ret + +NEWSYM sa1230Er + mov al,10h + ret + +; Approximate H loc +NEWSYM sa12302r + test byte[SA1TimerSet],80h + jnz .timeron + mov al,byte[CurrentExecSA1] + shl al,2 + add al,dh + ret +.timeron + mov al,[SA1TimerCount] + ret +NEWSYM sa12303r + test byte[SA1TimerSet],80h + jnz .timeron + mov al,byte[CurrentExecSA1] + shr al,3 + ret +.timeron + mov al,[SA1TimerCount+1] + and al,1 + ret +NEWSYM sa12304r + test byte[SA1TimerSet],80h + jnz .timeron + mov al,[curypos] + ret +.timeron + mov bx,[SA1TimerCount+1] + shr bx,1 + mov al,bl + ret +NEWSYM sa12305r + test byte[SA1TimerSet],80h + jnz .timeron + mov al,[curypos+1] + ret +.timeron + mov bx,[SA1TimerCount+2] + shr bx,1 + mov al,bl + and al,1 + ret + +NEWSYM sa12210w ; Timer Settings + mov [SA1TimerSet],al + ret +NEWSYM sa12211w ; Timer Clear + mov dword[SA1TimerVal],0 + ret +NEWSYM sa12212w + mov [SA1TimerCount],al + ret +NEWSYM sa12213w + mov [SA1TimerCount+1],al + ret +NEWSYM sa12214w + mov [SA1TimerCount+2],al + ret +NEWSYM sa12215w + mov [SA1TimerCount+3],al + ret + +NEWSYM sa12230w + mov [SA1DMAInfo],al + ret +NEWSYM sa12231w + mov [SA1DMAChar],al + ; if b7=1, then end of chdma process + ret +SA1QuickF sa12232w, SA1DMASource +SA1QuickF sa12233w, SA1DMASource+1 +SA1QuickF sa12234w, SA1DMASource+2 +SA1QuickF sa12235w, SA1DMADest +NEWSYM sa12236w + mov [SA1DMADest+1],al + test byte[SA1DMAInfo],10h + jnz near sa1chconv + test byte[SA1DMAInfo],4 + jnz .noiram + jmp sa1dmairam +.noiram + ret +NEWSYM sa12237w + mov [SA1DMADest+2],al + test byte[SA1DMAInfo],10h + jnz .nobwram + test byte[SA1DMAInfo],4 + jz .nobwram + jmp sa1dmabwram +.nobwram + ret +NEWSYM sa12238w + mov [SA1DMACount],al + ret +NEWSYM sa12239w + mov [SA1DMACount+1],al + ret + +NEWSYM sa1dmaptr, dd 0 +NEWSYM sa1dmaptrs, dd 0 + +NEWSYM sa1dmairam + mov ebx,[SA1DMADest] + and ebx,7FFh + add ebx,IRAM + mov [sa1dmaptr],ebx + jmp executesa1dma +NEWSYM sa1dmabwram + mov ebx,[SA1DMADest] + and ebx,3FFFFh + add ebx,[SA1RAMArea] + mov [sa1dmaptr],ebx +executesa1dma: + test byte[SA1DMAInfo],1 + jz .nobwram + mov ebx,[SA1DMASource] + and ebx,3FFFFh + add ebx,[SA1RAMArea] + mov [sa1dmaptrs],ebx + jmp .doneram +.nobwram + test byte[SA1DMAInfo],2 + jz .noiram + mov ebx,[SA1DMASource] + and ebx,7FFh + add ebx,IRAM + mov [sa1dmaptrs],ebx + jmp .doneram +.noiram + xor ebx,ebx + mov bl,[SA1DMASource+2] + mov ebx,[snesmmap+ebx*4] + push ecx + xor ecx,ecx + mov cx,[SA1DMASource] + add ebx,ecx + mov [sa1dmaptrs],ebx + pop ecx +.doneram + push edx + push eax + push ecx + mov ecx,[SA1DMACount] + or ecx,ecx + jz .notransfer + mov ebx,[sa1dmaptrs] + mov edx,[sa1dmaptr] +.loop + mov al,[ebx] + mov [edx],al + inc ebx + inc edx + loop .loop +.notransfer + pop ecx + pop eax + pop edx + ret + +; Character Conversion DMA +sa1chconv: +; or byte[SA1DoIRQ],4 + or byte[SA1DoIRQ],8 + ret + + mov ebx,[SA1DMADest] + mov byte[debstop4],1 +; and ebx,7FFh + and ebx,3FFFFh + add ebx,[SA1RAMArea] + mov [sa1dmaptr],ebx + mov ebx,[SA1DMASource] + and ebx,3FFFFh + add ebx,[SA1RAMArea] + mov [sa1dmaptrs],ebx + ; 4 colors = 32 bytes, 16 colors = 64 bytes, 256 colors = 128 bytes + ; SA1DMAChar,bit 2-4 = # of 8x8 tiles/horizontal row (0=1,1=2,2=3,..,5=32) + ; SA1DMAChar,bit 0-1 = Color Mode (0=8b,1=4b,2=2b,3=?) + test byte[SA1DMAChar],1 + jnz .4bit + test byte[SA1DMAChar],2 + jnz .2bit + mov ebx,[sa1dmaptr] + push ecx + pop ecx + ret +.4bit + mov ebx,[sa1dmaptr] + push ecx + pop ecx + ret +.2bit + push ecx + mov ecx,8 + mov ebx,[sa1dmaptr] + push edx + mov edx,[sa1dmaptrs] +; sub ebx,1000h + jmp .skipall + mov ecx,1000h +.loops + and edx,07FFh + mov al,[ebx] + mov [IRAM+edx],al + inc ebx + inc edx + loop .loops + pop edx + pop ecx + ret +.skipall + jmp .conv + ; repeat for 320 tiles + mov ecx,320 +.chl2 + mov al,[ebx] + mov dword[.numrows],16 +.chl + mov [edx],al + inc edx + dec dword[.numrows] + jne .chl + inc ebx + dec ecx + jnz .chl2 + pop edx + pop ecx + ret + ; Convert 10 rows into bitplane from ebx to edx +.conv + mov dword[.numrows],10 +.cloop3 + mov ch,32 +.cloop + mov cl,8 +.cloop2 + mov ax,[ebx] + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ax,ax + rcl byte[edx+8],1 + add ax,ax + rcl byte[edx],1 + add ebx,64 + inc edx + dec cl + jnz near .cloop2 + add edx,8 + sub ebx,64*8-2 + dec ch + jnz near .cloop + sub ebx,2*32 + add ebx,8*64 + dec dword[.numrows] + jnz near .cloop3 + pop edx + pop ecx + + mov ebx,[sa1dmaptr] + push ecx + mov ecx,32 +.loop +; mov dword[IRAM+ebx],0FFFFFFFFh + add ebx,4 + loop .loop + pop ecx + ret +.numrows dd 0 + +NEWSYM initSA1regs + setreg 2300h*4,sa12300r + setreg 2301h*4,sa12301r + setreg 2302h*4,sa12302r + setreg 2303h*4,sa12303r + setreg 2304h*4,sa12304r + setreg 2305h*4,sa12305r + setreg 2306h*4,sa12306r + setreg 2307h*4,sa12307r + setreg 2308h*4,sa12308r + setreg 2309h*4,sa12309r + setreg 230Ah*4,sa1230Ar + setreg 230Bh*4,sa1230Br + setreg 230Ch*4,sa1230Cr + setreg 230Dh*4,sa1230Dr + setreg 230Eh*4,sa1230Er + ; Set IRam, memory address 3000-37FF + + mov edi,3000h*4 + add edi,[regptr] + mov eax,IRamRead + mov ecx,800h +.loopr + mov [edi],eax + add edi,4 + loop .loopr + ret + +NEWSYM initSA1regsw + setregw 2200h*4,sa12200w + setregw 2201h*4,sa12201w + setregw 2202h*4,sa12202w + setregw 2203h*4,sa12203w + setregw 2204h*4,sa12204w + setregw 2205h*4,sa12205w + setregw 2206h*4,sa12206w + setregw 2207h*4,sa12207w + setregw 2208h*4,sa12208w + setregw 2209h*4,sa12209w + setregw 220Ah*4,sa1220Aw + setregw 220Bh*4,sa1220Bw + setregw 220Ch*4,sa1220Cw + setregw 220Dh*4,sa1220Dw + setregw 220Eh*4,sa1220Ew + setregw 220Fh*4,sa1220Fw + setregw 2210h*4,sa12210w + setregw 2211h*4,sa12211w + setregw 2212h*4,sa12212w + setregw 2213h*4,sa12213w + setregw 2214h*4,sa12214w + setregw 2215h*4,sa12215w + + setregw 2220h*4,sa12220w + setregw 2221h*4,sa12221w + setregw 2222h*4,sa12222w + setregw 2223h*4,sa12223w + + setregw 2224h*4,sa12224w + setregw 2225h*4,sa12225w + + setregw 2230h*4,sa12230w + setregw 2231h*4,sa12231w + setregw 2232h*4,sa12232w + setregw 2233h*4,sa12233w + setregw 2234h*4,sa12234w + setregw 2235h*4,sa12235w + setregw 2236h*4,sa12236w + setregw 2237h*4,sa12237w + setregw 2238h*4,sa12238w + setregw 2239h*4,sa12239w + setregw 223Fh*4,sa1223Fw + + setregw 2250h*4,sa12250w + setregw 2251h*4,sa12251w + setregw 2252h*4,sa12252w + setregw 2253h*4,sa12253w + setregw 2254h*4,sa12254w + + setregw 2259h*4,sa12259w + setregw 225Ah*4,sa1225Aw + setregw 225Bh*4,sa1225Bw + + mov edi,3000h*4 + add edi,[regptw] + mov eax,IRamWrite + mov ecx,800h +.loopw + mov [edi],eax + add edi,4 + loop .loopw + setregw 3000h*4,IRamWrite2 + ret + +NEWSYM SDD1Reset + setregw 4801h*4,sdd14801w + setregw 4802h*4,dbstop + setregw 4803h*4,dbstop + setregw 4804h*4,sdd14804w + setregw 4805h*4,sdd14805w + setregw 4806h*4,sdd14806w + setregw 4807h*4,sdd14807w + setregw 4808h*4,dbstop + setregw 4809h*4,dbstop + setregw 480Ah*4,dbstop + setregw 480Bh*4,dbstop + setregw 480Ch*4,dbstop + setregw 480Dh*4,dbstop + setregw 480Eh*4,dbstop + setregw 480Fh*4,dbstop + ret + +NEWSYM initSDD1regs + setreg 4804h*4,sdd14804 + setreg 4805h*4,sdd14805 + setreg 4806h*4,sdd14806 + setreg 4807h*4,sdd14807 + ret + +dbstop: + mov byte[debstop3],1 + ret + +NEWSYM sdd14801w + cmp al,0 + jne .notzero + ret +.notzero + mov byte[AddrNoIncr],0 + ; set banks C0h-FFh to decompressing routine + push eax + push ebx + mov eax,memtabler8+0C0h*4 + mov ebx,40h +.loop + mov dword[eax],memaccessbankr8sdd1 + add eax,4 + dec ebx + jnz .loop + mov dword[Sdd1Mode],1 + pop ebx + pop eax + ret + \ No newline at end of file diff --git a/zsnes/src/chips/sfxproc.asm b/zsnes/src/chips/sfxproc.asm new file mode 100644 index 00000000..c7c849e0 --- /dev/null +++ b/zsnes/src/chips/sfxproc.asm @@ -0,0 +1,670 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM NumberOfOpcodes,SfxB,SfxBRAMR,SfxCBR,SfxCFGR,SfxCLSR,SfxCPB,SfxCROM +EXTSYM SfxCarry,SfxMemTable,SfxOverflow,SfxPBR,SfxPIPE,SfxR0,SfxR1,SfxR10 +EXTSYM SfxR11,SfxR12,SfxR13,SfxR14,SfxR15,SfxR2,SfxR3,SfxR4,SfxR5,SfxR6 +EXTSYM SfxR7,SfxR8,SfxR9,SfxRAMBR,SfxRAMMem,SfxROMBR,SfxSCBR,SfxSCMR,SfxSFR +EXTSYM SfxSignZero,SfxnRamBanks,StartSFX,regptr,regptw,sfxramdata,ChangeOps +EXTSYM SfxPOR,sfxclineloc,UpdatePORSCMR,UpdateCLSR,UpdateSCBRCOLR,SfxAC +EXTSYM sfx128lineloc,sfx160lineloc,sfx192lineloc,sfxobjlineloc,SFXProc + +%include "cpu\regs.mac" +%include "cpu\regsw.mac" + + + + + + +%macro AssembleSFXFlags 0 + and word[SfxSFR],8F60h + test byte[SfxCarry],1 + jz .nosfxcarry + or word[SfxSFR],04h +.nosfxcarry + cmp word[SfxSignZero],0 + jne .nozero + or word[SfxSFR],02h +.nozero + test word[SfxSignZero],8000h + jz .noneg + or word[SfxSFR],08h +.noneg + cmp byte[SfxOverflow],0 + je .noof + or word[SfxSFR],10h +.noof + cmp byte[SfxB],0 + je .bzero + or word[SfxSFR],1000h +.bzero +%endmacro + + +NEWSYM initsfxregsr + setreg 3000h*4,reg3000r + setreg 3001h*4,reg3001r + setreg 3002h*4,reg3002r + setreg 3003h*4,reg3003r + setreg 3004h*4,reg3004r + setreg 3005h*4,reg3005r + setreg 3006h*4,reg3006r + setreg 3007h*4,reg3007r + setreg 3008h*4,reg3008r + setreg 3009h*4,reg3009r + setreg 300Ah*4,reg300Ar + setreg 300Bh*4,reg300Br + setreg 300Ch*4,reg300Cr + setreg 300Dh*4,reg300Dr + setreg 300Eh*4,reg300Er + setreg 300Fh*4,reg300Fr + setreg 3010h*4,reg3010r + setreg 3011h*4,reg3011r + setreg 3012h*4,reg3012r + setreg 3013h*4,reg3013r + setreg 3014h*4,reg3014r + setreg 3015h*4,reg3015r + setreg 3016h*4,reg3016r + setreg 3017h*4,reg3017r + setreg 3018h*4,reg3018r + setreg 3019h*4,reg3019r + setreg 301Ah*4,reg301Ar + setreg 301Bh*4,reg301Br + setreg 301Ch*4,reg301Cr + setreg 301Dh*4,reg301Dr + setreg 301Eh*4,reg301Er + setreg 301Fh*4,reg301Fr + setreg 3030h*4,reg3030r + setreg 3031h*4,reg3031r + setreg 3032h*4,reg3032r + setreg 3033h*4,reg3033r + setreg 3034h*4,reg3034r + setreg 3035h*4,reg3035r + setreg 3036h*4,reg3036r + setreg 3037h*4,reg3037r + setreg 3038h*4,reg3038r + setreg 3039h*4,reg3039r + setreg 303Ah*4,reg303Ar + setreg 303Bh*4,reg303Br + setreg 303Ch*4,reg303Cr + setreg 303Dh*4,reg303Dr + setreg 303Eh*4,reg303Er + setreg 303Fh*4,reg303Fr + ; set 3100-31FF to cacheregr + mov edi,3100h*4 + add edi,[regptr] + mov eax,cacheregr + mov ecx,200h +.loop + mov [edi],eax + add edi,4 + dec ecx + jnz .loop + ret + +NEWSYM initsfxregsw + setregw 3000h*4,reg3000w + setregw 3001h*4,reg3001w + setregw 3002h*4,reg3002w + setregw 3003h*4,reg3003w + setregw 3004h*4,reg3004w + setregw 3005h*4,reg3005w + setregw 3006h*4,reg3006w + setregw 3007h*4,reg3007w + setregw 3008h*4,reg3008w + setregw 3009h*4,reg3009w + setregw 300Ah*4,reg300Aw + setregw 300Bh*4,reg300Bw + setregw 300Ch*4,reg300Cw + setregw 300Dh*4,reg300Dw + setregw 300Eh*4,reg300Ew + setregw 300Fh*4,reg300Fw + setregw 3010h*4,reg3010w + setregw 3011h*4,reg3011w + setregw 3012h*4,reg3012w + setregw 3013h*4,reg3013w + setregw 3014h*4,reg3014w + setregw 3015h*4,reg3015w + setregw 3016h*4,reg3016w + setregw 3017h*4,reg3017w + setregw 3018h*4,reg3018w + setregw 3019h*4,reg3019w + setregw 301Ah*4,reg301Aw + setregw 301Bh*4,reg301Bw + setregw 301Ch*4,reg301Cw + setregw 301Dh*4,reg301Dw + setregw 301Eh*4,reg301Ew + setregw 301Fh*4,reg301Fw + setregw 3030h*4,reg3030w + setregw 3031h*4,reg3031w + setregw 3032h*4,reg3032w + setregw 3033h*4,reg3033w + setregw 3034h*4,reg3034w + setregw 3035h*4,reg3035w + setregw 3036h*4,reg3036w + setregw 3037h*4,reg3037w + setregw 3038h*4,reg3038w + setregw 3039h*4,reg3039w + setregw 303Ah*4,reg303Aw + setregw 303Bh*4,reg303Bw + setregw 303Ch*4,reg303Cw + setregw 303Dh*4,reg303Dw + setregw 303Eh*4,reg303Ew + setregw 303Fh*4,reg303Fw + ; set 3100-31FF to cacheregw + mov edi,3100h*4 + add edi,[regptw] + mov eax,cacheregw + mov ecx,200h +.loop + mov [edi],eax + add edi,4 + dec ecx + jnz .loop + ret + +NEWSYM cacheregr + or byte[cachewarning],1 + ret + +NEWSYM cacheregw + or byte[cachewarning],2 + ret + +NEWSYM cachewarning, db 0 + +; SFX Registers + +NEWSYM reg3000r + mov al,[SfxR0] + ret +NEWSYM reg3001r + mov al,[SfxR0+1] + ret +NEWSYM reg3002r + mov al,[SfxR1] + ret +NEWSYM reg3003r + mov al,[SfxR1+1] + ret +NEWSYM reg3004r + mov al,[SfxR2] + ret +NEWSYM reg3005r + mov al,[SfxR2+1] + ret +NEWSYM reg3006r + mov al,[SfxR3] + ret +NEWSYM reg3007r + mov al,[SfxR3+1] + ret +NEWSYM reg3008r + mov al,[SfxR4] + ret +NEWSYM reg3009r + mov al,[SfxR4+1] + ret +NEWSYM reg300Ar + mov al,[SfxR5] + ret +NEWSYM reg300Br + mov al,[SfxR5+1] + ret +NEWSYM reg300Cr + mov al,[SfxR6] + ret +NEWSYM reg300Dr + mov al,[SfxR6+1] + ret +NEWSYM reg300Er + mov al,[SfxR7] + ret +NEWSYM reg300Fr + mov al,[SfxR7+1] + ret +NEWSYM reg3010r + mov al,[SfxR8] + ret +NEWSYM reg3011r + mov al,[SfxR8+1] + ret +NEWSYM reg3012r + mov al,[SfxR9] + ret +NEWSYM reg3013r + mov al,[SfxR9+1] + ret +NEWSYM reg3014r + mov al,[SfxR10] + ret +NEWSYM reg3015r + mov al,[SfxR10+1] + ret +NEWSYM reg3016r + mov al,[SfxR11] + ret +NEWSYM reg3017r + mov al,[SfxR11+1] + ret +NEWSYM reg3018r + mov al,[SfxR12] + ret +NEWSYM reg3019r + mov al,[SfxR12+1] + ret +NEWSYM reg301Ar + mov al,[SfxR13] + ret +NEWSYM reg301Br + mov al,[SfxR13+1] + ret +NEWSYM reg301Cr + mov al,[SfxR14] + ret +NEWSYM reg301Dr + mov al,[SfxR14+1] + ret +NEWSYM reg301Er + mov al,[SfxR15] + ret +NEWSYM reg301Fr + mov al,[SfxR15+1] + ret + +; Other SFX stuff + +NEWSYM reg3030r + AssembleSFXFlags + mov al,[SfxSFR] + ret +NEWSYM reg3031r + cmp byte[SfxAC],1 + je .alwaysclear + cmp dword[ChangeOps],-350*240 + jl .noclear +.alwaysclear + and byte[SfxSFR+1],07fh ; clear IRQ flag + jmp .cleared +.noclear + cmp dword[ChangeOps],-350*240*4 + jge .clear + mov dword[ChangeOps],-350*240*4 + jmp .cleared +.clear + add dword[ChangeOps],350*240 +.cleared + mov al,[SfxSFR+1] + ret +.test db 0 +NEWSYM reg3032r ; Unused + xor al,al + ret +NEWSYM reg3033r ; BRAMR Backup Ram Read only on/off (bits 1-15 unused) + mov al,[SfxBRAMR] + ret +NEWSYM reg3034r ; PBR (Program Bank) + mov al,[SfxPBR] + ret +NEWSYM reg3035r ; Unused + xor al,al + ret +NEWSYM reg3036r ; ROMBR (Gamepak Rom Bank Register) + mov al,[SfxROMBR] + ret +NEWSYM reg3037r ; CFGR (Control Flags Register) + mov al,[SfxCFGR] + ret +NEWSYM reg3038r ; SCBR (Screen Bank Register) + mov al,[SfxSCBR] + ret +NEWSYM reg3039r ; CLSR (Clock Speed Register) + mov al,[SfxCLSR] + ret +NEWSYM reg303Ar ; SCMR (Screen Mode Register) + mov al,[SfxSCMR] + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + ret +NEWSYM reg303Br ; VCR (Version Code Register) + mov al,20h + ret +NEWSYM reg303Cr ; RAMBR (Ram bank register) + mov al,[SfxRAMBR] + ret +NEWSYM reg303Dr ; Unused + xor al,al + ret +NEWSYM reg303Er ; CBR (Cache Base Register), lower byte + mov al,[SfxCBR] + ret +NEWSYM reg303Fr ; CBR (Cache Base Register), upper byte + mov al,[SfxCBR+1] + ret + +; SFX Write Registers + +NEWSYM reg3000w + mov [SfxR0],al + ret +NEWSYM reg3001w + mov [SfxR0+1],al + ret +NEWSYM reg3002w + mov [SfxR1],al + ret +NEWSYM reg3003w + mov [SfxR1+1],al + ret +NEWSYM reg3004w + mov [SfxR2],al + ret +NEWSYM reg3005w + mov [SfxR2+1],al + ret +NEWSYM reg3006w + mov [SfxR3],al + ret +NEWSYM reg3007w + mov [SfxR3+1],al + ret +NEWSYM reg3008w + mov [SfxR4],al + ret +NEWSYM reg3009w + mov [SfxR4+1],al + ret +NEWSYM reg300Aw + mov [SfxR5],al + ret +NEWSYM reg300Bw + mov [SfxR5+1],al + ret +NEWSYM reg300Cw + mov [SfxR6],al + ret +NEWSYM reg300Dw + mov [SfxR6+1],al + ret +NEWSYM reg300Ew + mov [SfxR7],al + ret +NEWSYM reg300Fw + mov [SfxR7+1],al + ret +NEWSYM reg3010w + mov [SfxR8],al + ret +NEWSYM reg3011w + mov [SfxR8+1],al + ret +NEWSYM reg3012w + mov [SfxR9],al + ret +NEWSYM reg3013w + mov [SfxR9+1],al + ret +NEWSYM reg3014w + mov [SfxR10],al + ret +NEWSYM reg3015w + mov [SfxR10+1],al + ret +NEWSYM reg3016w + mov [SfxR11],al + ret +NEWSYM reg3017w + mov [SfxR11+1],al + ret +NEWSYM reg3018w + mov [SfxR12],al + ret +NEWSYM reg3019w + mov [SfxR12+1],al + ret +NEWSYM reg301Aw + mov [SfxR13],al + ret +NEWSYM reg301Bw + mov [SfxR13+1],al + ret +NEWSYM reg301Cw + mov [SfxR14],al + ret +NEWSYM reg301Dw + mov [SfxR14+1],al + ret +NEWSYM reg301Ew + mov [SfxR15],al + ret +NEWSYM reg301Fw + mov [SfxR15+1],al + ; start execution + push edx + mov edx,[SfxPBR] + mov edx,[SfxMemTable+edx*4] + add edx,[SfxR15] + mov dl,[edx] + mov [SfxPIPE],dl + pop edx + inc word[SfxR15] + or byte[SfxSFR],20h + or dword [SfxSFR],08000h ; Set IRQ Flag + mov dword[SFXProc],1 +; call StartSFXret + ret + +; Other SFX stuff + +NEWSYM reg3030w + mov [SfxSFR],al +; mov dh,10 + ; Disassemble Flags + test al,20h + jz .noexec + pushad + mov dword [NumberOfOpcodes],100 + call StartSFX + popad +.noexec + ret +NEWSYM reg3031w + mov [SfxSFR+1],al + ret +NEWSYM reg3032w ; Unused + ret +NEWSYM reg3033w ; BRAMR Backup Ram Read only on/off (bits 1-15 unused) + and al,0FEh + mov [SfxBRAMR],al + ret +NEWSYM reg3034w ; PBR (Program Bank) + mov [SfxPBR],al + xor ebx,ebx + mov bl,al + mov ebx,[SfxMemTable+ebx*4] + mov [SfxCPB],ebx + ret +NEWSYM reg3035w ; Unused + ret +NEWSYM reg3036w ; ROMBR (Gamepak Rom Bank Register) + mov [SfxROMBR],al + xor ebx,ebx + mov bl,al + mov ebx,[SfxMemTable+ebx*4] + mov [SfxCROM],ebx + ret +NEWSYM reg3037w ; CFGR (Control Flags Register) + mov [SfxCFGR],al + ret +NEWSYM reg3038w ; SCBR (Screen Bank Register) + mov [SfxSCBR],al + call UpdateSCBRCOLR + ret +NEWSYM reg3039w ; CLSR (Clock Speed Register) + and al,0FEh + mov [SfxCLSR],al + call UpdateCLSR + ret +NEWSYM reg303Aw ; SCMR (Screen Mode Register) + mov [SfxSCMR],al + call UpdatePORSCMR + ret +NEWSYM reg303Bw ; VCR (Version Code Register) + ret +NEWSYM reg303Cw ; RAMBR (Ram bank register) + mov bl,[SfxnRamBanks] + dec bl + and al,bl + mov ebx,[SfxnRamBanks] + dec ebx + and eax,ebx + mov [SfxRAMBR],eax + xor ebx,ebx + mov bl,al + shl ebx,16 + add ebx,[sfxramdata] + mov dword [SfxRAMMem],ebx + ret +NEWSYM reg303Dw ; Unused + ret +NEWSYM reg303Ew ; CBR (Cache Base Register), lower byte + mov [SfxCBR],al + ret +NEWSYM reg303Fw ; CBR (Cache Base Register), upper byte + mov [SfxCBR+1],al + ret + +NEWSYM sfxaccessbankr8 + mov ebx,[sfxramdata] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw8 + mov ebx,[sfxramdata] + mov [ebx+ecx],al + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr16 + mov ebx,[sfxramdata] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw16 + mov ebx,[sfxramdata] + mov [ebx+ecx],ax + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr8b + mov ebx,[sfxramdata] + mov al,[ebx+ecx+65536] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw8b + mov ebx,[sfxramdata] + mov [ebx+ecx+65536],al + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr16b + mov ebx,[sfxramdata] + mov ax,[ebx+ecx+65536] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw16b + mov ebx,[sfxramdata] + mov [ebx+ecx+65536],ax + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr8c + mov ebx,[sfxramdata] + mov al,[ebx+ecx+65536*2] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw8c + mov ebx,[sfxramdata] + mov [ebx+ecx+65536*2],al + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr16c + mov ebx,[sfxramdata] + mov ax,[ebx+ecx+65536*2] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw16c + mov ebx,[sfxramdata] + mov [ebx+ecx+65536*2],ax + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr8d + mov ebx,[sfxramdata] + mov al,[ebx+ecx+65536*3] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw8d + mov ebx,[sfxramdata] + mov [ebx+ecx+65536*3],al + xor ebx,ebx + ret + +NEWSYM sfxaccessbankr16d + mov ebx,[sfxramdata] + mov ax,[ebx+ecx+65536*3] + xor ebx,ebx + ret + +NEWSYM sfxaccessbankw16d + mov ebx,[sfxramdata] + mov [ebx+ecx+65536*3],ax + xor ebx,ebx + ret + + \ No newline at end of file diff --git a/zsnes/src/cpu/65816d.inc b/zsnes/src/cpu/65816d.inc new file mode 100644 index 00000000..86f9a3dc --- /dev/null +++ b/zsnes/src/cpu/65816d.inc @@ -0,0 +1,1623 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM flagnz, flago, flagc, execloopdeb +EXTSYM Sjoinflags,Ssplitflags,SA1RegP + + + + + + +;******************************************************* +; Flag Setting Macros +;******************************************************* + + +%macro endloop 0 + jmp execloopdeb +%endmacro + +%macro restoredl 0 + mov dword[flagnz],0 + test dl,80h + jz %%noneg + or dword[flagnz],10000h +%%noneg + test dl,2h + jnz %%zero + or dword[flagnz],1 +%%zero + mov dword[flagc],0 + test dl,01h + jz %%nocarry + mov dword[flagc],0FFh +%%nocarry + mov dword[flago],0 + test dl,40h + jz %%nov + mov dword[flago],0FFh +%%nov +%endmacro + +%macro makedl 0 + and dl,00111100b + test dword[flagnz],18000h + jz %%noneg + or dl,80h +%%noneg + test dword[flagnz],0FFFFh + jnz %%nozero + or dl,02h +%%nozero + test dword[flagc],0FFh + jz %%nocarry + or dl,01h +%%nocarry + test dword[flago],0FFh + jz %%nov + or dl,40h +%%nov +%endmacro + +NEWSYM splitflags + push edx + mov dl,[SA1RegP] + call Ssplitflags + pop edx + restoredl + ret + +NEWSYM joinflags + makedl + push edx + mov dl,[SA1RegP] + call Sjoinflags + mov [SA1RegP],dl + pop edx + ret + +; Sets flags n and z according to al +%macro flagsetnz8b 0 + mov dword[flagnz],0 + mov [flagnz+1],al + endloop +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16b 0 + mov cx,ax + mov [flagnz],ecx + endloop +%endmacro + +; Sets flags n and z according to al +%macro flagsetnz8bnel 0 + mov dword[flagnz],0 + mov [flagnz+1],al +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16bnel 0 + mov cx,ax + mov [flagnz],ecx +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzc8b 0 + mov dword[flagnz],0 + mov al,[xa] + seto byte[flago] + mov [flagnz+1],al + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +%macro flagsetnvzc16b 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzcs8b 0 + mov dword[flagnz],0 + mov al,[xa] + seto byte[flago] + mov [flagnz+1],al + jc .carry + mov dword[flagc],0FFh + endloop +.carry + mov dword[flagc],0h + endloop +%endmacro + +%macro flagsetnvzcs16b 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0FFh + endloop +.carry + mov dword[flagc],0h + endloop +%endmacro + +; Sets flags N V . . . . Z C for 16-bit decimal mode only +%macro flagsetnvzcd 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc8b 0 + mov dword[flagnz],0 + mov dword[flagc],0h + mov [flagnz+1],al + jnc .carry + mov dword[flagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc 0 + mov cx,ax + mov dword[flagc],0h + mov [flagnz],ecx + jnc .carry + mov dword[flagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and jump to execloop +%macro flagsetnzcel8b 0 + mov dword[flagnz],0h + jc .carry + mov [flagnz+1],cl + mov dword[flagc],0FFh + endloop +.carry + mov [flagnz+1],cl + mov dword[flagc],0h + endloop +%endmacro + +%macro flagsetnzcel16b 0 + jc .carry + mov [flagnz],ecx + mov dword[flagc],0FFh + endloop +.carry + mov [flagnz],ecx + mov dword[flagc],0h + endloop +%endmacro + +;******************************************************* +; Opcode Instructions +;******************************************************* + +%macro ADCMacro8bnd 0 + mov cl,[flagc] + add cl,cl + adc [xa],al + flagsetnvzc8b +%endmacro + +%macro ADCMacro16bnd 0 + mov cl,[flagc] + add cl,cl + adc [xa],ax + flagsetnvzc16b +%endmacro + +%macro ADCMacro8bd 0 + mov cl,[flagc] + add cl,cl + mov cl,al + mov al,[xa] + adc al,cl + daa + mov [xa],al + flagsetnvzc8b + endloop +%endmacro + +%macro ADCMacro16bd 0 + mov cl,[flagc] + add cl,cl + mov cx,ax + mov al,[xa] + adc al,cl + daa + mov [xa],al + mov al,[xa+1] + adc al,ch + daa + mov [xa+1],al + flagsetnvzcd +%endmacro + +%macro ANDMacro8b 0 + and al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro ANDMacro16b 0 + and eax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro ASLMacro8b 0 + add al,al + flagsetnzc8b +%endmacro + +%macro ASLMacro16b 0 + add ax,ax + flagsetnzc +%endmacro + +%macro JumpMacro 0 + movsx eax,byte[esi] + add esi,eax +.skip + inc esi + endloop +%endmacro + +%macro BITMacroim8b 0 + mov al,[esi] + test dword[flagnz],18000h + jz .notflagnz + or dword[flagnz],10000h +.notflagnz + inc esi + test [xa],al + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacroim16b 0 + mov ax,[esi] + test dword[flagnz],18000h + jz .notflagnz + or dword[flagnz],10000h +.notflagnz + add esi,2 + test [xa],ax + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacro8b 0 + mov dword[flagnz],10000h + test al,80h + jnz .flagn + mov dword[flagnz],0 +.flagn + mov dword[flago],1 + test al,40h + jnz .flago + mov dword[flago],0 +.flago + test [xa],al + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacro16b 0 + mov dword[flagnz],10000h + test ax,8000h + jnz .flagn + mov dword[flagnz],0 +.flagn + mov dword[flago],1 + test ax,4000h + jnz .flago + mov dword[flago],0 +.flago + test [xa],ax + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BRKMacro 0 + inc esi + test byte[xe],1 + jne near BRKemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[brkv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +BRKemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,[xpb] + xor eax,eax + mov ax,[brkv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro BRLMacro 0 + mov ebx,esi + sub ebx,[initaddrl] + add bx,2 + xor eax,eax + add bx,[esi] + mov ax,bx + xor ebx,ebx + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CMPMacro8b 0 + mov cl,[xa] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CMPMacro16b 0 + mov cx,[xa] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro COPMacro 0 + inc esi + test byte[xe],1 + jne near COPemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[copv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +COPemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,[xpb] + xor eax,eax + mov ax,[copv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CPXMacro8b 0 + mov cl,[xx] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPXMacro16b 0 + mov cx,[xx] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro CPYMacro8b 0 + mov cl,[xy] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPYMacro16b 0 + mov cx,[xy] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro EORMacro8b 0 + xor al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro EORMacro16b 0 + xor eax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro JMLMacro 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + add cx,2 + push eax + call membank0r8 + mov bl,al + pop eax + mov [xpc],ax + mov [xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro4C 0 + xor eax,eax + mov ax,[esi] + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr +; mov esi,[snesmap2+ebx*4] +; mov [initaddrl],esi +; add esi,eax +; endloop + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro6C 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro7C 0 + mov cx,[esi] + xor eax,eax + add cx,[xx] + mov bl,[xpb] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro5C 0 + xor eax,eax + mov bl,[esi+2] + mov ax,[esi] + mov [xpb],bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSLMacro 0 + mov ebx,esi + sub ebx,[initaddrl] + add bx,2 + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov [xs],bx + xor eax,eax + xor bh,bh + mov ax,[esi] + mov bl,[esi+2] + mov [xpc],ax + mov [xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacro20 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + xor eax,eax + mov [xs],bx + mov ax,[esi] + xor bh,bh + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacroFC 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov [xs],bx + xor eax,eax + xor bh,bh + mov cx,[esi] + mov bl,[xpb] + add cx,[xx] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro LDAMacro8b 0 + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDAMacro16b 0 + mov [xa],ax + flagsetnz16b + endloop +%endmacro + +%macro LDXMacro8b 0 + mov dword[flagnz],0 + mov [xx],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDXMacro16b 0 + mov [xx],ax + flagsetnz16b + endloop +%endmacro + +%macro LDYMacro8b 0 + mov dword[flagnz],0 + mov [xy],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDYMacro16b 0 + mov [xy],ax + flagsetnz16b + endloop +%endmacro + +%macro LSRMacro8b 0 + shr al,1 + flagsetnzc8b +%endmacro + +%macro LSRMacro16b 0 + shr ax,1 + flagsetnzc +%endmacro + +%macro MVNMacro 0 + mov ax,[esi] + mov [xdb],al + mov bl,ah + mov cx,[xx] + call dword near [memtabler8+ebx*4] + mov bl,[xdb] + mov cx,[xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz .pagezero + inc word[xx] + inc word[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + inc byte[xx] + inc byte[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro MVPMacro 0 + mov ax,[esi] + mov [xdb],al + mov bl,ah + mov cx,[xx] + call dword near [memtabler8+ebx*4] + mov bl,[xdb] + mov cx,[xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz .pagezero + dec word[xx] + dec word[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + dec byte[xx] + dec byte[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro ORAMacro8b 0 + or al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro ORAMacro16b 0 + or ax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro PUSHMacro8b 1 + mov eax,[wramdata] + mov cx,[xs] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PUSHMacro8bp 0 + mov eax,[wramdata] + makedl + mov cx,[xs] + mov al,dl + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PUSHMacro16b 2 + mov cx,[xs] + mov al,%2 + call membank0w8 + dec cx + or cx,word[stackor] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PEAMacro 0 + mov cx,[xs] + mov al,[esi+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[esi] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + add esi,2 + endloop +%endmacro + +%macro PEIMacro 0 + xor ah,ah + mov al,[esi] + mov cx,[xd] + inc esi + add cx,ax + call membank0r16 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PERMacro 0 + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr + mov eax,[snesmmap+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + xor ebx,ebx + endloop +.loweraddr + mov eax,[snesmap2+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + xor ebx,ebx + endloop +%endmacro + +%macro POPMacro8b 1 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [xs],cx + mov %1,al + flagsetnz8b + endloop +%endmacro + +%macro POPMacro16b 2 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + mov [xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacro16bd 2 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + call UpdateDPage + mov [xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacroP 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + mov [xs],bx + xor bh,bh + mov dl,cl + restoredl + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[tablead+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tablead+ebx*4] + endloop +%endmacro + +%macro REPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz .extraflags + not al + and dl,al + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[tablead+ebx*4] + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tablead+ebx*4] + endloop + +.extraflags + not al + makedl + and dl,al + restoredl + test byte[xe],01h + jnz .emul2 + mov bl,dl + mov edi,[tablead+ebx*4] + endloop +.emul2 + or dl,00110000b + mov bl,dl + mov edi,[tablead+ebx*4] + endloop +%endmacro + +%macro ROLMacro8b 0 + mov cl,[flagc] + add cl,cl + rcl al,1 + flagsetnzc8b +%endmacro + +%macro ROLMacro16b 0 + mov cl,[flagc] + add cl,cl + rcl ax,1 + flagsetnzc +%endmacro + +%macro RORMacro8b 0 + mov cl,[flagc] + add cl,cl + rcr al,1 + flagsetnzc8b +%endmacro + +%macro RORMacro16b 0 + mov cl,[flagc] + add cl,cl + rcr ax,1 + flagsetnzc +%endmacro + +%macro RTIMacro 0 + mov byte[doirqnext],0 + cmp byte[nmistatus],3 + jne .nodis658162 + test byte[curexecstate],01h + jz .nodis65816 + and byte[curexecstate],0FEh + call changeexecloop +.nodis65816 + cmp byte[curexecstate],0 + jne .nn + xor dh,dh +.nn +.nodis658162 + mov byte[curnmi],0 + test byte[xe],1 + jne near emulRTI + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov dl,[eax+ebx] + restoredl + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + inc bx + and bx,word[stackand] + mov al,[eax+ebx] + mov [xpb],al + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + mov bl,dl + mov edi,[tablead+ebx*4] + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop + +emulRTI + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov dl,[eax+ebx] + or dl,00110000b + restoredl + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + mov bl,dl + mov edi,[tablead+ebx*4] + xor bl,bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTLMacro 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + inc bx + and bx,word[stackand] + mov al,[eax+ebx] + mov [xpb],al + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + inc ax + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTSMacro 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + inc ax + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro SBCMacro8bnd 0 + mov cl,[flagc] + sub cl,1 + sbb [xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bnd 0 + mov cl,[flagc] + sub cl,1 + sbb [xa],ax + flagsetnvzcs16b + endloop +%endmacro + +%macro SBCMacro8bd 0 + mov cl,[flagc] + sub cl,1 + mov cl,al + mov al,[xa] + sbb al,cl + das + mov [xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bd 0 + mov cl,[flagc] + sub cl,1 + mov cx,ax + mov al,[xa] + sbb al,cl + das + mov [xa],al + mov al,[xa+1] + sbb al,ch + das + mov [xa+1],al + cmc + flagsetnvzcd + endloop +%endmacro + +%macro SEPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz .extraflags + or dl,al + mov bl,dl + mov edi,[tablead+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.extraflags + makedl + or dl,al + restoredl + mov bl,dl + mov edi,[tablead+ebx*4] + test dl,00010000b + jnz .setx2 + endloop +.setx2 + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +%endmacro + +%macro STAMacro8b 0 + mov al,[xa] +%endmacro + +%macro STAMacro16b 0 + mov eax,[xa] +%endmacro + +%macro STXMacro8b 0 + mov al,[xx] +%endmacro + +%macro STXMacro16b 0 + mov eax,[xx] +%endmacro + +%macro STYMacro8b 0 + mov al,[xy] +%endmacro + +%macro STYMacro16b 0 + mov eax,[xy] +%endmacro + +%macro WAIMacro 0 + cmp byte[intrset],1 + jne .notws + dec esi + endloop +.notws + test byte[intrset],0FFh + jz .waitstate + cmp byte[intrset],2 + je .stopint + dec esi + endloop +.waitstate + mov byte[intrset],1 + dec esi + endloop +.stopint + mov byte[intrset],0 + mov byte[doirqnext],0 + endloop +%endmacro + +%macro XCEMacro 0 + mov al,[flagc] + mov dword[flagc],0 + and al,00000001b + cmp [xe],al + jne .nochange + endloop +.nochange + test byte[xe],0FFh + jz .noemul + mov dword[flagc],0FFh +.noemul + mov [xe],al + test byte[xe],01h + jnz .emul + or dl,00100000b + mov word[stackand],0FFFFh + mov word[stackor],0000h + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tablead+ebx*4] + mov byte[xx+1],0 + mov byte[xy+1],0 + mov byte[xs+1],1 + mov word[stackand],01FFh + mov word[stackor],0100h + endloop +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/65816db.inc b/zsnes/src/cpu/65816db.inc new file mode 100644 index 00000000..19b109f0 --- /dev/null +++ b/zsnes/src/cpu/65816db.inc @@ -0,0 +1,1621 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM flagnz, flago, flagc, cpucycle, doirqnext +EXTSYM dmadata + + + + + + +;******************************************************* +; Flag Setting Macros +;******************************************************* + + +%macro endloop 0 + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc %%cpuover + jmp dword near [edi+ebx*4] +%%cpuover + ret +%endmacro + +%macro restoredl 0 + mov dword[flagnz],0 + test dl,80h + jz %%noneg + or dword[flagnz],10000h +%%noneg + test dl,2h + jnz %%zero + or dword[flagnz],1 +%%zero + mov dword[flagc],0 + test dl,01h + jz %%nocarry + mov dword[flagc],0FFh +%%nocarry + mov dword[flago],0 + test dl,40h + jz %%nov + mov dword[flago],0FFh +%%nov +%endmacro + +%macro makedl 0 + and dl,00111100b + test dword[flagnz],18000h + jz %%noneg + or dl,80h +%%noneg + test dword[flagnz],0FFFFh + jnz %%nozero + or dl,02h +%%nozero + test dword[flagc],0FFh + jz %%nocarry + or dl,01h +%%nocarry + test dword[flago],0FFh + jz %%nov + or dl,40h +%%nov +%endmacro + +; Sets flags n and z according to al +%macro flagsetnz8b 0 + mov dword[flagnz],0 + mov [flagnz+1],al + endloop +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16b 0 + mov cx,ax + mov [flagnz],ecx + endloop +%endmacro + +; Sets flags n and z according to al +%macro flagsetnz8bnel 0 + mov dword[flagnz],0 + mov [flagnz+1],al +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16bnel 0 + mov cx,ax + mov [flagnz],ecx +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzc8b 0 + mov dword[flagnz],0 + mov al,[xa] + seto byte[flago] + mov [flagnz+1],al + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +%macro flagsetnvzc16b 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzcs8b 0 + mov dword[flagnz],0 + mov al,[xa] + seto byte[flago] + mov [flagnz+1],al + jc .carry + mov dword[flagc],0FFh + endloop +.carry + mov dword[flagc],0h + endloop +%endmacro + +%macro flagsetnvzcs16b 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0FFh + endloop +.carry + mov dword[flagc],0h + endloop +%endmacro + +; Sets flags N V . . . . Z C for 16-bit decimal mode only +%macro flagsetnvzcd 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc8b 0 + mov dword[flagnz],0 + mov dword[flagc],0h + mov [flagnz+1],al + jnc .carry + mov dword[flagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc 0 + mov cx,ax + mov dword[flagc],0h + mov [flagnz],ecx + jnc .carry + mov dword[flagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and jump to execloop +%macro flagsetnzcel8b 0 + mov dword[flagnz],0h + jc .carry + mov [flagnz+1],cl + mov dword[flagc],0FFh + endloop +.carry + mov [flagnz+1],cl + mov dword[flagc],0h + endloop +%endmacro + +%macro flagsetnzcel16b 0 + jc .carry + mov [flagnz],ecx + mov dword[flagc],0FFh + endloop +.carry + mov [flagnz],ecx + mov dword[flagc],0h + endloop +%endmacro + +;******************************************************* +; Opcode Instructions +;******************************************************* + +%macro ADCMacro8bnd 0 + mov cl,[flagc] + add cl,cl + adc [xa],al + flagsetnvzc8b +%endmacro + +%macro ADCMacro16bnd 0 + mov cl,[flagc] + add cl,cl + adc [xa],ax + flagsetnvzc16b +%endmacro + +%macro ADCMacro8bd 0 + mov cl,[flagc] + add cl,cl + mov cl,al + mov al,[xa] + adc al,cl + daa + mov [xa],al + flagsetnvzc8b + endloop +%endmacro + +%macro ADCMacro16bd 0 + mov cl,[flagc] + add cl,cl + mov cx,ax + mov al,[xa] + adc al,cl + daa + mov [xa],al + mov al,[xa+1] + adc al,ch + daa + mov [xa+1],al + flagsetnvzcd +%endmacro + +%macro ANDMacro8b 0 + and al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro ANDMacro16b 0 + and eax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro ASLMacro8b 0 + add al,al + flagsetnzc8b +%endmacro + +%macro ASLMacro16b 0 + add ax,ax + flagsetnzc +%endmacro + +%macro JumpMacro 0 + movsx eax,byte[esi] + add esi,eax +.skip + inc esi + endloop +%endmacro + +%macro BITMacroim8b 0 + mov al,[esi] + test dword[flagnz],18000h + jz .notflagnz + or dword[flagnz],10000h +.notflagnz + inc esi + test [xa],al + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacroim16b 0 + mov ax,[esi] + test dword[flagnz],18000h + jz .notflagnz + or dword[flagnz],10000h +.notflagnz + add esi,2 + test [xa],ax + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacro8b 0 + mov dword[flagnz],10000h + test al,80h + jnz .flagn + mov dword[flagnz],0 +.flagn + mov dword[flago],1 + test al,40h + jnz .flago + mov dword[flago],0 +.flago + test [xa],al + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacro16b 0 + mov dword[flagnz],10000h + test ax,8000h + jnz .flagn + mov dword[flagnz],0 +.flagn + mov dword[flago],1 + test ax,4000h + jnz .flago + mov dword[flago],0 +.flago + test [xa],ax + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BRKMacro 0 + inc esi + test byte[xe],1 + jne near BRKemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[brkv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +BRKemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,[xpb] + xor eax,eax + mov ax,[brkv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro BRLMacro 0 + mov ax,[xpc] + mov bl,[xpb] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + add bx,2 + xor eax,eax + add bx,[esi] + mov ax,bx + xor ebx,ebx + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CMPMacro8b 0 + mov cl,[xa] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CMPMacro16b 0 + mov cx,[xa] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro COPMacro 0 + inc esi + test byte[xe],1 + jne near COPemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[copv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +COPemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,[xpb] + xor eax,eax + mov ax,[copv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CPXMacro8b 0 + mov cl,[xx] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPXMacro16b 0 + mov cx,[xx] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro CPYMacro8b 0 + mov cl,[xy] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPYMacro16b 0 + mov cx,[xy] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro EORMacro8b 0 + xor al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro EORMacro16b 0 + xor eax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro JMLMacro 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + add cx,2 + push eax + call membank0r8 + mov bl,al + pop eax + mov [xpc],ax + mov [xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + + +%macro JMPMacro4C 0 + xor eax,eax + mov ax,[esi] + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr +; mov esi,[snesmap2+ebx*4] +; mov [initaddrl],esi +; add esi,eax +; endloop + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro6C 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro7C 0 + mov cx,[esi] + xor eax,eax + add cx,[xx] + mov bl,[xpb] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro5C 0 + xor eax,eax + mov bl,[esi+2] + mov ax,[esi] + mov [xpb],bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSLMacro 0 + mov ebx,esi + sub ebx,[initaddrl] + add bx,2 + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov [xs],bx + xor eax,eax + xor bh,bh + mov ax,[esi] + mov bl,[esi+2] + mov [xpc],ax + mov [xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacro20 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + xor eax,eax + mov [xs],bx + mov ax,[esi] + xor bh,bh + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacroFC 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov [xs],bx + xor eax,eax + xor bh,bh + mov cx,[esi] + mov bl,[xpb] + add cx,[xx] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro LDAMacro8b 0 + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDAMacro16b 0 + mov [xa],ax + flagsetnz16b + endloop +%endmacro + +%macro LDXMacro8b 0 + mov dword[flagnz],0 + mov [xx],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDXMacro16b 0 + mov [xx],ax + flagsetnz16b + endloop +%endmacro + +%macro LDYMacro8b 0 + mov dword[flagnz],0 + mov [xy],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDYMacro16b 0 + mov [xy],ax + flagsetnz16b + endloop +%endmacro + +%macro LSRMacro8b 0 + shr al,1 + flagsetnzc8b +%endmacro + +%macro LSRMacro16b 0 + shr ax,1 + flagsetnzc +%endmacro + +%macro MVNMacro 0 + mov ax,[esi] + mov [xdb],al + mov bl,ah + mov cx,[xx] + call dword near [memtabler8+ebx*4] + mov bl,[xdb] + mov cx,[xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz .pagezero + inc word[xx] + inc word[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + inc byte[xx] + inc byte[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro MVPMacro 0 + mov ax,[esi] + mov [xdb],al + mov bl,ah + mov cx,[xx] + call dword near [memtabler8+ebx*4] + mov bl,[xdb] + mov cx,[xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz .pagezero + dec word[xx] + dec word[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + dec byte[xx] + dec byte[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro ORAMacro8b 0 + or al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro ORAMacro16b 0 + or ax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro PUSHMacro8b 1 + mov eax,[wramdata] + mov cx,[xs] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PUSHMacro8bp 0 + mov eax,[wramdata] + makedl + mov cx,[xs] + mov al,dl + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PUSHMacro16b 2 + mov cx,[xs] + mov al,%2 + call membank0w8 + dec cx + or cx,word[stackor] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PEAMacro 0 + mov cx,[xs] + mov al,[esi+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[esi] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + add esi,2 + endloop +%endmacro + +%macro PEIMacro 0 + xor ah,ah + mov al,[esi] + mov cx,[xd] + inc esi + add cx,ax + call membank0r16 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PERMacro 0 + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr + mov eax,[snesmmap+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + xor ebx,ebx + endloop +.loweraddr + mov eax,[snesmap2+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + xor ebx,ebx + endloop +%endmacro + +%macro POPMacro8b 1 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [xs],cx + mov %1,al + flagsetnz8b + endloop +%endmacro + +%macro POPMacro16b 2 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + mov [xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacro16bd 2 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + call UpdateDPage + mov [xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacroP 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + mov [xs],bx + xor bh,bh + mov dl,cl + restoredl + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[tableadb+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop +%endmacro + +%macro REPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz .extraflags + not al + and dl,al + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop + +.extraflags + not al + makedl + and dl,al + restoredl + test byte[xe],01h + jnz .emul2 + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop +.emul2 + or dl,00110000b + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop +%endmacro + +%macro ROLMacro8b 0 + mov cl,[flagc] + add cl,cl + rcl al,1 + flagsetnzc8b +%endmacro + +%macro ROLMacro16b 0 + mov cl,[flagc] + add cl,cl + rcl ax,1 + flagsetnzc +%endmacro + +%macro RORMacro8b 0 + mov cl,[flagc] + add cl,cl + rcr al,1 + flagsetnzc8b +%endmacro + +%macro RORMacro16b 0 + mov cl,[flagc] + add cl,cl + rcr ax,1 + flagsetnzc +%endmacro + +%macro RTIMacro 0 + cmp byte[nmistatus],3 + jne .nodis658162 + test byte[curexecstate],01h + jz .nodis65816 + and byte[curexecstate],0FEh + call changeexecloop +.nodis65816 + cmp byte[curexecstate],0 + jne .nn + xor dh,dh +.nn +.nodis658162 + mov byte[curnmi],0 + test byte[xe],1 + jne near emulRTI + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov dl,[eax+ebx] + restoredl + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + inc bx + and bx,word[stackand] + mov al,[eax+ebx] + mov [xpb],al + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + mov bl,dl + mov edi,[tableadb+ebx*4] + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop + +emulRTI + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov dl,[eax+ebx] + or dl,00110000b + restoredl + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + mov bl,dl + mov edi,[tableadb+ebx*4] + xor bl,bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTLMacro 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + inc bx + and bx,word[stackand] + mov al,[eax+ebx] + mov [xpb],al + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + inc ax + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTSMacro 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + inc ax + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro SBCMacro8bnd 0 + mov cl,[flagc] + sub cl,1 + sbb [xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bnd 0 + mov cl,[flagc] + sub cl,1 + sbb [xa],ax + flagsetnvzcs16b + endloop +%endmacro + +%macro SBCMacro8bd 0 + mov cl,[flagc] + sub cl,1 + mov cl,al + mov al,[xa] + sbb al,cl + das + mov [xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bd 0 + mov cl,[flagc] + sub cl,1 + mov cx,ax + mov al,[xa] + sbb al,cl + das + mov [xa],al + mov al,[xa+1] + sbb al,ch + das + mov [xa+1],al + cmc + flagsetnvzcd + endloop +%endmacro + +%macro SEPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz .extraflags + or dl,al + mov bl,dl + mov edi,[tableadb+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.extraflags + makedl + or dl,al + restoredl + mov bl,dl + mov edi,[tableadb+ebx*4] + test dl,00010000b + jnz .setx2 + endloop +.setx2 + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +%endmacro + +%macro STAMacro8b 0 + mov al,[xa] +%endmacro + +%macro STAMacro16b 0 + mov eax,[xa] +%endmacro + +%macro STXMacro8b 0 + mov al,[xx] +%endmacro + +%macro STXMacro16b 0 + mov eax,[xx] +%endmacro + +%macro STYMacro8b 0 + mov al,[xy] +%endmacro + +%macro STYMacro16b 0 + mov eax,[xy] +%endmacro + +%macro WAIMacro 0 + cmp byte[intrset],1 + jne .notws + dec esi + endloop +.notws + test byte[intrset],0FFh + jz .waitstate + cmp byte[intrset],2 + je .stopint + dec esi + endloop +.waitstate + mov byte[intrset],1 + dec esi + endloop +.stopint + mov byte[intrset],0 + mov byte[doirqnext],0 + endloop +%endmacro + +%macro XCEMacro 0 + mov al,[flagc] + mov dword[flagc],0 + and al,00000001b + cmp [xe],al + jne .nochange + endloop +.nochange + test byte[xe],0FFh + jz .noemul + mov dword[flagc],0FFh +.noemul + mov [xe],al + test byte[xe],01h + jnz .emul + or dl,00100000b + mov word[stackand],0FFFFh + mov word[stackor],0000h + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tableadb+ebx*4] + mov byte[xx+1],0 + mov byte[xy+1],0 + mov byte[xs+1],1 + mov word[stackand],01FFh + mov word[stackor],0100h + endloop +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/65816dc.inc b/zsnes/src/cpu/65816dc.inc new file mode 100644 index 00000000..d7553674 --- /dev/null +++ b/zsnes/src/cpu/65816dc.inc @@ -0,0 +1,1631 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM flagnz, flago, flagc, cpucycle, cycpbl, cycpblt, opcjmptab, doirqnext +EXTSYM dmadata + + + + + + +;******************************************************* +; Flag Setting Macros +;******************************************************* + + +%macro endloop 0 + sub dword[cycpbl],55 + jnc %%skipallspc + mov eax,[cycpblt] + mov bl,[ebp] + add dword[cycpbl],eax + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx +%%skipallspc + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc %%cpuover + jmp dword near [edi+ebx*4] +%%cpuover + ret +%endmacro + +%macro restoredl 0 + mov dword[flagnz],0 + test dl,80h + jz %%noneg + or dword[flagnz],10000h +%%noneg + test dl,2h + jnz %%zero + or dword[flagnz],1 +%%zero + mov dword[flagc],0 + test dl,01h + jz %%nocarry + mov dword[flagc],0FFh +%%nocarry + mov dword[flago],0 + test dl,40h + jz %%nov + mov dword[flago],0FFh +%%nov +%endmacro + +%macro makedl 0 + and dl,00111100b + test dword[flagnz],18000h + jz %%noneg + or dl,80h +%%noneg + test dword[flagnz],0FFFFh + jnz %%nozero + or dl,02h +%%nozero + test dword[flagc],0FFh + jz %%nocarry + or dl,01h +%%nocarry + test dword[flago],0FFh + jz %%nov + or dl,40h +%%nov +%endmacro + +; Sets flags n and z according to al +%macro flagsetnz8b 0 + mov dword[flagnz],0 + mov [flagnz+1],al + endloop +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16b 0 + mov cx,ax + mov [flagnz],ecx + endloop +%endmacro + +; Sets flags n and z according to al +%macro flagsetnz8bnel 0 + mov dword[flagnz],0 + mov [flagnz+1],al +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16bnel 0 + mov cx,ax + mov [flagnz],ecx +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzc8b 0 + mov dword[flagnz],0 + mov al,[xa] + seto byte[flago] + mov [flagnz+1],al + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +%macro flagsetnvzc16b 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzcs8b 0 + mov dword[flagnz],0 + mov al,[xa] + seto byte[flago] + mov [flagnz+1],al + jc .carry + mov dword[flagc],0FFh + endloop +.carry + mov dword[flagc],0h + endloop +%endmacro + +%macro flagsetnvzcs16b 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0FFh + endloop +.carry + mov dword[flagc],0h + endloop +%endmacro + +; Sets flags N V . . . . Z C for 16-bit decimal mode only +%macro flagsetnvzcd 0 + mov cx,[xa] + seto byte[flago] + mov [flagnz],ecx + jc .carry + mov dword[flagc],0h + endloop +.carry + mov dword[flagc],0FFh + endloop +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc8b 0 + mov dword[flagnz],0 + mov dword[flagc],0h + mov [flagnz+1],al + jnc .carry + mov dword[flagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc 0 + mov cx,ax + mov dword[flagc],0h + mov [flagnz],ecx + jnc .carry + mov dword[flagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and jump to execloop +%macro flagsetnzcel8b 0 + mov dword[flagnz],0h + jc .carry + mov [flagnz+1],cl + mov dword[flagc],0FFh + endloop +.carry + mov [flagnz+1],cl + mov dword[flagc],0h + endloop +%endmacro + +%macro flagsetnzcel16b 0 + jc .carry + mov [flagnz],ecx + mov dword[flagc],0FFh + endloop +.carry + mov [flagnz],ecx + mov dword[flagc],0h + endloop +%endmacro + +;******************************************************* +; Opcode Instructions +;******************************************************* + +%macro ADCMacro8bnd 0 + mov cl,[flagc] + add cl,cl + adc [xa],al + flagsetnvzc8b +%endmacro + +%macro ADCMacro16bnd 0 + mov cl,[flagc] + add cl,cl + adc [xa],ax + flagsetnvzc16b +%endmacro + +%macro ADCMacro8bd 0 + mov cl,[flagc] + add cl,cl + mov cl,al + mov al,[xa] + adc al,cl + daa + mov [xa],al + flagsetnvzc8b + endloop +%endmacro + +%macro ADCMacro16bd 0 + mov cl,[flagc] + add cl,cl + mov cx,ax + mov al,[xa] + adc al,cl + daa + mov [xa],al + mov al,[xa+1] + adc al,ch + daa + mov [xa+1],al + flagsetnvzcd +%endmacro + +%macro ANDMacro8b 0 + and al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro ANDMacro16b 0 + and eax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro ASLMacro8b 0 + add al,al + flagsetnzc8b +%endmacro + +%macro ASLMacro16b 0 + add ax,ax + flagsetnzc +%endmacro + +%macro JumpMacro 0 + movsx eax,byte[esi] + add esi,eax +.skip + inc esi + endloop +%endmacro + +%macro BITMacroim8b 0 + mov al,[esi] + test dword[flagnz],18000h + jz .notflagnz + or dword[flagnz],10000h +.notflagnz + inc esi + test [xa],al + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacroim16b 0 + mov ax,[esi] + test dword[flagnz],18000h + jz .notflagnz + or dword[flagnz],10000h +.notflagnz + add esi,2 + test [xa],ax + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacro8b 0 + mov dword[flagnz],10000h + test al,80h + jnz .flagn + mov dword[flagnz],0 +.flagn + mov dword[flago],1 + test al,40h + jnz .flago + mov dword[flago],0 +.flago + test [xa],al + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BITMacro16b 0 + mov dword[flagnz],10000h + test ax,8000h + jnz .flagn + mov dword[flagnz],0 +.flagn + mov dword[flago],1 + test ax,4000h + jnz .flago + mov dword[flago],0 +.flago + test [xa],ax + jz .zero + mov word[flagnz],1 + endloop +.zero + mov word[flagnz],0 + endloop +%endmacro + +%macro BRKMacro 0 + inc esi + test byte[xe],1 + jne near BRKemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[brkv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +BRKemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,[xpb] + xor eax,eax + mov ax,[brkv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro BRLMacro 0 + mov ax,[xpc] + mov bl,[xpb] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + add bx,2 + xor eax,eax + add bx,[esi] + mov ax,bx + xor ebx,ebx + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CMPMacro8b 0 + mov cl,[xa] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CMPMacro16b 0 + mov cx,[xa] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro COPMacro 0 + inc esi + test byte[xe],1 + jne near COPemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[copv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +COPemulmode + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + mov bl,[xpb] + xor eax,eax + mov ax,[copv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CPXMacro8b 0 + mov cl,[xx] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPXMacro16b 0 + mov cx,[xx] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro CPYMacro8b 0 + mov cl,[xy] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPYMacro16b 0 + mov cx,[xy] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro EORMacro8b 0 + xor al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro EORMacro16b 0 + xor eax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro JMLMacro 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + add cx,2 + push eax + call membank0r8 + mov bl,al + pop eax + mov [xpc],ax + mov [xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + + +%macro JMPMacro4C 0 + xor eax,eax + mov ax,[esi] + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr +; mov esi,[snesmap2+ebx*4] +; mov [initaddrl],esi +; add esi,eax +; endloop + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro6C 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro7C 0 + mov cx,[esi] + xor eax,eax + add cx,[xx] + mov bl,[xpb] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro5C 0 + xor eax,eax + mov bl,[esi+2] + mov ax,[esi] + mov [xpb],bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSLMacro 0 + mov ebx,esi + sub ebx,[initaddrl] + add bx,2 + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov [xs],bx + xor eax,eax + xor bh,bh + mov ax,[esi] + mov bl,[esi+2] + mov [xpc],ax + mov [xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacro20 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + xor eax,eax + mov [xs],bx + mov ax,[esi] + xor bh,bh + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacroFC 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + or bx,word[stackor] + mov [xs],bx + xor eax,eax + xor bh,bh + mov cx,[esi] + mov bl,[xpb] + add cx,[xx] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro LDAMacro8b 0 + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDAMacro16b 0 + mov [xa],ax + flagsetnz16b + endloop +%endmacro + +%macro LDXMacro8b 0 + mov dword[flagnz],0 + mov [xx],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDXMacro16b 0 + mov [xx],ax + flagsetnz16b + endloop +%endmacro + +%macro LDYMacro8b 0 + mov dword[flagnz],0 + mov [xy],al + mov [flagnz+1],al + endloop +%endmacro + +%macro LDYMacro16b 0 + mov [xy],ax + flagsetnz16b + endloop +%endmacro + +%macro LSRMacro8b 0 + shr al,1 + flagsetnzc8b +%endmacro + +%macro LSRMacro16b 0 + shr ax,1 + flagsetnzc +%endmacro + +%macro MVNMacro 0 + mov ax,[esi] + mov [xdb],al + mov bl,ah + mov cx,[xx] + call dword near [memtabler8+ebx*4] + mov bl,[xdb] + mov cx,[xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz near .pagezero + inc word[xx] + inc word[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + inc byte[xx] + inc byte[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro MVPMacro 0 + mov ax,[esi] + mov [xdb],al + mov bl,ah + mov cx,[xx] + call dword near [memtabler8+ebx*4] + mov bl,[xdb] + mov cx,[xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz near .pagezero + dec word[xx] + dec word[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + dec byte[xx] + dec byte[xy] + dec word[xa] + cmp word[xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro ORAMacro8b 0 + or al,[xa] + mov dword[flagnz],0 + mov [xa],al + mov [flagnz+1],al + endloop +%endmacro + +%macro ORAMacro16b 0 + or ax,[xa] + mov [xa],ax + flagsetnz16b +%endmacro + +%macro PUSHMacro8b 1 + mov eax,[wramdata] + mov cx,[xs] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PUSHMacro8bp 0 + mov eax,[wramdata] + makedl + mov cx,[xs] + mov al,dl + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PUSHMacro16b 2 + mov cx,[xs] + mov al,%2 + call membank0w8 + dec cx + or cx,word[stackor] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PEAMacro 0 + mov cx,[xs] + mov al,[esi+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[esi] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + add esi,2 + endloop +%endmacro + +%macro PEIMacro 0 + xor ah,ah + mov al,[esi] + mov cx,[xd] + inc esi + add cx,ax + call membank0r16 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + endloop +%endmacro + +%macro PERMacro 0 + mov bl,[xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr + mov eax,[snesmmap+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + xor ebx,ebx + endloop +.loweraddr + mov eax,[snesmap2+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [xs],cx + xor ebx,ebx + endloop +%endmacro + +%macro POPMacro8b 1 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [xs],cx + mov %1,al + flagsetnz8b + endloop +%endmacro + +%macro POPMacro16b 2 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + mov [xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacro16bd 2 + mov eax,[wramdata] + mov cx,[xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + call UpdateDPage + mov [xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacroP 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + mov [xs],bx + xor bh,bh + mov dl,cl + restoredl + test byte[xe],01h + jnz near .emul + mov bl,dl + mov edi,[tableadc+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop +%endmacro + +%macro REPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz near .extraflags + not al + and dl,al + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop + +.extraflags + not al + makedl + and dl,al + restoredl + test byte[xe],01h + jnz .emul2 + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop +.emul2 + or dl,00110000b + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop +%endmacro + +%macro ROLMacro8b 0 + mov cl,[flagc] + add cl,cl + rcl al,1 + flagsetnzc8b +%endmacro + +%macro ROLMacro16b 0 + mov cl,[flagc] + add cl,cl + rcl ax,1 + flagsetnzc +%endmacro + +%macro RORMacro8b 0 + mov cl,[flagc] + add cl,cl + rcr al,1 + flagsetnzc8b +%endmacro + +%macro RORMacro16b 0 + mov cl,[flagc] + add cl,cl + rcr ax,1 + flagsetnzc +%endmacro + +%macro RTIMacro 0 + cmp byte[nmistatus],3 + jne .nodis658162 + test byte[curexecstate],01h + jz .nodis65816 + and byte[curexecstate],0FEh + call changeexecloop +.nodis65816 + cmp byte[curexecstate],0 + jne .nn + xor dh,dh +.nn +.nodis658162 + mov byte[curnmi],0 + test byte[xe],1 + jne near emulRTI + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov dl,[eax+ebx] + restoredl + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + inc bx + and bx,word[stackand] + mov al,[eax+ebx] + mov [xpb],al + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + mov bl,dl + mov edi,[tableadc+ebx*4] + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz near .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz near .setx + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae near .upperlower + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je near .dma + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz near .setx + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz near .setx + endloop + +emulRTI + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov dl,[eax+ebx] + or dl,00110000b + restoredl + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + mov bl,dl + mov edi,[tableadc+ebx*4] + xor bl,bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTLMacro 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + inc bx + and bx,word[stackand] + mov al,[eax+ebx] + mov [xpb],al + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + inc ax + mov bl,[xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTSMacro 0 + mov eax,[wramdata] + mov bx,[xs] + inc bx + and bx,word[stackand] + mov cl,[eax+ebx] + inc bx + and bx,word[stackand] + mov ch,[eax+ebx] + mov [xs],bx + xor bh,bh + xor eax,eax + mov ax,cx + inc ax + mov [xpc],ax + mov bl,[xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro SBCMacro8bnd 0 + mov cl,[flagc] + sub cl,1 + sbb [xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bnd 0 + mov cl,[flagc] + sub cl,1 + sbb [xa],ax + flagsetnvzcs16b + endloop +%endmacro + +%macro SBCMacro8bd 0 + mov cl,[flagc] + sub cl,1 + mov cl,al + mov al,[xa] + sbb al,cl + das + mov [xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bd 0 + mov cl,[flagc] + sub cl,1 + mov cx,ax + mov al,[xa] + sbb al,cl + das + mov [xa],al + mov al,[xa+1] + sbb al,ch + das + mov [xa+1],al + cmc + flagsetnvzcd + endloop +%endmacro + +%macro SEPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz near .extraflags + or dl,al + mov bl,dl + mov edi,[tableadc+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +.extraflags + makedl + or dl,al + restoredl + mov bl,dl + mov edi,[tableadc+ebx*4] + test dl,00010000b + jnz .setx2 + endloop +.setx2 + mov byte[xx+1],0 + mov byte[xy+1],0 + endloop +%endmacro + +%macro STAMacro8b 0 + mov al,[xa] +%endmacro + +%macro STAMacro16b 0 + mov eax,[xa] +%endmacro + +%macro STXMacro8b 0 + mov al,[xx] +%endmacro + +%macro STXMacro16b 0 + mov eax,[xx] +%endmacro + +%macro STYMacro8b 0 + mov al,[xy] +%endmacro + +%macro STYMacro16b 0 + mov eax,[xy] +%endmacro + +%macro WAIMacro 0 + cmp byte[intrset],1 + jne .notws + dec esi + endloop +.notws + test byte[intrset],0FFh + jz .waitstate + cmp byte[intrset],2 + je .stopint + dec esi + endloop +.waitstate + mov byte[intrset],1 + dec esi + endloop +.stopint + mov byte[intrset],0 + mov byte[doirqnext],0 + endloop +%endmacro + +%macro XCEMacro 0 + mov al,[flagc] + mov dword[flagc],0 + and al,00000001b + cmp [xe],al + jne .nochange + endloop +.nochange + test byte[xe],0FFh + jz .noemul + mov dword[flagc],0FFh +.noemul + mov [xe],al + test byte[xe],01h + jnz .emul + or dl,00100000b + mov word[stackand],0FFFFh + mov word[stackor],0000h + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[tableadc+ebx*4] + mov byte[xx+1],0 + mov byte[xy+1],0 + mov byte[xs+1],1 + mov word[stackand],01FFh + mov word[stackor],0100h + endloop +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/address.inc b/zsnes/src/cpu/address.inc new file mode 100644 index 00000000..212e4583 --- /dev/null +++ b/zsnes/src/cpu/address.inc @@ -0,0 +1,812 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +EXTSYM membank0w8ram + + + + + + +;******************************************************* +; Address Modes +;******************************************************* + +; 1. Immediate Addressing -- # - DONE IN PROGRAM + +%macro addr_I_8br 0 + mov al,[esi] + inc esi +%endmacro + +%macro addr_I_16br 0 + mov eax,[esi] + add esi,2 +%endmacro + +; 2. Absolute -- a (TESTED) + +%macro addr_a_8br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_a_16br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_a_8bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_a_16bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtablew16+ebx*4] +%endmacro + +; 3. Absolute Long -- al + +%macro addr_al_8br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_al_16br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_al_8bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_al_16bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtablew16+ebx*4] +%endmacro + +; 4. Direct -- d (TESTED) + +%macro addr_d_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR8] +%endmacro + +%macro addr_d_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] +%endmacro + + +%macro addr_d_8bw 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageW8] +%endmacro + +%macro addr_d_16bw 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageW16] +%endmacro + +; 5. Accumulator -- A + +%macro addr_A_8br 0 + mov al,[xa] +%endmacro + +%macro addr_A_16br 0 + mov eax,[xa] +%endmacro + +%macro addr_A_8bw 0 + mov [xa],al +%endmacro + +%macro addr_A_16bw 0 + mov [xa],ax +%endmacro + +; 7. Direct Indirect Indexed -- (d),y + +%macro addr_BdBCy_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdBCy_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdBCy_8bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdBCy_16bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 8. Direct Indirect Indexed Long -- [d],y + +%macro addr_LdLCy_8br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdLCy_16br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_LdLCy_8bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + pop ax + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_LdLCy_16bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + xor bl,bl + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + pop ax + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 9. Direct Indexed Indirect -- (d,x) + +%macro addr_BdCxB_8br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCxB_16br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdCxB_8bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdCxB_16bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 10. Direct Indexed With X -- d,x + +%macro addr_dCx_8br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0r8 +%endmacro + +%macro addr_dCx_16br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0r16 +%endmacro + +%macro addr_dCx_8bw 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0w8 +%endmacro + +%macro addr_dCx_16bw 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xx] + call membank0w16 +%endmacro + +; 11. Direct Indexed With Y -- d,y + +%macro addr_dCy_8br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xy] + call membank0r8 +%endmacro + +%macro addr_dCy_16br 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xy] + call membank0r16 +%endmacro + +%macro addr_dCy_8bw 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xy] + call membank0w8 +%endmacro + +%macro addr_dCy_16bw 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[xy] + call membank0w16 +%endmacro + +; 12. Absolute Indexed With X -- a,x + +%macro addr_aCx_8br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCx_16br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_aCx_8bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_aCx_16bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 13. Absolute Indexed With Y -- a,y + +%macro addr_aCy_8br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCy_16br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_aCy_8bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_aCy_16bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 14. Absolute Long Indexed With X -- al,x + +%macro addr_alCx_8br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_alCx_16br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_alCx_8bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_alCx_16bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 18. Direct Indirect -- (d) +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; | 00 | (direct address) | +; + | DB | +; ------------------------------- +; Address: | effective address | + +%macro addr_BdB_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdB_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdB_8bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdB_16bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 19. Direct Indirect Long -- [d] +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; ------------------------------- +; Address: | (direct address) | + +%macro addr_LdL_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdL_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_LdL_8bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_LdL_16bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 22. Stack Relative -- d,s + +%macro addr_dCs_8br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r8 +%endmacro + +%macro addr_dCs_16br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 +%endmacro + +%macro addr_dCs_8bw 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0w8 +%endmacro + +%macro addr_dCs_16bw 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0w16 +%endmacro + +; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED) + +%macro addr_BdCsBCy_8br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdCsBCy_8bw 0 + push ax + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + pop ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16bw 0 + push ax + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + pop ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/address2.inc b/zsnes/src/cpu/address2.inc new file mode 100644 index 00000000..fd5a9963 --- /dev/null +++ b/zsnes/src/cpu/address2.inc @@ -0,0 +1,792 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM DPageR8,DPageR16,DPageW8,DPageW16 + + + + + + +;******************************************************* +; Address Modes +;******************************************************* + +; 1. Immediate Addressing -- # - DONE IN PROGRAM + +%macro addr_I_8br 0 + mov al,[esi] + inc esi +%endmacro + +%macro addr_I_16br 0 + mov eax,[esi] + add esi,2 +%endmacro + +; 2. Absolute -- a (TESTED) + +%macro addr_a_8br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_a_16br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_a_8bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_a_16bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + call dword near [memtablew16+ebx*4] +%endmacro + +; 3. Absolute Long -- al + +%macro addr_al_8br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_al_16br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_al_8bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_al_16bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtablew16+ebx*4] +%endmacro + +; 4. Direct -- d (TESTED) + +%macro addr_d_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR8] +%endmacro + +%macro addr_d_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] +%endmacro + +%macro addr_d_8bw 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageW8] +%endmacro + +%macro addr_d_16bw 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageW16] +%endmacro + +; 5. Accumulator -- A + +%macro addr_A_8br 0 + mov al,[xa] +%endmacro + +%macro addr_A_16br 0 + mov eax,[xa] +%endmacro + +%macro addr_A_8bw 0 + mov [xa],al +%endmacro + +%macro addr_A_16bw 0 + mov [xa],ax +%endmacro + +; 7. Direct Indirect Indexed -- (d),y + +%macro addr_BdBCy_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdBCy_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdBCy_8bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdBCy_16bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 8. Direct Indirect Indexed Long -- [d],y + +%macro addr_LdLCy_8br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdLCy_16br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_LdLCy_8bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + pop ax + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_LdLCy_16bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + xor bl,bl + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + pop ax + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 9. Direct Indexed Indirect -- (d,x) + +%macro addr_BdCxB_8br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCxB_16br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdCxB_8bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdCxB_16bw 0 + push ax + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 10. Direct Indexed With X -- d,x + +%macro addr_dCx_8br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageR8] +%endmacro + +%macro addr_dCx_16br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageR16] +%endmacro + +%macro addr_dCx_8bw 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageW8] +%endmacro + +%macro addr_dCx_16bw 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xx] + call dword near [DPageW16] +%endmacro + +; 11. Direct Indexed With Y -- d,y + +%macro addr_dCy_8br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xy] + call dword near [DPageR8] +%endmacro + +%macro addr_dCy_16br 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xy] + call dword near [DPageR16] +%endmacro + +%macro addr_dCy_8bw 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xy] + call dword near [DPageW8] +%endmacro + +%macro addr_dCy_16bw 0 + mov ecx,[xd] + mov bl,[esi] + inc esi + add cx,[xy] + call dword near [DPageW16] +%endmacro + +; 12. Absolute Indexed With X -- a,x + +%macro addr_aCx_8br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCx_16br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_aCx_8bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_aCx_16bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 13. Absolute Indexed With Y -- a,y + +%macro addr_aCy_8br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCy_16br 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_aCy_8bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_aCy_16bw 0 + mov cx,[esi] + mov bl,[xdb] + add esi,2 + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 14. Absolute Long Indexed With X -- al,x + +%macro addr_alCx_8br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_alCx_16br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_alCx_8bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_alCx_16bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[xx] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 18. Direct Indirect -- (d) +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; | 00 | (direct address) | +; + | DB | +; ------------------------------- +; Address: | effective address | + +%macro addr_BdB_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdB_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdB_8bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdB_16bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 19. Direct Indirect Long -- [d] +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; ------------------------------- +; Address: | (direct address) | + +%macro addr_LdL_8br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdL_16br 0 + mov bl,[esi] + mov ecx,[xd] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_LdL_8bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_LdL_16bw 0 + push ax + mov bl,[esi] + mov ecx,[xd] + inc esi + push cx + call dword near [DPageR16] + pop cx + add cx,2 + push ax + call dword near [DPageR8] + mov bl,al + pop ax + mov cx,ax + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 22. Stack Relative -- d,s + +%macro addr_dCs_8br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r8 +%endmacro + +%macro addr_dCs_16br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 +%endmacro + +%macro addr_dCs_8bw 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0w8 +%endmacro + +%macro addr_dCs_16bw 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0w16 +%endmacro + +; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED) + +%macro addr_BdCsBCy_8br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16br 0 + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdCsBCy_8bw 0 + push ax + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + pop ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16bw 0 + push ax + mov bl,[esi] + mov cx,[xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + pop ax + add cx,[xy] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/addrni.asm b/zsnes/src/cpu/addrni.asm new file mode 100644 index 00000000..4cbd85d0 --- /dev/null +++ b/zsnes/src/cpu/addrni.asm @@ -0,0 +1,409 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +;******************************************************* +; Address Modes +;******************************************************* + +; 1. Immediate Addressing -- # - DONE IN PROGRAM + +%macro addr_I_8brni 0 + mov al,[esi] +%endmacro + +%macro addr_I_16brni 0 + mov ax,[esi] +%endmacro + +; 2. Absolute -- a (TESTED) + +%macro addr_a_8brni 0 + mov cx,[esi] + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_a_16brni 0 + mov cx,[esi] + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 3. Absolute Long -- al + +%macro addr_al_8brni 0 + mov cx,[esi] + mov bl,[esi+2] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_al_16brni 0 + mov cx,[esi] + mov bl,[esi+2] + call dword near [memtabler16+ebx*4] +%endmacro + +; 4. Direct -- d (TESTED) + +%macro addr_d_8brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR8] +%endmacro + +%macro addr_d_16brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] +%endmacro + +; 5. Accumulator -- A + +%macro addr_A_8brni 0 + mov al,[xa] +%endmacro + +%macro addr_A_16brni 0 + mov ax,[xa] +%endmacro + +; 7. Direct Indirect Indexed -- (d),y + +%macro addr_BdBCy_8brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdBCy_16brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 8. Direct Indirect Indexed Long -- [d],y + +%macro addr_LdLCy_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdLCy_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 9. Direct Indexed Indirect -- (d,x) + +%macro addr_BdCxB_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCxB_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 10. Direct Indexed With X -- d,x + +%macro addr_dCx_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r8 +%endmacro + +%macro addr_dCx_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r16 +%endmacro + +; 11. Direct Indexed With Y -- d,y + +%macro addr_dCy_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xy] + call membank0r8 +%endmacro + +%macro addr_dCy_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xy] + call membank0r16 +%endmacro + +; 12. Absolute Indexed With X -- a,x + +%macro addr_aCx_8brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCx_16brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 13. Absolute Indexed With Y -- a,y + +%macro addr_aCy_8brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCy_16brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 14. Absolute Long Indexed With X -- al,x + +%macro addr_alCx_8brni 0 + mov cx,[esi] + mov bl,[esi+2] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_alCx_16brni 0 + mov cx,[esi] + mov bl,[esi+2] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 18. Direct Indirect -- (d) +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; | 00 | (direct address) | +; + | DB | +; ------------------------------- +; Address: | effective address | + +%macro addr_BdB_8brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdB_16brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 19. Direct Indirect Long -- [d] +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; ------------------------------- +; Address: | (direct address) | + +%macro addr_LdL_8brni 0 + mov bl,[esi] + mov ecx,[xd] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdL_16brni 0 + mov bl,[esi] + mov ecx,[xd] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler16+ebx*4] +%endmacro + +; 22. Stack Relative -- d,s + +%macro addr_dCs_8brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r8 +%endmacro + +%macro addr_dCs_16brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r16 +%endmacro + +; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED) + +%macro addr_BdCsBCy_8brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/cpu/addrni.inc b/zsnes/src/cpu/addrni.inc new file mode 100644 index 00000000..82de3a47 --- /dev/null +++ b/zsnes/src/cpu/addrni.inc @@ -0,0 +1,405 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + +;******************************************************* +; Address Modes +;******************************************************* + + +; 1. Immediate Addressing -- # - DONE IN PROGRAM + +%macro addr_I_8brni 0 + mov al,[esi] +%endmacro + +%macro addr_I_16brni 0 + mov ax,[esi] +%endmacro + +; 2. Absolute -- a (TESTED) + +%macro addr_a_8brni 0 + mov cx,[esi] + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_a_16brni 0 + mov cx,[esi] + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 3. Absolute Long -- al + +%macro addr_al_8brni 0 + mov cx,[esi] + mov bl,[esi+2] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_al_16brni 0 + mov cx,[esi] + mov bl,[esi+2] + call dword near [memtabler16+ebx*4] +%endmacro + +; 4. Direct -- d (TESTED) + +%macro addr_d_8brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR8] +%endmacro + +%macro addr_d_16brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] +%endmacro + +; 5. Accumulator -- A + +%macro addr_A_8brni 0 + mov al,[xa] +%endmacro + +%macro addr_A_16brni 0 + mov ax,[xa] +%endmacro + +; 7. Direct Indirect Indexed -- (d),y + +%macro addr_BdBCy_8brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdBCy_16brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 8. Direct Indirect Indexed Long -- [d],y + +%macro addr_LdLCy_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdLCy_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 9. Direct Indexed Indirect -- (d,x) + +%macro addr_BdCxB_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCxB_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r16 + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 10. Direct Indexed With X -- d,x + +%macro addr_dCx_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r8 +%endmacro + +%macro addr_dCx_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xx] + call membank0r16 +%endmacro + +; 11. Direct Indexed With Y -- d,y + +%macro addr_dCy_8brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xy] + call membank0r8 +%endmacro + +%macro addr_dCy_16brni 0 + mov ecx,[xd] + mov bl,[esi] + add cx,bx + add cx,[xy] + call membank0r16 +%endmacro + +; 12. Absolute Indexed With X -- a,x + +%macro addr_aCx_8brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCx_16brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 13. Absolute Indexed With Y -- a,y + +%macro addr_aCy_8brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCy_16brni 0 + mov cx,[esi] + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 14. Absolute Long Indexed With X -- al,x + +%macro addr_alCx_8brni 0 + mov cx,[esi] + mov bl,[esi+2] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_alCx_16brni 0 + mov cx,[esi] + mov bl,[esi+2] + add cx,[xx] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 18. Direct Indirect -- (d) +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; | 00 | (direct address) | +; + | DB | +; ------------------------------- +; Address: | effective address | + +%macro addr_BdB_8brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdB_16brni 0 + mov bl,[esi] + mov ecx,[xd] + call dword near [DPageR16] + mov cx,ax + mov bl,[xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 19. Direct Indirect Long -- [d] +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; ------------------------------- +; Address: | (direct address) | + +%macro addr_LdL_8brni 0 + mov bl,[esi] + mov ecx,[xd] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdL_16brni 0 + mov bl,[esi] + mov ecx,[xd] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler16+ebx*4] +%endmacro + +; 22. Stack Relative -- d,s + +%macro addr_dCs_8brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r8 +%endmacro + +%macro addr_dCs_16brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r16 +%endmacro + +; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED) + +%macro addr_BdCsBCy_8brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16brni 0 + mov bl,[esi] + mov cx,[xs] + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[xdb] + add cx,[xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/cpu/dma.asm b/zsnes/src/cpu/dma.asm new file mode 100644 index 00000000..e1f2c9c1 --- /dev/null +++ b/zsnes/src/cpu/dma.asm @@ -0,0 +1,1355 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM memtabler8,regptw,snesmap2,snesmmap,debstop3 +;EXTSYM soundcycleft,pexecs2 +EXTSYM memtablew8,regptr +EXTSYM dmadata +EXTSYM hdmatype +EXTSYM nexthdma +EXTSYM curhdma,curypos,disablehdma,hdmadata,hdmadelay,hdmaearlstart +EXTSYM resolutn +EXTSYM memtabler16 + + + + + + +;******************************************************* +; Transfer DMA Inits & Transfers DMA +;******************************************************* +; DMA transfer register + +NEWSYM AddrNoIncr, db 0 + +%macro ExecSPCCycles 0 + xor ebx,ebx + mov bx,[esi+5] + inc bx + inc ebx + shr ebx,2 + mov [soundcycleft],ebx + or ebx,ebx + jz .nocycles + xor ebx,ebx + xor ecx,ecx + call pexecs2 +.nocycles +%endmacro + +NEWSYM transdma + push eax + cmp word[esi+5],480h + jne .no +; mov byte[debstop3],1 +.no +; ExecSPCCycles + + mov al,[esi] + test al,80h + jnz near transdmappu2cpu + + ; set address increment value + mov dword[.addrincr],0 + test al,00001000b + jnz .skipaddrincr + test al,00010000b + jnz .autodec + mov dword[.addrincr],1 + jmp .skipaddrincr +.autodec + mov dword[.addrincr],0FFFFFFFFh +.skipaddrincr + + mov byte[AddrNoIncr],0 + cmp dword[.addrincr],0 + jne .notzero + mov byte[AddrNoIncr],1 +.notzero + ; get address order to be written + xor ebx,ebx + and al,00000111b + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptra],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptrb],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptrc],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptrd],eax + + mov dx,[esi+5] ; Number of bytes to transfer + xor ebx,ebx + mov bl,[esi+4] ; Bank # + mov ecx,[esi+2] ; address offset # + and ecx,0FFFFh + mov [.curbank],bl + mov word[esi+5],0 + + mov ebx,[.curbank] + mov eax,snesmap2 + test ecx,8000h + jz .nomap1 + mov eax,snesmmap +.nomap1 + and edx,0FFFFh + mov ebx,[eax+ebx*4] + +;snesmmap times 256 dd 0 ; addresses 8000-FFFF +;snesmap2 times 256 dd 0 ; addresses 0000-7FFF + + push esi + mov esi,ebx + xor ebx,ebx + mov bl,[.curbank] + ; do loop + cmp edx,0 + jne .no0 + mov edx,65536 +.no0 + mov ebx,[memtabler8+ebx*4] + mov [.readaddr],ebx + xor ebx,ebx + mov bl,[.curbank] + mov [.cebx],ebx +.againloop + cmp edx,4 + jbe .deccheckloop + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptra] + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrb] + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrc] + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrd] + sub edx,4 + jmp .againloop +.deccheckloop + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptra] + dec edx + jz .findma + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrb] + dec edx + jz .findma + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrc] + dec edx + jz .findma + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrd] +.findma + pop esi + mov [esi+2],cx + pop eax + mov byte[AddrNoIncr],0 + ret + +ALIGN32 + +.curbank dd 0 +.addrincr dd 0 +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +; pointer address of registers +.regptra dd 0 +.regptrb dd 0 +.regptrc dd 0 +.regptrd dd 0 +.readaddr dd 0 +.cebx dd 0 + +NEWSYM transdmappu2cpu + ; set address increment value + mov dword[.addrincr],0 + test al,00001000b + jnz .skipaddrincr + test al,00010000b + jnz .autodec + mov dword[.addrincr],1 + jmp .skipaddrincr +.autodec + mov dword[.addrincr],0FFFFFFFFh +.skipaddrincr + + ; get address order to be written + xor ebx,ebx + and al,00000111b + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptra],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptrb],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptrc],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptrd],eax + + mov dx,[esi+5] ; Number of bytes to transfer + xor ebx,ebx + mov bl,[esi+4] ; Bank # + mov ecx,[esi+2] ; address offset # + and ecx,0FFFFh + mov [.curbank],bl + mov word[esi+5],0 + + mov ebx,[.curbank] + mov eax,snesmap2 + test ecx,8000h + jz .nomap1 + mov eax,snesmmap +.nomap1 + and edx,0FFFFh + mov ebx,[eax+ebx*4] + +;snesmmap times 256 dd 0 ; addresses 8000-FFFF +;snesmap2 times 256 dd 0 ; addresses 0000-7FFF + + push esi + mov esi,ebx + xor ebx,ebx + mov bl,[.curbank] + ; do loop + cmp edx,0 + jne .no0 + mov edx,65536 +.no0 + mov ebx,[memtablew8+ebx*4] + mov [.writeaddr],ebx + xor ebx,ebx + mov bl,[.curbank] + mov [.cebx],ebx +.againloop + cmp edx,4 + jbe .deccheckloop + call dword near [.regptra] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + call dword near [.regptrb] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + call dword near [.regptrc] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + call dword near [.regptrd] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + sub edx,4 + jmp .againloop +.deccheckloop + call dword near [.regptra] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + dec edx + jz .findma + call dword near [.regptrb] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + dec edx + jz .findma + call dword near [.regptrc] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + dec edx + jz .findma + call dword near [.regptrd] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] +.findma + pop esi + mov [esi+2],cx + pop eax + ret + +ALIGN32 + +.curbank dd 0 +.addrincr dd 0 +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +; pointer address of registers +.regptra dd 0 +.regptrb dd 0 +.regptrc dd 0 +.regptrd dd 0 +.writeaddr dd 0 +.cebx dd 0 + +; DMA enable register +; use dmadata for input on dma +NEWSYM reg420Bw + push eax + push esi + push edi + push ecx + push edx + mov esi,dmadata + test al,01h + jz .notransa + call transdma +.notransa + add esi,16 + test al,02h + jz .notransb + call transdma +.notransb + add esi,16 + test al,04h + jz .notransc + call transdma +.notransc + add esi,16 + test al,08h + jz .notransd + call transdma +.notransd + add esi,16 + test al,10h + jz .notranse + call transdma +.notranse + add esi,16 + test al,20h + jz .notransf + call transdma +.notransf + add esi,16 + test al,40h + jz .notransg + call transdma +.notransg + add esi,16 + test al,80h + jz .notransh + call transdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop eax + ret + +;******************************************************* +; HDMA Settings +;******************************************************* +NEWSYM setuphdma + push eax + + ; transfer old address to new address + mov ax,[esi+2] + mov [esi+8],ax + mov [edx+17],ax + ; get address order to be written + xor ebx,ebx + xor eax,eax + xor ecx,ecx + mov al,[esi] + and al,00000111b + mov ah,[.addrnumt+eax] + mov [edx+16],ah + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+4],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+8],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+12],eax + + xor ebx,ebx + mov byte[esi+10],0 + pop eax + or [hdmatype],ah + ret + +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +.addrnumt db 1,2,2,4,4,4,4,4 + +NEWSYM setuphdmars + push eax + + ; get address order to be written + xor ebx,ebx + xor eax,eax + xor ecx,ecx + mov al,[esi] + and al,00000111b + mov ah,[.addrnumt+eax] + mov [edx+16],ah + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+4],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+8],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+12],eax + + xor ebx,ebx + pop eax + ret + +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +.addrnumt db 1,2,2,4,4,4,4,4 + +NEWSYM setuphdma2 + push eax + + cmp byte[esi+10],0 + je near .nohdma + + ; transfer old address to new address + mov ax,[esi+8] + mov [edx+17],ax + ; get address order to be written + xor ebx,ebx + xor eax,eax + xor ecx,ecx + mov al,[esi] + and al,00000111b + mov ah,[.addrnumt+eax] + mov [edx+16],ah + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+4],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+8],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+12],eax + + xor ebx,ebx + pop eax + and [hdmatype],ah + ret +.nohdma + pop eax + and [nexthdma],ah + ret + +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +.addrnumt db 1,2,2,4,4,4,4,4 + +NEWSYM hdmastartsc, db 0 +NEWSYM hdmarestart, db 0 + +NEWSYM reg420Cw + mov [curhdma],al + mov bx,[resolutn] + cmp word[curypos],bx + jae near .nohdma + cmp byte[disablehdma],0 + jne near .nohdma +; jmp starthdma + mov al,[curhdma] + mov [nexthdma],al + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call setuphdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call setuphdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call setuphdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call setuphdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call setuphdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call setuphdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call setuphdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call setuphdma +.notransh + mov bl,[hdmaearlstart] + mov [hdmadelay],bl + pop edx + pop ecx + pop edi + pop esi + pop ebx +; call exechdma +; call exechdma +.nohdma + mov byte[hdmarestart],0 + ret + +; HDMA enable register +NEWSYM starthdma + mov al,[curhdma] +NEWSYM startnexthdma + mov [nexthdma],al + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call setuphdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call setuphdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call setuphdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call setuphdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call setuphdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call setuphdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call setuphdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call setuphdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +.nohdma + ret + +NEWSYM dohdma + xor ebx,ebx + test byte[esi],40h + jnz near indirectaddr + push eax + test byte[esi+10],07Fh + jnz near .nozero + test byte[esi+10],80h + jnz near .noincr + test [hdmatype],ah + jnz .noincr + mov bl,[edx+16] + add word[edx+17],bx +.noincr + mov bl,ah + not bl + and [hdmatype],bl + mov bl,[esi+4] + mov cx,[edx+17] + call dword near [memtabler8+ebx*4] + inc word[edx+17] + mov byte[esi+10],al + test al,0FFh + jnz .yeszero + xor [nexthdma],ah + jmp .finhdma2 +.yeszero + cmp byte[esi+10],80h + ja near hdmatype2 + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc cx + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + add cx,2 + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + add cx,3 + call dword near [memtabler8+ebx*4] + call dword near [edx+12] + jmp .finhdma +.nozero + test byte[esi+10],80h + jnz near hdmatype2 +.finhdma + mov ax,[edx+17] + mov [esi+8],ax + pop eax + dec byte[esi+10] + ret +.finhdma2 + mov ax,[edx+17] + mov [esi+8],ax + pop eax + ret + +.tempdecr db 0 + +NEWSYM hdmatype2 + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx+12] +.finhdma + mov ax,[edx+17] + mov [esi+8],ax + pop eax + dec byte[esi+10] + ret + +.tempdecr db 0 + +NEWSYM indirectaddr + push eax + test byte[esi+10],07Fh + jnz near .nozero + test [hdmatype],ah + jnz .noincr + add word[edx+17],2 +.noincr + mov bl,ah + not bl + and [hdmatype],bl + mov bl,[esi+4] + mov cx,[edx+17] + call dword near [memtabler8+ebx*4] + inc word[edx+17] + mov byte[esi+10],al + push eax + mov bl,[esi+4] + mov cx,[edx+17] + call dword near [memtabler16+ebx*4] + mov [esi+5],ax + pop eax + test al,0FFh + jnz .yeszero + xor [nexthdma],ah + jmp .finhdma2 +.yeszero + cmp byte[esi+10],80h + ja near hdmatype2indirect + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc cx + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + add cx,2 + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + add cx,3 + call dword near [memtabler8+ebx*4] + call dword near [edx+12] + jmp .finhdma +.nozero + test byte[esi+10],80h + jnz near hdmatype2indirect +.finhdma + mov ax,[edx+17] + mov [esi+8],ax + pop eax + dec byte[esi+10] + ret +.finhdma2 + mov ax,[edx+17] + mov [esi+8],ax + pop eax + ret + +.tempdecr db 0 +.fname2 db 9,'vram2.dat',0 + +NEWSYM hdmatype2indirect + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx+12] +.finhdma + pop eax + dec byte[esi+10] + ret + +.tempdecr db 0 + + +NEWSYM dohdma2 + ; new hdma routines + xor ebx,ebx + push eax + test [hdmatype],ah + jz .nostart + xor ah,0FFh + xor ecx,ecx + and [hdmatype],ah + test byte[esi],40h + jnz near .indir + mov bl,[esi+4] + mov cx,[esi+8] + call dword near [memtabler8+ebx*4] + inc word[esi+8] + xor ebx,ebx + mov [esi+10],al + jmp .nostart +.indir + mov bl,[esi+4] + mov [esi+7],bl + mov cx,[esi+2] + mov [esi+5],cx + call dword near [memtabler8+ebx*4] + xor ebx,ebx + inc word[esi+5] + mov bl,[esi+7] + mov [esi+10],al + mov cx,[esi+5] + call dword near [memtabler8+ebx*4] + xor ebx,ebx + inc word[esi+5] + mov bl,[esi+7] + mov [esi+8],al + mov cx,[esi+5] + call dword near [memtabler8+ebx*4] + inc word[esi+5] + mov [esi+9],al + xor ebx,ebx +.nostart + + cmp byte[esi+10],0 + je near .endhdma + mov bl,[esi+4] + mov al,[edx+16] + mov [.tempdecr],al + xor ecx,ecx + mov bl,[esi+4] + mov cx,[esi+8] ; increment/decrement/keep pointer location + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .nomorehdma + xor ebx,ebx + mov cx,[esi+8] ; increment/decrement/keep pointer location + mov bl,[esi+4] + inc cx + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .nomorehdma + xor ebx,ebx + mov cx,[esi+8] ; increment/decrement/keep pointer location + mov bl,[esi+4] + add cx,2 + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .nomorehdma + xor ebx,ebx + mov cx,[esi+8] ; increment/decrement/keep pointer location + mov bl,[esi+4] + add cx,3 + call dword near [memtabler8+ebx*4] + call dword near [edx+12] +.nomorehdma + dec byte[esi+10] + test byte[esi+10],7Fh + jz .zeroed + test byte[esi+10],80h + jz .noadd + xor ebx,ebx + mov bl,[edx+16] + add [esi+8],bx +.noadd + pop eax + ret +.zeroed + test byte[esi],40h + jnz near .indirzero + xor ebx,ebx + mov bl,[edx+16] + add [esi+8],bx + mov bl,[esi+4] + mov cx,[esi+8] + call dword near [memtabler8+ebx*4] + inc word[esi+8] + mov [esi+10],al + pop eax + ret +.indirzero + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] + call dword near [memtabler8+ebx*4] + xor ebx,ebx + inc word[esi+5] + mov bl,[esi+7] + mov [esi+10],al + mov cx,[esi+5] + call dword near [memtabler8+ebx*4] + xor ebx,ebx + inc word[esi+5] + mov bl,[esi+7] + mov [esi+8],al + mov cx,[esi+5] + call dword near [memtabler8+ebx*4] + inc word[esi+5] + mov [esi+9],al + pop eax + ret +.endhdma + pop eax + xor [nexthdma],ah + ret + +.tempdecr db 0 + +NEWSYM exechdma + cmp byte[hdmarestart],1 + je near exechdmars + mov al,[nexthdma] + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call dohdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call dohdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call dohdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call dohdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call dohdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call dohdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call dohdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call dohdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +.nohdma + ret + +NEWSYM exechdmars + mov al,[nexthdma] + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call setuphdmars + call dohdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call setuphdmars + call dohdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call setuphdmars + call dohdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call setuphdmars + call dohdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call setuphdmars + call dohdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call setuphdmars + call dohdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call setuphdmars + call dohdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call setuphdmars + call dohdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +.nohdma + mov byte[hdmarestart],0 + ret + + + + \ No newline at end of file diff --git a/zsnes/src/cpu/dsp.asm b/zsnes/src/cpu/dsp.asm new file mode 100644 index 00000000..e48613d1 --- /dev/null +++ b/zsnes/src/cpu/dsp.asm @@ -0,0 +1,3054 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM BRRPlace0,BRRPlace1,BRRPlace2,BRRPlace3,BRRPlace4,BRRPlace5,BRRPlace6 +EXTSYM BRRPlace7,Decrease,DecreaseRateExp,EchoFB,EchoRate,EchoVL,EchoVR +EXTSYM FIRTAPVal0,FIRTAPVal1,FIRTAPVal2,FIRTAPVal3,FIRTAPVal4,FIRTAPVal5 +EXTSYM FIRTAPVal6,FIRTAPVal7,GlobalVL,GlobalVR,Increase,IncreaseBent +EXTSYM MaxEcho,MusicVol,NoiseInc,NoiseSpeeds,SBToSPC,Voice0End,Voice0EnvInc +EXTSYM Voice0IncNumber,Voice0Loop,Voice0Noise,Voice0Prev0,Voice0Prev1 +EXTSYM Voice0Start,Voice0State,Voice0Status,Voice0Time,Voice1End,Voice1Noise +EXTSYM Voice1Prev0,Voice1Prev1,Voice1Start,Voice2End,Voice2Noise,Voice2Prev0 +EXTSYM Voice2Prev1,Voice2Start,Voice3End,Voice3Noise,Voice3Prev0,Voice3Prev1 +EXTSYM Voice3Start,Voice4End,Voice4Noise,Voice4Prev0,Voice4Prev1,Voice4Start +EXTSYM Voice5End,Voice5Noise,Voice5Prev0,Voice5Prev1,Voice5Start,Voice6End +EXTSYM Voice6Noise,Voice6Prev0,Voice6Prev1,Voice6Start,Voice7End,Voice7Noise +EXTSYM Voice7Prev0,Voice7Prev1,Voice7Start,VolumeConvTable,VolumeTableb,keyonsn +EXTSYM RevStereo,Voice1Status,Voice2Status,Voice3Status,Voice4Status,Voice5Status +EXTSYM Voice6Status,Voice7Status +EXTSYM GainDecBendDataPos,GainDecBendDataTime,GainDecBendDataDat +EXTSYM AdsrSustLevLoc,AdsrBlocksLeft,AdsrNextTimeDepth +EXTSYM MuteVoiceF,VoiceStarter +EXTSYM DecayRate,SustainRate,SustainValue +EXTSYM KeyOnStA,KeyOnStB,SoundTest + +%include "betauser.mac" + + + + + +;none times 256 db 0 + +identcode db 255,1,78,78 +idcodedata db USERNAMEI +;sardcode db 234,76,80,128,65,65 ; 6 +;efxcode db 17,47,62,97,26,126,98 ; 7 +;zopcode db 54,39,21,0,0,8,14,12,18 ; 9 +;yoshcode db 0,68,23,76,123,98,34,87,12,98,65 ; 11 +;deejcode db 78,39,240,150,15,78,39,68,89,54,32,33 ; 12 +;vmprcode db 127,127,127,127,255,255,255,255,0,0,0,0,1,0,1,0 ; 16 +;conjcode db 32,32,25,20,78,232,242,242,0,1,4,98,98,45,13,12,99 ; 17 +;wnelcode db 32,64,123,76,123,76,12,0,1,7,43,12,87,18,51,136,65,132 ; 18 +;crascode db 82,48,89,26,65,10,200,26,73,84,29,120,37,213,78,89,111,23,84,13,200 ; 21 - Crashman + +; Digital Sound Processor of the SPC700 By _Demo_ + +%macro initrevsthelp 1 + mov al,[DSPMem+01h+%1] + mov ah,[DSPMem+00h+%1] + mov [DSPMem+01h+%1],ah + mov [DSPMem+00h+%1],al +%endmacro + +NEWSYM initrevst + cmp byte[RevStereo],0 +; jne .norev + ret +.norev + initrevsthelp 00h + initrevsthelp 10h + initrevsthelp 20h + initrevsthelp 30h + initrevsthelp 40h + initrevsthelp 50h + initrevsthelp 60h + initrevsthelp 70h + ret + +ALIGN32 + +NEWSYM DSPMem, times 256 db 0 + +;Read DSP Registers functions + +NEWSYM RDSPReg00 ; Voice 0 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+00h] + ret +.rev + mov al,[DSPMem+01h] + ret + +NEWSYM RDSPReg01 ; Voice 0 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+01h] + ret +.rev + mov al,[DSPMem+00h] + ret + +NEWSYM RDSPReg02 ; Voice 0 Pitch Low + mov al,[DSPMem+02h] + ret + +NEWSYM RDSPReg03 ; Voice 0 Pitch High + mov al,[DSPMem+03h] + ret + +NEWSYM RDSPReg04 ; Voice 0 SCRN + mov al,[DSPMem+04h] + ret + +NEWSYM RDSPReg05 ; Voice 0 ADSR (1) + mov al,[DSPMem+05h] + ret + +NEWSYM RDSPReg06 ; Voice 0 ADSR (2) + mov al,[DSPMem+06h] + ret + +NEWSYM RDSPReg07 ; Voice 0 GAIN + mov al,[DSPMem+07h] + ret + +NEWSYM RDSPReg08 ; Voice 0 ENVX + mov al,[DSPMem+08h] + xor al,al + ret + +NEWSYM RDSPReg09 ; Voice 0 OUTX + mov al,[DSPMem+09h] + ret + +NEWSYM RDSPReg0A ; + mov al,[DSPMem+0Ah] + ret + +NEWSYM RDSPReg0B ; + mov al,[DSPMem+0Bh] + ret + +NEWSYM RDSPReg0C ; + mov al,[DSPMem+0Ch] + ret + +NEWSYM RDSPReg0D ; + mov al,[DSPMem+0Dh] + ret + +NEWSYM RDSPReg0E ; + mov al,[DSPMem+0Eh] + ret + +NEWSYM RDSPReg0F ; Voice 0 Echo coefficient + mov al,[DSPMem+0Fh] + ret + +NEWSYM RDSPReg10 ; Voice 1 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+10h] + ret +.rev + mov al,[DSPMem+11h] + ret + +NEWSYM RDSPReg11 ; Voice 1 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+11h] + ret +.rev + mov al,[DSPMem+10h] + ret + +NEWSYM RDSPReg12 ; Voice 1 Pitch Low + mov al,[DSPMem+012h] + ret + +NEWSYM RDSPReg13 ; Voice 1 Pitch High + mov al,[DSPMem+013h] + ret + +NEWSYM RDSPReg14 ; Voice 1 SCRN + mov al,[DSPMem+014h] + ret + +NEWSYM RDSPReg15 ; Voice 1 ADSR (1) + mov al,[DSPMem+015h] + ret + +NEWSYM RDSPReg16 ; Voice 1 ADSR (2) + mov al,[DSPMem+016h] + ret + +NEWSYM RDSPReg17 ; Voice 1 GAIN + mov al,[DSPMem+017h] + ret + +NEWSYM RDSPReg18 ; Voice 1 ENVX + mov al,[DSPMem+018h] + xor al,al + ret + +NEWSYM RDSPReg19 ; Voice 1 OUTX + mov al,[DSPMem+019h] + ret + +NEWSYM RDSPReg1A ; + mov al,[DSPMem+01Ah] + ret + +NEWSYM RDSPReg1B ; + mov al,[DSPMem+01Bh] + ret + +NEWSYM RDSPReg1C ; + mov al,[DSPMem+01Ch] + ret + +NEWSYM RDSPReg1D ; + mov al,[DSPMem+01Dh] + ret + +NEWSYM RDSPReg1E ; + mov al,[DSPMem+01Eh] + ret + +NEWSYM RDSPReg1F ; Voice 1 Echo coefficient + mov al,[DSPMem+01Fh] + ret + +NEWSYM RDSPReg20 ; Voice 2 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+20h] + ret +.rev + mov al,[DSPMem+21h] + ret + +NEWSYM RDSPReg21 ; Voice 2 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+21h] + ret +.rev + mov al,[DSPMem+20h] + ret + +NEWSYM RDSPReg22 ; Voice 2 Pitch Low + mov al,[DSPMem+022h] + ret + +NEWSYM RDSPReg23 ; Voice 2 Pitch High + mov al,[DSPMem+023h] + ret + +NEWSYM RDSPReg24 ; Voice 2 SCRN + mov al,[DSPMem+024h] + ret + +NEWSYM RDSPReg25 ; Voice 2 ADSR (1) + mov al,[DSPMem+025h] + ret + +NEWSYM RDSPReg26 ; Voice 2 ADSR (2) + mov al,[DSPMem+026h] + ret + +NEWSYM RDSPReg27 ; Voice 2 GAIN + mov al,[DSPMem+027h] + ret + +NEWSYM RDSPReg28 ; Voice 2 ENVX + mov al,[DSPMem+028h] + xor al,al + ret + +NEWSYM RDSPReg29 ; Voice 2 OUTX + mov al,[DSPMem+029h] + ret + +NEWSYM RDSPReg2A ; + mov al,[DSPMem+02Ah] + ret + +NEWSYM RDSPReg2B ; + mov al,[DSPMem+02Bh] + ret + +NEWSYM RDSPReg2C ; + mov al,[DSPMem+02Ch] + ret + +NEWSYM RDSPReg2D ; + mov al,[DSPMem+02Dh] + ret + +NEWSYM RDSPReg2E ; + mov al,[DSPMem+02Eh] + ret + +NEWSYM RDSPReg2F ; Voice 2 Echo coefficient + mov al,[DSPMem+02Fh] + ret + +NEWSYM RDSPReg30 ; Voice 3 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+30h] + ret +.rev + mov al,[DSPMem+31h] + ret + +NEWSYM RDSPReg31 ; Voice 3 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+31h] + ret +.rev + mov al,[DSPMem+30h] + ret + +NEWSYM RDSPReg32 ; Voice 3 Pitch Low + mov al,[DSPMem+032h] + ret + +NEWSYM RDSPReg33 ; Voice 3 Pitch High + mov al,[DSPMem+033h] + ret + +NEWSYM RDSPReg34 ; Voice 3 SCRN + mov al,[DSPMem+034h] + ret + +NEWSYM RDSPReg35 ; Voice 3 ADSR (1) + mov al,[DSPMem+035h] + ret + +NEWSYM RDSPReg36 ; Voice 3 ADSR (2) + mov al,[DSPMem+036h] + ret + +NEWSYM RDSPReg37 ; Voice 3 GAIN + mov al,[DSPMem+037h] + ret + +NEWSYM RDSPReg38 ; Voice 3 ENVX + mov al,[DSPMem+038h] + xor al,al + ret + +NEWSYM RDSPReg39 ; Voice 3 OUTX + mov al,[DSPMem+039h] + ret + +NEWSYM RDSPReg3A ; + mov al,[DSPMem+03Ah] + ret + +NEWSYM RDSPReg3B ; + mov al,[DSPMem+03Bh] + ret + +NEWSYM RDSPReg3C ; + mov al,[DSPMem+03Ch] + ret + +NEWSYM RDSPReg3D ; + mov al,[DSPMem+03Dh] + ret + +NEWSYM RDSPReg3E ; + mov al,[DSPMem+03Eh] + ret + +NEWSYM RDSPReg3F ; Voice 3 Echo coefficient + mov al,[DSPMem+03Fh] + ret + +NEWSYM RDSPReg40 ; Voice 4 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+40h] + ret +.rev + mov al,[DSPMem+41h] + ret + +NEWSYM RDSPReg41 ; Voice 4 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+41h] + ret +.rev + mov al,[DSPMem+40h] + ret + +NEWSYM RDSPReg42 ; Voice 4 Pitch Low + mov al,[DSPMem+042h] + ret + +NEWSYM RDSPReg43 ; Voice 4 Pitch High + mov al,[DSPMem+043h] + ret + +NEWSYM RDSPReg44 ; Voice 4 SCRN + mov al,[DSPMem+044h] + ret + +NEWSYM RDSPReg45 ; Voice 4 ADSR (1) + mov al,[DSPMem+045h] + ret + +NEWSYM RDSPReg46 ; Voice 4 ADSR (2) + mov al,[DSPMem+046h] + ret + +NEWSYM RDSPReg47 ; Voice 4 GAIN + mov al,[DSPMem+047h] + ret + +NEWSYM RDSPReg48 ; Voice 4 ENVX + mov al,[DSPMem+048h] + xor al,al + ret + +NEWSYM RDSPReg49 ; Voice 4 OUTX + mov al,[DSPMem+049h] + ret + +NEWSYM RDSPReg4A ; + mov al,[DSPMem+04Ah] + ret + +NEWSYM RDSPReg4B ; + mov al,[DSPMem+04Bh] + ret + +NEWSYM RDSPReg4C ; + mov al,[DSPMem+04Ch] + ret + +NEWSYM RDSPReg4D ; + mov al,[DSPMem+04Dh] + ret + +NEWSYM RDSPReg4E ; + mov al,[DSPMem+04Eh] + ret + +NEWSYM RDSPReg4F ; Voice 4 Echo coefficient + mov al,[DSPMem+04Fh] + ret + +NEWSYM RDSPReg50 ; Voice 5 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+50h] + ret +.rev + mov al,[DSPMem+51h] + ret + +NEWSYM RDSPReg51 ; Voice 5 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+51h] + ret +.rev + mov al,[DSPMem+50h] + ret + +NEWSYM RDSPReg52 ; Voice 5 Pitch Low + mov al,[DSPMem+052h] + ret + +NEWSYM RDSPReg53 ; Voice 5 Pitch High + mov al,[DSPMem+053h] + ret + +NEWSYM RDSPReg54 ; Voice 5 SCRN + mov al,[DSPMem+054h] + ret + +NEWSYM RDSPReg55 ; Voice 5 ADSR (1) + mov al,[DSPMem+055h] + ret + +NEWSYM RDSPReg56 ; Voice 5 ADSR (2) + mov al,[DSPMem+056h] + ret + +NEWSYM RDSPReg57 ; Voice 5 GAIN + mov al,[DSPMem+057h] + ret + +NEWSYM RDSPReg58 ; Voice 5 ENVX + mov al,[DSPMem+058h] + xor al,al + ret + +NEWSYM RDSPReg59 ; Voice 5 OUTX + mov al,[DSPMem+059h] + ret + +NEWSYM RDSPReg5A ; + mov al,[DSPMem+05Ah] + ret + +NEWSYM RDSPReg5B ; + mov al,[DSPMem+05Bh] + ret + +NEWSYM RDSPReg5C ; + mov al,[DSPMem+05Ch] + ret + +NEWSYM RDSPReg5D ; + mov al,[DSPMem+05Dh] + ret + +NEWSYM RDSPReg5E ; + mov al,[DSPMem+05Eh] + ret + +NEWSYM RDSPReg5F ; Voice 5 Echo coefficient + mov al,[DSPMem+05Fh] + ret + +NEWSYM RDSPReg60 ; Voice 6 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+60h] + ret +.rev + mov al,[DSPMem+61h] + ret + +NEWSYM RDSPReg61 ; Voice 6 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+61h] + ret +.rev + mov al,[DSPMem+60h] + ret + +NEWSYM RDSPReg62 ; Voice 6 Pitch Low + mov al,[DSPMem+062h] + ret + +NEWSYM RDSPReg63 ; Voice 6 Pitch High + mov al,[DSPMem+063h] + ret + +NEWSYM RDSPReg64 ; Voice 6 SCRN + mov al,[DSPMem+064h] + ret + +NEWSYM RDSPReg65 ; Voice 6 ADSR (1) + mov al,[DSPMem+065h] + ret + +NEWSYM RDSPReg66 ; Voice 6 ADSR (2) + mov al,[DSPMem+066h] + ret + +NEWSYM RDSPReg67 ; Voice 6 GAIN + mov al,[DSPMem+067h] + ret + +NEWSYM RDSPReg68 ; Voice 6 ENVX + mov al,[DSPMem+068h] + xor al,al + ret + +NEWSYM RDSPReg69 ; Voice 6 OUTX + mov al,[DSPMem+069h] + ret + +NEWSYM RDSPReg6A ; + mov al,[DSPMem+06Ah] + ret + +NEWSYM RDSPReg6B ; + mov al,[DSPMem+06Bh] + ret + +NEWSYM RDSPReg6C ; + mov al,[DSPMem+06Ch] + ret + +NEWSYM RDSPReg6D ; + mov al,[DSPMem+06Dh] + ret + +NEWSYM RDSPReg6E ; + mov al,[DSPMem+06Eh] + ret + +NEWSYM RDSPReg6F ; Voice 6 Echo coefficient + mov al,[DSPMem+06Fh] + ret + +NEWSYM RDSPReg70 ; Voice 7 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+70h] + ret +.rev + mov al,[DSPMem+71h] + ret + +NEWSYM RDSPReg71 ; Voice 7 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov al,[DSPMem+71h] + ret +.rev + mov al,[DSPMem+70h] + ret + +NEWSYM RDSPReg72 ; Voice 7 Pitch Low + mov al,[DSPMem+072h] + ret + +NEWSYM RDSPReg73 ; Voice 7 Pitch High + mov al,[DSPMem+073h] + ret + +NEWSYM RDSPReg74 ; Voice 7 SCRN + mov al,[DSPMem+074h] + ret + +NEWSYM RDSPReg75 ; Voice 7 ADSR (1) + mov al,[DSPMem+075h] + ret + +NEWSYM RDSPReg76 ; Voice 7 ADSR (2) + mov al,[DSPMem+076h] + ret + +NEWSYM RDSPReg77 ; Voice 7 GAIN + mov al,[DSPMem+077h] + ret + +NEWSYM RDSPReg78 ; Voice 7 ENVX + mov al,[DSPMem+078h] + xor al,al + ret + +NEWSYM RDSPReg79 ; Voice 7 OUTX + mov al,[DSPMem+079h] + ret + +NEWSYM RDSPReg7A ; + mov al,[DSPMem+07Ah] + ret + +NEWSYM RDSPReg7B ; + mov al,[DSPMem+07Bh] + ret + +NEWSYM RDSPReg7C ; + mov al,[DSPMem+07Ch] + ret + +NEWSYM RDSPReg7D ; + mov al,[DSPMem+07Dh] + ret + +NEWSYM RDSPReg7E ; + mov al,[DSPMem+07Eh] + ret + +NEWSYM RDSPReg7F ; Voice 7 Echo coefficient + mov al,[DSPMem+07Fh] + ret + +NEWSYM RDSPReg80 ; + mov al,[DSPMem+080h] + ret + +NEWSYM RDSPReg81 ; + mov al,[DSPMem+081h] + ret + +NEWSYM RDSPReg82 ; + mov al,[DSPMem+082h] + ret + +NEWSYM RDSPReg83 ; + mov al,[DSPMem+083h] + ret + +NEWSYM RDSPReg84 ; + mov al,[DSPMem+084h] + ret + +NEWSYM RDSPReg85 ; + mov al,[DSPMem+085h] + ret + +NEWSYM RDSPReg86 ; + mov al,[DSPMem+086h] + ret + +NEWSYM RDSPReg87 ; + mov al,[DSPMem+087h] + ret + +NEWSYM RDSPReg88 ; + mov al,[DSPMem+088h] + ret + +NEWSYM RDSPReg89 ; + mov al,[DSPMem+089h] + ret + +NEWSYM RDSPReg8A ; + mov al,[DSPMem+08Ah] + ret + +NEWSYM RDSPReg8B ; + mov al,[DSPMem+08Bh] + ret + +NEWSYM RDSPReg8C ; + mov al,[DSPMem+08Ch] + ret + +NEWSYM RDSPReg8D ; + mov al,[DSPMem+08Dh] + ret + +NEWSYM RDSPReg8E ; + mov al,[DSPMem+08Eh] + ret + +NEWSYM RDSPReg8F ; + mov al,[DSPMem+08Fh] + ret + +NEWSYM RDSPReg90 ; + mov al,[DSPMem+090h] + ret + +NEWSYM RDSPReg91 ; + mov al,[DSPMem+091h] + ret + +NEWSYM RDSPReg92 ; + mov al,[DSPMem+092h] + ret + +NEWSYM RDSPReg93 ; + mov al,[DSPMem+093h] + ret + +NEWSYM RDSPReg94 ; + mov al,[DSPMem+094h] + ret + +NEWSYM RDSPReg95 ; + mov al,[DSPMem+095h] + ret + +NEWSYM RDSPReg96 ; + mov al,[DSPMem+096h] + ret + +NEWSYM RDSPReg97 ; + mov al,[DSPMem+097h] + ret + +NEWSYM RDSPReg98 ; + mov al,[DSPMem+098h] + ret + +NEWSYM RDSPReg99 ; + mov al,[DSPMem+099h] + ret + +NEWSYM RDSPReg9A ; + mov al,[DSPMem+09Ah] + ret + +NEWSYM RDSPReg9B ; + mov al,[DSPMem+09Bh] + ret + +NEWSYM RDSPReg9C ; + mov al,[DSPMem+09Ch] + ret + +NEWSYM RDSPReg9D ; + mov al,[DSPMem+09Dh] + ret + +NEWSYM RDSPReg9E ; + mov al,[DSPMem+09Eh] + ret + +NEWSYM RDSPReg9F ; + mov al,[DSPMem+09Fh] + ret + +NEWSYM RDSPRegA0 ; + mov al,[DSPMem+0A0h] + ret + +NEWSYM RDSPRegA1 ; + mov al,[DSPMem+0A1h] + ret + +NEWSYM RDSPRegA2 ; + mov al,[DSPMem+0A2h] + ret + +NEWSYM RDSPRegA3 ; + mov al,[DSPMem+0A3h] + ret + +NEWSYM RDSPRegA4 ; + mov al,[DSPMem+0A4h] + ret + +NEWSYM RDSPRegA5 ; + mov al,[DSPMem+0A5h] + ret + +NEWSYM RDSPRegA6 ; + mov al,[DSPMem+0A6h] + ret + +NEWSYM RDSPRegA7 ; + mov al,[DSPMem+0A7h] + ret + +NEWSYM RDSPRegA8 ; + mov al,[DSPMem+0A8h] + ret + +NEWSYM RDSPRegA9 ; + mov al,[DSPMem+0A9h] + ret + +NEWSYM RDSPRegAA ; + mov al,[DSPMem+0AAh] + ret + +NEWSYM RDSPRegAB ; + mov al,[DSPMem+0ABh] + ret + +NEWSYM RDSPRegAC ; + mov al,[DSPMem+0ACh] + ret + +NEWSYM RDSPRegAD ; + mov al,[DSPMem+0ADh] + ret + +NEWSYM RDSPRegAE ; + mov al,[DSPMem+0AEh] + ret + +NEWSYM RDSPRegAF ; + mov al,[DSPMem+0AFh] + ret + +NEWSYM RDSPRegB0 ; + mov al,[DSPMem+0B0h] + ret + +NEWSYM RDSPRegB1 ; + mov al,[DSPMem+0B1h] + ret + +NEWSYM RDSPRegB2 ; + mov al,[DSPMem+0B2h] + ret + +NEWSYM RDSPRegB3 ; + mov al,[DSPMem+0B3h] + ret + +NEWSYM RDSPRegB4 ; + mov al,[DSPMem+0B4h] + ret + +NEWSYM RDSPRegB5 ; + mov al,[DSPMem+0B5h] + ret + +NEWSYM RDSPRegB6 ; + mov al,[DSPMem+0B6h] + ret + +NEWSYM RDSPRegB7 ; + mov al,[DSPMem+0B7h] + ret + +NEWSYM RDSPRegB8 ; + mov al,[DSPMem+0B8h] + ret + +NEWSYM RDSPRegB9 ; + mov al,[DSPMem+0B9h] + ret + +NEWSYM RDSPRegBA ; + mov al,[DSPMem+0BAh] + ret + +NEWSYM RDSPRegBB ; + mov al,[DSPMem+0BBh] + ret + +NEWSYM RDSPRegBC ; + mov al,[DSPMem+0BCh] + ret + +NEWSYM RDSPRegBD ; + mov al,[DSPMem+0BDh] + ret + +NEWSYM RDSPRegBE ; + mov al,[DSPMem+0BEh] + ret + +NEWSYM RDSPRegBF ; + mov al,[DSPMem+0BFh] + ret + +NEWSYM RDSPRegC0 ; + mov al,[DSPMem+0C0h] + ret + +NEWSYM RDSPRegC1 ; + mov al,[DSPMem+0C1h] + ret + +NEWSYM RDSPRegC2 ; + mov al,[DSPMem+0C2h] + ret + +NEWSYM RDSPRegC3 ; + mov al,[DSPMem+0C3h] + ret + +NEWSYM RDSPRegC4 ; + mov al,[DSPMem+0C4h] + ret + +NEWSYM RDSPRegC5 ; + mov al,[DSPMem+0C5h] + ret + +NEWSYM RDSPRegC6 ; + mov al,[DSPMem+0C6h] + ret + +NEWSYM RDSPRegC7 ; + mov al,[DSPMem+0C7h] + ret + +NEWSYM RDSPRegC8 ; + mov al,[DSPMem+0C8h] + ret + +NEWSYM RDSPRegC9 ; + mov al,[DSPMem+0C9h] + ret + +NEWSYM RDSPRegCA ; + mov al,[DSPMem+0CAh] + ret + +NEWSYM RDSPRegCB ; + mov al,[DSPMem+0CBh] + ret + +NEWSYM RDSPRegCC ; + mov al,[DSPMem+0CCh] + ret + +NEWSYM RDSPRegCD ; + mov al,[DSPMem+0CDh] + ret + +NEWSYM RDSPRegCE ; + mov al,[DSPMem+0CEh] + ret + +NEWSYM RDSPRegCF ; + mov al,[DSPMem+0CFh] + ret + +NEWSYM RDSPRegD0 ; + mov al,[DSPMem+0D0h] + ret + +NEWSYM RDSPRegD1 ; + mov al,[DSPMem+0D1h] + ret + +NEWSYM RDSPRegD2 ; + mov al,[DSPMem+0D2h] + ret + +NEWSYM RDSPRegD3 ; + mov al,[DSPMem+0D3h] + ret + +NEWSYM RDSPRegD4 ; + mov al,[DSPMem+0D4h] + ret + +NEWSYM RDSPRegD5 ; + mov al,[DSPMem+0D5h] + ret + +NEWSYM RDSPRegD6 ; + mov al,[DSPMem+0D6h] + ret + +NEWSYM RDSPRegD7 ; + mov al,[DSPMem+0D7h] + ret + +NEWSYM RDSPRegD8 ; + mov al,[DSPMem+0D8h] + ret + +NEWSYM RDSPRegD9 ; + mov al,[DSPMem+0D9h] + ret + +NEWSYM RDSPRegDA ; + mov al,[DSPMem+0DAh] + ret + +NEWSYM RDSPRegDB ; + mov al,[DSPMem+0DBh] + ret + +NEWSYM RDSPRegDC ; + mov al,[DSPMem+0DCh] + ret + +NEWSYM RDSPRegDD ; + mov al,[DSPMem+0DDh] + ret + +NEWSYM RDSPRegDE ; + mov al,[DSPMem+0DEh] + ret + +NEWSYM RDSPRegDF ; + mov al,[DSPMem+0DFh] + ret + +NEWSYM RDSPRegE0 ; + mov al,[DSPMem+0E0h] + ret + +NEWSYM RDSPRegE1 ; + mov al,[DSPMem+0E1h] + ret + +NEWSYM RDSPRegE2 ; + mov al,[DSPMem+0E2h] + ret + +NEWSYM RDSPRegE3 ; + mov al,[DSPMem+0E3h] + ret + +NEWSYM RDSPRegE4 ; + mov al,[DSPMem+0E4h] + ret + +NEWSYM RDSPRegE5 ; + mov al,[DSPMem+0E5h] + ret + +NEWSYM RDSPRegE6 ; + mov al,[DSPMem+0E6h] + ret + +NEWSYM RDSPRegE7 ; + mov al,[DSPMem+0E7h] + ret + +NEWSYM RDSPRegE8 ; + mov al,[DSPMem+0E8h] + ret + +NEWSYM RDSPRegE9 ; + mov al,[DSPMem+0E9h] + ret + +NEWSYM RDSPRegEA ; + mov al,[DSPMem+0EAh] + ret + +NEWSYM RDSPRegEB ; + mov al,[DSPMem+0EBh] + ret + +NEWSYM RDSPRegEC ; + mov al,[DSPMem+0ECh] + ret + +NEWSYM RDSPRegED ; + mov al,[DSPMem+0EDh] + ret + +NEWSYM RDSPRegEE ; + mov al,[DSPMem+0EEh] + ret + +NEWSYM RDSPRegEF ; + mov al,[DSPMem+0EFh] + ret + +NEWSYM RDSPRegF0 ; + mov al,[DSPMem+0F0h] + ret + +NEWSYM RDSPRegF1 ; + mov al,[DSPMem+0F1h] + ret + +NEWSYM RDSPRegF2 ; + mov al,[DSPMem+0F2h] + ret + +NEWSYM RDSPRegF3 ; + mov al,[DSPMem+0F3h] + ret + +NEWSYM RDSPRegF4 ; + mov al,[DSPMem+0F4h] + ret + +NEWSYM RDSPRegF5 ; + mov al,[DSPMem+0F5h] + ret + +NEWSYM RDSPRegF6 ; + mov al,[DSPMem+0F6h] + ret + +NEWSYM RDSPRegF7 ; + mov al,[DSPMem+0F7h] + ret + +NEWSYM RDSPRegF8 ; + mov al,[DSPMem+0F8h] + ret + +NEWSYM RDSPRegF9 ; + mov al,[DSPMem+0F9h] + ret + +NEWSYM RDSPRegFA ; + mov al,[DSPMem+0FAh] + ret + +NEWSYM RDSPRegFB ; + mov al,[DSPMem+0FBh] + ret + +NEWSYM RDSPRegFC ; + mov al,[DSPMem+0FCh] + ret + +NEWSYM RDSPRegFD ; + mov al,[DSPMem+0FDh] + ret + +NEWSYM RDSPRegFE ; + mov al,[DSPMem+0FEh] + ret + +NEWSYM RDSPRegFF ; + mov al,[DSPMem+0FFh] + ret + +%macro ProcessGain 1 + push eax + push ebx + push edx + test byte [DSPMem+07h+%1*10h],80h + jz near %%Direct + test byte [DSPMem+07h+%1*10h],40h + jnz near %%Increase + test byte [DSPMem+07h+%1*10h],20h + jz near %%LinearDec + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[DecreaseRateExp+eax*4] + mov dword[Voice0EnvInc+%1*4],007FFFFFh + shr ebx,5 + mov dword[Voice0Time+%1*4],ebx + mov [GainDecBendDataTime+%1*4],ebx + xor edx,edx + mov eax,127*65536 + sub eax,118*65536 + mov byte[GainDecBendDataPos+%1],0 + mov byte[GainDecBendDataDat+%1],127 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],7 + ret +%%LinearDec + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Decrease+eax*4] + mov dword[Voice0EnvInc+%1*4],007FFFFFh + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],5 + ret +%%Increase + test byte [DSPMem+07h+%1*10h],20h + jz %%LinearInc + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + mov ebx,[Voice0Time+%1*4] + mov eax,ebx + shr eax,2 + sub ebx,eax + dec ebx + mov [Voice0Time+%1*4],ebx + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],6 + ret +%%LinearInc + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],3 + ret +%%Direct + mov al,[DSPMem+07h+%1*10h] + and al,7Fh + mov dword[Voice0EnvInc+%1*4],0 + mov byte [Voice0EnvInc+%1*4+2],al + mov dword [Voice0Time+%1*4],0FFFFFFFFh + mov dword [Voice0IncNumber+%1*4],0 + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],4 + ret +%endmacro + +%macro ProcessGain2 1 + push eax + push ebx + push edx + test byte [DSPMem+07h+%1*10h],80h + jz near %%Direct + test byte [DSPMem+07h+%1*10h],40h + jnz near %%Increase + test byte [DSPMem+07h+%1*10h],20h + jz near %%LinearDec + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[DecreaseRateExp+eax*4] + shr ebx,5 + mov dword[Voice0Time+%1*4],ebx + mov [GainDecBendDataTime+%1*4],ebx + xor edx,edx + mov dh,118 + mov dl,[Voice0EnvInc+%1*4+2] + xor eax,eax + mov al,[VolumeConvTable+edx*2] + xor edx,edx + shl eax,16 + mov dl,[Voice0EnvInc+%1*4+2] + neg eax + shl edx,16 + add eax,edx + xor edx,edx + mov byte[GainDecBendDataPos+%1],0 + div ebx + neg eax + mov [Voice0IncNumber+%1*4],eax + mov al,[Voice0EnvInc+%1*4+2] + mov [GainDecBendDataDat+%1],al + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],7 + ret +%%LinearDec + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Decrease+eax*4] + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + xor eax,eax + mov al,[Voice0EnvInc+%1*4+2] + shl eax,16 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],5 + ret +%%Increase + test byte [DSPMem+07h+%1*10h],20h + jz %%LinearInc + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + xor eax,eax + mov al,[Voice0EnvInc+%1*4+2] + inc al + test al,80h + jz %%noof + mov al,127 +%%noof + xor al,127 + shl eax,16 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + mov ebx,[Voice0Time+%1*4] + mov eax,ebx + shr eax,2 + sub ebx,eax + dec ebx + mov [Voice0Time+%1*4],ebx + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],6 + ret +%%LinearInc + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + xor eax,eax + mov al,[Voice0EnvInc+%1*4+2] + inc al + test al,80h + jz %%noof2 + mov al,127 +%%noof2 + xor al,127 + shl eax,16 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],3 + ret +%%Direct + mov al,[DSPMem+07h+%1*10h] + and al,7Fh + mov dword[Voice0EnvInc+%1*4],0 + mov byte [Voice0EnvInc+%1*4+2],al + mov dword [Voice0Time+%1*4],0FFFFFFFFh + mov dword [Voice0IncNumber+%1*4],0 + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],4 + ret +%%end + pop edx + pop ebx + pop eax + ret +%endmacro + + +%macro SwitchSustain 1 + push eax + push ebx + push edx + mov al,[Voice0EnvInc+%1*4+2] + mov [GainDecBendDataDat+%1],al + cmp byte[Voice0State+%1],8 + je %%full + cmp byte[Voice0State+%1],2 + jae %%nofull +%%full + mov byte[GainDecBendDataDat+%1],7Fh +%%nofull + mov al,[DSPMem+05h+%1*10h] + shr al,4 + and eax,07h + mov edx,[DecayRate+eax*4] + xor eax,eax + mov al,[DSPMem+06h+%1*10h] + and al,1Fh + mov ebx,[SustainRate+eax*4] + cmp edx,ebx + jae near %%decayover + ; ebx = total sustain time + xor eax,eax + mov al,[DSPMem+06h+%1*10h] + shr al,5 + mov al,[AdsrSustLevLoc+eax] + ; traverse through al entries in edx time + ; then through 64-al entries in ebx-edx time + mov [AdsrBlocksLeft+%1],al + sub ebx,edx + push ebx + push eax + mov ebx,eax + mov eax,edx + xor edx,edx + div ebx + mov [Voice0Time+%1*4],eax + mov [GainDecBendDataTime+%1*4],eax + pop eax + pop ebx + mov edx,ebx + mov ebx,64 + sub bl,al + mov eax,edx + xor edx,edx + div ebx + mov [AdsrNextTimeDepth+%1*4],eax + mov dword[Voice0EnvInc+%1*4],0 + mov al,[GainDecBendDataDat+%1] + mov [Voice0EnvInc+%1*4+2],al + mov ebx,[Voice0Time+%1*4] + xor edx,edx + + mov dh,122 + mov dl,[Voice0EnvInc+%1*4+2] + xor eax,eax + mov al,[VolumeConvTable+edx*2] + xor edx,edx + shl eax,16 + mov dl,[Voice0EnvInc+%1*4+2] + neg eax + shl edx,16 + add eax,edx + xor edx,edx + mov byte[GainDecBendDataPos+%1],0 + div ebx + neg eax + mov [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],9 + ret +%%decayover + sub edx,ebx + push ebx + mov eax,edx + xor ebx,ebx + mov bl,[DSPMem+06h+%1*10h] + shr bl,5 + xor bl,07h + mul ebx + mov ebx,7 + div ebx + pop ebx + add ebx,eax + mov dword[Voice0EnvInc+%1*4],007FFFFFh + shr ebx,5 + mov dword[Voice0Time+%1*4],ebx + mov [GainDecBendDataTime+%1*4],ebx + xor edx,edx + + mov dh,118 + mov dl,[Voice0EnvInc+%1*4+2] + xor eax,eax + mov al,[VolumeConvTable+edx*2] + xor edx,edx + shl eax,16 + mov dl,[Voice0EnvInc+%1*4+2] + neg eax + shl edx,16 + add eax,edx + xor edx,edx + mov byte[GainDecBendDataPos+%1],0 + div ebx + neg eax + mov [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + pop eax + mov byte [Voice0State+%1],7 + ret +%endmacro + +%macro VoiceAdsr 1 + test byte[MuteVoiceF],1 << %1 + jnz near .nogain + cmp byte[Voice0State+%1],200 + je near .nogain + cmp [DSPMem+05h+%1*10h],al + je near .nogain + test al,80h + jz near .gain + mov [DSPMem+05h+%1*10h],al + SwitchSustain %1 + ret +.nogain + mov [DSPMem+05h+%1*10h],al + ret +.gain + cmp byte[Voice0Status+%1],1 + jne .nogain + cmp word[DSPMem+06h+%1*10h],0A0E0h + je .nogain + test byte[DSPMem+05h+%1*10h],80h + jz near .gain2 + cmp byte[Voice0State+%1],8 + je .gain1 + cmp byte[Voice0State+%1],2 + jae near .gain2 +.gain1 + mov [DSPMem+05h+%1*10h],al + ProcessGain %1 ; Normal + ret +.gain2 + mov [DSPMem+05h+%1*10h],al + cmp byte [Voice0State+%1],210 + jne %%noendofsamp2 + push eax + push ebx + mov al,%1 + call VoiceStarter + mov dword[Voice0EnvInc+%1*4],007FFFFFh + pop ebx + pop eax +%%noendofsamp2 + ProcessGain2 %1 + ret +%endmacro + +%macro VoiceAdsr2 1 + test byte[MuteVoiceF],1 << %1 + jnz near .noadsrswitch + cmp byte[Voice0State+%1],200 + je near .noadsrswitch + cmp [DSPMem+06h+%1*10h],al + je near .noadsrswitch + mov [DSPMem+06h+%1*10h],al + test byte[DSPMem+05h+%1*10h],80h + jz near .noadsrswitch + SwitchSustain %1 + ret +.noadsrswitch + mov [DSPMem+06h+%1*10h],al + ret +%endmacro + + +%macro VoiceGain 1 + test byte[MuteVoiceF],1 << %1 + jnz near .nogain + cmp byte[Voice0State+%1],200 + je near .nogain + cmp [DSPMem+07h+%1*10h],al + je near .nogain + mov [DSPMem+07h+%1*10h],al + cmp byte[Voice0Status+%1],1 + jne .nogain + test byte[DSPMem+05h+%1*10h],80h + jz .gain +.nogain + mov [DSPMem+07h+%1*10h],al + ret +.gain + cmp byte [Voice0State+%1],210 + jne %%noendofsamp + push eax + push ebx + mov al,%1 + call VoiceStarter + pop ebx + pop eax +%%noendofsamp + ProcessGain2 %1 +%endmacro + +NEWSYM ADSRGAINSwitch, db 0 + +;Write DSP Registers functions + +NEWSYM WDSPReg00 ; Voice 0 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+00h],al + ret +.rev + mov [DSPMem+01h],al + ret + +NEWSYM WDSPReg01 ; Voice 0 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+01h],al + ret +.rev + mov [DSPMem+00h],al + ret + +NEWSYM WDSPReg02 ; Voice 0 Pitch Low + mov [DSPMem+02h],al + ret + +NEWSYM WDSPReg03 ; Voice 0 Pitch High + mov [DSPMem+03h],al + ret + +NEWSYM WDSPReg04 ; Voice 0 SCRN + mov [DSPMem+04h],al + ret + +NEWSYM TempValueSnd, db 0 + +NEWSYM WDSPReg05 ; Voice 0 ADSR (1) + inc byte[TempValueSnd] + VoiceAdsr 0 + ret + +NEWSYM WDSPReg06 ; Voice 0 ADSR (2) + inc byte[TempValueSnd] + VoiceAdsr2 0 + ret + +NEWSYM WDSPReg07 ; Voice 0 GAIN + inc byte[TempValueSnd] + VoiceGain 0 + ret + +NEWSYM WDSPReg08 ; Voice 0 ENVX + mov [DSPMem+08h],al + ret + +NEWSYM WDSPReg09 ; Voice 0 OUTX + mov [DSPMem+09h],al + ret + +NEWSYM WDSPReg0A ; Voice 0 + mov [DSPMem+0Ah],al + ret + +NEWSYM WDSPReg0B ; Voice 0 + mov [DSPMem+0Bh],al + ret + +NEWSYM WDSPReg0C ; Voice 0 + mov [DSPMem+0Ch],al + push eax + and eax,0FFh + mov al,[VolumeTableb+eax] + mov ah,[MusicVol] + mov al,[VolumeConvTable+eax*2] +; cmp byte[RevStereo],1 +; je .rev + mov [GlobalVL],al + pop eax + ret +.rev + mov [GlobalVR],al + pop eax + ret + +NEWSYM WDSPReg0D ; Echo Feedback + mov [DSPMem+0Dh],al + push eax + and eax,0FFh + mov al,[VolumeTableb+eax] + mov [EchoFB],eax + pop eax + ret + +NEWSYM WDSPReg0E ; Voice 0 + mov [DSPMem+0Eh],al + ret + +NEWSYM WDSPReg0F ; Voice 0 Echo coefficient + mov [DSPMem+0Fh],al + push eax + movsx eax,al + mov [FIRTAPVal0],eax + pop eax + ret + +NEWSYM WDSPReg10 ; Voice 1 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+10h],al + ret +.rev + mov [DSPMem+11h],al + ret + +NEWSYM WDSPReg11 ; Voice 1 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+11h],al + ret +.rev + mov [DSPMem+10h],al + ret + +NEWSYM WDSPReg12 ; Voice 1 Pitch Low + mov [DSPMem+012h],al + ret + +NEWSYM WDSPReg13 ; Voice 1 Pitch High + mov [DSPMem+013h],al + ret + +NEWSYM WDSPReg14 ; Voice 1 SCRN + mov [DSPMem+14h],al + ret + +NEWSYM WDSPReg15 ; Voice 1 ADSR (1) + VoiceAdsr 1 + ret + +NEWSYM WDSPReg16 ; Voice 1 ADSR (2) + VoiceAdsr2 1 + ret + +NEWSYM WDSPReg17 ; Voice 1 GAIN + VoiceGain 1 + ret + +NEWSYM WDSPReg18 ; Voice 1 ENVX + mov [DSPMem+018h],al + ret + +NEWSYM WDSPReg19 ; Voice 1 OUTX + mov [DSPMem+019h],al + ret + +NEWSYM WDSPReg1A ; Voice 1 + mov [DSPMem+01Ah],al + ret + +NEWSYM WDSPReg1B ; Voice 1 + mov [DSPMem+01Bh],al + ret + +NEWSYM WDSPReg1C ; Voice 1 + mov [DSPMem+01Ch],al + push eax + and eax,0FFh + mov al,[VolumeTableb+eax] + mov ah,[MusicVol] + mov al,[VolumeConvTable+eax*2] +; cmp byte[RevStereo],1 +; je .rev + mov [GlobalVR],al + pop eax + ret +.rev + mov [GlobalVL],al + pop eax + ret + +NEWSYM WDSPReg1D ; Voice 1 + mov [DSPMem+01Dh],al + ret + +NEWSYM WDSPReg1E ; Voice 1 + mov [DSPMem+01Eh],al + ret + +NEWSYM WDSPReg1F ; Voice 1 Echo coefficient + mov [DSPMem+01Fh],al + push eax + movsx eax,al + mov [FIRTAPVal1],eax + pop eax + ret + +NEWSYM WDSPReg20 ; Voice 2 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+20h],al + ret +.rev + mov [DSPMem+21h],al + ret + +NEWSYM WDSPReg21 ; Voice 2 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+21h],al + ret +.rev + mov [DSPMem+20h],al + ret + +NEWSYM WDSPReg22 ; Voice 2 Pitch Low + mov [DSPMem+022h],al + ret + +NEWSYM WDSPReg23 ; Voice 2 Pitch High + mov [DSPMem+023h],al + ret + +NEWSYM WDSPReg24 ; Voice 2 SCRN + mov [DSPMem+24h],al + ret + +NEWSYM WDSPReg25 ; Voice 2 ADSR (1) + VoiceAdsr 2 + ret + +NEWSYM WDSPReg26 ; Voice 2 ADSR (2) + VoiceAdsr2 2 + ret + +NEWSYM WDSPReg27 ; Voice 2 GAIN + VoiceGain 2 + ret + +NEWSYM WDSPReg28 ; Voice 2 ENVX + mov [DSPMem+028h],al + ret + +NEWSYM WDSPReg29 ; Voice 2 OUTX + mov [DSPMem+029h],al + ret + +NEWSYM WDSPReg2A ; Voice 2 + mov [DSPMem+02Ah],al + ret + +NEWSYM WDSPReg2B ; Voice 2 + mov [DSPMem+02Bh],al + ret + +NEWSYM WDSPReg2C ; Voice 2 + mov [DSPMem+02Ch],al + push eax + and eax,0FFh + mov al,[VolumeTableb+eax] + mov ah,[MusicVol] + mov al,[VolumeConvTable+eax*2] +; cmp byte[RevStereo],1 +; je .rev + mov [EchoVL],al + pop eax + ret +.rev + mov [EchoVR],al + pop eax + ret + +NEWSYM WDSPReg2D ; Voice 2 + mov [DSPMem+02Dh],al + ret + +NEWSYM WDSPReg2E ; Voice 2 + mov [DSPMem+02Eh],al + ret + +NEWSYM WDSPReg2F ; Voice 2 Echo coefficient + mov [DSPMem+02Fh],al + push eax + movsx eax,al + mov [FIRTAPVal2],eax + pop eax + ret + +NEWSYM WDSPReg30 ; Voice 3 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+30h],al + ret +.rev + mov [DSPMem+31h],al + ret + +NEWSYM WDSPReg31 ; Voice 3 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+31h],al + ret +.rev + mov [DSPMem+30h],al + ret + +NEWSYM WDSPReg32 ; Voice 3 Pitch Low + mov [DSPMem+032h],al + ret + +NEWSYM WDSPReg33 ; Voice 3 Pitch High + mov [DSPMem+033h],al + ret + +NEWSYM WDSPReg34 ; Voice 3 SCRN + mov [DSPMem+34h],al + ret + +NEWSYM WDSPReg35 ; Voice 3 ADSR (1) + VoiceAdsr 3 + ret + +NEWSYM WDSPReg36 ; Voice 3 ADSR (2) + VoiceAdsr2 3 + ret + +NEWSYM WDSPReg37 ; Voice 3 GAIN + VoiceGain 3 + ret + +NEWSYM WDSPReg38 ; Voice 3 ENVX + mov [DSPMem+038h],al + ret + +NEWSYM WDSPReg39 ; Voice 3 OUTX + mov [DSPMem+039h],al + ret + +NEWSYM WDSPReg3A ; Voice 3 + mov [DSPMem+03Ah],al + ret + +NEWSYM WDSPReg3B ; Voice 3 + mov [DSPMem+03Bh],al + ret + +NEWSYM WDSPReg3C ; Voice 3 + mov [DSPMem+03Ch],al + push eax + and eax,0FFh + mov al,[VolumeTableb+eax] + mov ah,[MusicVol] + mov al,[VolumeConvTable+eax*2] +; cmp byte[RevStereo],1 +; je .rev + mov [EchoVR],al + pop eax + ret +.rev + mov [EchoVL],al + pop eax + ret + +NEWSYM WDSPReg3D ; Voice 3 + mov byte [Voice0Noise],0 + mov byte [Voice1Noise],0 + mov byte [Voice2Noise],0 + mov byte [Voice3Noise],0 + mov byte [Voice4Noise],0 + mov byte [Voice5Noise],0 + mov byte [Voice6Noise],0 + mov byte [Voice7Noise],0 + test al,1 + jz .TestVoice1 + mov byte [Voice0Noise],1 +.TestVoice1 + test al,2 + jz .TestVoice2 + mov byte [Voice1Noise],1 +.TestVoice2 + test al,4 + jz .TestVoice3 + mov byte [Voice2Noise],1 +.TestVoice3 + test al,8 + jz .TestVoice4 + mov byte [Voice3Noise],1 +.TestVoice4 + test al,16 + jz .TestVoice5 + mov byte [Voice4Noise],1 +.TestVoice5 + test al,32 + jz .TestVoice6 + mov byte [Voice5Noise],1 +.TestVoice6 + test al,64 + jz .TestVoice7 + mov byte [Voice6Noise],1 +.TestVoice7 + test al,128 + jz .TestVoice8 + mov byte [Voice7Noise],1 +.TestVoice8 + mov [DSPMem+03Dh],al + ret + +NEWSYM WDSPReg3E ; Voice 3 + mov [DSPMem+03Eh],al + ret + +NEWSYM WDSPReg3F ; Voice 3 Echo coefficient + mov [DSPMem+03Fh],al + push eax + movsx eax,al + mov [FIRTAPVal3],eax + pop eax + ret + +NEWSYM WDSPReg40 ; Voice 4 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+40h],al + ret +.rev + mov [DSPMem+41h],al + ret + +NEWSYM WDSPReg41 ; Voice 4 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+41h],al + ret +.rev + mov [DSPMem+40h],al + ret + +NEWSYM WDSPReg42 ; Voice 4 Pitch Low + mov [DSPMem+042h],al + ret + +NEWSYM WDSPReg43 ; Voice 4 Pitch High + mov [DSPMem+043h],al + ret + +NEWSYM WDSPReg44 ; Voice 4 SCRN + mov [DSPMem+44h],al + ret + +NEWSYM WDSPReg45 ; Voice 4 ADSR (1) + VoiceAdsr 4 + ret + +NEWSYM WDSPReg46 ; Voice 4 ADSR (2) + VoiceAdsr2 4 + ret + +NEWSYM WDSPReg47 ; Voice 4 GAIN + VoiceGain 4 + ret + +NEWSYM WDSPReg48 ; Voice 4 ENVX + mov [DSPMem+048h],al + ret + +NEWSYM WDSPReg49 ; Voice 4 OUTX + mov [DSPMem+049h],al + ret + +NEWSYM WDSPReg4A ; Voice 4 + mov [DSPMem+04Ah],al + ret + +NEWSYM WDSPReg4B ; Voice 4 + mov [DSPMem+04Bh],al + ret + + +NEWSYM WDSPReg4C ; Key On + push ebx + mov bl,[MuteVoiceF] + xor bl,0FFh + and bl,al + or byte[KeyOnStA],bl + pop ebx + test al,80h + jz .nokon + inc byte[SoundTest] +.nokon + mov [DSPMem+04Ch],al + push eax + xor al,0FFh + and byte [DSPMem+07Ch],al + pop eax + ret + +NEWSYM ProcessKeyOn + test al,1 + jz .TestVoice1 + push edx + call Voice0Start + pop edx +.TestVoice1 + test al,2 + jz .TestVoice2 + push edx + call Voice1Start + pop edx +.TestVoice2 + test al,4 + jz .TestVoice3 + push edx + call Voice2Start + pop edx +.TestVoice3 + test al,8 + jz .TestVoice4 + push edx + call Voice3Start + pop edx +.TestVoice4 + test al,16 + jz .TestVoice5 + push edx + call Voice4Start + pop edx +.TestVoice5 + test al,32 + jz .TestVoice6 + push edx + call Voice5Start + pop edx +.TestVoice6 + test al,64 + jz .TestVoice7 + push edx + call Voice6Start + pop edx +.TestVoice7 + test al,128 + jz .TestVoice8 + push edx + call Voice7Start + pop edx +.TestVoice8 + test al,0FFh + jz .novoice + mov byte[keyonsn],1 +.novoice + ret + +NEWSYM WDSPReg4D ; Voice 4 + mov [DSPMem+04Dh],al + ret + +NEWSYM WDSPReg4E ; Voice 4 + mov [DSPMem+04Eh],al + ret + +NEWSYM WDSPReg4F ; Voice 4 Echo coefficient + mov [DSPMem+04Fh],al + push eax + movsx eax,al + mov [FIRTAPVal4],eax + pop eax + ret + +NEWSYM WDSPReg50 ; Voice 5 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+50h],al + ret +.rev + mov [DSPMem+51h],al + ret + +NEWSYM WDSPReg51 ; Voice 5 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+51h],al + ret +.rev + mov [DSPMem+50h],al + ret + +NEWSYM WDSPReg52 ; Voice 5 Pitch Low + mov [DSPMem+052h],al + ret + +NEWSYM WDSPReg53 ; Voice 5 Pitch High + mov [DSPMem+053h],al + ret + +NEWSYM WDSPReg54 ; Voice 5 SCRN + mov [DSPMem+54h],al + ret + +NEWSYM WDSPReg55 ; Voice 5 ADSR (1) + VoiceAdsr 5 + ret + +NEWSYM WDSPReg56 ; Voice 5 ADSR (2) + VoiceAdsr2 5 + ret + +NEWSYM WDSPReg57 ; Voice 5 GAIN + VoiceGain 5 + ret + +NEWSYM WDSPReg58 ; Voice 5 ENVX + mov [DSPMem+058h],al + ret + +NEWSYM WDSPReg59 ; Voice 5 OUTX + mov [DSPMem+059h],al + ret + +NEWSYM WDSPReg5A ; Voice 5 + mov [DSPMem+05Ah],al + ret + +NEWSYM WDSPReg5B ; Voice 5 + mov [DSPMem+05Bh],al + ret + +%macro keyoffm 1 + test byte[MuteVoiceF],1 << %1 + jnz %%nokeyoff + push eax + push edx + push ebx + mov dword[Voice0Time+%1*4],255 + mov eax,[Voice0EnvInc+%1*4] + shr eax,8 + neg eax + mov dword[Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],200 + mov byte [DSPMem+08h+%1*10h],0 + or byte [DSPMem+7Ch],1 << %1 + pop ebx + pop edx + pop eax +%%nokeyoff +%endmacro + +NEWSYM WDSPReg5C ; Key Off + push eax + xor al,0FFh + and byte[KeyOnStA],al + and byte[KeyOnStB],al + pop eax + test al,1 + jz .TestVoice1 + keyoffm 0 +.TestVoice1 + test al,2 + jz .TestVoice2 + keyoffm 1 +.TestVoice2 + test al,4 + jz .TestVoice3 + keyoffm 2 +.TestVoice3 + test al,8 + jz .TestVoice4 + keyoffm 3 +.TestVoice4 + test al,16 + jz .TestVoice5 + keyoffm 4 +.TestVoice5 + test al,32 + jz .TestVoice6 + keyoffm 5 +.TestVoice6 + test al,64 + jz .TestVoice7 + keyoffm 6 +.TestVoice7 + test al,128 + jz .TestVoice8 + keyoffm 7 +.TestVoice8 + mov [DSPMem+05Ch],al + ret + +NEWSYM WDSPReg5D ; Voice 5 + mov [DSPMem+05Dh],al + ret + +NEWSYM WDSPReg5E ; Voice 5 + mov [DSPMem+05Eh],al + ret + +NEWSYM WDSPReg5F ; Voice 5 Echo coefficient + mov [DSPMem+05Fh],al + push eax + movsx eax,al + mov [FIRTAPVal5],eax + pop eax + ret + +NEWSYM WDSPReg60 ; Voice 6 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+60h],al + ret +.rev + mov [DSPMem+61h],al + ret + +NEWSYM WDSPReg61 ; Voice 6 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+61h],al + ret +.rev + mov [DSPMem+60h],al + ret + +NEWSYM WDSPReg62 ; Voice 6 Pitch Low + mov [DSPMem+062h],al + ret + +NEWSYM WDSPReg63 ; Voice 6 Pitch High + mov [DSPMem+063h],al + ret + +NEWSYM WDSPReg64 ; Voice 6 SCRN + mov [DSPMem+64h],al + ret + +NEWSYM WDSPReg65 ; Voice 6 ADSR (1) + VoiceAdsr 6 + ret + +NEWSYM WDSPReg66 ; Voice 6 ADSR (2) + VoiceAdsr2 6 + ret + +NEWSYM WDSPReg67 ; Voice 6 GAIN + VoiceGain 6 + ret + +NEWSYM WDSPReg68 ; Voice 6 ENVX + mov [DSPMem+068h],al + ret + +NEWSYM WDSPReg69 ; Voice 6 OUTX + mov [DSPMem+069h],al + ret + +NEWSYM WDSPReg6A ; Voice 6 + mov [DSPMem+06Ah],al + ret + +NEWSYM WDSPReg6B ; Voice 6 + mov [DSPMem+06Bh],al + ret + +spcres db 0 + +NEWSYM WDSPReg6C ; Voice 6 + mov [DSPMem+06Ch],al + and byte [DSPMem+06Ch],7Fh + test al,128 + jz .NoRes + inc byte[spcres] +.NoRes + test al,0C0h + jz .NoRes2 + mov byte[Voice0Status],0 + mov byte[Voice1Status],0 + mov byte[Voice2Status],0 + mov byte[Voice3Status],0 + mov byte[Voice4Status],0 + mov byte[Voice5Status],0 + mov byte[Voice6Status],0 + mov byte[Voice7Status],0 +.NoRes2 + push eax + push ebx + push ecx + push edx + and eax,1Fh + xor edx,edx + mov eax,[NoiseSpeeds+eax*4] + mov ebx,[SBToSPC] + shl eax,16 + div ebx + shl eax,2 + mov [NoiseInc],eax + pop edx + pop ecx + pop ebx + pop eax + ret + +NEWSYM WDSPReg6D ; Voice 6 + mov [DSPMem+06Dh],al + ret + +NEWSYM WDSPReg6E ; Voice 6 + mov [DSPMem+06Eh],al + ret + +NEWSYM WDSPReg6F ; Voice 6 Echo coefficient + mov [DSPMem+06Fh],al + push eax + movsx eax,al + mov [FIRTAPVal6],eax + pop eax + ret + +NEWSYM WDSPReg70 ; Voice 7 Volume Left +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+70h],al + ret +.rev + mov [DSPMem+71h],al + ret + +NEWSYM WDSPReg71 ; Voice 7 Volume Right +; cmp byte[RevStereo],1 +; je .rev + mov [DSPMem+71h],al + ret +.rev + mov [DSPMem+70h],al + ret + +NEWSYM WDSPReg72 ; Voice 7 Pitch Low + mov [DSPMem+072h],al + ret + +NEWSYM WDSPReg73 ; Voice 7 Pitch High + mov [DSPMem+073h],al + ret + +NEWSYM WDSPReg74 ; Voice 7 SCRN + mov [DSPMem+74h],al + ret + +NEWSYM WDSPReg75 ; Voice 7 ADSR (1) + VoiceAdsr 7 + ret + +NEWSYM WDSPReg76 ; Voice 7 ADSR (2) + VoiceAdsr2 7 + ret + +NEWSYM WDSPReg77 ; Voice 7 GAIN + VoiceGain 7 + ret + +NEWSYM WDSPReg78 ; Voice 7 ENVX + mov [DSPMem+078h],al + ret + +NEWSYM WDSPReg79 ; Voice 7 OUTX + mov [DSPMem+079h],al + ret + +NEWSYM WDSPReg7A ; Voice 7 + mov [DSPMem+07Ah],al + ret + +NEWSYM WDSPReg7B ; Voice 7 + mov [DSPMem+07Bh],al + ret + +NEWSYM WDSPReg7C ; ENDX + mov byte [DSPMem+07Ch],0 + ret + +NEWSYM WDSPReg7D ; Echo Delay + mov [DSPMem+07Dh],al + push ebx + mov ebx,eax + and ebx,0Fh + mov ebx,[EchoRate+ebx*4] + mov [MaxEcho],ebx + pop ebx + ret + +NEWSYM WDSPReg7E ; Voice 7 + mov [DSPMem+07Eh],al + ret + +NEWSYM WDSPReg7F ; Voice 7 Echo coefficient + mov [DSPMem+07Fh],al + push eax + movsx eax,al + mov [FIRTAPVal7],eax + pop eax + ret + +NEWSYM WDSPReg80 ; + mov [DSPMem+080h],al + ret + +NEWSYM WDSPReg81 ; + mov [DSPMem+081h],al + ret + +NEWSYM WDSPReg82 ; + mov [DSPMem+082h],al + ret + +NEWSYM WDSPReg83 ; + mov [DSPMem+083h],al + ret + +NEWSYM WDSPReg84 ; + mov [DSPMem+084h],al + ret + +NEWSYM WDSPReg85 ; + mov [DSPMem+085h],al + ret + +NEWSYM WDSPReg86 ; + mov [DSPMem+086h],al + ret + +NEWSYM WDSPReg87 ; + mov [DSPMem+087h],al + ret + +NEWSYM WDSPReg88 ; + mov [DSPMem+088h],al + ret + +NEWSYM WDSPReg89 ; + mov [DSPMem+089h],al + ret + +NEWSYM WDSPReg8A ; + mov [DSPMem+08Ah],al + ret + +NEWSYM WDSPReg8B ; + mov [DSPMem+08Bh],al + ret + +NEWSYM WDSPReg8C ; + mov [DSPMem+08Ch],al + ret + +NEWSYM WDSPReg8D ; + mov [DSPMem+08Dh],al + ret + +NEWSYM WDSPReg8E ; + mov [DSPMem+08Eh],al + ret + +NEWSYM WDSPReg8F ; + mov [DSPMem+08Fh],al + ret + +NEWSYM WDSPReg90 ; + mov [DSPMem+090h],al + ret + +NEWSYM WDSPReg91 ; + mov [DSPMem+091h],al + ret + +NEWSYM WDSPReg92 ; + mov [DSPMem+092h],al + ret + +NEWSYM WDSPReg93 ; + mov [DSPMem+093h],al + ret + +NEWSYM WDSPReg94 ; + mov [DSPMem+094h],al + ret + +NEWSYM WDSPReg95 ; + mov [DSPMem+095h],al + ret + +NEWSYM WDSPReg96 ; + mov [DSPMem+096h],al + ret + +NEWSYM WDSPReg97 ; + mov [DSPMem+097h],al + ret + +NEWSYM WDSPReg98 ; + mov [DSPMem+098h],al + ret + +NEWSYM WDSPReg99 ; + mov [DSPMem+099h],al + ret + +NEWSYM WDSPReg9A ; + mov [DSPMem+09Ah],al + ret + +NEWSYM WDSPReg9B ; + mov [DSPMem+09Bh],al + ret + +NEWSYM WDSPReg9C ; + mov [DSPMem+09Ch],al + ret + +NEWSYM WDSPReg9D ; + mov [DSPMem+09Dh],al + ret + +NEWSYM WDSPReg9E ; + mov [DSPMem+09Eh],al + ret + +NEWSYM WDSPReg9F ; + mov [DSPMem+09Fh],al + ret + +NEWSYM WDSPRegA0 ; + mov [DSPMem+0A0h],al + ret + +NEWSYM WDSPRegA1 ; + mov [DSPMem+0A1h],al + ret + +NEWSYM WDSPRegA2 ; + mov [DSPMem+0A2h],al + ret + +NEWSYM WDSPRegA3 ; + mov [DSPMem+0A3h],al + ret + +NEWSYM WDSPRegA4 ; + mov [DSPMem+0A4h],al + ret + +NEWSYM WDSPRegA5 ; + mov [DSPMem+0A5h],al + ret + +NEWSYM WDSPRegA6 ; + mov [DSPMem+0A6h],al + ret + +NEWSYM WDSPRegA7 ; + mov [DSPMem+0A7h],al + ret + +NEWSYM WDSPRegA8 ; + mov [DSPMem+0A8h],al + ret + +NEWSYM WDSPRegA9 ; + mov [DSPMem+0A9h],al + ret + +NEWSYM WDSPRegAA ; + mov [DSPMem+0AAh],al + ret + +NEWSYM WDSPRegAB ; + mov [DSPMem+0ABh],al + ret + +NEWSYM WDSPRegAC ; + mov [DSPMem+0ACh],al + ret + +NEWSYM WDSPRegAD ; + mov [DSPMem+0ADh],al + ret + +NEWSYM WDSPRegAE ; + mov [DSPMem+0AEh],al + ret + +NEWSYM WDSPRegAF ; + mov [DSPMem+0AFh],al + ret + +NEWSYM WDSPRegB0 ; + mov [DSPMem+0B0h],al + ret + +NEWSYM WDSPRegB1 ; + mov [DSPMem+0B1h],al + ret + +NEWSYM WDSPRegB2 ; + mov [DSPMem+0B2h],al + ret + +NEWSYM WDSPRegB3 ; + mov [DSPMem+0B3h],al + ret + +NEWSYM WDSPRegB4 ; + mov [DSPMem+0B4h],al + ret + +NEWSYM WDSPRegB5 ; + mov [DSPMem+0B5h],al + ret + +NEWSYM WDSPRegB6 ; + mov [DSPMem+0B6h],al + ret + +NEWSYM WDSPRegB7 ; + mov [DSPMem+0B7h],al + ret + +NEWSYM WDSPRegB8 ; + mov [DSPMem+0B8h],al + ret + +NEWSYM WDSPRegB9 ; + mov [DSPMem+0B9h],al + ret + +NEWSYM WDSPRegBA ; + mov [DSPMem+0BAh],al + ret + +NEWSYM WDSPRegBB ; + mov [DSPMem+0BBh],al + ret + +NEWSYM WDSPRegBC ; + mov [DSPMem+0BCh],al + ret + +NEWSYM WDSPRegBD ; + mov [DSPMem+0BDh],al + ret + +NEWSYM WDSPRegBE ; + mov [DSPMem+0BEh],al + ret + +NEWSYM WDSPRegBF ; + mov [DSPMem+0BFh],al + ret + +NEWSYM WDSPRegC0 ; + mov [DSPMem+0C0h],al + ret + +NEWSYM WDSPRegC1 ; + mov [DSPMem+0C1h],al + ret + +NEWSYM WDSPRegC2 ; + mov [DSPMem+0C2h],al + ret + +NEWSYM WDSPRegC3 ; + mov [DSPMem+0C3h],al + ret + +NEWSYM WDSPRegC4 ; + mov [DSPMem+0C4h],al + ret + +NEWSYM WDSPRegC5 ; + mov [DSPMem+0C5h],al + ret + +NEWSYM WDSPRegC6 ; + mov [DSPMem+0C6h],al + ret + +NEWSYM WDSPRegC7 ; + mov [DSPMem+0C7h],al + ret + +NEWSYM WDSPRegC8 ; + mov [DSPMem+0C8h],al + ret + +NEWSYM WDSPRegC9 ; + mov [DSPMem+0C9h],al + ret + +NEWSYM WDSPRegCA ; + mov [DSPMem+0CAh],al + ret + +NEWSYM WDSPRegCB ; + mov [DSPMem+0CBh],al + ret + +NEWSYM WDSPRegCC ; + mov [DSPMem+0CCh],al + ret + +NEWSYM WDSPRegCD ; + mov [DSPMem+0CDh],al + ret + +NEWSYM WDSPRegCE ; + mov [DSPMem+0CEh],al + ret + +NEWSYM WDSPRegCF ; + mov [DSPMem+0CFh],al + ret + +NEWSYM WDSPRegD0 ; + mov [DSPMem+0D0h],al + ret + +NEWSYM WDSPRegD1 ; + mov [DSPMem+0D1h],al + ret + +NEWSYM WDSPRegD2 ; + mov [DSPMem+0D2h],al + ret + +NEWSYM WDSPRegD3 ; + mov [DSPMem+0D3h],al + ret + +NEWSYM WDSPRegD4 ; + mov [DSPMem+0D4h],al + ret + +NEWSYM WDSPRegD5 ; + mov [DSPMem+0D5h],al + ret + +NEWSYM WDSPRegD6 ; + mov [DSPMem+0D6h],al + ret + +NEWSYM WDSPRegD7 ; + mov [DSPMem+0D7h],al + ret + +NEWSYM WDSPRegD8 ; + mov [DSPMem+0D8h],al + ret + +NEWSYM WDSPRegD9 ; + mov [DSPMem+0D9h],al + ret + +NEWSYM WDSPRegDA ; + mov [DSPMem+0DAh],al + ret + +NEWSYM WDSPRegDB ; + mov [DSPMem+0DBh],al + ret + +NEWSYM WDSPRegDC ; + mov [DSPMem+0DCh],al + ret + +NEWSYM WDSPRegDD ; + mov [DSPMem+0DDh],al + ret + +NEWSYM WDSPRegDE ; + mov [DSPMem+0DEh],al + ret + +NEWSYM WDSPRegDF ; + mov [DSPMem+0DFh],al + ret + +NEWSYM WDSPRegE0 ; + mov [DSPMem+0E0h],al + ret + +NEWSYM WDSPRegE1 ; + mov [DSPMem+0E1h],al + ret + +NEWSYM WDSPRegE2 ; + mov [DSPMem+0E2h],al + ret + +NEWSYM WDSPRegE3 ; + mov [DSPMem+0E3h],al + ret + +NEWSYM WDSPRegE4 ; + mov [DSPMem+0E4h],al + ret + +NEWSYM WDSPRegE5 ; + mov [DSPMem+0E5h],al + ret + +NEWSYM WDSPRegE6 ; + mov [DSPMem+0E6h],al + ret + +NEWSYM WDSPRegE7 ; + mov [DSPMem+0E7h],al + ret + +NEWSYM WDSPRegE8 ; + mov [DSPMem+0E8h],al + ret + +NEWSYM WDSPRegE9 ; + mov [DSPMem+0E9h],al + ret + +NEWSYM WDSPRegEA ; + mov [DSPMem+0EAh],al + ret + +NEWSYM WDSPRegEB ; + mov [DSPMem+0EBh],al + ret + +NEWSYM WDSPRegEC ; + mov [DSPMem+0ECh],al + ret + +NEWSYM WDSPRegED ; + mov [DSPMem+0EDh],al + ret + +NEWSYM WDSPRegEE ; + mov [DSPMem+0EEh],al + ret + +NEWSYM WDSPRegEF ; + mov [DSPMem+0EFh],al + ret + +NEWSYM WDSPRegF0 ; + mov [DSPMem+0F0h],al + ret + +NEWSYM WDSPRegF1 ; + mov [DSPMem+0F1h],al + ret + +NEWSYM WDSPRegF2 ; + mov [DSPMem+0F2h],al + ret + +NEWSYM WDSPRegF3 ; + mov [DSPMem+0F3h],al + ret + +NEWSYM WDSPRegF4 ; + mov [DSPMem+0F4h],al + ret + +NEWSYM WDSPRegF5 ; + mov [DSPMem+0F5h],al + ret + +NEWSYM WDSPRegF6 ; + mov [DSPMem+0F6h],al + ret + +NEWSYM WDSPRegF7 ; + mov [DSPMem+0F7h],al + ret + +NEWSYM WDSPRegF8 ; + mov [DSPMem+0F8h],al + ret + +NEWSYM WDSPRegF9 ; + mov [DSPMem+0F9h],al + ret + +NEWSYM WDSPRegFA ; + mov [DSPMem+0FAh],al + ret + +NEWSYM WDSPRegFB ; + mov [DSPMem+0FBh],al + ret + +NEWSYM WDSPRegFC ; + mov [DSPMem+0FCh],al + ret + +NEWSYM WDSPRegFD ; + mov [DSPMem+0FDh],al + ret + +NEWSYM WDSPRegFE ; + mov [DSPMem+0FEh],al + ret + +NEWSYM WDSPRegFF ; + mov [DSPMem+0FFh],al + ret + + \ No newline at end of file diff --git a/zsnes/src/cpu/dspproc.asm b/zsnes/src/cpu/dspproc.asm new file mode 100644 index 00000000..4854705b --- /dev/null +++ b/zsnes/src/cpu/dspproc.asm @@ -0,0 +1,5698 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM spcRam, spcPCRam, spcRamDP, spcS, spcX, MovieProcessing +EXTSYM CNetType, soundon, RevStereo +EXTSYM PitchModEn,SoundNoiseDis +EXTSYM DosExit,Invalidopcode,RSPCRegF0,RSPCRegF1,RSPCRegF2,RSPCRegF3 +EXTSYM RSPCRegF4,RSPCRegF5,RSPCRegF6,RSPCRegF7,RSPCRegF8,RSPCRegF9 +EXTSYM RSPCRegFA,RSPCRegFB,RSPCRegFC,RSPCRegFD,RSPCRegFE,RSPCRegFF +EXTSYM SPCRegF0,SPCRegF1,SPCRegF2,SPCRegF3,SPCRegF4,SPCRegF5,SPCRegF6 +EXTSYM SPCRegF7,SPCRegF8,SPCRegF9,SPCRegFA,SPCRegFB,SPCRegFC,SPCRegFD +EXTSYM SPCRegFE,SPCRegFF,VolumeConvTable,dspRptr,dspWptr,opcjmptab +EXTSYM Op00,Op01,Op02,Op03,Op04,Op05,Op06,Op07,Op08,Op09,Op0A,Op0B +EXTSYM Op0C,Op0D,Op0E,Op0F,Op10,Op11,Op12,Op13,Op14,Op15,Op16,Op17 +EXTSYM Op18,Op19,Op1A,Op1B,Op1C,Op1D,Op1E,Op1F,Op20,Op21,Op22,Op23 +EXTSYM Op24,Op25,Op26,Op27,Op28,Op29,Op2A,Op2B,Op2C,Op2D,Op2E,Op2F +EXTSYM Op30,Op31,Op32,Op33,Op34,Op35,Op36,Op37,Op38,Op39,Op3A,Op3B +EXTSYM Op3C,Op3D,Op3E,Op3F,Op40,Op41,Op42,Op43,Op44,Op45,Op46,Op47 +EXTSYM Op48,Op49,Op4A,Op4B,Op4C,Op4D,Op4E,Op4F,Op50,Op51,Op52,Op53 +EXTSYM Op54,Op55,Op56,Op57,Op58,Op59,Op5A,Op5B,Op5C,Op5D,Op5E,Op5F +EXTSYM Op60,Op61,Op62,Op63,Op64,Op65,Op66,Op67,Op68,Op69,Op6A,Op6B +EXTSYM Op6C,Op6D,Op6E,Op6F,Op70,Op71,Op72,Op73,Op74,Op75,Op76,Op77 +EXTSYM Op78,Op79,Op7A,Op7B,Op7C,Op7D,Op7E,Op7F,Op80,Op81,Op82,Op83 +EXTSYM Op84,Op85,Op86,Op87,Op88,Op89,Op8A,Op8B,Op8C,Op8D,Op8E,Op8F +EXTSYM Op90,Op91,Op92,Op93,Op94,Op95,Op96,Op97,Op98,Op99,Op9A,Op9B +EXTSYM Op9C,Op9D,Op9E,Op9F,OpA0,OpA1,OpA2,OpA3,OpA4,OpA5,OpA6,OpA7 +EXTSYM OpA8,OpA9,OpAA,OpAB,OpAC,OpAD,OpAE,OpAF,OpB0,OpB1,OpB2,OpB3 +EXTSYM OpB4,OpB5,OpB6,OpB7,OpB8,OpB9,OpBA,OpBB,OpBC,OpBD,OpBE,OpBF +EXTSYM OpC0,OpC1,OpC2,OpC3,OpC4,OpC5,OpC6,OpC7,OpC8,OpC9,OpCA,OpCB +EXTSYM OpCC,OpCD,OpCE,OpCF,OpD0,OpD1,OpD2,OpD3,OpD4,OpD5,OpD6,OpD7 +EXTSYM OpD8,OpD9,OpDA,OpDB,OpDC,OpDD,OpDE,OpDF,OpE0,OpE1,OpE2,OpE3 +EXTSYM OpE4,OpE5,OpE6,OpE7,OpE8,OpE9,OpEA,OpEB,OpEC,OpED,OpEE,OpEF +EXTSYM OpF0,OpF1,OpF2,OpF3,OpF4,OpF5,OpF6,OpF7,OpF8,OpF9,OpFA,OpFB +EXTSYM OpFC,OpFD,OpFE,OpFF +EXTSYM RDSPReg00,RDSPReg01,RDSPReg02,RDSPReg03,RDSPReg04,RDSPReg05,RDSPReg06 +EXTSYM RDSPReg07,RDSPReg08,RDSPReg09,RDSPReg0A,RDSPReg0B,RDSPReg0C,RDSPReg0D +EXTSYM RDSPReg0E,RDSPReg0F,RDSPReg10,RDSPReg11,RDSPReg12,RDSPReg13,RDSPReg14 +EXTSYM RDSPReg15,RDSPReg16,RDSPReg17,RDSPReg18,RDSPReg19,RDSPReg1A,RDSPReg1B +EXTSYM RDSPReg1C,RDSPReg1D,RDSPReg1E,RDSPReg1F,RDSPReg20,RDSPReg21,RDSPReg22 +EXTSYM RDSPReg23,RDSPReg24,RDSPReg25,RDSPReg26,RDSPReg27,RDSPReg28,RDSPReg29 +EXTSYM RDSPReg2A,RDSPReg2B,RDSPReg2C,RDSPReg2D,RDSPReg2E,RDSPReg2F,RDSPReg30 +EXTSYM RDSPReg31,RDSPReg32,RDSPReg33,RDSPReg34,RDSPReg35,RDSPReg36,RDSPReg37 +EXTSYM RDSPReg38,RDSPReg39,RDSPReg3A,RDSPReg3B,RDSPReg3C,RDSPReg3D,RDSPReg3E +EXTSYM RDSPReg3F,RDSPReg40,RDSPReg41,RDSPReg42,RDSPReg43,RDSPReg44,RDSPReg45 +EXTSYM RDSPReg46,RDSPReg47,RDSPReg48,RDSPReg49,RDSPReg4A,RDSPReg4B,RDSPReg4C +EXTSYM RDSPReg4D,RDSPReg4E,RDSPReg4F,RDSPReg50,RDSPReg51,RDSPReg52,RDSPReg53 +EXTSYM RDSPReg54,RDSPReg55,RDSPReg56,RDSPReg57,RDSPReg58,RDSPReg59,RDSPReg5A +EXTSYM RDSPReg5B,RDSPReg5C,RDSPReg5D,RDSPReg5E,RDSPReg5F,RDSPReg60,RDSPReg61 +EXTSYM RDSPReg62,RDSPReg63,RDSPReg64,RDSPReg65,RDSPReg66,RDSPReg67,RDSPReg68 +EXTSYM RDSPReg69,RDSPReg6A,RDSPReg6B,RDSPReg6C,RDSPReg6D,RDSPReg6E,RDSPReg6F +EXTSYM RDSPReg70,RDSPReg71,RDSPReg72,RDSPReg73,RDSPReg74,RDSPReg75,RDSPReg76 +EXTSYM RDSPReg77,RDSPReg78,RDSPReg79,RDSPReg7A,RDSPReg7B,RDSPReg7C,RDSPReg7D +EXTSYM RDSPReg7E,RDSPReg7F,RDSPReg80,RDSPReg81,RDSPReg82,RDSPReg83,RDSPReg84 +EXTSYM RDSPReg85,RDSPReg86,RDSPReg87,RDSPReg88,RDSPReg89,RDSPReg8A,RDSPReg8B +EXTSYM RDSPReg8C,RDSPReg8D,RDSPReg8E,RDSPReg8F,RDSPReg90,RDSPReg91,RDSPReg92 +EXTSYM RDSPReg93,RDSPReg94,RDSPReg95,RDSPReg96,RDSPReg97,RDSPReg98,RDSPReg99 +EXTSYM RDSPReg9A,RDSPReg9B,RDSPReg9C,RDSPReg9D,RDSPReg9E,RDSPReg9F,RDSPRegA0 +EXTSYM RDSPRegA1,RDSPRegA2,RDSPRegA3,RDSPRegA4,RDSPRegA5,RDSPRegA6,RDSPRegA7 +EXTSYM RDSPRegA8,RDSPRegA9,RDSPRegAA,RDSPRegAB,RDSPRegAC,RDSPRegAD,RDSPRegAE +EXTSYM RDSPRegAF,RDSPRegB0,RDSPRegB1,RDSPRegB2,RDSPRegB3,RDSPRegB4,RDSPRegB5 +EXTSYM RDSPRegB6,RDSPRegB7,RDSPRegB8,RDSPRegB9,RDSPRegBA,RDSPRegBB,RDSPRegBC +EXTSYM RDSPRegBD,RDSPRegBE,RDSPRegBF,RDSPRegC0,RDSPRegC1,RDSPRegC2,RDSPRegC3 +EXTSYM RDSPRegC4,RDSPRegC5,RDSPRegC6,RDSPRegC7,RDSPRegC8,RDSPRegC9,RDSPRegCA +EXTSYM RDSPRegCB,RDSPRegCC,RDSPRegCD,RDSPRegCE,RDSPRegCF,RDSPRegD0,RDSPRegD1 +EXTSYM RDSPRegD2,RDSPRegD3,RDSPRegD4,RDSPRegD5,RDSPRegD6,RDSPRegD7,RDSPRegD8 +EXTSYM RDSPRegD9,RDSPRegDA,RDSPRegDB,RDSPRegDC,RDSPRegDD,RDSPRegDE,RDSPRegDF +EXTSYM RDSPRegE0,RDSPRegE1,RDSPRegE2,RDSPRegE3,RDSPRegE4,RDSPRegE5,RDSPRegE6 +EXTSYM RDSPRegE7,RDSPRegE8,RDSPRegE9,RDSPRegEA,RDSPRegEB,RDSPRegEC,RDSPRegED +EXTSYM RDSPRegEE,RDSPRegEF,RDSPRegF0,RDSPRegF1,RDSPRegF2,RDSPRegF3,RDSPRegF4 +EXTSYM RDSPRegF5,RDSPRegF6,RDSPRegF7,RDSPRegF8,RDSPRegF9,RDSPRegFA,RDSPRegFB +EXTSYM RDSPRegFC,RDSPRegFD,RDSPRegFE,RDSPRegFF +EXTSYM WDSPReg00,WDSPReg01,WDSPReg02,WDSPReg03,WDSPReg04,WDSPReg05,WDSPReg06 +EXTSYM WDSPReg07,WDSPReg08,WDSPReg09,WDSPReg0A,WDSPReg0B,WDSPReg0C,WDSPReg0D +EXTSYM WDSPReg0E,WDSPReg0F,WDSPReg10,WDSPReg11,WDSPReg12,WDSPReg13,WDSPReg14 +EXTSYM WDSPReg15,WDSPReg16,WDSPReg17,WDSPReg18,WDSPReg19,WDSPReg1A,WDSPReg1B +EXTSYM WDSPReg1C,WDSPReg1D,WDSPReg1E,WDSPReg1F,WDSPReg20,WDSPReg21,WDSPReg22 +EXTSYM WDSPReg23,WDSPReg24,WDSPReg25,WDSPReg26,WDSPReg27,WDSPReg28,WDSPReg29 +EXTSYM WDSPReg2A,WDSPReg2B,WDSPReg2C,WDSPReg2D,WDSPReg2E,WDSPReg2F,WDSPReg30 +EXTSYM WDSPReg31,WDSPReg32,WDSPReg33,WDSPReg34,WDSPReg35,WDSPReg36,WDSPReg37 +EXTSYM WDSPReg38,WDSPReg39,WDSPReg3A,WDSPReg3B,WDSPReg3C,WDSPReg3D,WDSPReg3E +EXTSYM WDSPReg3F,WDSPReg40,WDSPReg41,WDSPReg42,WDSPReg43,WDSPReg44,WDSPReg45 +EXTSYM WDSPReg46,WDSPReg47,WDSPReg48,WDSPReg49,WDSPReg4A,WDSPReg4B,WDSPReg4C +EXTSYM WDSPReg4D,WDSPReg4E,WDSPReg4F,WDSPReg50,WDSPReg51,WDSPReg52,WDSPReg53 +EXTSYM WDSPReg54,WDSPReg55,WDSPReg56,WDSPReg57,WDSPReg58,WDSPReg59,WDSPReg5A +EXTSYM WDSPReg5B,WDSPReg5C,WDSPReg5D,WDSPReg5E,WDSPReg5F,WDSPReg60,WDSPReg61 +EXTSYM WDSPReg62,WDSPReg63,WDSPReg64,WDSPReg65,WDSPReg66,WDSPReg67,WDSPReg68 +EXTSYM WDSPReg69,WDSPReg6A,WDSPReg6B,WDSPReg6C,WDSPReg6D,WDSPReg6E,WDSPReg6F +EXTSYM WDSPReg70,WDSPReg71,WDSPReg72,WDSPReg73,WDSPReg74,WDSPReg75,WDSPReg76 +EXTSYM WDSPReg77,WDSPReg78,WDSPReg79,WDSPReg7A,WDSPReg7B,WDSPReg7C,WDSPReg7D +EXTSYM WDSPReg7E,WDSPReg7F,WDSPReg80,WDSPReg81,WDSPReg82,WDSPReg83,WDSPReg84 +EXTSYM WDSPReg85,WDSPReg86,WDSPReg87,WDSPReg88,WDSPReg89,WDSPReg8A,WDSPReg8B +EXTSYM WDSPReg8C,WDSPReg8D,WDSPReg8E,WDSPReg8F,WDSPReg90,WDSPReg91,WDSPReg92 +EXTSYM WDSPReg93,WDSPReg94,WDSPReg95,WDSPReg96,WDSPReg97,WDSPReg98,WDSPReg99 +EXTSYM WDSPReg9A,WDSPReg9B,WDSPReg9C,WDSPReg9D,WDSPReg9E,WDSPReg9F,WDSPRegA0 +EXTSYM WDSPRegA1,WDSPRegA2,WDSPRegA3,WDSPRegA4,WDSPRegA5,WDSPRegA6,WDSPRegA7 +EXTSYM WDSPRegA8,WDSPRegA9,WDSPRegAA,WDSPRegAB,WDSPRegAC,WDSPRegAD,WDSPRegAE +EXTSYM WDSPRegAF,WDSPRegB0,WDSPRegB1,WDSPRegB2,WDSPRegB3,WDSPRegB4,WDSPRegB5 +EXTSYM WDSPRegB6,WDSPRegB7,WDSPRegB8,WDSPRegB9,WDSPRegBA,WDSPRegBB,WDSPRegBC +EXTSYM WDSPRegBD,WDSPRegBE,WDSPRegBF,WDSPRegC0,WDSPRegC1,WDSPRegC2,WDSPRegC3 +EXTSYM WDSPRegC4,WDSPRegC5,WDSPRegC6,WDSPRegC7,WDSPRegC8,WDSPRegC9,WDSPRegCA +EXTSYM WDSPRegCB,WDSPRegCC,WDSPRegCD,WDSPRegCE,WDSPRegCF,WDSPRegD0,WDSPRegD1 +EXTSYM WDSPRegD2,WDSPRegD3,WDSPRegD4,WDSPRegD5,WDSPRegD6,WDSPRegD7,WDSPRegD8 +EXTSYM WDSPRegD9,WDSPRegDA,WDSPRegDB,WDSPRegDC,WDSPRegDD,WDSPRegDE,WDSPRegDF +EXTSYM WDSPRegE0,WDSPRegE1,WDSPRegE2,WDSPRegE3,WDSPRegE4,WDSPRegE5,WDSPRegE6 +EXTSYM WDSPRegE7,WDSPRegE8,WDSPRegE9,WDSPRegEA,WDSPRegEB,WDSPRegEC,WDSPRegED +EXTSYM WDSPRegEE,WDSPRegEF,WDSPRegF0,WDSPRegF1,WDSPRegF2,WDSPRegF3,WDSPRegF4 +EXTSYM WDSPRegF5,WDSPRegF6,WDSPRegF7,WDSPRegF8,WDSPRegF9,WDSPRegFA,WDSPRegFB +EXTSYM WDSPRegFC,WDSPRegFD,WDSPRegFE,WDSPRegFF,OSPort,RaisePitch +EXTSYM delay +EXTSYM spcBuffera +EXTSYM DSPMem +EXTSYM InterSound +EXTSYM NoiseData,SoundCompD,Voice0Disable,csounddisable,dssel,spcRamcmp +EXTSYM cfgecho,Surround,SoundBufEn + EXTSYM echobuf + EXTSYM LowPassFilter + + + + + + + +tempstuff db 0 +; MixEcho +; modpitch + +; How the sound code works : +; Clear memory at $01 to $EF +; Store $BBAA into $2140 +; Wait for $CC in $2142 +; Goto FFEF: +;FFD6: +; Move $2140 into Y +; Repeat until Y = 0 +;FFDA: +; If $2140 <> 0, then jump to FFE9 +; Move $2141 into A +; Move Y into $2140 +; Move A into [$00]+Y +; Increment Y +; Jump to FFDA if Y <> 0 +; Increment value at $01 +;FFE9: +; If plus flag set, goto FFDA +; If (Y-$2140) <> 0, goto FFE9 +;FFEF: +; Move 2142 into YA +; Move YA into Address $00 +; Move A into 2140 +; Move Y into A +; Move A into X +; If A is not zero, goto FFD6 +; Jump to Address [0000] + + +ALIGN32 + +DSPInterP: + times 512 dw 0 + dw 1305,1305,1304,1304,1304,1304,1304,1303 + dw 1303,1303,1302,1302,1301,1300,1300,1299 + dw 1298,1297,1297,1296,1295,1294,1293,1292 + dw 1291,1290,1288,1287,1286,1284,1283,1282 + dw 1280,1279,1277,1275,1274,1272,1270,1269 + dw 1267,1265,1263,1261,1259,1257,1255,1253 + dw 1251,1248,1246,1244,1241,1239,1237,1234 + dw 1232,1229,1227,1224,1221,1219,1216,1213 + dw 1210,1207,1205,1202,1199,1196,1193,1190 + dw 1186,1183,1180,1177,1174,1170,1167,1164 + dw 1160,1157,1153,1150,1146,1143,1139,1136 + dw 1132,1128,1125,1121,1117,1113,1109,1106 + dw 1102,1098,1094,1090,1086,1082,1078,1074 + dw 1070,1066,1061,1057,1053,1049,1045,1040 + dw 1036,1032,1027,1023,1019,1014,1010,1005 + dw 1001, 997, 992, 988, 983, 978, 974, 969 + dw 965, 960, 955, 951, 946, 941, 937, 932 + dw 927, 923, 918, 913, 908, 904, 899, 894 + dw 889, 884, 880, 875, 870, 865, 860, 855 + dw 851, 846, 841, 836, 831, 826, 821, 816 + dw 811, 806, 802, 797, 792, 787, 782, 777 + dw 772, 767, 762, 757, 752, 747, 742, 737 + dw 732, 728, 723, 718, 713, 708, 703, 698 + dw 693, 688, 683, 678, 674, 669, 664, 659 + dw 654, 649, 644, 640, 635, 630, 625, 620 + dw 615, 611, 606, 601, 596, 592, 587, 582 + dw 577, 573, 568, 563, 559, 554, 550, 545 + dw 540, 536, 531, 527, 522, 517, 513, 508 + dw 504, 499, 495, 491, 486, 482, 477, 473 + dw 469, 464, 460, 456, 451, 447, 443, 439 + dw 434, 430, 426, 422, 418, 414, 410, 405 + dw 401, 397, 393, 389, 385, 381, 378, 374 + dw 370, 366, 362, 358, 354, 351, 347, 343 + dw 339, 336, 332, 328, 325, 321, 318, 314 + dw 311, 307, 304, 300, 297, 293, 290, 286 + dw 283, 280, 276, 273, 270, 267, 263, 260 + dw 257, 254, 251, 248, 245, 242, 239, 236 + dw 233, 230, 227, 224, 221, 218, 215, 212 + dw 210, 207, 204, 201, 199, 196, 193, 191 + dw 188, 186, 183, 180, 178, 175, 173, 171 + dw 168, 166, 163, 161, 159, 156, 154, 152 + dw 150, 147, 145, 143, 141, 139, 137, 134 + dw 132, 130, 128, 126, 124, 122, 120, 118 + dw 117, 115, 113, 111, 109, 107, 106, 104 + dw 102, 100, 99, 97, 95, 94, 92, 90 + dw 89, 87, 86, 84, 83, 81, 80, 78 + dw 77, 76, 74, 73, 71, 70, 69, 67 + dw 66, 65, 64, 62, 61, 60, 59, 58 + dw 56, 55, 54, 53, 52, 51, 50, 49 + dw 48, 47, 46, 45, 44, 43, 42, 41 + dw 40, 39, 38, 37, 36, 36, 35, 34 + dw 33, 32, 32, 31, 30, 29, 29, 28 + dw 27, 27, 26, 25, 24, 24, 23, 23 + dw 22, 21, 21, 20, 20, 19, 19, 18 + dw 17, 17, 16, 16, 15, 15, 15, 14 + dw 14, 13, 13, 12, 12, 11, 11, 11 + dw 10, 10, 10, 9, 9, 9, 8, 8 + dw 8, 7, 7, 7, 6, 6, 6, 6 + dw 5, 5, 5, 5, 4, 4, 4, 4 + dw 4, 3, 3, 3, 3, 3, 2, 2 + dw 2, 2, 2, 2, 2, 1, 1, 1 + dw 1, 1, 1, 1, 1, 1, 1, 1 + dw 0, 0, 0, 0, 0, 0, 0, 0 + dw 0, 0, 0, 0, 0, 0, 0, 0 + + dw 0, 0, 0, 0, 0, 0, 0, 0 + dw 0, 0, 0, 0, 0, 0, 0, 0 + dw 0, 0, 0, 0, 0, 0, 0, 0 + dw 0, 0, 0, 0, 0, 0, 0, 0 + dw 0, 0, 0, 0, 0, 0, 0, 0 + dw 0, 0, 0, 0, 0, 0, 0, 0 + +ALIGN32 + +NEWSYM spcWptr, times 16 dd 0 ; SPC Write pointers (point to their own functions) +NEWSYM spcRptr, times 16 dd 0 ; SPC Read pointers (point to their own functions) + +;dspWptr times 256 dd 0 ; DSP Write pointers (point to their own functions) +;dspRptr times 256 dd 0 ; DSP Read pointers (point to their own functions) + +NEWSYM SoundQuality, dd 2 +NEWSYM StereoSound, db 0 +NEWSYM SBToSPC, dd 22050 +NEWSYM NumBRRconv, dd 0 +NEWSYM BufferSizeB, dd 320 +NEWSYM BufferSizeW, dd 640 +NEWSYM SBBufferLoc, dd 0 +NEWSYM SBBufferMov, dd 0 +NEWSYM SBBufferInc, dd 0 +NEWSYM SoundInterrupt, dd 0 + +;TIME_CONSTANT = 256 - 1000000 / frequency + +NEWSYM BufferSize, dw 320, 320, 320, 500, 320, 400, 400 +NEWSYM BufferSizes, dw 320, 320, 500, 900, 400, 750, 750 +NEWSYM SoundSpeeds, db 131, 165, 211, 233, 193, 225, 235 ; 8khz,11khz,22khz,44khz +NEWSYM SoundSpeedt, db 193, 210, 233 ; 8khz,11khz,22khz +NEWSYM SBToSPCSpeeds, dd 8000,10989,22222,43478,15874,32258,48000 +NEWSYM SBToSPCSpeeds2, dd 8192,11289,22579,45158,16384,32768,48000 +NEWSYM NumofSPCBlock, dd 626,456,228,114,314,156,104 +NEWSYM SPCBlockNum, dd 0 +NEWSYM NoiseSpeeds + dd 1,16,21,25,31,42,50,63,83,100,125,170,200,250,333,400,500,667, + dd 800,1000,1300,1600,2000,2700,3200,4000,5300,6400,8000,10700, + dd 16000,32000 + +NEWSYM conv2speedb +.next + mov eax,[esi] + mov ebx,[SBToSPC] + shr ebx,4 + mul ebx + mov ebx,[SBRateb] + shr ebx,4 + div ebx + cmp eax,0 + jne .nozero + mov eax,1 +.nozero +; mov [esi],eax + add esi,4 + dec ecx + jnz .next + ret + +%macro initpitchm 1 + mov ax,[DSPMem+02h+%1*10h] + mov word[Voice0Pitch+%1*2],ax + xor ebx,ebx + xor edx,edx + and eax,03FFFh + shl eax,2 + mov dl,ah + shl eax,24 + mov ebx,[SBToSPC] + div ebx + shl eax,1 + mov [Voice0Freq+%1*4],eax + ; modpitch +%endmacro + +NEWSYM initpitch + initpitchm 0 + initpitchm 1 + initpitchm 2 + initpitchm 3 + initpitchm 4 + initpitchm 5 + initpitchm 6 + initpitchm 7 + ret + +%macro fixdspm 1 + mov esi,%1 + mov ecx,8 + call conv2speedb +%endmacro + +NEWSYM fixdsp +; mov dword[SBRateb],22050 + cmp dword[SBRateb],0 + je near .nofix + fixdspm Voice0Freq + fixdspm Voice0Time + fixdspm Voice0Attack + fixdspm Voice0Decay + fixdspm Voice0SustainR + fixdspm Voice0SustainR2 + fixdspm Voice0IncNumber + fixdspm Voice0SLenNumber + fixdspm Voice0SEndNumber + fixdspm Voice0SEndLNumber + fixdspm Voice0DecreaseNumber + mov ebx,[SBToSPC] + mov [SBRateb],ebx +.nofix + ret + +NEWSYM conv2speed +.next + mov eax,[edi] + mov ebx,[SBToSPC] + shr ebx,4 + mul ebx + mov ebx,11025 + shr ebx,4 + div ebx + mov [esi],eax + add esi,4 + add edi,4 + dec ecx + jnz .next + ret + + +NEWSYM AdjustFrequency + cmp byte[StereoSound],1 + jne .nostereo8b + cmp byte[SBHDMA],0 + jne .nostereo8b + cmp dword[SoundQuality],2 + jbe .nostereo8b + mov dword[SoundQuality],2 +.nostereo8b + + mov eax,[SoundQuality] + mov ebx,[NumofSPCBlock+eax*4] + cmp byte[StereoSound],1 + jne .nostereo + shr ebx,1 +.nostereo + mov [SPCBlockNum],ebx +.next + + mov ecx,[SoundQuality] + mov eax,dword [SBToSPCSpeeds+ecx*4] + cmp byte [SBHDMA],0 + je .not16bit + mov eax,dword [SBToSPCSpeeds2+ecx*4] +.not16bit + cmp byte[RaisePitch],0 + jne .nopitchmodify + ; *1000/1024 + mov ebx,1024 + mul ebx + xor edx,edx + mov ebx,1000 + div ebx +.nopitchmodify + mov [SBToSPC],eax + mov [SBRateb],eax + + ; Init all rates + mov esi,EchoRate + mov edi,EchoRateO + mov ecx,16 + call conv2speed + mov esi,AttackRate + mov edi,AttackRateO + mov ecx,16 + call conv2speed + mov esi,DecayRate + mov edi,DecayRateO + mov ecx,8 + call conv2speed + mov esi,SustainRate+4 + mov edi,SustainRateO+4 + mov ecx,31 + call conv2speed + mov esi,Increase+4 + mov edi,IncreaseO+4 + mov ecx,31 + call conv2speed + mov esi,IncreaseBent+4 + mov edi,IncreaseBentO+4 + mov ecx,31 + call conv2speed + mov esi,Decrease+4 + mov edi,DecreaseO+4 + mov ecx,31 + call conv2speed + mov esi,DecreaseRateExp+4 + mov edi,DecreaseRateExpO+4 + mov ecx,31 + call conv2speed + mov dword[Voice0Pitch],0xFFFEFFFE + mov dword[Voice0Pitch+4],0xFFFEFFFE + mov dword[Voice0Pitch+8],0xFFFEFFFE + mov dword[Voice0Pitch+12],0xFFFEFFFE + ret + +NEWSYM InitSPC + push eax + push ebx + push ecx + push edx + + ; Mirror Interpolation Table + mov ebx,DSPInterP + mov edx,DSPInterP+2046 + mov ecx,512 +.intrploop + xor eax,eax + mov ax,[edx] + or ax,ax + jz .nodec + dec ax +.nodec + mov [edx],ax + mov [ebx],ax + add ebx,2 + sub edx,2 + loop .intrploop + + call AdjustFrequency + + mov ecx,32768 + mov edx,32767 +.nextvol + mov al,dh + imul dl + shr ax,7 + movsx bx,al + mov [VolumeConvTable+edx*2],bx + dec edx + dec ecx + jnz .nextvol + + mov eax,spcRam + mov ebx,0EFh +.loop2 + mov byte[eax],0 + inc eax + dec ebx + jnz .loop2 + mov byte[spcX],0 + + xor eax,eax + xor ebx,ebx + mov ebp,spcRam + mov ax,0FFC9h + add ebp,eax + mov [spcPCRam],ebp + mov dword [spcS],1EFh + mov dword [spcRamDP],spcRam + + ; initialize all the SPC write registers + mov dword[spcWptr+0],SPCRegF0 + mov dword[spcWptr+4],SPCRegF1 + mov dword[spcWptr+8],SPCRegF2 + mov dword[spcWptr+12],SPCRegF3 + mov dword[spcWptr+16],SPCRegF4 + mov dword[spcWptr+20],SPCRegF5 + mov dword[spcWptr+24],SPCRegF6 + mov dword[spcWptr+28],SPCRegF7 + mov dword[spcWptr+32],SPCRegF8 + mov dword[spcWptr+36],SPCRegF9 + mov dword[spcWptr+40],SPCRegFA + mov dword[spcWptr+44],SPCRegFB + mov dword[spcWptr+48],SPCRegFC + mov dword[spcWptr+52],SPCRegFD + mov dword[spcWptr+56],SPCRegFE + mov dword[spcWptr+60],SPCRegFF + mov dword[spcRptr+0],RSPCRegF0 + mov dword[spcRptr+4],RSPCRegF1 + mov dword[spcRptr+8],RSPCRegF2 + mov dword[spcRptr+12],RSPCRegF3 + mov dword[spcRptr+16],RSPCRegF4 + mov dword[spcRptr+20],RSPCRegF5 + mov dword[spcRptr+24],RSPCRegF6 + mov dword[spcRptr+28],RSPCRegF7 + mov dword[spcRptr+32],RSPCRegF8 + mov dword[spcRptr+36],RSPCRegF9 + mov dword[spcRptr+40],RSPCRegFA + mov dword[spcRptr+44],RSPCRegFB + mov dword[spcRptr+48],RSPCRegFC + mov dword[spcRptr+52],RSPCRegFD + mov dword[spcRptr+56],RSPCRegFE + mov dword[spcRptr+60],RSPCRegFF + mov dword [dspRptr+00h],RDSPReg00 + mov dword [dspRptr+04h],RDSPReg01 + mov dword [dspRptr+08h],RDSPReg02 + mov dword [dspRptr+0Ch],RDSPReg03 + mov dword [dspRptr+010h],RDSPReg04 + mov dword [dspRptr+014h],RDSPReg05 + mov dword [dspRptr+018h],RDSPReg06 + mov dword [dspRptr+01Ch],RDSPReg07 + mov dword [dspRptr+020h],RDSPReg08 + mov dword [dspRptr+024h],RDSPReg09 + mov dword [dspRptr+028h],RDSPReg0A + mov dword [dspRptr+02Ch],RDSPReg0B + mov dword [dspRptr+030h],RDSPReg0C + mov dword [dspRptr+034h],RDSPReg0D + mov dword [dspRptr+038h],RDSPReg0E + mov dword [dspRptr+03Ch],RDSPReg0F + mov dword [dspRptr+040h],RDSPReg10 + mov dword [dspRptr+044h],RDSPReg11 + mov dword [dspRptr+048h],RDSPReg12 + mov dword [dspRptr+04Ch],RDSPReg13 + mov dword [dspRptr+050h],RDSPReg14 + mov dword [dspRptr+054h],RDSPReg15 + mov dword [dspRptr+058h],RDSPReg16 + mov dword [dspRptr+05Ch],RDSPReg17 + mov dword [dspRptr+060h],RDSPReg18 + mov dword [dspRptr+064h],RDSPReg19 + mov dword [dspRptr+068h],RDSPReg1A + mov dword [dspRptr+06Ch],RDSPReg1B + mov dword [dspRptr+070h],RDSPReg1C + mov dword [dspRptr+074h],RDSPReg1D + mov dword [dspRptr+078h],RDSPReg1E + mov dword [dspRptr+07Ch],RDSPReg1F + mov dword [dspRptr+080h],RDSPReg20 + mov dword [dspRptr+084h],RDSPReg21 + mov dword [dspRptr+088h],RDSPReg22 + mov dword [dspRptr+08Ch],RDSPReg23 + mov dword [dspRptr+090h],RDSPReg24 + mov dword [dspRptr+094h],RDSPReg25 + mov dword [dspRptr+098h],RDSPReg26 + mov dword [dspRptr+09Ch],RDSPReg27 + mov dword [dspRptr+0A0h],RDSPReg28 + mov dword [dspRptr+0A4h],RDSPReg29 + mov dword [dspRptr+0A8h],RDSPReg2A + mov dword [dspRptr+0ACh],RDSPReg2B + mov dword [dspRptr+0B0h],RDSPReg2C + mov dword [dspRptr+0B4h],RDSPReg2D + mov dword [dspRptr+0B8h],RDSPReg2E + mov dword [dspRptr+0BCh],RDSPReg2F + mov dword [dspRptr+0C0h],RDSPReg30 + mov dword [dspRptr+0C4h],RDSPReg31 + mov dword [dspRptr+0C8h],RDSPReg32 + mov dword [dspRptr+0CCh],RDSPReg33 + mov dword [dspRptr+0D0h],RDSPReg34 + mov dword [dspRptr+0D4h],RDSPReg35 + mov dword [dspRptr+0D8h],RDSPReg36 + mov dword [dspRptr+0DCh],RDSPReg37 + mov dword [dspRptr+0E0h],RDSPReg38 + mov dword [dspRptr+0E4h],RDSPReg39 + mov dword [dspRptr+0E8h],RDSPReg3A + mov dword [dspRptr+0ECh],RDSPReg3B + mov dword [dspRptr+0F0h],RDSPReg3C + mov dword [dspRptr+0F4h],RDSPReg3D + mov dword [dspRptr+0F8h],RDSPReg3E + mov dword [dspRptr+0FCh],RDSPReg3F + mov dword [dspRptr+0100h],RDSPReg40 + mov dword [dspRptr+0104h],RDSPReg41 + mov dword [dspRptr+0108h],RDSPReg42 + mov dword [dspRptr+010Ch],RDSPReg43 + mov dword [dspRptr+0110h],RDSPReg44 + mov dword [dspRptr+0114h],RDSPReg45 + mov dword [dspRptr+0118h],RDSPReg46 + mov dword [dspRptr+011Ch],RDSPReg47 + mov dword [dspRptr+0120h],RDSPReg48 + mov dword [dspRptr+0124h],RDSPReg49 + mov dword [dspRptr+0128h],RDSPReg4A + mov dword [dspRptr+012Ch],RDSPReg4B + mov dword [dspRptr+0130h],RDSPReg4C + mov dword [dspRptr+0134h],RDSPReg4D + mov dword [dspRptr+0138h],RDSPReg4E + mov dword [dspRptr+013Ch],RDSPReg4F + mov dword [dspRptr+0140h],RDSPReg50 + mov dword [dspRptr+0144h],RDSPReg51 + mov dword [dspRptr+0148h],RDSPReg52 + mov dword [dspRptr+014Ch],RDSPReg53 + mov dword [dspRptr+0150h],RDSPReg54 + mov dword [dspRptr+0154h],RDSPReg55 + mov dword [dspRptr+0158h],RDSPReg56 + mov dword [dspRptr+015Ch],RDSPReg57 + mov dword [dspRptr+0160h],RDSPReg58 + mov dword [dspRptr+0164h],RDSPReg59 + mov dword [dspRptr+0168h],RDSPReg5A + mov dword [dspRptr+016Ch],RDSPReg5B + mov dword [dspRptr+0170h],RDSPReg5C + mov dword [dspRptr+0174h],RDSPReg5D + mov dword [dspRptr+0178h],RDSPReg5E + mov dword [dspRptr+017Ch],RDSPReg5F + mov dword [dspRptr+0180h],RDSPReg60 + mov dword [dspRptr+0184h],RDSPReg61 + mov dword [dspRptr+0188h],RDSPReg62 + mov dword [dspRptr+018Ch],RDSPReg63 + mov dword [dspRptr+0190h],RDSPReg64 + mov dword [dspRptr+0194h],RDSPReg65 + mov dword [dspRptr+0198h],RDSPReg66 + mov dword [dspRptr+019Ch],RDSPReg67 + mov dword [dspRptr+01A0h],RDSPReg68 + mov dword [dspRptr+01A4h],RDSPReg69 + mov dword [dspRptr+01A8h],RDSPReg6A + mov dword [dspRptr+01ACh],RDSPReg6B + mov dword [dspRptr+01B0h],RDSPReg6C + mov dword [dspRptr+01B4h],RDSPReg6D + mov dword [dspRptr+01B8h],RDSPReg6E + mov dword [dspRptr+01BCh],RDSPReg6F + mov dword [dspRptr+01C0h],RDSPReg70 + mov dword [dspRptr+01C4h],RDSPReg71 + mov dword [dspRptr+01C8h],RDSPReg72 + mov dword [dspRptr+01CCh],RDSPReg73 + mov dword [dspRptr+01D0h],RDSPReg74 + mov dword [dspRptr+01D4h],RDSPReg75 + mov dword [dspRptr+01D8h],RDSPReg76 + mov dword [dspRptr+01DCh],RDSPReg77 + mov dword [dspRptr+01E0h],RDSPReg78 + mov dword [dspRptr+01E4h],RDSPReg79 + mov dword [dspRptr+01E8h],RDSPReg7A + mov dword [dspRptr+01ECh],RDSPReg7B + mov dword [dspRptr+01F0h],RDSPReg7C + mov dword [dspRptr+01F4h],RDSPReg7D + mov dword [dspRptr+01F8h],RDSPReg7E + mov dword [dspRptr+01FCh],RDSPReg7F + mov dword [dspRptr+0200h],RDSPReg80 + mov dword [dspRptr+0204h],RDSPReg81 + mov dword [dspRptr+0208h],RDSPReg82 + mov dword [dspRptr+020Ch],RDSPReg83 + mov dword [dspRptr+0210h],RDSPReg84 + mov dword [dspRptr+0214h],RDSPReg85 + mov dword [dspRptr+0218h],RDSPReg86 + mov dword [dspRptr+021Ch],RDSPReg87 + mov dword [dspRptr+0220h],RDSPReg88 + mov dword [dspRptr+0224h],RDSPReg89 + mov dword [dspRptr+0228h],RDSPReg8A + mov dword [dspRptr+022Ch],RDSPReg8B + mov dword [dspRptr+0230h],RDSPReg8C + mov dword [dspRptr+0234h],RDSPReg8D + mov dword [dspRptr+0238h],RDSPReg8E + mov dword [dspRptr+023Ch],RDSPReg8F + mov dword [dspRptr+0240h],RDSPReg90 + mov dword [dspRptr+0244h],RDSPReg91 + mov dword [dspRptr+0248h],RDSPReg92 + mov dword [dspRptr+024Ch],RDSPReg93 + mov dword [dspRptr+0250h],RDSPReg94 + mov dword [dspRptr+0254h],RDSPReg95 + mov dword [dspRptr+0258h],RDSPReg96 + mov dword [dspRptr+025Ch],RDSPReg97 + mov dword [dspRptr+0260h],RDSPReg98 + mov dword [dspRptr+0264h],RDSPReg99 + mov dword [dspRptr+0268h],RDSPReg9A + mov dword [dspRptr+026Ch],RDSPReg9B + mov dword [dspRptr+0270h],RDSPReg9C + mov dword [dspRptr+0274h],RDSPReg9D + mov dword [dspRptr+0278h],RDSPReg9E + mov dword [dspRptr+027Ch],RDSPReg9F + mov dword [dspRptr+0280h],RDSPRegA0 + mov dword [dspRptr+0284h],RDSPRegA1 + mov dword [dspRptr+0288h],RDSPRegA2 + mov dword [dspRptr+028Ch],RDSPRegA3 + mov dword [dspRptr+0290h],RDSPRegA4 + mov dword [dspRptr+0294h],RDSPRegA5 + mov dword [dspRptr+0298h],RDSPRegA6 + mov dword [dspRptr+029Ch],RDSPRegA7 + mov dword [dspRptr+02A0h],RDSPRegA8 + mov dword [dspRptr+02A4h],RDSPRegA9 + mov dword [dspRptr+02A8h],RDSPRegAA + mov dword [dspRptr+02ACh],RDSPRegAB + mov dword [dspRptr+02B0h],RDSPRegAC + mov dword [dspRptr+02B4h],RDSPRegAD + mov dword [dspRptr+02B8h],RDSPRegAE + mov dword [dspRptr+02BCh],RDSPRegAF + mov dword [dspRptr+02C0h],RDSPRegB0 + mov dword [dspRptr+02C4h],RDSPRegB1 + mov dword [dspRptr+02C8h],RDSPRegB2 + mov dword [dspRptr+02CCh],RDSPRegB3 + mov dword [dspRptr+02D0h],RDSPRegB4 + mov dword [dspRptr+02D4h],RDSPRegB5 + mov dword [dspRptr+02D8h],RDSPRegB6 + mov dword [dspRptr+02DCh],RDSPRegB7 + mov dword [dspRptr+02E0h],RDSPRegB8 + mov dword [dspRptr+02E4h],RDSPRegB9 + mov dword [dspRptr+02E8h],RDSPRegBA + mov dword [dspRptr+02ECh],RDSPRegBB + mov dword [dspRptr+02F0h],RDSPRegBC + mov dword [dspRptr+02F4h],RDSPRegBD + mov dword [dspRptr+02F8h],RDSPRegBE + mov dword [dspRptr+02FCh],RDSPRegBF + mov dword [dspRptr+0300h],RDSPRegC0 + mov dword [dspRptr+0304h],RDSPRegC1 + mov dword [dspRptr+0308h],RDSPRegC2 + mov dword [dspRptr+030Ch],RDSPRegC3 + mov dword [dspRptr+0310h],RDSPRegC4 + mov dword [dspRptr+0314h],RDSPRegC5 + mov dword [dspRptr+0318h],RDSPRegC6 + mov dword [dspRptr+031Ch],RDSPRegC7 + mov dword [dspRptr+0320h],RDSPRegC8 + mov dword [dspRptr+0324h],RDSPRegC9 + mov dword [dspRptr+0328h],RDSPRegCA + mov dword [dspRptr+032Ch],RDSPRegCB + mov dword [dspRptr+0330h],RDSPRegCC + mov dword [dspRptr+0334h],RDSPRegCD + mov dword [dspRptr+0338h],RDSPRegCE + mov dword [dspRptr+033Ch],RDSPRegCF + mov dword [dspRptr+0340h],RDSPRegD0 + mov dword [dspRptr+0344h],RDSPRegD1 + mov dword [dspRptr+0348h],RDSPRegD2 + mov dword [dspRptr+034Ch],RDSPRegD3 + mov dword [dspRptr+0350h],RDSPRegD4 + mov dword [dspRptr+0354h],RDSPRegD5 + mov dword [dspRptr+0358h],RDSPRegD6 + mov dword [dspRptr+035Ch],RDSPRegD7 + mov dword [dspRptr+0360h],RDSPRegD8 + mov dword [dspRptr+0364h],RDSPRegD9 + mov dword [dspRptr+0368h],RDSPRegDA + mov dword [dspRptr+036Ch],RDSPRegDB + mov dword [dspRptr+0370h],RDSPRegDC + mov dword [dspRptr+0374h],RDSPRegDD + mov dword [dspRptr+0378h],RDSPRegDE + mov dword [dspRptr+037Ch],RDSPRegDF + mov dword [dspRptr+0380h],RDSPRegE0 + mov dword [dspRptr+0384h],RDSPRegE1 + mov dword [dspRptr+0388h],RDSPRegE2 + mov dword [dspRptr+038Ch],RDSPRegE3 + mov dword [dspRptr+0390h],RDSPRegE4 + mov dword [dspRptr+0394h],RDSPRegE5 + mov dword [dspRptr+0398h],RDSPRegE6 + mov dword [dspRptr+039Ch],RDSPRegE7 + mov dword [dspRptr+03A0h],RDSPRegE8 + mov dword [dspRptr+03A4h],RDSPRegE9 + mov dword [dspRptr+03A8h],RDSPRegEA + mov dword [dspRptr+03ACh],RDSPRegEB + mov dword [dspRptr+03B0h],RDSPRegEC + mov dword [dspRptr+03B4h],RDSPRegED + mov dword [dspRptr+03B8h],RDSPRegEE + mov dword [dspRptr+03BCh],RDSPRegEF + mov dword [dspRptr+03C0h],RDSPRegF0 + mov dword [dspRptr+03C4h],RDSPRegF1 + mov dword [dspRptr+03C8h],RDSPRegF2 + mov dword [dspRptr+03CCh],RDSPRegF3 + mov dword [dspRptr+03D0h],RDSPRegF4 + mov dword [dspRptr+03D4h],RDSPRegF5 + mov dword [dspRptr+03D8h],RDSPRegF6 + mov dword [dspRptr+03DCh],RDSPRegF7 + mov dword [dspRptr+03E0h],RDSPRegF8 + mov dword [dspRptr+03E4h],RDSPRegF9 + mov dword [dspRptr+03E8h],RDSPRegFA + mov dword [dspRptr+03ECh],RDSPRegFB + mov dword [dspRptr+03F0h],RDSPRegFC + mov dword [dspRptr+03F4h],RDSPRegFD + mov dword [dspRptr+03F8h],RDSPRegFE + mov dword [dspRptr+03FCh],RDSPRegFF + + mov dword [dspWptr+00h],WDSPReg00 + mov dword [dspWptr+04h],WDSPReg01 + mov dword [dspWptr+08h],WDSPReg02 + mov dword [dspWptr+0Ch],WDSPReg03 + mov dword [dspWptr+010h],WDSPReg04 + mov dword [dspWptr+014h],WDSPReg05 + mov dword [dspWptr+018h],WDSPReg06 + mov dword [dspWptr+01Ch],WDSPReg07 + mov dword [dspWptr+020h],WDSPReg08 + mov dword [dspWptr+024h],WDSPReg09 + mov dword [dspWptr+028h],WDSPReg0A + mov dword [dspWptr+02Ch],WDSPReg0B + mov dword [dspWptr+030h],WDSPReg0C + mov dword [dspWptr+034h],WDSPReg0D + mov dword [dspWptr+038h],WDSPReg0E + mov dword [dspWptr+03Ch],WDSPReg0F + mov dword [dspWptr+040h],WDSPReg10 + mov dword [dspWptr+044h],WDSPReg11 + mov dword [dspWptr+048h],WDSPReg12 + mov dword [dspWptr+04Ch],WDSPReg13 + mov dword [dspWptr+050h],WDSPReg14 + mov dword [dspWptr+054h],WDSPReg15 + mov dword [dspWptr+058h],WDSPReg16 + mov dword [dspWptr+05Ch],WDSPReg17 + mov dword [dspWptr+060h],WDSPReg18 + mov dword [dspWptr+064h],WDSPReg19 + mov dword [dspWptr+068h],WDSPReg1A + mov dword [dspWptr+06Ch],WDSPReg1B + mov dword [dspWptr+070h],WDSPReg1C + mov dword [dspWptr+074h],WDSPReg1D + mov dword [dspWptr+078h],WDSPReg1E + mov dword [dspWptr+07Ch],WDSPReg1F + mov dword [dspWptr+080h],WDSPReg20 + mov dword [dspWptr+084h],WDSPReg21 + mov dword [dspWptr+088h],WDSPReg22 + mov dword [dspWptr+08Ch],WDSPReg23 + mov dword [dspWptr+090h],WDSPReg24 + mov dword [dspWptr+094h],WDSPReg25 + mov dword [dspWptr+098h],WDSPReg26 + mov dword [dspWptr+09Ch],WDSPReg27 + mov dword [dspWptr+0A0h],WDSPReg28 + mov dword [dspWptr+0A4h],WDSPReg29 + mov dword [dspWptr+0A8h],WDSPReg2A + mov dword [dspWptr+0ACh],WDSPReg2B + mov dword [dspWptr+0B0h],WDSPReg2C + mov dword [dspWptr+0B4h],WDSPReg2D + mov dword [dspWptr+0B8h],WDSPReg2E + mov dword [dspWptr+0BCh],WDSPReg2F + mov dword [dspWptr+0C0h],WDSPReg30 + mov dword [dspWptr+0C4h],WDSPReg31 + mov dword [dspWptr+0C8h],WDSPReg32 + mov dword [dspWptr+0CCh],WDSPReg33 + mov dword [dspWptr+0D0h],WDSPReg34 + mov dword [dspWptr+0D4h],WDSPReg35 + mov dword [dspWptr+0D8h],WDSPReg36 + mov dword [dspWptr+0DCh],WDSPReg37 + mov dword [dspWptr+0E0h],WDSPReg38 + mov dword [dspWptr+0E4h],WDSPReg39 + mov dword [dspWptr+0E8h],WDSPReg3A + mov dword [dspWptr+0ECh],WDSPReg3B + mov dword [dspWptr+0F0h],WDSPReg3C + mov dword [dspWptr+0F4h],WDSPReg3D + mov dword [dspWptr+0F8h],WDSPReg3E + mov dword [dspWptr+0FCh],WDSPReg3F + mov dword [dspWptr+0100h],WDSPReg40 + mov dword [dspWptr+0104h],WDSPReg41 + mov dword [dspWptr+0108h],WDSPReg42 + mov dword [dspWptr+010Ch],WDSPReg43 + mov dword [dspWptr+0110h],WDSPReg44 + mov dword [dspWptr+0114h],WDSPReg45 + mov dword [dspWptr+0118h],WDSPReg46 + mov dword [dspWptr+011Ch],WDSPReg47 + mov dword [dspWptr+0120h],WDSPReg48 + mov dword [dspWptr+0124h],WDSPReg49 + mov dword [dspWptr+0128h],WDSPReg4A + mov dword [dspWptr+012Ch],WDSPReg4B + mov dword [dspWptr+0130h],WDSPReg4C + mov dword [dspWptr+0134h],WDSPReg4D + mov dword [dspWptr+0138h],WDSPReg4E + mov dword [dspWptr+013Ch],WDSPReg4F + mov dword [dspWptr+0140h],WDSPReg50 + mov dword [dspWptr+0144h],WDSPReg51 + mov dword [dspWptr+0148h],WDSPReg52 + mov dword [dspWptr+014Ch],WDSPReg53 + mov dword [dspWptr+0150h],WDSPReg54 + mov dword [dspWptr+0154h],WDSPReg55 + mov dword [dspWptr+0158h],WDSPReg56 + mov dword [dspWptr+015Ch],WDSPReg57 + mov dword [dspWptr+0160h],WDSPReg58 + mov dword [dspWptr+0164h],WDSPReg59 + mov dword [dspWptr+0168h],WDSPReg5A + mov dword [dspWptr+016Ch],WDSPReg5B + mov dword [dspWptr+0170h],WDSPReg5C + mov dword [dspWptr+0174h],WDSPReg5D + mov dword [dspWptr+0178h],WDSPReg5E + mov dword [dspWptr+017Ch],WDSPReg5F + mov dword [dspWptr+0180h],WDSPReg60 + mov dword [dspWptr+0184h],WDSPReg61 + mov dword [dspWptr+0188h],WDSPReg62 + mov dword [dspWptr+018Ch],WDSPReg63 + mov dword [dspWptr+0190h],WDSPReg64 + mov dword [dspWptr+0194h],WDSPReg65 + mov dword [dspWptr+0198h],WDSPReg66 + mov dword [dspWptr+019Ch],WDSPReg67 + mov dword [dspWptr+01A0h],WDSPReg68 + mov dword [dspWptr+01A4h],WDSPReg69 + mov dword [dspWptr+01A8h],WDSPReg6A + mov dword [dspWptr+01ACh],WDSPReg6B + mov dword [dspWptr+01B0h],WDSPReg6C + mov dword [dspWptr+01B4h],WDSPReg6D + mov dword [dspWptr+01B8h],WDSPReg6E + mov dword [dspWptr+01BCh],WDSPReg6F + mov dword [dspWptr+01C0h],WDSPReg70 + mov dword [dspWptr+01C4h],WDSPReg71 + mov dword [dspWptr+01C8h],WDSPReg72 + mov dword [dspWptr+01CCh],WDSPReg73 + mov dword [dspWptr+01D0h],WDSPReg74 + mov dword [dspWptr+01D4h],WDSPReg75 + mov dword [dspWptr+01D8h],WDSPReg76 + mov dword [dspWptr+01DCh],WDSPReg77 + mov dword [dspWptr+01E0h],WDSPReg78 + mov dword [dspWptr+01E4h],WDSPReg79 + mov dword [dspWptr+01E8h],WDSPReg7A + mov dword [dspWptr+01ECh],WDSPReg7B + mov dword [dspWptr+01F0h],WDSPReg7C + mov dword [dspWptr+01F4h],WDSPReg7D + mov dword [dspWptr+01F8h],WDSPReg7E + mov dword [dspWptr+01FCh],WDSPReg7F + mov dword [dspWptr+0200h],WDSPReg80 + mov dword [dspWptr+0204h],WDSPReg81 + mov dword [dspWptr+0208h],WDSPReg82 + mov dword [dspWptr+020Ch],WDSPReg83 + mov dword [dspWptr+0210h],WDSPReg84 + mov dword [dspWptr+0214h],WDSPReg85 + mov dword [dspWptr+0218h],WDSPReg86 + mov dword [dspWptr+021Ch],WDSPReg87 + mov dword [dspWptr+0220h],WDSPReg88 + mov dword [dspWptr+0224h],WDSPReg89 + mov dword [dspWptr+0228h],WDSPReg8A + mov dword [dspWptr+022Ch],WDSPReg8B + mov dword [dspWptr+0230h],WDSPReg8C + mov dword [dspWptr+0234h],WDSPReg8D + mov dword [dspWptr+0238h],WDSPReg8E + mov dword [dspWptr+023Ch],WDSPReg8F + mov dword [dspWptr+0240h],WDSPReg90 + mov dword [dspWptr+0244h],WDSPReg91 + mov dword [dspWptr+0248h],WDSPReg92 + mov dword [dspWptr+024Ch],WDSPReg93 + mov dword [dspWptr+0250h],WDSPReg94 + mov dword [dspWptr+0254h],WDSPReg95 + mov dword [dspWptr+0258h],WDSPReg96 + mov dword [dspWptr+025Ch],WDSPReg97 + mov dword [dspWptr+0260h],WDSPReg98 + mov dword [dspWptr+0264h],WDSPReg99 + mov dword [dspWptr+0268h],WDSPReg9A + mov dword [dspWptr+026Ch],WDSPReg9B + mov dword [dspWptr+0270h],WDSPReg9C + mov dword [dspWptr+0274h],WDSPReg9D + mov dword [dspWptr+0278h],WDSPReg9E + mov dword [dspWptr+027Ch],WDSPReg9F + mov dword [dspWptr+0280h],WDSPRegA0 + mov dword [dspWptr+0284h],WDSPRegA1 + mov dword [dspWptr+0288h],WDSPRegA2 + mov dword [dspWptr+028Ch],WDSPRegA3 + mov dword [dspWptr+0290h],WDSPRegA4 + mov dword [dspWptr+0294h],WDSPRegA5 + mov dword [dspWptr+0298h],WDSPRegA6 + mov dword [dspWptr+029Ch],WDSPRegA7 + mov dword [dspWptr+02A0h],WDSPRegA8 + mov dword [dspWptr+02A4h],WDSPRegA9 + mov dword [dspWptr+02A8h],WDSPRegAA + mov dword [dspWptr+02ACh],WDSPRegAB + mov dword [dspWptr+02B0h],WDSPRegAC + mov dword [dspWptr+02B4h],WDSPRegAD + mov dword [dspWptr+02B8h],WDSPRegAE + mov dword [dspWptr+02BCh],WDSPRegAF + mov dword [dspWptr+02C0h],WDSPRegB0 + mov dword [dspWptr+02C4h],WDSPRegB1 + mov dword [dspWptr+02C8h],WDSPRegB2 + mov dword [dspWptr+02CCh],WDSPRegB3 + mov dword [dspWptr+02D0h],WDSPRegB4 + mov dword [dspWptr+02D4h],WDSPRegB5 + mov dword [dspWptr+02D8h],WDSPRegB6 + mov dword [dspWptr+02DCh],WDSPRegB7 + mov dword [dspWptr+02E0h],WDSPRegB8 + mov dword [dspWptr+02E4h],WDSPRegB9 + mov dword [dspWptr+02E8h],WDSPRegBA + mov dword [dspWptr+02ECh],WDSPRegBB + mov dword [dspWptr+02F0h],WDSPRegBC + mov dword [dspWptr+02F4h],WDSPRegBD + mov dword [dspWptr+02F8h],WDSPRegBE + mov dword [dspWptr+02FCh],WDSPRegBF + mov dword [dspWptr+0300h],WDSPRegC0 + mov dword [dspWptr+0304h],WDSPRegC1 + mov dword [dspWptr+0308h],WDSPRegC2 + mov dword [dspWptr+030Ch],WDSPRegC3 + mov dword [dspWptr+0310h],WDSPRegC4 + mov dword [dspWptr+0314h],WDSPRegC5 + mov dword [dspWptr+0318h],WDSPRegC6 + mov dword [dspWptr+031Ch],WDSPRegC7 + mov dword [dspWptr+0320h],WDSPRegC8 + mov dword [dspWptr+0324h],WDSPRegC9 + mov dword [dspWptr+0328h],WDSPRegCA + mov dword [dspWptr+032Ch],WDSPRegCB + mov dword [dspWptr+0330h],WDSPRegCC + mov dword [dspWptr+0334h],WDSPRegCD + mov dword [dspWptr+0338h],WDSPRegCE + mov dword [dspWptr+033Ch],WDSPRegCF + mov dword [dspWptr+0340h],WDSPRegD0 + mov dword [dspWptr+0344h],WDSPRegD1 + mov dword [dspWptr+0348h],WDSPRegD2 + mov dword [dspWptr+034Ch],WDSPRegD3 + mov dword [dspWptr+0350h],WDSPRegD4 + mov dword [dspWptr+0354h],WDSPRegD5 + mov dword [dspWptr+0358h],WDSPRegD6 + mov dword [dspWptr+035Ch],WDSPRegD7 + mov dword [dspWptr+0360h],WDSPRegD8 + mov dword [dspWptr+0364h],WDSPRegD9 + mov dword [dspWptr+0368h],WDSPRegDA + mov dword [dspWptr+036Ch],WDSPRegDB + mov dword [dspWptr+0370h],WDSPRegDC + mov dword [dspWptr+0374h],WDSPRegDD + mov dword [dspWptr+0378h],WDSPRegDE + mov dword [dspWptr+037Ch],WDSPRegDF + mov dword [dspWptr+0380h],WDSPRegE0 + mov dword [dspWptr+0384h],WDSPRegE1 + mov dword [dspWptr+0388h],WDSPRegE2 + mov dword [dspWptr+038Ch],WDSPRegE3 + mov dword [dspWptr+0390h],WDSPRegE4 + mov dword [dspWptr+0394h],WDSPRegE5 + mov dword [dspWptr+0398h],WDSPRegE6 + mov dword [dspWptr+039Ch],WDSPRegE7 + mov dword [dspWptr+03A0h],WDSPRegE8 + mov dword [dspWptr+03A4h],WDSPRegE9 + mov dword [dspWptr+03A8h],WDSPRegEA + mov dword [dspWptr+03ACh],WDSPRegEB + mov dword [dspWptr+03B0h],WDSPRegEC + mov dword [dspWptr+03B4h],WDSPRegED + mov dword [dspWptr+03B8h],WDSPRegEE + mov dword [dspWptr+03BCh],WDSPRegEF + mov dword [dspWptr+03C0h],WDSPRegF0 + mov dword [dspWptr+03C4h],WDSPRegF1 + mov dword [dspWptr+03C8h],WDSPRegF2 + mov dword [dspWptr+03CCh],WDSPRegF3 + mov dword [dspWptr+03D0h],WDSPRegF4 + mov dword [dspWptr+03D4h],WDSPRegF5 + mov dword [dspWptr+03D8h],WDSPRegF6 + mov dword [dspWptr+03DCh],WDSPRegF7 + mov dword [dspWptr+03E0h],WDSPRegF8 + mov dword [dspWptr+03E4h],WDSPRegF9 + mov dword [dspWptr+03E8h],WDSPRegFA + mov dword [dspWptr+03ECh],WDSPRegFB + mov dword [dspWptr+03F0h],WDSPRegFC + mov dword [dspWptr+03F4h],WDSPRegFD + mov dword [dspWptr+03F8h],WDSPRegFE + mov dword [dspWptr+03FCh],WDSPRegFF + + ; first fill all pointer to an invalid access function + mov ecx,256 + mov eax,Invalidopcode + mov ebp,0 + .loop + mov [opcjmptab+ebp],eax + add ebp,4 + dec ecx + jnz .loop + ; now fill the table + mov dword [opcjmptab+00h],Op00 + mov dword [opcjmptab+04h],Op01 + mov dword [opcjmptab+08h],Op02 + mov dword [opcjmptab+0Ch],Op03 + mov dword [opcjmptab+010h],Op04 + mov dword [opcjmptab+014h],Op05 + mov dword [opcjmptab+018h],Op06 + mov dword [opcjmptab+01Ch],Op07 + mov dword [opcjmptab+020h],Op08 + mov dword [opcjmptab+024h],Op09 + mov dword [opcjmptab+028h],Op0A + mov dword [opcjmptab+02Ch],Op0B + mov dword [opcjmptab+030h],Op0C + mov dword [opcjmptab+034h],Op0D + mov dword [opcjmptab+038h],Op0E + mov dword [opcjmptab+03Ch],Op0F + mov dword [opcjmptab+040h],Op10 + mov dword [opcjmptab+044h],Op11 + mov dword [opcjmptab+048h],Op12 + mov dword [opcjmptab+04Ch],Op13 + mov dword [opcjmptab+050h],Op14 + mov dword [opcjmptab+054h],Op15 + mov dword [opcjmptab+058h],Op16 + mov dword [opcjmptab+05Ch],Op17 + mov dword [opcjmptab+060h],Op18 + mov dword [opcjmptab+064h],Op19 + mov dword [opcjmptab+068h],Op1A + mov dword [opcjmptab+06Ch],Op1B + mov dword [opcjmptab+070h],Op1C + mov dword [opcjmptab+074h],Op1D + mov dword [opcjmptab+078h],Op1E + mov dword [opcjmptab+07Ch],Op1F + mov dword [opcjmptab+080h],Op20 + mov dword [opcjmptab+084h],Op21 + mov dword [opcjmptab+088h],Op22 + mov dword [opcjmptab+08Ch],Op23 + mov dword [opcjmptab+090h],Op24 + mov dword [opcjmptab+094h],Op25 + mov dword [opcjmptab+098h],Op26 + mov dword [opcjmptab+09Ch],Op27 + mov dword [opcjmptab+0A0h],Op28 + mov dword [opcjmptab+0A4h],Op29 + mov dword [opcjmptab+0A8h],Op2A + mov dword [opcjmptab+0ACh],Op2B + mov dword [opcjmptab+0B0h],Op2C + mov dword [opcjmptab+0B4h],Op2D + mov dword [opcjmptab+0B8h],Op2E + mov dword [opcjmptab+0BCh],Op2F + mov dword [opcjmptab+0C0h],Op30 + mov dword [opcjmptab+0C4h],Op31 + mov dword [opcjmptab+0C8h],Op32 + mov dword [opcjmptab+0CCh],Op33 + mov dword [opcjmptab+0D0h],Op34 + mov dword [opcjmptab+0D4h],Op35 + mov dword [opcjmptab+0D8h],Op36 + mov dword [opcjmptab+0DCh],Op37 + mov dword [opcjmptab+0E0h],Op38 + mov dword [opcjmptab+0E4h],Op39 + mov dword [opcjmptab+0E8h],Op3A + mov dword [opcjmptab+0ECh],Op3B + mov dword [opcjmptab+0F0h],Op3C + mov dword [opcjmptab+0F4h],Op3D + mov dword [opcjmptab+0F8h],Op3E + mov dword [opcjmptab+0FCh],Op3F + mov dword [opcjmptab+0100h],Op40 + mov dword [opcjmptab+0104h],Op41 + mov dword [opcjmptab+0108h],Op42 + mov dword [opcjmptab+010Ch],Op43 + mov dword [opcjmptab+0110h],Op44 + mov dword [opcjmptab+0114h],Op45 + mov dword [opcjmptab+0118h],Op46 + mov dword [opcjmptab+011Ch],Op47 + mov dword [opcjmptab+0120h],Op48 + mov dword [opcjmptab+0124h],Op49 + mov dword [opcjmptab+0128h],Op4A + mov dword [opcjmptab+012Ch],Op4B + mov dword [opcjmptab+0130h],Op4C + mov dword [opcjmptab+0134h],Op4D + mov dword [opcjmptab+0138h],Op4E + mov dword [opcjmptab+013Ch],Op4F + mov dword [opcjmptab+0140h],Op50 + mov dword [opcjmptab+0144h],Op51 + mov dword [opcjmptab+0148h],Op52 + mov dword [opcjmptab+014Ch],Op53 + mov dword [opcjmptab+0150h],Op54 + mov dword [opcjmptab+0154h],Op55 + mov dword [opcjmptab+0158h],Op56 + mov dword [opcjmptab+015Ch],Op57 + mov dword [opcjmptab+0160h],Op58 + mov dword [opcjmptab+0164h],Op59 + mov dword [opcjmptab+0168h],Op5A + mov dword [opcjmptab+016Ch],Op5B + mov dword [opcjmptab+0170h],Op5C + mov dword [opcjmptab+0174h],Op5D + mov dword [opcjmptab+0178h],Op5E + mov dword [opcjmptab+017Ch],Op5F + mov dword [opcjmptab+0180h],Op60 + mov dword [opcjmptab+0184h],Op61 + mov dword [opcjmptab+0188h],Op62 + mov dword [opcjmptab+018Ch],Op63 + mov dword [opcjmptab+0190h],Op64 + mov dword [opcjmptab+0194h],Op65 + mov dword [opcjmptab+0198h],Op66 + mov dword [opcjmptab+019Ch],Op67 + mov dword [opcjmptab+01A0h],Op68 + mov dword [opcjmptab+01A4h],Op69 + mov dword [opcjmptab+01A8h],Op6A + mov dword [opcjmptab+01ACh],Op6B + mov dword [opcjmptab+01B0h],Op6C + mov dword [opcjmptab+01B4h],Op6D + mov dword [opcjmptab+01B8h],Op6E + mov dword [opcjmptab+01BCh],Op6F + mov dword [opcjmptab+01C0h],Op70 + mov dword [opcjmptab+01C4h],Op71 + mov dword [opcjmptab+01C8h],Op72 + mov dword [opcjmptab+01CCh],Op73 + mov dword [opcjmptab+01D0h],Op74 + mov dword [opcjmptab+01D4h],Op75 + mov dword [opcjmptab+01D8h],Op76 + mov dword [opcjmptab+01DCh],Op77 + mov dword [opcjmptab+01E0h],Op78 + mov dword [opcjmptab+01E4h],Op79 + mov dword [opcjmptab+01E8h],Op7A + mov dword [opcjmptab+01ECh],Op7B + mov dword [opcjmptab+01F0h],Op7C + mov dword [opcjmptab+01F4h],Op7D + mov dword [opcjmptab+01F8h],Op7E + mov dword [opcjmptab+01FCh],Op7F + mov dword [opcjmptab+0200h],Op80 + mov dword [opcjmptab+0204h],Op81 + mov dword [opcjmptab+0208h],Op82 + mov dword [opcjmptab+020Ch],Op83 + mov dword [opcjmptab+0210h],Op84 + mov dword [opcjmptab+0214h],Op85 + mov dword [opcjmptab+0218h],Op86 + mov dword [opcjmptab+021Ch],Op87 + mov dword [opcjmptab+0220h],Op88 + mov dword [opcjmptab+0224h],Op89 + mov dword [opcjmptab+0228h],Op8A + mov dword [opcjmptab+022Ch],Op8B + mov dword [opcjmptab+0230h],Op8C + mov dword [opcjmptab+0234h],Op8D + mov dword [opcjmptab+0238h],Op8E + mov dword [opcjmptab+023Ch],Op8F + mov dword [opcjmptab+0240h],Op90 + mov dword [opcjmptab+0244h],Op91 + mov dword [opcjmptab+0248h],Op92 + mov dword [opcjmptab+024Ch],Op93 + mov dword [opcjmptab+0250h],Op94 + mov dword [opcjmptab+0254h],Op95 + mov dword [opcjmptab+0258h],Op96 + mov dword [opcjmptab+025Ch],Op97 + mov dword [opcjmptab+0260h],Op98 + mov dword [opcjmptab+0264h],Op99 + mov dword [opcjmptab+0268h],Op9A + mov dword [opcjmptab+026Ch],Op9B + mov dword [opcjmptab+0270h],Op9C + mov dword [opcjmptab+0274h],Op9D + mov dword [opcjmptab+0278h],Op9E + mov dword [opcjmptab+027Ch],Op9F + mov dword [opcjmptab+0280h],OpA0 + mov dword [opcjmptab+0284h],OpA1 + mov dword [opcjmptab+0288h],OpA2 + mov dword [opcjmptab+028Ch],OpA3 + mov dword [opcjmptab+0290h],OpA4 + mov dword [opcjmptab+0294h],OpA5 + mov dword [opcjmptab+0298h],OpA6 + mov dword [opcjmptab+029Ch],OpA7 + mov dword [opcjmptab+02A0h],OpA8 + mov dword [opcjmptab+02A4h],OpA9 + mov dword [opcjmptab+02A8h],OpAA + mov dword [opcjmptab+02ACh],OpAB + mov dword [opcjmptab+02B0h],OpAC + mov dword [opcjmptab+02B4h],OpAD + mov dword [opcjmptab+02B8h],OpAE + mov dword [opcjmptab+02BCh],OpAF + mov dword [opcjmptab+02C0h],OpB0 + mov dword [opcjmptab+02C4h],OpB1 + mov dword [opcjmptab+02C8h],OpB2 + mov dword [opcjmptab+02CCh],OpB3 + mov dword [opcjmptab+02D0h],OpB4 + mov dword [opcjmptab+02D4h],OpB5 + mov dword [opcjmptab+02D8h],OpB6 + mov dword [opcjmptab+02DCh],OpB7 + mov dword [opcjmptab+02E0h],OpB8 + mov dword [opcjmptab+02E4h],OpB9 + mov dword [opcjmptab+02E8h],OpBA + mov dword [opcjmptab+02ECh],OpBB + mov dword [opcjmptab+02F0h],OpBC + mov dword [opcjmptab+02F4h],OpBD + mov dword [opcjmptab+02F8h],OpBE + mov dword [opcjmptab+02FCh],OpBF + mov dword [opcjmptab+0300h],OpC0 + mov dword [opcjmptab+0304h],OpC1 + mov dword [opcjmptab+0308h],OpC2 + mov dword [opcjmptab+030Ch],OpC3 + mov dword [opcjmptab+0310h],OpC4 + mov dword [opcjmptab+0314h],OpC5 + mov dword [opcjmptab+0318h],OpC6 + mov dword [opcjmptab+031Ch],OpC7 + mov dword [opcjmptab+0320h],OpC8 + mov dword [opcjmptab+0324h],OpC9 + mov dword [opcjmptab+0328h],OpCA + mov dword [opcjmptab+032Ch],OpCB + mov dword [opcjmptab+0330h],OpCC + mov dword [opcjmptab+0334h],OpCD + mov dword [opcjmptab+0338h],OpCE + mov dword [opcjmptab+033Ch],OpCF + mov dword [opcjmptab+0340h],OpD0 + mov dword [opcjmptab+0344h],OpD1 + mov dword [opcjmptab+0348h],OpD2 + mov dword [opcjmptab+034Ch],OpD3 + mov dword [opcjmptab+0350h],OpD4 + mov dword [opcjmptab+0354h],OpD5 + mov dword [opcjmptab+0358h],OpD6 + mov dword [opcjmptab+035Ch],OpD7 + mov dword [opcjmptab+0360h],OpD8 + mov dword [opcjmptab+0364h],OpD9 + mov dword [opcjmptab+0368h],OpDA + mov dword [opcjmptab+036Ch],OpDB + mov dword [opcjmptab+0370h],OpDC + mov dword [opcjmptab+0374h],OpDD + mov dword [opcjmptab+0378h],OpDE + mov dword [opcjmptab+037Ch],OpDF + mov dword [opcjmptab+0380h],OpE0 + mov dword [opcjmptab+0384h],OpE1 + mov dword [opcjmptab+0388h],OpE2 + mov dword [opcjmptab+038Ch],OpE3 + mov dword [opcjmptab+0390h],OpE4 + mov dword [opcjmptab+0394h],OpE5 + mov dword [opcjmptab+0398h],OpE6 + mov dword [opcjmptab+039Ch],OpE7 + mov dword [opcjmptab+03A0h],OpE8 + mov dword [opcjmptab+03A4h],OpE9 + mov dword [opcjmptab+03A8h],OpEA + mov dword [opcjmptab+03ACh],OpEB + mov dword [opcjmptab+03B0h],OpEC + mov dword [opcjmptab+03B4h],OpED + mov dword [opcjmptab+03B8h],OpEE + mov dword [opcjmptab+03BCh],OpEF + mov dword [opcjmptab+03C0h],OpF0 + mov dword [opcjmptab+03C4h],OpF1 + mov dword [opcjmptab+03C8h],OpF2 + mov dword [opcjmptab+03CCh],OpF3 + mov dword [opcjmptab+03D0h],OpF4 + mov dword [opcjmptab+03D4h],OpF5 + mov dword [opcjmptab+03D8h],OpF6 + mov dword [opcjmptab+03DCh],OpF7 + mov dword [opcjmptab+03E0h],OpF8 + mov dword [opcjmptab+03E4h],OpF9 + mov dword [opcjmptab+03E8h],OpFA + mov dword [opcjmptab+03ECh],OpFB + mov dword [opcjmptab+03F0h],OpFC + mov dword [opcjmptab+03F4h],OpFD + mov dword [opcjmptab+03F8h],OpFE + mov dword [opcjmptab+03FCh],OpFF + cmp byte[soundon],0 +; je near .nosound + cmp byte[OSPort],2 + ja near .nosound + + mov ax,0100h ; Allocate DOS memory + mov bx,16384/16 ; Allocate 16384 bytes + int 31h + ; To delocate this, use ax=0101h, dx=selector of block/int 31h + jc near .error + ; Check which 8192 byte boundary doesn't cross a page + mov word[memoryloc+2],0 + mov dword[memoryloc],0 + mov [memoryloc],ax + mov [sbselec],dx + shl dword[memoryloc],4 + mov edx,[memoryloc] + shr edx,16 + mov al,dl + mov edx,[memoryloc] + add edx,8192 + shr edx,16 + mov dword[sbpmofs],0 + cmp al,dl + je .nonextarea + mov dword[sbpmofs],8192 + add dword[memoryloc],8192 +.nonextarea + mov edi,[sbpmofs] + mov [SBBufferLoc],edi + mov dword[SBBufferMov],1 + mov dword[SBBufferInc],4 + ; clear dos memory + push es + mov es,[sbselec] + mov edi,[sbpmofs] + mov ecx,2048 + mov eax,0 + rep stosd + pop es +.nosound + pop edx + pop ecx + pop ebx + pop eax + ret +.error + mov edx,.nohand ;use extended + mov ah,9 ;DOS- API + int 21h ;to print a string + call DosExit + +.nohand db 'Unable to allocate conventional memory!',13,10,'$' + + +NEWSYM InitSB + call initSB + ret + +NEWSYM DeInitSPC + cmp byte[SBDeinitType],0 + je .nodoublereset + call ResetSBDSP + call ResetSBDSP +.nodoublereset + ; Turn off speakers + mov al,0d3h + call WriteDSP + +; k) Perform Halt DMA Operation, 8-bit command (0D0h - for virtual speaker) + mov al,0d0h + call WriteDSP +; l) Perform Exit Auto-Initialize DMA Operation, 8-bit command (0DAh) + cmp byte[SBHDMA],0 + je .8b + mov al,0d9h + call WriteDSP + jmp .16b +.8b + mov al,0dAh + call WriteDSP +.16b +; m) Perform Halt DMA Operation, 8-bit command (0D0h - for virtual speaker) + mov al,0d0h + call WriteDSP + ; Disable DMA + mov al,4 + add al,[SBDMA] + mov dx,0ah + out dx,al + ret + +;SoundBlaster DSP Ports +NEWSYM SBPort, dw 220 +NEWSYM SBInt, db 5+8 +NEWSYM SBIrq, db 5 +NEWSYM SBDMA, db 1 +NEWSYM SBDMAPage, db 83 +NEWSYM SBHDMA, db 0 +NEWSYM SBHDMAPage, db 0 + +NEWSYM ResetSBDSP + mov dx,[SBPort] + add dl,06h + mov al,01h + out dx,al + nop + nop + nop + nop + nop + nop + mov al,00h + out dx,al + ; wait until port[SBDSPRdStat] AND 80h = 80h + mov cx,20000 +.tryagain + mov dx,[SBPort] + add dl,0Eh + dec cx + jz .cardfailed + in al,dx + test al,80h + jz .tryagain +.tryagain2 + mov dx,[SBPort] + add dl,0Ah + dec cx + jz .cardfailed + in al,dx + cmp al,0AAh + jne .tryagain + ret +.cardfailed + mov ax,0003h + int 10h + mov edx,initfailed ;use extended + mov ah,9 ;DOS- API + int 21h ;to print a string + jmp DosExit + +NEWSYM initfailed, db 'Sound card failed to initialize!',13,10,'$' + +; Write AL into DSP port +NEWSYM WriteDSP + mov dx,[SBPort] + add dl,0Ch + mov bl,al +.tryagain + in al,dx + test al,80h + jnz .tryagain + mov al,bl + out dx,al + ret +; Read DSP port into AL +NEWSYM ReadDSP + mov dx,[SBPort] + add dl,0Eh + mov bl,al +.tryagain + in al,dx + test al,80h + jz .tryagain + mov dx,[SBPort] + add dl,0Ah + mov al,bl + in al,dx + ret + +;**************************************************** +; Sound Blaster Interrupt Stuff +;**************************************************** + +NEWSYM Interror + sti + mov edx,.nohand ;use extended + mov ah,9 ;DOS- API + int 21h ;to print a string + call DosExit + +.nohand db 'Cannot process interrupt handler!',13,10,'$' + +NEWSYM oldhandSBs, dw 0 +NEWSYM oldhandSBo, dd 0 +NEWSYM SBswitch, db 0 ; which block to process next + +PSampleBuf times 22*8 dd 0 + +NEWSYM LPFsample1, dd 0 +NEWSYM LPFsample2, dd 0 + +%macro ProcessA 0 + shr al,4 +%endmacro + +%macro ProcessB 0 + and al,0Fh +%endmacro + +%macro ProcessSample 1 + xor eax,eax + mov cl,[bshift] + mov al,[esi] + %1 + test al,08h + jz %%noneg + or eax,0FFFFFFF0h +%%noneg + shl eax,cl + mov edx,eax + + mov eax,[prev1] + mov ebx,[filter1] + imul eax,ebx + sar eax,8 + add edx,eax + + mov eax,[prev0] + mov ebx,[filter0] + imul eax,ebx + sar eax,8 + add edx,eax + + mov eax,[prev0] + mov [prev0],edx + mov [prev1],eax + cmp edx,-32768 + jnl %%notless + mov edx,-32768 + mov byte[filteron],1 +%%notless + cmp edx,32767 + jng %%notgreater + mov edx,32767 + mov byte[filteron],1 +%%notgreater +%endmacro + +BRRDecode: + mov byte[lastbl],0 + mov byte[loopbl],0 + cmp dword[esi],21FECD8Ah + jne .notophack + mov byte[VoiceNoiseEn+ecx],0 +.notophack + push ecx + mov al,[esi] + and al,0Ch + cmp al,04h + je .yesfilterb + test al,0Ch + jnz .skipfilter + cmp byte[esi+9],88h + jne .yesfilterb + mov byte[VoiceNoiseEn+ecx],101 + jmp .skipfilter +.yesfilterb + mov byte[VoiceNoiseEn+ecx],100 +.skipfilter + + xor eax,eax + mov al,[esi] + test al,01h + jz .nolast + mov byte[lastbl],1 + test al,02h + jz .nolast + mov byte[loopbl],1 +.nolast + mov cl,al + and al,0Ch + inc esi + mov ebx,[Filter+eax*2] + shr cl,4 + mov [filter0],ebx + mov ebx,[Filter+eax*2+4] + mov [bshift],cl + mov [filter1],ebx + mov byte[sampleleft],8 + mov byte[filteron],0 + +.nextsample + ProcessSample ProcessA + mov [edi],dx + ProcessSample ProcessB + mov [edi+2],dx + add edi,4 + inc esi + dec byte[sampleleft] + jnz near .nextsample + + pop ecx + cmp byte[VoiceNoiseEn+ecx],10 + je .yesfilter + cmp byte[VoiceNoiseEn+ecx],0 + je .nofilter2 + cmp byte[VoiceNoiseEn+ecx],10 + jae .nofilter2 + mov al,[esi-9] + and al,0Ch + cmp byte[esi-9],08h + jb .nofilter2 + inc byte[VoiceNoiseEn+ecx] +.nofilter2 + cmp byte[filteron],1 + jne .nofilter + cmp byte[VoiceNoiseEn+ecx],100 + je .strfilter + cmp byte[VoiceNoiseEn+ecx],101 + je .nofilter + mov byte[VoiceNoiseEn+ecx],8 + test byte[esi],01h + jnz .nofilter + mov byte[VoiceNoiseEn+ecx],9 + test byte[esi+9],01h + jnz .nofilter + mov byte[VoiceNoiseEn+ecx],10 +.nofilter + ret +.strfilter + mov byte[VoiceNoiseEn+ecx],8 + ret + +.yesfilter + cmp byte[SoundNoiseDis],1 + je .nofilter + push ecx + sub edi,32 + mov ecx,8 + mov ebx,[NoisePtr] +.nloop + mov ax,[NoiseData+ebx*2] + inc ebx + and ebx,1FFFh + sar ax,1 + mov word[edi],ax + mov word[edi+2],ax + add edi,4 + loop .nloop + mov [NoisePtr],ebx + pop ecx + ret + +ALIGN32 + +; Original Values +NEWSYM EchoRateO + dd 2,172,344,517,689,861,1033,1205,1378,1550,1722,1895, + dd 2067,2239,2412,2584 +NEWSYM AttackRateO + dd 45202,28665,16537,11025,7056,4189,2866,1764,1058,705,441 + dd 264,176,110,66,4 +NEWSYM DecayRateO + dd 13230,8158,4851,2697,2284,1212,815,407 +NEWSYM SustainRateO + dd 0FFFFFFFFh,418950,308700,265600,209475,154350,132300 + dd 103635,78277,65047,51817,38587,31972,26460,19845,16537 + dd 13230,9702,8158,6504,4851,3879,2697,2050 + dd 1572,1212,1014,815,606,407,202,125 + +NEWSYM SustainValueO + db 15,31,47,63,89,95,111,127 +NEWSYM IncreaseO + dd 0FFFFFFFFh,45202,34177,28665,22050,16537,14332,11025 + dd 8489,7056,5622,4189,3528,2866,2094,1764 + dd 1433,1058,882,705,529,441,352,264 + dd 220,176,132,110,88,66,44,22 +NEWSYM IncreaseBentO + dd 0FFFFFFFFh,79100,59535,50160,38580,28665,25000,19250 + dd 14332,12127,9800,7320,6160,4961,3650,3060 + dd 2425,1845,1540,1212,920,770,614,460 + dd 383,306,229,190,152,113,75,36 +NEWSYM DecreaseO + dd 0FFFFFFFFh,45202,34177,28665,22050,16537,14332,11025 + dd 8489,7056,5622,4189,3528,2866,2094,1764 + dd 1433,1058,882,705,529,441,352,264 + dd 220,176,132,110,88,66,44,22 +NEWSYM DecreaseRateExpO + dd 0FFFFFFFFh,418950,308700,264600,209470,154350,132300,103635 + dd 78277,65047,51817,38587,31972,26460,19845,16537 + dd 13230,9702,8158,6504,4851,4079,3197,2425 + dd 1984,1653,1212,1014,815,606,407,198 + +filteron dd 0 +NoisePtr dd 0 + +; used only in dspproc.asm +Filter dd 0,0,240,0,488,-240,460,-208 +prev0 dd 0 ; previous value 1 +prev1 dd 0 ; previous value 2 +nextsamp dd 0 ; next sample +filter0 dd 0 ; filter 0 +filter1 dd 0 ; filter 1 +bshift dd 0 +sampleleft dd 0 ; 8 bytes/sample + +lastbl dd 0 ; Last block if = 1 +loopbl dd 0 ; Loop if = 1 +usenoisedata dd 0 + +VolumeTableD +db 0,3,6,9,12,15,17,18,19,21,22,23,24,24,26,28,30,31,33,35,36,38,40,41,43,45,46,48,49 +db 51,52,54,56,57,58,60,61,63,64,66,67,68,70,71,72,74,75,76,78,79,80,81,82,84,85,86 +db 87,88,89,90,91,92,93,94,96,96,97,98,99,100,101,102,103,104,105,106,106,107,108 +db 109,110,110,111,112,112,113,114,114,115,116,116,117,117,118,118,119,120,120,120 +db 121,121,122,122,123,123,123,124,124,124,125,125,125,126,126,126,126,126,127,127 +db 127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128 +db 128,129,129,129,129,129,130,130,130,131,131,131,132,132,132,133,133,134,134,135 +db 135,135,136,137,137,138,138,139,139,140,141,141,142,143,143,144,145,145,146,147 +db 148,149,149,150,151,152,153,154,155,156,157,158,159,159,161,162,163,164,165,166 +db 167,168,169,170,171,173,174,175,176,177,179,180,181,183,184,185,187,188,189,191 +db 192,194,195,197,198,199,201,203,204,206,207,209,210,212,214,215,217,219,220,222 +db 224,225,227,229,231,231,232,233,234,236,237,238,240,243,246,249,252,255 + +db 0,1,3,5,7,9,11,13,15,17,19,21,22,24,26,28,30,31,33,35,36,38,40,41,43,45,46,48,49 +db 51,52,54,56,57,58,60,61,63,64,66,67,68,70,71,72,74,75,76,78,79,80,81,82,84,85,86 +db 87,88,89,90,91,92,93,94,96,96,97,98,99,100,101,102,103,104,105,106,106,107,108 +db 109,110,110,111,112,112,113,114,114,115,116,116,117,117,118,118,119,120,120,120 +db 121,121,122,122,123,123,123,124,124,124,125,125,125,126,126,126,126,126,127,127 +db 127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128 +db 128,129,129,129,129,129,130,130,130,131,131,131,132,132,132,133,133,134,134,135 +db 135,135,136,137,137,138,138,139,139,140,141,141,142,143,143,144,145,145,146,147 +db 148,149,149,150,151,152,153,154,155,156,157,158,159,159,161,162,163,164,165,166 +db 167,168,169,170,171,173,174,175,176,177,179,180,181,183,184,185,187,188,189,191 +db 192,194,195,197,198,199,201,203,204,206,207,209,210,212,214,215,217,219,220,222 +db 224,225,227,229,231,233,234,236,238,240,242,244,246,248,250,252,254,255 + +NEWSYM VolumeTableb + db 00h,01h,02h,03h,04h,05h,06h,07h,08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh + db 10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Ch,1Dh,1Eh,1Fh + db 20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,2Ah,2Bh,2Ch,2Dh,2Eh,2Fh + db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,3Ah,3Bh,3Ch,3Dh,3Eh,3Fh + db 40h,41h,42h,43h,44h,45h,46h,47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh + db 50h,51h,52h,53h,54h,55h,56h,57h,58h,59h,5Ah,5Bh,5Ch,5Dh,5Eh,5Fh + db 60h,61h,62h,63h,64h,65h,66h,67h,68h,69h,6Ah,6Bh,6Ch,6Dh,6Eh,6Fh + db 70h,71h,72h,73h,74h,75h,76h,77h,78h,79h,7Ah,7Bh,7Ch,7Dh,7Eh,7Fh + db 7Fh,7Eh,7Dh,7Ch,7Bh,7Ah,79h,78h,77h,76h,75h,74h,73h,72h,71h,70h + db 6Fh,6Eh,6Dh,6Ch,6Bh,6Ah,69h,68h,67h,66h,65h,64h,63h,62h,61h,60h + db 5Fh,5Eh,5Dh,5Ch,5Bh,5Ah,59h,58h,57h,56h,55h,54h,53h,52h,51h,50h + db 4Fh,4Eh,4Dh,4Ch,4Bh,4Ah,49h,48h,47h,46h,45h,44h,43h,42h,41h,40h + db 3Fh,3Eh,3Dh,3Ch,3Bh,3Ah,39h,38h,37h,36h,35h,34h,33h,32h,31h,30h + db 2Fh,2Eh,2Dh,2Ch,2Bh,2Ah,29h,28h,27h,26h,25h,24h,23h,22h,21h,20h + db 1Fh,1Eh,1Dh,1Ch,1Bh,1Ah,19h,18h,17h,16h,15h,14h,13h,12h,11h,10h + db 0Fh,0Eh,0Dh,0Ch,0Bh,0Ah,09h,08h,07h,06h,05h,04h,03h,02h,01h,00h + +; appears to only be used in dspproc.asm + +;VolumeTable: db 0,2,4,6,8,10,12,14,16,18 +; db 20,22,24,26,28,30,32,34,36,38 +; db 40,42,44,46,48,50,52,54,56,58 +; db 60,62,64,66,68,70,72,74,76,78 +; db 80,82,84,86,88,90,92,94,96,98 +; db 100,102,104,106,108,110,112,114,116,118 +; db 120,122,124,126,127,127,127,127,127,127 +;VolumeTable: db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127,127,127 +; db 127,127,127,127,127,127,127,127 +;VolumeTable db 1,1,2,3,4,5,6,7,8,9 +; db 10,11,12,13,14,15,16,17,18,19 +; db 20,21,22,23,24,25,26,27,28,29 +; db 30,31,32,33,34,35,36,37,38,39 +; db 40,41,42,43,44,45,46,47,48,49 +; db 50,51,52,53,54,55,46,57,58,59 +; db 60,61,62,63,64,65,56,67,68,69 +; db 70,71,72,73,74,75,66,77,78,79 +; db 80,81,82,83,84,85,76,87,88,89 +; db 90,91,92,93,94,95,86,97,98,99 +; db 100,101,102,103,104,105,106,107,108,109 +; db 110,111,112,113,114,115,116,117,118,119 +; db 120,121,122,123,124,125,126,127 +;VolumeTable db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1,1,1 +; db 1,1,1,1,1,1,1,1 + +ALIGN32 + +NEWSYM DSPBuffer, times 320*4 dd 00h ; The play buffer... +NEWSYM EchoBuffer, times 320*4 dd 00h ; The play buffer... +NEWSYM PModBuffer, times 320*4 dd 00h ; The play buffer... +NEWSYM BRRBuffer, times 32 db 0 ; The BRR Decode Buffer + +NEWSYM BRRPlace0, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp0, dd 0 ; Keep this 0 +NEWSYM BRRPlace1, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp1, dd 0 ; Keep this 0 +NEWSYM BRRPlace2, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp2, dd 0 ; Keep this 0 +NEWSYM BRRPlace3, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp3, dd 0 ; Keep this 0 +NEWSYM BRRPlace4, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp4, dd 0 ; Keep this 0 +NEWSYM BRRPlace5, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp5, dd 0 ; Keep this 0 +NEWSYM BRRPlace6, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp6, dd 0 ; Keep this 0 +NEWSYM BRRPlace7, dd 0 ; Place in the BRRBuffer for Voice 0 +NEWSYM BRRTemp7, dd 0 ; Keep this 0 + +NEWSYM Voice0Freq, dd 1 ; Frequency of Voice 0 (Delta Freq) +NEWSYM Voice1Freq, dd 1 ; Frequency of Voice 1 (Delta Freq) +NEWSYM Voice2Freq, dd 1 ; Frequency of Voice 2 (Delta Freq) +NEWSYM Voice3Freq, dd 1 ; Frequency of Voice 3 (Delta Freq) +NEWSYM Voice4Freq, dd 1 ; Frequency of Voice 4 (Delta Freq) +NEWSYM Voice5Freq, dd 1 ; Frequency of Voice 5 (Delta Freq) +NEWSYM Voice6Freq, dd 1 ; Frequency of Voice 6 (Delta Freq) +NEWSYM Voice7Freq, dd 1 ; Frequency of Voice 7 (Delta Freq) + +; appears to only be used in dspproc.asm +Voice0Pitch dw 1 ; Previous Pitch for Voice 0 +Voice1Pitch dw 1 ; Previous Pitch for Voice 1 +Voice2Pitch dw 1 ; Previous Pitch for Voice 2 +Voice3Pitch dw 1 ; Previous Pitch for Voice 3 +Voice4Pitch dw 1 ; Previous Pitch for Voice 4 +Voice5Pitch dw 1 ; Previous Pitch for Voice 5 +Voice6Pitch dw 1 ; Previous Pitch for Voice 6 +Voice7Pitch dw 1 ; Previous Pitch for Voice 7 + + +NEWSYM Voice0Status, db 0 ; 0=Not Playing 1=Playing +NEWSYM Voice1Status, db 0 +NEWSYM Voice2Status, db 0 +NEWSYM Voice3Status, db 0 +NEWSYM Voice4Status, db 0 +NEWSYM Voice5Status, db 0 +NEWSYM Voice6Status, db 0 +NEWSYM Voice7Status, db 0 + +NEWSYM Voice0Ptr, dd 0 ; Ptr to Next BRR Block to be played +NEWSYM Voice1Ptr, dd 0 +NEWSYM Voice2Ptr, dd 0 +NEWSYM Voice3Ptr, dd 0 +NEWSYM Voice4Ptr, dd 0 +NEWSYM Voice5Ptr, dd 0 +NEWSYM Voice6Ptr, dd 0 +NEWSYM Voice7Ptr, dd 0 +NEWSYM Voice0LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice1LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice2LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice3LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice4LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice5LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice6LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice7LoopPtr, dd 0 ; Ptr to Loop BRR Block to be played + +NEWSYM Voice0BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice1BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice2BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice3BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice4BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice5BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice6BufPtr, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice7BufPtr, dd 0 ; Ptr to Buffer Block to be played + +NEWSYM SoundCounter, dd 0 ; Counter used for sound generation +NEWSYM SoundCounter2, dd 0 ; Counter used for sound generation +NEWSYM Voice0Prev0, dd 0 +NEWSYM Voice1Prev0, dd 0 +NEWSYM Voice2Prev0, dd 0 +NEWSYM Voice3Prev0, dd 0 +NEWSYM Voice4Prev0, dd 0 +NEWSYM Voice5Prev0, dd 0 +NEWSYM Voice6Prev0, dd 0 +NEWSYM Voice7Prev0, dd 0 +NEWSYM Voice0Prev1, dd 0 +NEWSYM Voice1Prev1, dd 0 +NEWSYM Voice2Prev1, dd 0 +NEWSYM Voice3Prev1, dd 0 +NEWSYM Voice4Prev1, dd 0 +NEWSYM Voice5Prev1, dd 0 +NEWSYM Voice6Prev1, dd 0 +NEWSYM Voice7Prev1, dd 0 + +NEWSYM Voice0Loop, db 0 +NEWSYM Voice1Loop, db 0 +NEWSYM Voice2Loop, db 0 +NEWSYM Voice3Loop, db 0 +NEWSYM Voice4Loop, db 0 +NEWSYM Voice5Loop, db 0 +NEWSYM Voice6Loop, db 0 +NEWSYM Voice7Loop, db 0 + +NEWSYM Voice0End, db 0 +NEWSYM Voice1End, db 0 +NEWSYM Voice2End, db 0 +NEWSYM Voice3End, db 0 +NEWSYM Voice4End, db 0 +NEWSYM Voice5End, db 0 +NEWSYM Voice6End, db 0 +NEWSYM Voice7End, db 0 + +NEWSYM Voice0Noise, db 1 +NEWSYM Voice1Noise, db 1 +NEWSYM Voice2Noise, db 1 +NEWSYM Voice3Noise, db 1 +NEWSYM Voice4Noise, db 1 +NEWSYM Voice5Noise, db 1 +NEWSYM Voice6Noise, db 1 +NEWSYM Voice7Noise, db 1 + +NEWSYM Voice0Volume, db 0 +NEWSYM Voice1Volume, db 0 +NEWSYM Voice2Volume, db 0 +NEWSYM Voice3Volume, db 0 +NEWSYM Voice4Volume, db 0 +NEWSYM Voice5Volume, db 0 +NEWSYM Voice6Volume, db 0 +NEWSYM Voice7Volume, db 0 + +NEWSYM Voice0VolumeR, db 0 +NEWSYM Voice1VolumeR, db 0 +NEWSYM Voice2VolumeR, db 0 +NEWSYM Voice3VolumeR, db 0 +NEWSYM Voice4VolumeR, db 0 +NEWSYM Voice5VolumeR, db 0 +NEWSYM Voice6VolumeR, db 0 +NEWSYM Voice7VolumeR, db 0 + +NEWSYM Voice0VolumeL, db 0 +NEWSYM Voice1VolumeL, db 0 +NEWSYM Voice2VolumeL, db 0 +NEWSYM Voice3VolumeL, db 0 +NEWSYM Voice4VolumeL, db 0 +NEWSYM Voice5VolumeL, db 0 +NEWSYM Voice6VolumeL, db 0 +NEWSYM Voice7VolumeL, db 0 + +NEWSYM Voice0Env, db 1 +NEWSYM Voice1Env, db 1 +NEWSYM Voice2Env, db 1 +NEWSYM Voice3Env, db 1 +NEWSYM Voice4Env, db 1 +NEWSYM Voice5Env, db 1 +NEWSYM Voice6Env, db 1 +NEWSYM Voice7Env, db 1 + +NEWSYM Voice0Out, db 0 +NEWSYM Voice1Out, db 0 +NEWSYM Voice2Out, db 0 +NEWSYM Voice3Out, db 0 +NEWSYM Voice4Out, db 0 +NEWSYM Voice5Out, db 0 +NEWSYM Voice6Out, db 0 +NEWSYM Voice7Out, db 0 + +; 1 Attack, 2 Decrease,3 Sustain, 0 Gain +NEWSYM Voice0State, db 0 +NEWSYM Voice1State, db 0 +NEWSYM Voice2State, db 0 +NEWSYM Voice3State, db 0 +NEWSYM Voice4State, db 0 +NEWSYM Voice5State, db 0 +NEWSYM Voice6State, db 0 +NEWSYM Voice7State, db 0 + +NEWSYM Voice0Time, dd 1 +NEWSYM Voice1Time, dd 1 +NEWSYM Voice2Time, dd 1 +NEWSYM Voice3Time, dd 1 +NEWSYM Voice4Time, dd 1 +NEWSYM Voice5Time, dd 1 +NEWSYM Voice6Time, dd 1 +NEWSYM Voice7Time, dd 1 + +NEWSYM Voice0Attack, dd 1 +NEWSYM Voice1Attack, dd 1 +NEWSYM Voice2Attack, dd 1 +NEWSYM Voice3Attack, dd 1 +NEWSYM Voice4Attack, dd 1 +NEWSYM Voice5Attack, dd 1 +NEWSYM Voice6Attack, dd 1 +NEWSYM Voice7Attack, dd 1 + +NEWSYM Voice0Decay, dd 1 +NEWSYM Voice1Decay, dd 1 +NEWSYM Voice2Decay, dd 1 +NEWSYM Voice3Decay, dd 1 +NEWSYM Voice4Decay, dd 1 +NEWSYM Voice5Decay, dd 1 +NEWSYM Voice6Decay, dd 1 +NEWSYM Voice7Decay, dd 1 + +NEWSYM Voice0SustainL, db 1 +NEWSYM Voice1SustainL, db 1 +NEWSYM Voice2SustainL, db 1 +NEWSYM Voice3SustainL, db 1 +NEWSYM Voice4SustainL, db 1 +NEWSYM Voice5SustainL, db 1 +NEWSYM Voice6SustainL, db 1 +NEWSYM Voice7SustainL, db 1 + +NEWSYM Voice0SustainL2, db 1 +NEWSYM Voice1SustainL2, db 1 +NEWSYM Voice2SustainL2, db 1 +NEWSYM Voice3SustainL2, db 1 +NEWSYM Voice4SustainL2, db 1 +NEWSYM Voice5SustainL2, db 1 +NEWSYM Voice6SustainL2, db 1 +NEWSYM Voice7SustainL2, db 1 + +NEWSYM Voice0SustainR, dd 1 +NEWSYM Voice1SustainR, dd 1 +NEWSYM Voice2SustainR, dd 1 +NEWSYM Voice3SustainR, dd 1 +NEWSYM Voice4SustainR, dd 1 +NEWSYM Voice5SustainR, dd 1 +NEWSYM Voice6SustainR, dd 1 +NEWSYM Voice7SustainR, dd 1 + +NEWSYM Voice0SustainR2, dd 1 +NEWSYM Voice1SustainR2, dd 1 +NEWSYM Voice2SustainR2, dd 1 +NEWSYM Voice3SustainR2, dd 1 +NEWSYM Voice4SustainR2, dd 1 +NEWSYM Voice5SustainR2, dd 1 +NEWSYM Voice6SustainR2, dd 1 +NEWSYM Voice7SustainR2, dd 1 + +NEWSYM Voice0IncNumber, dd 1 +NEWSYM Voice1IncNumber, dd 1 +NEWSYM Voice2IncNumber, dd 1 +NEWSYM Voice3IncNumber, dd 1 +NEWSYM Voice4IncNumber, dd 1 +NEWSYM Voice5IncNumber, dd 1 +NEWSYM Voice6IncNumber, dd 1 +NEWSYM Voice7IncNumber, dd 1 + +NEWSYM Voice0SLenNumber, dd 0 +NEWSYM Voice1SLenNumber, dd 0 +NEWSYM Voice2SLenNumber, dd 0 +NEWSYM Voice3SLenNumber, dd 0 +NEWSYM Voice4SLenNumber, dd 0 +NEWSYM Voice5SLenNumber, dd 0 +NEWSYM Voice6SLenNumber, dd 0 +NEWSYM Voice7SLenNumber, dd 0 + +NEWSYM Voice0SEndNumber, dd 0 +NEWSYM Voice1SEndNumber, dd 0 +NEWSYM Voice2SEndNumber, dd 0 +NEWSYM Voice3SEndNumber, dd 0 +NEWSYM Voice4SEndNumber, dd 0 +NEWSYM Voice5SEndNumber, dd 0 +NEWSYM Voice6SEndNumber, dd 0 +NEWSYM Voice7SEndNumber, dd 0 + +NEWSYM Voice0SEndLNumber, dd 0 +NEWSYM Voice1SEndLNumber, dd 0 +NEWSYM Voice2SEndLNumber, dd 0 +NEWSYM Voice3SEndLNumber, dd 0 +NEWSYM Voice4SEndLNumber, dd 0 +NEWSYM Voice5SEndLNumber, dd 0 +NEWSYM Voice6SEndLNumber, dd 0 +NEWSYM Voice7SEndLNumber, dd 0 + +NEWSYM Voice0DecreaseNumber, dd 1 +NEWSYM Voice1DecreaseNumber, dd 1 +NEWSYM Voice2DecreaseNumber, dd 1 +NEWSYM Voice3DecreaseNumber, dd 1 +NEWSYM Voice4DecreaseNumber, dd 1 +NEWSYM Voice5DecreaseNumber, dd 1 +NEWSYM Voice6DecreaseNumber, dd 1 +NEWSYM Voice7DecreaseNumber, dd 1 + +NEWSYM Voice0EnvInc, dd 1 +NEWSYM Voice1EnvInc, dd 1 +NEWSYM Voice2EnvInc, dd 1 +NEWSYM Voice3EnvInc, dd 1 +NEWSYM Voice4EnvInc, dd 1 +NEWSYM Voice5EnvInc, dd 1 +NEWSYM Voice6EnvInc, dd 1 +NEWSYM Voice7EnvInc, dd 1 + +; 0 = Direct, 1 = Increase, 2 = Increase2, 3 = Decrease, 4 = Decrease2 +NEWSYM Voice0GainType, db 0 +NEWSYM Voice1GainType, db 0 +NEWSYM Voice2GainType, db 0 +NEWSYM Voice3GainType, db 0 +NEWSYM Voice4GainType, db 0 +NEWSYM Voice5GainType, db 0 +NEWSYM Voice6GainType, db 0 +NEWSYM Voice7GainType, db 0 + +NEWSYM Voice0GainTime, dd 1 +NEWSYM Voice1GainTime, dd 1 +NEWSYM Voice2GainTime, dd 1 +NEWSYM Voice3GainTime, dd 1 +NEWSYM Voice4GainTime, dd 1 +NEWSYM Voice5GainTime, dd 1 +NEWSYM Voice6GainTime, dd 1 +NEWSYM Voice7GainTime, dd 1 + +NEWSYM Voice0Starting, db 0 +NEWSYM Voice1Starting, db 0 +NEWSYM Voice2Starting, db 0 +NEWSYM Voice3Starting, db 0 +NEWSYM Voice4Starting, db 0 +NEWSYM Voice5Starting, db 0 +NEWSYM Voice6Starting, db 0 +NEWSYM Voice7Starting, db 0 + +NEWSYM Freqdisp, dd 0 +NEWSYM SBRateb, dd 0 + +NEWSYM Voice0Looped, db 0 +NEWSYM Voice1Looped, db 0 +NEWSYM Voice2Looped, db 0 +NEWSYM Voice3Looped, db 0 +NEWSYM Voice4Looped, db 0 +NEWSYM Voice5Looped, db 0 +NEWSYM Voice6Looped, db 0 +NEWSYM Voice7Looped, db 0 + +VoiceNoiseEn times 8 db 0 +NEWSYM GainDecBendDataPos, times 8 db 0 +NEWSYM GainDecBendDataTime, times 8 dd 0 +NEWSYM GainDecBendDataDat, times 8 db 0 + +NEWSYM AdsrBlocksLeft, times 8 db 0 +NEWSYM AdsrNextTimeDepth, times 8 dd 0 + +TimeTemp dd 0,0,0,0,0,0,0,0 ; 104 bytes +IncNTemp dd 0,0,0,0,0,0,0,0 +EnvITemp dd 0,0,0,0,0,0,0,0 +StatTemp dd 0,0 + +NEWSYM FutureExpand, times 44 db 0 +; pharos equ hack *sigh* +marksave: + +NEWSYM echoon0, db 0 +NEWSYM echoon1, db 0 +NEWSYM echoon2, db 0 +NEWSYM echoon3, db 0 +NEWSYM echoon4, db 0 +NEWSYM echoon5, db 0 +NEWSYM echoon6, db 0 +NEWSYM echoon7, db 0 + +NEWSYM GlobalVL, dd 0 +NEWSYM GlobalVR, dd 0 +NEWSYM EchoVL, dd 0 +NEWSYM EchoVR, dd 0 +NEWSYM EchoT, dd 0 + +NEWSYM Voice0Volumee, db 0 +NEWSYM Voice1Volumee, db 0 +NEWSYM Voice2Volumee, db 0 +NEWSYM Voice3Volumee, db 0 +NEWSYM Voice4Volumee, db 0 +NEWSYM Voice5Volumee, db 0 +NEWSYM Voice6Volumee, db 0 +NEWSYM Voice7Volumee, db 0 + +NEWSYM Voice0VolumeRe, db 0 +NEWSYM Voice1VolumeRe, db 0 +NEWSYM Voice2VolumeRe, db 0 +NEWSYM Voice3VolumeRe, db 0 +NEWSYM Voice4VolumeRe, db 0 +NEWSYM Voice5VolumeRe, db 0 +NEWSYM Voice6VolumeRe, db 0 +NEWSYM Voice7VolumeRe, db 0 + +NEWSYM Voice0VolumeLe, db 0 +NEWSYM Voice1VolumeLe, db 0 +NEWSYM Voice2VolumeLe, db 0 +NEWSYM Voice3VolumeLe, db 0 +NEWSYM Voice4VolumeLe, db 0 +NEWSYM Voice5VolumeLe, db 0 +NEWSYM Voice6VolumeLe, db 0 +NEWSYM Voice7VolumeLe, db 0 + +NEWSYM FIRTAPVal0, dd 0 +NEWSYM FIRTAPVal1, dd 0 +NEWSYM FIRTAPVal2, dd 0 +NEWSYM FIRTAPVal3, dd 0 +NEWSYM FIRTAPVal4, dd 0 +NEWSYM FIRTAPVal5, dd 0 +NEWSYM FIRTAPVal6, dd 0 +NEWSYM FIRTAPVal7, dd 0 + +NEWSYM MaxEcho, dd 172 +NEWSYM CEchoPtr, dd 0 +NEWSYM EchoFB, dd 0 + +NEWSYM Voice0Ptre, dd 0 ; Ptr to Next BRR Block to be played +NEWSYM Voice1Ptre, dd 0 +NEWSYM Voice2Ptre, dd 0 +NEWSYM Voice3Ptre, dd 0 +NEWSYM Voice4Ptre, dd 0 +NEWSYM Voice5Ptre, dd 0 +NEWSYM Voice6Ptre, dd 0 +NEWSYM Voice7Ptre, dd 0 +NEWSYM Voice0LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice1LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice2LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice3LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice4LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice5LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice6LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played +NEWSYM Voice7LoopPtre, dd 0 ; Ptr to Loop BRR Block to be played + +NEWSYM Voice0BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice1BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice2BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice3BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice4BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice5BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice6BufPtre, dd 0 ; Ptr to Buffer Block to be played +NEWSYM Voice7BufPtre, dd 0 ; Ptr to Buffer Block to be played + +NEWSYM CurFiltPtr, dd 0 +NEWSYM FiltLoop, times 16 dd 0 +NEWSYM FiltLoopR, times 16 dd 0 + +NEWSYM SoundLooped0, db 0 +NEWSYM SoundLooped1, db 0 +NEWSYM SoundLooped2, db 0 +NEWSYM SoundLooped3, db 0 +NEWSYM SoundLooped4, db 0 +NEWSYM SoundLooped5, db 0 +NEWSYM SoundLooped6, db 0 +NEWSYM SoundLooped7, db 0 + +NEWSYM UniqueSoundv, dd 0 + +; |AR Time 0 to 1|DR|Time 1 to SL|SL|Ratio| SR Time 1to 1/10| +;--------------------------------------------------------------------- +; |0 | 4.1 sec | 0| 1.2 sec | 0| 1/8 | 0| INF |10|1.2 sec +; |1 | 2.6 | 1| 740 msec | 1| 2/8 | 1| 38 |11|880 msec +; |2 | 1.5 | 2| 440 | 2| 3/8 | 2| 28 |12|740 +; |3 | 1.0 | 3| 290 | 3| 4/8 | 3| 24 |13|590 +; |4 |640 msec | 4| 180 | 4| 5/8 | 4| 19 |14|440 +; |5 |380 | 5| 110 | 5| 6/8 | 5| 14 |15|370 +; |6 |260 | 6| 74 | 6| 7/8 | 6| 12 |16|290 +; |7 |160 | 7| 37 | 7| 1 | 7| 9.4 |17|220 +; |8 | 96 -------------------------- 8| 7.1 |18|180 +; |9 | 64 | | 9| 5.9 |19|150 +; |A | 40 | | A| 4.7 |1A|110 +; |B | 24 | | B| 3.5 |1B| 92 +; |C | 16 | | C| 2.9 |1C| 74 +; |D | 10 | | D| 2.4 |1D| 55 +; |E | 6 | | E| 1.8 |1E| 37 +; |F | 0 | | F| 1.5 |1F| 28 +; --------------- --------------------------- + +; All the values are in 1/11025 + +NEWSYM EchoRate + dd 2,172,344,517,689,861,1033,1205,1378,1550,1722,1895, + dd 2067,2239,2412,2584 + +NEWSYM AttackRate + dd 45202,28665,16537,11025,7056,4189,2866,1764,1058,705,441 + dd 264,176,110,66,4 + +NEWSYM DecayRate + dd 13230,8158,4851,2697,1984,815,407,125 +NEWSYM SustainRate + dd 0FFFFFFFFh,418950,308700,265600,209475,154350,132300 + dd 103635,78277,65047,51817,38587,31972,26460,19845,16537 + dd 13230,9702,8158,6504,4851,3879,2697,1450 + dd 1212,1014,815,606,407,202,125,70 + +NEWSYM SustainValue + db 15,31,47,63,89,95,111,127 + +NEWSYM Increase + dd 0FFFFFFFFh,45202,34177,28665,22050,16537,14332,11025 + dd 8489,7056,5622,4189,3528,2866,2094,1764 + dd 1433,1058,882,705,529,441,352,264 + dd 220,176,132,110,88,66,44,22 + +NEWSYM IncreaseBent + dd 0FFFFFFFFh,79100,59535,50160,38580,28665,25000,19250 + dd 14332,12127,9800,7320,6160,4961,3650,3060 + dd 2425,1845,1540,1212,920,770,614,460 + dd 383,306,229,190,152,113,75,36 + +NEWSYM Decrease + dd 0FFFFFFFFh,45202,34177,28665,22050,16537,14332,11025 + dd 8489,7056,5622,4189,3528,2866,2094,1764 + dd 1433,1058,882,705,529,441,352,264 + dd 220,176,132,110,88,66,44,22 + +NEWSYM DecreaseRateExp + dd 0FFFFFFFFh,418950,308700,264600,209470,154350,132300,103635 + dd 78277,65047,51817,38587,31972,26460,19845,16537 + dd 13230,9702,8158,6504,4851,4079,3197,2425 + dd 1984,1653,1212,1014,815,606,407,198 + +GainDecBendData db 118,110,102,95,89,83,77,72,67,62,58,54,50,47,44,41,38,35 + db 33,30,28,26,24,23,21,20,18,17,16,15,14,13 + db 12,11,10,9,9,8,7,7,6,6,5,5,5,4,4,4,3,3,3,3,2,2,2,2,2,1,1,1,1 + db 255 + +AdsrBendData db 122,118,114,110,106,102,99,95,92,89,86,83,80,77,74,72,69,67 + db 64,62,60,58,56,54,52,50,48,47,45,44,42,41,39,38,36,35,34,33 + db 32,30,29,28,27,26,25,24,24,23,22,21,20,20,19,18,18,17,16,16 + db 15,15,14,14,13,13,12,12,11,11,11,10,10,9,9,9,8,8,8,7,7,7,7,6 + db 6,6,6,5,5,5,5,5,4,4,4,4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2 + db 2,2,1,1,1,1,1,1,1,1,1,1,1,1,255 + +NEWSYM AdsrSustLevLoc, db 58,39,27,19,13,8,3,1 + + +dspsave equ marksave-BRRBuffer +dspconvb equ marksave-Voice0Freq +NEWSYM PHdspsave, dd dspsave +NEWSYM PHdspconvb, dd dspconvb + + + + +NEWSYM PrepareSaveState + push edi + mov edi,[Voice0BufPtr] + sub edi,[spcBuffera] + mov [Voice0BufPtr],edi + mov edi,[Voice1BufPtr] + sub edi,[spcBuffera] + mov [Voice1BufPtr],edi + mov edi,[Voice2BufPtr] + sub edi,[spcBuffera] + mov [Voice2BufPtr],edi + mov edi,[Voice3BufPtr] + sub edi,[spcBuffera] + mov [Voice3BufPtr],edi + mov edi,[Voice4BufPtr] + sub edi,[spcBuffera] + mov [Voice4BufPtr],edi + mov edi,[Voice5BufPtr] + sub edi,[spcBuffera] + mov [Voice5BufPtr],edi + mov edi,[Voice6BufPtr] + sub edi,[spcBuffera] + mov [Voice6BufPtr],edi + mov edi,[Voice7BufPtr] + sub edi,[spcBuffera] + mov [Voice7BufPtr],edi + pop edi + ret + +%macro ResState 1 + mov edi,%1 + add edi,[spcBuffera] + mov eax,[spcBuffera] + add eax,65536*4 + cmp edi,eax + jb %%noof + mov edi,[spcBuffera] +%%noof + mov %1,edi +%endmacro +NEWSYM ResetState + push edi + ResState [Voice0BufPtr] + ResState [Voice1BufPtr] + ResState [Voice2BufPtr] + ResState [Voice3BufPtr] + ResState [Voice4BufPtr] + ResState [Voice5BufPtr] + ResState [Voice6BufPtr] + ResState [Voice7BufPtr] + pop edi + ret + +;VolumeConvTable times 32768 db 0 + +spc700temp dd 0,0 + +%macro VoiceStart 2 + mov dword[spc700temp+4],0 + cmp byte[Voice0Status+%1],0 + je .moveon + push eax + mov eax,[Voice0EnvInc+%1*4] + mov [spc700temp],eax + mov dword[spc700temp+4],1 + pop eax +.moveon + mov byte[Voice0Status+%1],0 + push eax + push ebx + push edx + mov eax,[DSPMem+%1*10h] + cmp al,40h + jae .noskip + cmp ah,40h + jae .noskip + mov eax,[DSPMem+%1*10h+4] + cmp eax,0050FF07h + jne .noskip + cmp byte[DSPMem+5Dh],6 + jne .noskip + mov byte[DSPMem+%1*10h],15 + mov byte[DSPMem+%1*10h+1],15 + pop edx + pop ebx + pop eax + ret +.noskip + + ; Check if adsr or gain + test byte[DSPMem+05h+%1*10h],80h + jz near .gain + + ; Calculate attack rate + xor eax,eax + mov al,[DSPMem+05h+%1*10h] + and al,0Fh + cmp eax,0Fh + je .skipattack + mov ebx,dword [AttackRate+eax*4] + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],8 + mov dword[Voice0EnvInc+%1*4],0 + mov byte[GainDecBendDataDat+%1],7Fh + mov byte[Voice0Status+%1],1 + jmp .finproc +.skipattack + mov al,[DSPMem+05h+%1*10h] + shr al,4 + and eax,07h + mov edx,[DecayRate+eax*4] + xor eax,eax + mov al,[DSPMem+06h+%1*10h] + and al,1Fh + mov ebx,[SustainRate+eax*4] + cmp edx,ebx + jae near .decayover + + ; ebx = total sustain time + xor eax,eax + mov al,[DSPMem+06h+%1*10h] + shr al,5 + mov al,[AdsrSustLevLoc+eax] + ; traverse through al entries in edx time + ; then through 64-al entries in ebx-edx time + mov [AdsrBlocksLeft+%1],al + sub ebx,edx + push ebx + push eax + mov ebx,eax + mov eax,edx + xor edx,edx + div ebx + mov [Voice0Time+%1*4],eax + mov [GainDecBendDataTime+%1*4],eax + pop eax + pop ebx + mov edx,ebx + mov ebx,64 + sub bl,al + mov eax,edx + xor edx,edx + div ebx + mov [AdsrNextTimeDepth+%1*4],eax + mov dword[Voice0EnvInc+%1*4],007FFFFFh + mov ebx,[Voice0Time+%1*4] + xor edx,edx + mov eax,127*65536 + sub eax,122*65536 + mov byte[GainDecBendDataPos+%1],0 + mov byte[GainDecBendDataDat+%1],127 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],9 + mov byte[Voice0Status+%1],1 + jmp .finproc +.decayover + sub edx,ebx + push ebx + mov eax,edx + xor ebx,ebx + mov bl,[DSPMem+06h+%1*10h] + shr bl,5 + xor bl,07h + mul ebx + mov ebx,7 + div ebx + pop ebx + add ebx,eax + mov dword[Voice0EnvInc+%1*4],007FFFFFh + shr ebx,5 + mov dword[Voice0Time+%1*4],ebx + mov [GainDecBendDataTime+%1*4],ebx + xor edx,edx + mov eax,127*65536 + sub eax,118*65536 + mov byte[GainDecBendDataPos+%1],0 + mov byte[GainDecBendDataDat+%1],127 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],7 + mov byte[Voice0Status+%1],1 + jmp .finproc +.gain + test byte [DSPMem+07h+%1*10h],80h + jz near .Direct + test byte [DSPMem+07h+%1*10h],40h + jnz near .Increase + test byte [DSPMem+07h+%1*10h],20h + jz near .LinearDec + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[DecreaseRateExp+eax*4] + mov dword[Voice0EnvInc+%1*4],007FFFFFh + shr ebx,5 + mov dword[Voice0Time+%1*4],ebx + mov [GainDecBendDataTime+%1*4],ebx + xor edx,edx + mov eax,127*65536 + sub eax,118*65536 + mov byte[GainDecBendDataPos+%1],0 + mov byte[GainDecBendDataDat+%1],127 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],7 + mov byte[Voice0Status+%1],1 + jmp .finproc +.LinearDec + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Decrease+eax*4] + mov dword[Voice0EnvInc+%1*4],007FFFFFh + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],5 + mov byte[Voice0Status+%1],1 + jmp .finproc +.Increase + test byte [DSPMem+07h+%1*10h],20h + jz .LinearInc + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + mov ebx,[Voice0Time+%1*4] + mov eax,ebx + shr eax,2 + sub ebx,eax + dec ebx + mov [Voice0Time+%1*4],ebx + mov byte [Voice0State+%1],6 + mov byte[Voice0Status+%1],1 + jmp .finproc +.LinearInc + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0Time+%1*4],ebx + xor edx,edx + mov eax,127*65536 + div ebx + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],3 + mov byte[Voice0Status+%1],1 + jmp .finproc +.Direct + mov al,[DSPMem+07h+%1*10h] + and al,7Fh + mov dword[Voice0EnvInc+%1*4],0 + mov byte [Voice0EnvInc+%1*4+2],al + mov dword [Voice0Time+%1*4],0FFFFFFFFh + mov dword [Voice0IncNumber+%1*4],0 + mov byte [Voice0State+%1],4 + mov byte[Voice0Status+%1],1 + jmp .finproc +.finproc + cmp dword[spc700temp+4],0 + je .skipall + mov eax,dword[Voice0Time+%1*4] + mov [TimeTemp+%1*4],eax + mov eax,dword[Voice0IncNumber+%1*4] + mov [IncNTemp+%1*4],eax + mov eax,dword[Voice0EnvInc+%1*4] + mov [EnvITemp+%1*4],eax + mov al,[Voice0State+%1] + mov [StatTemp+%1],al + mov eax,[spc700temp] + mov [Voice0EnvInc+%1*4],eax + mov dword[Voice0Time+%1*4],127 + shr eax,7 + neg eax + mov dword[Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],210 + jmp .novoice +.skipall + mov ax,[DSPMem+02h+%1*10h] + cmp word[Voice0Pitch+%1*2],ax + je .nopitchc + mov word[Voice0Pitch+%1*2],ax + xor ebx,ebx + xor edx,edx + and eax,03FFFh + shl eax,2 + mov dl,ah + shl eax,24 + mov ebx,[SBToSPC] + div ebx + shl eax,1 + mov [Voice0Freq+%1*4],eax + ; modpitch +.nopitchc + mov dword[BRRPlace0+%1*8],10000000h + mov dword [Voice0Prev0+%1*4],0 + mov dword [Voice0Prev1+%1*4],0 + mov byte [Voice0End+%1],0 + mov byte [Voice0Loop+%1],0 + mov byte[VoiceNoiseEn+%1],0 + mov dword[WaveIndex+%1*4],0 + mov dword[PSampleBuf+%1*22*4+19*4],0 + mov dword[PSampleBuf+%1*22*4+20*4],0 + mov dword[PSampleBuf+%1*22*4+21*4],0 + mov byte[SoundLooped0+%1],0 + mov byte[echoon0+%1],0 + test byte[DSPMem+4Dh],%2 + jz .noecho + mov byte[echoon0+%1],1 +.noecho +.novoice + mov edx,[DSPMem+04h+%1*10h] + and edx,0ffh + shl edx,2 + xor eax,eax + mov ah,[DSPMem+5Dh] + add ax,dx + xor ebx,ebx + mov bx,[spcRam+eax] + mov dword[Voice0Ptr+%1*4],ebx + xor ebx,ebx + mov bx,[spcRam+eax+2] + mov dword[Voice0LoopPtr+%1*4],ebx + pop edx + pop ebx + pop eax + ret +%endmacro + +NEWSYM Voice0Start + VoiceStart 0,1 + ret + +NEWSYM Voice1Start + VoiceStart 1,2 + ret + +NEWSYM Voice2Start + VoiceStart 2,4 + ret + +NEWSYM Voice3Start + VoiceStart 3,8 + ret + +NEWSYM Voice4Start + VoiceStart 4,16 + ret + +NEWSYM Voice5Start + VoiceStart 5,32 + ret + +NEWSYM Voice6Start + VoiceStart 6,64 + ret + +NEWSYM Voice7Start + VoiceStart 7,128 + ret + +; mov byte[Voice0Env+%1],3Fh +; jmp .Adsr +; Pass both voice # and next function name + +%macro VoiceStarterM 1 + cmp al,%1 + jne near %%nope + push edx + mov eax,[TimeTemp+%1*4] + mov [Voice0Time+%1*4],eax + mov eax,[IncNTemp+%1*4] + mov [Voice0IncNumber+%1*4],eax + mov eax,[EnvITemp+%1*4] + mov [Voice0EnvInc+%1*4],eax + mov al,[StatTemp+%1] + mov [Voice0State+%1],al + + mov byte[SoundLooped0+%1],0 + mov byte[echoon0+%1],0 + test byte[DSPMem+4Dh],1 << %1 + jz %%noecho + mov byte[echoon0+%1],1 +%%noecho + mov edx,[DSPMem+04h+%1*10h] + and edx,0ffh + shl edx,2 + xor eax,eax + mov ah,[DSPMem+5Dh] + add ax,dx + xor ebx,ebx + mov bx,[spcRam+eax] + mov dword[Voice0Ptr+%1*4],ebx + xor ebx,ebx + mov bx,[spcRam+eax+2] + mov dword[Voice0LoopPtr+%1*4],ebx + mov ax,[DSPMem+02h+%1*10h] + cmp word[Voice0Pitch+%1*2],ax + je %%nopitchc + mov word[Voice0Pitch+%1*2],ax + xor ebx,ebx + xor edx,edx + and eax,03FFFh + shl eax,2 + mov dl,ah + shl eax,24 + mov ebx,[SBToSPC] + div ebx + shl eax,1 + mov [Voice0Freq+%1*4],eax + ; modpitch +%%nopitchc + mov dword[BRRPlace0+%1*8],10000000h + mov dword [Voice0Prev0+%1*4],0 + mov dword [Voice0Prev1+%1*4],0 + mov byte [Voice0End+%1],0 + mov byte [Voice0Loop+%1],0 + mov byte[VoiceNoiseEn+%1],0 + mov dword[WaveIndex+%1*4],0 + mov dword[PSampleBuf+%1*22*4+19*4],0 + mov dword[PSampleBuf+%1*22*4+20*4],0 + mov dword[PSampleBuf+%1*22*4+21*4],0 + pop edx + ret +%%nope +%endmacro + +NEWSYM VoiceStarter + VoiceStarterM 0 + VoiceStarterM 1 + VoiceStarterM 2 + VoiceStarterM 3 + VoiceStarterM 4 + VoiceStarterM 5 + VoiceStarterM 6 + VoiceStarterM 7 + ret + +NEWSYM NoiseInc, dd 0 +NEWSYM NoisePointer, dd 0 +NEWSYM LastNoise, dd 0 + +%macro CalculatePMod 1 + xor eax,eax + mov al,[PModBuffer+esi] + mov ebx,[Voice0Freq+%1*4] + add al,80h + mul ebx + shr eax,7 + shl edx,25 + or eax,edx + mov ebx,eax +%endmacro + +%macro ProcessPMod 1 +;%endmacro +;%macro ProcessPModB 1 + push ecx + push edx + mov cl,[Voice0EnvInc+%1*4+2] + mov ax,[edi+edx*2] + imul cx + shr ax,7 + add dl,dl + or ah,dl + mov [PModBuffer+esi],ah + pop edx + pop ecx +%endmacro + +%macro NonEchoMonoPM 4 + xor eax,eax + mov al,[Voice0Volume+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1 + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1 +%%PMod + ProcessPMod %1 +%%NotNoise1 + mov ax,[edi+edx*2] +%%AfterNoise1 + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + mov [WaveIndex+%1*4], eax + add [DSPBuffer+esi*2],eax + add esi,2 + CalculatePMod %1 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro NonEchoStereoPM 4 + xor eax,eax + mov al,[Voice0VolumeR+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1b + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1b +%%PMod + ProcessPMod %1 +%%NotNoise1b + mov ax,[edi+edx*2] +%%AfterNoise1b + movsx eax,ax + mov [WaveIndex+%1*4], eax + push eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4],eax + xor eax,eax + mov al,[Voice0VolumeL+%1] + mov ah,[Voice0EnvInc+%1*4+2] + add esi,2 + mov cx,[VolumeConvTable+eax*2] + pop eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4-4],eax + CalculatePMod %1 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro EchoMonoPM 4 + xor eax,eax + mov al,[Voice0Volume+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1 + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1 +%%PMod + ProcessPMod %1 +%%NotNoise1 + mov ax,[edi+edx*2] +%%AfterNoise1 + movsx eax,ax + mov [WaveIndex+%1*4], eax + push eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [DSPBuffer+esi*2],eax + + xor eax,eax + mov al,[Voice0Volumee+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + pop eax + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [EchoBuffer+esi*2],eax + + add esi,2 + CalculatePMod %1 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro EchoStereoPM 4 + xor eax,eax + mov al,[Voice0VolumeR+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1b + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1b +%%PMod + ProcessPMod %1 +%%NotNoise1b + mov ax,[edi+edx*2] +%%AfterNoise1b + movsx eax,ax + mov [WaveIndex+%1*4], eax + mov ebx,eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4],eax + xor eax,eax + mov al,[Voice0VolumeRe+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + mov eax,ebx + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [EchoBuffer+esi*4],eax + + xor eax,eax + mov al,[Voice0VolumeL+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + + mov eax,ebx + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4+4],eax + xor eax,eax + mov al,[Voice0VolumeLe+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + mov eax,ebx + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + mov ebx,[Voice0Freq+%1*4] + add [EchoBuffer+esi*4+4],eax + + add esi,2 + CalculatePMod %1 + add [BRRPlace0+%1*8],ebx +%endmacro + +; interpolation is only done when the rate < mixRate, so ebx always contains +; less than 100000h. + +%macro GenerateNextSample 1 + mov edx, [BRRPlace0+%1*8+2] ; edx should now contain a 24 bit fractional + and edx, 0FFh + sub eax, [WaveIndex+%1*4] ; eax = the difference between sample - oldSample + imul eax, edx ; scale by the fractional + sar eax, 8 + add eax, [WaveIndex+%1*4] ; add the oldSample to the scaling. +%endmacro + +SaveSample times 8 dd 0 +WaveIndex times 8 dd 0 + +;DSPInterP + +; cmp ebx,01000000h ; +; jb %%DontFilter1 ; +; mov edx,eax ; +; mov eax,[WaveIndex+%1*4] ; low-pass filter applied to higher pitched +; sar eax,1 ; samples +; sar edx,1 ; +; add eax,edx ; +;%%DontFilter1 ; + +%macro DSPInterpolate 1 + xor ebx,ebx + mov bl,[BRRPlace0+%1*8+2] + + mov ax,[PSampleBuf+edx*4+0+%1*22*4] + mov dx,[DSPInterP+ebx*2+256*6] + imul dx + shl edx,16 + mov dx,ax + mov eax,[BRRPlace0+%1*8+3] + mov ecx,edx + + mov ax,[PSampleBuf+eax*4+4+%1*22*4] + mov dx,[DSPInterP+ebx*2+256*4] + imul dx + shl edx,16 + mov dx,ax + mov eax,[BRRPlace0+%1*8+3] + add ecx,edx + + mov ax,[PSampleBuf+eax*4+8+%1*22*4] + mov dx,[DSPInterP+ebx*2+256*2] + imul dx + shl edx,16 + mov dx,ax + mov eax,[BRRPlace0+%1*8+3] + add ecx,edx + + mov ax,[PSampleBuf+eax*4+12+%1*22*4] + mov dx,[DSPInterP+ebx*2] + imul dx + shl edx,16 + mov dx,ax + add ecx,edx + + sar ecx,11 + mov ax,cx +%endmacro + +%macro NonEchoMonoInterpolated 4 + mov edx,[BRRPlace0+%1*8+3] + cmp byte[UniqueSoundv],0 + je %%NotNoise1 + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1 +%%PMod + ProcessPMod %1 +%%NotNoise1 + DSPInterpolate %1 +; mov edx,[BRRPlace0+%1*8+3] +; mov ax,[edi+edx*2] + ; DSPInterP (Samp*i+Samp2*i2+Samp3*i3+Samp4*i3)>>11 +%%AfterNoise1 + xor edx,edx + mov dl,[Voice0Volume+%1] + mov dh,[Voice0EnvInc+%1*4+2] + mov ebx,[Voice0Freq+%1*4] + mov cx,[VolumeConvTable+edx*2] + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [DSPBuffer+esi*2],eax + add esi,2 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro EchoMonoInterpolated 4 + mov edx,[BRRPlace0+%1*8+3] + cmp byte[UniqueSoundv],0 + je %%NotNoise1 + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1 +%%PMod + ProcessPMod %1 +%%NotNoise1 + DSPInterpolate %1 +; mov edx,[BRRPlace0+%1*8+3] +; mov ax,[edi+edx*2] +%%AfterNoise1 + xor edx,edx + mov dl,[Voice0Volume+%1] + mov dh,[Voice0EnvInc+%1*4+2] + mov ebx,[Voice0Freq+%1*4] + mov cx,[VolumeConvTable+edx*2] + + add [BRRPlace0+%1*8],ebx ; *** + add esi,2 ; *** + mov ebx,eax + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [DSPBuffer+esi*2-4],eax + + xor eax,eax + mov al,[Voice0Volumee+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + + mov eax,ebx + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [EchoBuffer+esi*2-4],eax +%endmacro + +%macro NonEchoStereoInterpolated 4 + mov edx,[BRRPlace0+%1*8+3] + cmp byte[UniqueSoundv],0 + je %%NotNoise1b + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1b +%%PMod + ProcessPMod %1 +%%NotNoise1b + DSPInterpolate %1 +%%AfterNoise1b + xor edx,edx + mov dl,[Voice0VolumeR+%1] + mov dh,[Voice0EnvInc+%1*4+2] + mov ebx,[Voice0Freq+%1*4] + mov cx,[VolumeConvTable+edx*2] + + movsx eax,ax + mov [WaveIndex+%1*4], eax + push eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4],eax + xor eax,eax + mov al,[Voice0VolumeL+%1] + mov ah,[Voice0EnvInc+%1*4+2] + add esi,2 + mov cx,[VolumeConvTable+eax*2] + pop eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4-4],eax + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro EchoStereoInterpolated 4 + mov edx,[BRRPlace0+%1*8+3] + cmp byte[UniqueSoundv],0 + je %%NotNoise1b + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1b +%%PMod + ProcessPMod %1 +%%NotNoise1b +; mov ax,[edi+edx*2] + DSPInterpolate %1 +%%AfterNoise1b + xor edx,edx + mov dl,[Voice0VolumeR+%1] + mov dh,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+edx*2] + + movsx eax,ax + mov [WaveIndex+%1*4], eax + mov ebx,eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4],eax + xor eax,eax + mov al,[Voice0VolumeRe+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + mov eax,ebx + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [EchoBuffer+esi*4],eax + + xor eax,eax + mov al,[Voice0VolumeL+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + + mov eax,ebx + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4+4],eax + xor eax,eax + mov al,[Voice0VolumeLe+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + mov eax,ebx + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + mov ebx,[Voice0Freq+%1*4] + add [EchoBuffer+esi*4+4],eax + + add esi,2 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro NonEchoMono 4 + xor eax,eax + mov al,[Voice0Volume+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1 + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1 +%%PMod + ProcessPMod %1 +%%NotNoise1 + mov ax,[edi+edx*2] +%%AfterNoise1 + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + mov [WaveIndex+%1*4], eax + add [DSPBuffer+esi*2],eax + add esi,2 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro NonEchoStereo 4 + xor eax,eax + mov al,[Voice0VolumeR+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1b + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1b +%%PMod + ProcessPMod %1 +%%NotNoise1b + mov ax,[edi+edx*2] +%%AfterNoise1b + movsx eax,ax + mov [WaveIndex+%1*4], eax + push eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4],eax + xor eax,eax + mov al,[Voice0VolumeL+%1] + mov ah,[Voice0EnvInc+%1*4+2] + add esi,2 + mov cx,[VolumeConvTable+eax*2] + pop eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4-4],eax + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro EchoMono 4 + xor eax,eax + mov al,[Voice0Volume+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1 + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1 +%%PMod + ProcessPMod %1 +%%NotNoise1 + mov ax,[edi+edx*2] +%%AfterNoise1 + movsx eax,ax + mov [WaveIndex+%1*4], eax + push eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [DSPBuffer+esi*2],eax + + xor eax,eax + mov al,[Voice0Volumee+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + pop eax + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [EchoBuffer+esi*2],eax + + add esi,2 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro EchoStereo 4 + xor eax,eax + mov al,[Voice0VolumeR+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov edx,[BRRPlace0+%1*8+3] + mov cx,[VolumeConvTable+eax*2] + cmp byte[UniqueSoundv],0 + je %%NotNoise1b + test byte [DSPMem+3Dh],1 << %1 + jz %%PMod + mov eax, dword [NoiseInc] + add dword [NoisePointer],eax + mov eax,[NoisePointer] + shr eax,18 ; maybe will need a change + mov ax,[NoiseData+eax*2] + mov word [LastNoise],ax + jmp %%AfterNoise1b +%%PMod + ProcessPMod %1 +%%NotNoise1b + mov ax,[edi+edx*2] +%%AfterNoise1b + movsx eax,ax + mov [WaveIndex+%1*4], eax + mov ebx,eax + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4],eax + xor eax,eax + mov al,[Voice0VolumeRe+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + mov eax,ebx + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add [EchoBuffer+esi*4],eax + + xor eax,eax + mov al,[Voice0VolumeL+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + + mov eax,ebx + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + add dword [DSPBuffer+esi*4+4],eax + xor eax,eax + mov al,[Voice0VolumeLe+%1] + mov ah,[Voice0EnvInc+%1*4+2] + mov cx,[VolumeConvTable+eax*2] + mov eax,ebx + + imul cx + shr ax,7 + add dl,dl + or ah,dl + movsx eax,ax + mov ebx,[Voice0Freq+%1*4] + add [EchoBuffer+esi*4+4],eax + + add esi,2 + add [BRRPlace0+%1*8],ebx +%endmacro + +%macro ProcessVoiceStuff 8 + mov ax,[DSPMem+02h+%1*10h] + cmp word[Voice0Pitch+%1*2],ax + je %%nopitchc + mov word[Voice0Pitch+%1*2],ax + xor ebx,ebx + xor edx,edx + and eax,03FFFh + shl eax,2 + mov dl,ah + shl eax,24 + mov ebx,[SBToSPC] + div ebx + shl eax,1 + ; modpitch + mov [Voice0Freq+%1*4],eax +%%nopitchc + jmp %%SkipProcess +%%ProcessNextEnvelope + cmp byte [Voice0State+%1],10 + je near %%ADSRSustain + cmp byte [Voice0State+%1],9 + je near %%ADSRDecayProc + cmp byte [Voice0State+%1],7 + je near %%DecreaseBent + cmp byte [Voice0State+%1],8 + je near %%ADSRDecay + cmp byte [Voice0State+%1],1 + je near %%Decay + cmp byte [Voice0State+%1],2 + je near %%Sustain + cmp byte [Voice0State+%1],3 + je near %%Blank + cmp byte [Voice0State+%1],4 + je near %%EndofSamp + cmp byte [Voice0State+%1],200 + je near %%EndofSamp + cmp byte [Voice0State+%1],210 + je near %%EndofSamp2 + cmp byte [Voice0State+%1],5 + je %%MuteGain + cmp byte [Voice0State+%1],6 + je %%IncreaseBent + jmp %%EndofSamp +%%MuteGain + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0IncNumber+%1*4],0 + mov dword[Voice0Time+%1*4],0FFFFFFFFh + jmp %%ContinueGain +%%IncreaseBent + push ebx + xor eax,eax + mov al,[DSPMem+07h+%1*10h] + and al,1Fh + mov ebx,[Increase+eax*4] + mov dword[Voice0Time+%1*4],ebx + shr dword[Voice0IncNumber+%1*4],2 + mov byte[Voice0State+%1],3 + pop ebx + jmp %%ContinueGain +%%ADSRDecay + push ebx + push edx + mov al,[DSPMem+05h+%1*10h] + shr al,4 + and eax,07h + mov edx,[DecayRate+eax*4] + xor eax,eax + mov al,[DSPMem+06h+%1*10h] + and al,1Fh + mov ebx,[SustainRate+eax*4] + cmp edx,ebx + jae near %%decayover + ; ebx = total sustain time + xor eax,eax + mov al,[DSPMem+06h+%1*10h] + shr al,5 + mov al,[AdsrSustLevLoc+eax] + ; traverse through al entries in edx time + ; then through 64-al entries in ebx-edx time + mov [AdsrBlocksLeft+%1],al + sub ebx,edx + push ebx + push eax + mov ebx,eax + mov eax,edx + xor edx,edx + div ebx + mov [Voice0Time+%1*4],eax + mov [GainDecBendDataTime+%1*4],eax + pop eax + pop ebx + mov edx,ebx + mov ebx,64 + sub bl,al + mov eax,edx + xor edx,edx + div ebx + mov [AdsrNextTimeDepth+%1*4],eax + mov dword[Voice0EnvInc+%1*4],007FFFFFh + mov ebx,[Voice0Time+%1*4] + xor edx,edx + mov eax,127*65536 + sub eax,122*65536 + mov byte[GainDecBendDataPos+%1],0 + mov byte[GainDecBendDataDat+%1],127 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + mov byte [Voice0State+%1],9 + jmp %%ContinueGain +%%decayover + sub edx,ebx + push ebx + mov eax,edx + xor ebx,ebx + mov bl,[DSPMem+06h+%1*10h] + shr bl,5 + xor bl,07h + mul ebx + mov ebx,7 + div ebx + pop ebx + add ebx,eax + mov dword[Voice0EnvInc+%1*4],007FFFFFh + shr ebx,5 + mov dword[Voice0Time+%1*4],ebx + mov [GainDecBendDataTime+%1*4],ebx + xor edx,edx + mov eax,127*65536 + sub eax,118*65536 + mov byte[GainDecBendDataPos+%1],0 + mov byte[GainDecBendDataDat+%1],127 + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + mov byte [Voice0State+%1],7 + jmp %%ContinueGain +%%ADSRDecayProc + push ebx + push edx + xor ebx,ebx + xor edx,edx + xor eax,eax + mov dword[Voice0EnvInc+%1*4],0 + mov bl,[GainDecBendDataPos+%1] + mov dl,[GainDecBendDataDat+%1] + mov dh,[AdsrBendData+ebx] + mov al,[VolumeConvTable+edx*2] + mov [Voice0EnvInc+%1*4+2],al + mov dl,[GainDecBendDataDat+%1] + mov dh,[AdsrBendData+ebx+1] + sub al,[VolumeConvTable+edx*2] + mov ebx,[GainDecBendDataTime+%1*4] + mov [Voice0Time+%1*4],ebx + xor edx,edx + shl eax,16 + inc byte[GainDecBendDataPos+%1] + div ebx + neg eax + mov [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + dec byte[AdsrBlocksLeft+%1] + jz %%nomoredecay + jmp %%ContinueGain +%%nomoredecay + mov byte [Voice0State+%1],10 + jmp %%ContinueGain +%%ADSRSustain + push ebx + push edx + xor ebx,ebx + xor edx,edx + xor eax,eax + mov dword[Voice0EnvInc+%1*4],0 + mov bl,[GainDecBendDataPos+%1] + mov dl,[GainDecBendDataDat+%1] + mov dh,[AdsrBendData+ebx] + mov al,[VolumeConvTable+edx*2] + mov [Voice0EnvInc+%1*4+2],al + mov dl,[GainDecBendDataDat+%1] + mov dh,[AdsrBendData+ebx+1] + cmp dh,255 + je %%nomoreadsr + mov dl,[VolumeConvTable+edx*2] + mov ebx,[AdsrNextTimeDepth+%1*4] + sub al,dl + mov [Voice0Time+%1*4],ebx + xor edx,edx + shl eax,16 + inc byte[GainDecBendDataPos+%1] + div ebx + neg eax + mov [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + jmp %%ContinueGain +%%nomoreadsr + pop edx + pop ebx + mov byte [Voice0State+%1],5 + jmp %%MuteGain +%%DecreaseBent + push ebx + push edx + xor ebx,ebx + xor edx,edx + xor eax,eax + mov bl,[GainDecBendDataPos+%1] + mov dl,[GainDecBendDataDat+%1] + mov dh,[GainDecBendData+ebx] + mov dword[Voice0EnvInc+%1*4],0 + mov al,[VolumeConvTable+edx*2] + mov byte[Voice0EnvInc+%1*4+2],al + mov dh,[GainDecBendData+ebx+1] + cmp dh,255 + je %%nomore + mov ebx,[GainDecBendDataTime+%1*4] + sub al,[VolumeConvTable+edx*2] + mov [Voice0Time+%1*4],ebx + xor edx,edx + shl eax,16 + inc byte[GainDecBendDataPos+%1] + div ebx + neg eax + mov [Voice0IncNumber+%1*4],eax + pop edx + pop ebx + jmp %%ContinueGain +%%nomore + pop edx + pop ebx + mov byte [Voice0State+%1],5 + jmp %%MuteGain +%%Decay + ; Calculate Decay Value + push ebx + push edx + mov dword[Voice0EnvInc+%1*4],07FFFFFh + mov al,[DSPMem+05h+%1*10h] + mov dl,[DSPMem+06h+%1*10h] + shr al,4 + and eax,07h + and edx,1Fh + mov ebx,[DecayRate+eax*4] + cmp edx,1Fh + je %%nodecayfix + cmp ebx,[SustainRate+edx*4] + jbe %%nodecayfix + cmp al,0 + jne %%nodecayskip + mov al,[DSPMem+06h+%1*10h] + and al,0E0h + cmp al,0E0h + je near %%Sustain2 +%%nodecayskip + mov al,[DSPMem+05h+%1*10h] + shr al,4 + and eax,07h + mov ebx,[DecayRate+eax*4] + sub ebx,[SustainRate+edx*4] + cmp ebx,[SustainRate+edx*4] + jae %%nodecayfix + mov ebx,[SustainRate+edx*4] +%%nodecayfix + or ebx,ebx + jnz %%nozero + inc ebx +%%nozero + mov dl,[DSPMem+06h+%1*10h] + shr dl,5 + and dl,07h + mov dword[Voice0Time+%1*4],ebx + mov al,[SustainValue+edx] + xor al,7Fh + shl eax,16 + xor edx,edx + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],2 + pop edx + pop ebx + mov ebx,[Voice0Freq+%1*4] +; cmp byte[VoiceNoiseEn+%1],10 +; je %%notinterpsound + cmp byte [InterSound],1 + jne %%notinterpsound + cmp byte [StereoSound],1 + je near %%EndofProcessNEnvsi + jmp %%EndofProcessNEnvi +%%notinterpsound + cmp byte [StereoSound],1 + je near %%EndofProcessNEnvs + jmp %%EndofProcessNEnv +%%Sustain2 + mov ebx,[SustainRate+edx*4] + jmp %%continuesust +%%Sustain + ; Calculate Decay Value + push ebx + push edx + mov al,[DSPMem+05h+%1*10h] + mov dl,[DSPMem+06h+%1*10h] + and edx,1Fh + shr al,4 + and eax,07h + mov ebx,[SustainRate+edx*4] + test ebx,80000000h + jnz %%sustainokay + sub ebx,[DecayRate+eax*4] +%%continuesust + cmp ebx,100 + jg %%sustainokay + mov ebx,100 +%%sustainokay + mov dword[Voice0Time+%1*4],ebx + mov al,[Voice0EnvInc+%1*4+2] + shl eax,16 + xor edx,edx + div ebx + neg eax + mov dword [Voice0IncNumber+%1*4],eax + mov byte [Voice0State+%1],4 + pop edx + pop ebx + mov ebx,[Voice0Freq+%1*4] +; cmp byte[VoiceNoiseEn+%1],10 +; je %%notinterpsound2 + cmp byte [InterSound],1 + jne %%notinterpsound2 + cmp byte [StereoSound],1 + je near %%EndofProcessNEnvsi + jmp %%EndofProcessNEnvi +%%notinterpsound2 + cmp byte [StereoSound],1 + je near %%EndofProcessNEnvs + jmp %%EndofProcessNEnv +%%Blank + mov dword[Voice0EnvInc+%1*4],007F0000h + mov dword[Voice0IncNumber+%1*4],0 + mov dword[Voice0Time+%1*4],0FFFFFFFFh +%%ContinueGain + mov ebx,[Voice0Freq+%1*4] +; cmp byte[VoiceNoiseEn+%1],10 +; je %%notinterpsound3 + cmp byte [InterSound],1 + jne %%notinterpsound3 + cmp byte [StereoSound],1 + je near %%EndofProcessNEnvsi + jmp %%EndofProcessNEnvi +%%notinterpsound3 + cmp byte [StereoSound],1 + je near %%EndofProcessNEnvs + jmp %%EndofProcessNEnv +%%EndofSamp + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0IncNumber+%1*4],0 + mov byte [Voice0Status+%1],0 + mov byte [Voice0State+%1],0 + cmp byte[CNetType],20 + je %%SkipStuff + mov byte [DSPMem+08h+%1*10h],0 + mov byte [DSPMem+09h+%1*10h],0 + or byte [DSPMem+7Ch],%3 +%%SkipStuff + jmp %2 +%%EndofSamp2 + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0IncNumber+%1*4],0 + mov byte [Voice0State+%1],0 + cmp byte[CNetType],20 + je %%SkipStuff2 + mov byte [DSPMem+08h+%1*10h],0 + mov byte [DSPMem+09h+%1*10h],0 + or byte [DSPMem+7Ch],%3 +%%SkipStuff2 + mov al,%1 + call VoiceStarter + jmp %%SkipProcess2 +%%SkipProcess + xor esi,esi +%%SkipProcess2 + + xor eax,eax + xor ebx,ebx + mov al,[DSPMem+00h+%1*10h] + mov bl,[DSPMem+01h+%1*10h] + mov al,[VolumeTableD+eax] + mov bl,[VolumeTableD+ebx] + mov [Voice0VolumeRe+%1],al + mov [Voice0VolumeLe+%1],bl + mov ah,al + mov bh,bl + test ah,80h + jz %%notnegc + neg ah +%%notnegc + test bh,80h + jz %%notnegd + neg bh +%%notnegd + add ah,bh + shr ah,1 + test al,80h + jnz %%neg2 + test bl,80h + jz %%notneg2 +%%neg2 + neg ah +%%notneg2 + mov [Voice0Volumee+%1],ah + + xor eax,eax + xor ebx,ebx + mov al,[DSPMem+00h+%1*10h] + mov bl,[DSPMem+01h+%1*10h] + mov al,[VolumeTableD+eax] + mov bl,[VolumeTableD+ebx] + mov ah,[GlobalVL] + mov bh,[GlobalVR] + mov al,[VolumeConvTable+eax*2] + mov bl,[VolumeConvTable+ebx*2] + mov [Voice0VolumeR+%1],al + mov [Voice0VolumeL+%1],bl + mov ah,al + mov bh,bl + test ah,80h + jz %%notneg + neg ah +%%notneg + test bh,80h + jz %%notnegb + neg bh +%%notnegb + add ah,bh + shr ah,1 + test al,80h + jnz %%neg3 + test bl,80h + jz %%notneg3 +%%neg3 + neg ah +%%notneg3 + mov [Voice0Volume+%1],ah + +; cmp byte[Voice0Volume+%1],0 +; je %%volskip + mov byte [lastbl],0 + mov byte [loopbl],0 + mov ebx,[Voice0Freq+%1*4] + mov edi,[Voice0BufPtr+%1*4] + + mov byte[UniqueSoundv],0 + test byte [DSPMem+3Dh],%3 + jnz %%Unique +%if %1<7 ; added + test byte [DSPMem+2Dh],%3 << 1 + jnz %%Uniquepm +%endif ; added + jmp %%NotUnique +%%Uniquepm +; cmp byte[PitchModEn],0 +; je %%NotUnique +; mov al,%1 ; +; cmp al,0 ; commented out +; je %%NotUnique ; +%%Unique + mov byte [UniqueSoundv],1 +%%NotUnique + +; cmp byte[VoiceNoiseEn+%1],10 +; je %%notinterpsound4 + cmp byte [InterSound],1 + jne %%notinterpsound4 + cmp byte [StereoSound],1 + je near %%NextSampleSi + jmp %%NextSamplei +%%notinterpsound4 + cmp byte [StereoSound],1 + je near %%NextSampleS +%%NextSample + cmp dword[BRRPlace0+%1*8],10000000h + jae near %%ProcessBRR + mov eax,[Voice0IncNumber+%1*4] + add [Voice0EnvInc+%1*4],eax + dec dword[Voice0Time+%1*4] + jz near %%ProcessNextEnvelope +%%EndofProcessNEnv + %5 %1, %2, %3, %4 + cmp esi,[BufferSizeW] + jne near %%NextSample +; mov [DSPMem+09h+%1*10h],ah + mov al,[Voice0EnvInc+%1*4+2] + mov [DSPMem+08h+%1*10h],al + cmp byte[CNetType],20 + je %%clearenv + cmp byte[MovieProcessing],0 + je %%skipenvclear +%%clearenv + mov byte[DSPMem+08h+%1*10h],0 +%%skipenvclear + jmp %%ProcessVoice1 +%%NextSampleSi + cmp dword[BRRPlace0+%1*8],10000000h + jae near %%ProcessBRR + mov eax,[Voice0IncNumber+%1*4] + add [Voice0EnvInc+%1*4],eax + dec dword[Voice0Time+%1*4] + jz near %%ProcessNextEnvelope +%%EndofProcessNEnvsi + %8 %1, %2, %3, %4 + cmp esi,[BufferSizeB] + jne near %%NextSampleSi +; mov [DSPMem+09h+%1*10h],ah + mov al,[Voice0EnvInc+%1*4+2] + mov [DSPMem+08h+%1*10h],al + cmp byte[CNetType],20 + je %%clearenvsi + cmp byte[MovieProcessing],0 + je %%skipenvclearsi +%%clearenvsi + mov byte[DSPMem+08h+%1*10h],0 +%%skipenvclearsi + jmp %%ProcessVoice1 +%%NextSamplei + cmp dword[BRRPlace0+%1*8],10000000h + jae near %%ProcessBRR + mov eax,[Voice0IncNumber+%1*4] + add [Voice0EnvInc+%1*4],eax + dec dword[Voice0Time+%1*4] + jz near %%ProcessNextEnvelope +%%EndofProcessNEnvi + %7 %1, %2, %3, %4 + cmp esi,[BufferSizeW] + jne near %%NextSamplei +; mov [DSPMem+09h+%1*10h],ah + mov al,[Voice0EnvInc+%1*4+2] + mov [DSPMem+08h+%1*10h],al + cmp byte[CNetType],20 + je %%clearenvi + cmp byte[MovieProcessing],0 + je %%skipenvcleari +%%clearenvi + mov byte[DSPMem+08h+%1*10h],0 +%%skipenvcleari + jmp %%ProcessVoice1 +%%NextSampleS + cmp dword[BRRPlace0+%1*8],10000000h + jae near %%ProcessBRR + mov eax,[Voice0IncNumber+%1*4] + add [Voice0EnvInc+%1*4],eax + dec dword[Voice0Time+%1*4] + jz near %%ProcessNextEnvelope +%%EndofProcessNEnvs + %6 %1, %2, %3, %4 + cmp esi,[BufferSizeB] + jne near %%NextSampleS +; mov [DSPMem+09h+%1*10h],ah + mov al,[Voice0EnvInc+%1*4+2] + mov [DSPMem+08h+%1*10h],al + cmp byte[CNetType],20 + je %%clearenv2 + cmp byte[MovieProcessing],0 + je %%skipenvclear2 +%%clearenv2 + mov byte[DSPMem+08h+%1*10h],0 +%%skipenvclear2 +%%noclearenv + jmp %%ProcessVoice1 +%%ProcessBRR + cmp byte [Voice0End+%1],1 + je near %%noDecode1Block +%%Decode1Block + sub dword [BRRPlace0+%1*8],10000000h + push esi + mov esi, dword [Voice0Ptr+%1*4] +; cmp byte[Voice0Looped+%1],0 +; je %%nobrrcheck + + mov eax,[PSampleBuf+19*4+%1*22*4] + mov [PSampleBuf+0*4+%1*22*4],eax + mov eax,[PSampleBuf+20*4+%1*22*4] + mov [PSampleBuf+1*4+%1*22*4],eax + mov eax,[PSampleBuf+21*4+%1*22*4] + mov [PSampleBuf+2*4+%1*22*4],eax + + cmp byte[SoundBufEn],0 + je near %%convertBRR2 + jmp %%convertBRR2 + ; Check if looped +%%nobrrcheck + mov eax,[spcRam+esi] + mov ebx,[spcRam+esi+4] + cmp eax,[spcRamcmp+esi] + jne near %%convertBRR + cmp ebx,[spcRamcmp+esi+4] + jne near %%convertBRR + mov al,[spcRam+esi+8] + cmp al,[spcRamcmp+esi+8] + jne near %%convertBRR + mov byte[Voice0End+%1],0 + mov byte[Voice0Loop+%1],0 + test byte[spcRam+esi],01h + jz %%nolast + mov byte[Voice0End+%1],1 + test byte[spcRam+esi],02h + jnz %%looped + jmp %%last +%%looped + mov byte[Voice0Loop+%1],1 +%%nolast +%%last + mov edi,esi + inc edi + add dword [Voice0Ptr+%1*4],9 + shl edi,2 + pop esi + add edi,[spcBuffera] + mov ebx,[Voice0Freq+%1*4] + mov [Voice0BufPtr+%1*4],edi + + mov ax,[edi] + mov [PSampleBuf+3*4+%1*22*4],eax + mov ax,[edi+2*1] + mov [PSampleBuf+4*4+%1*22*4],eax + mov ax,[edi+2*2] + mov [PSampleBuf+5*4+%1*22*4],eax + mov ax,[edi+2*3] + mov [PSampleBuf+6*4+%1*22*4],eax + mov ax,[edi+2*4] + mov [PSampleBuf+7*4+%1*22*4],eax + mov ax,[edi+2*5] + mov [PSampleBuf+8*4+%1*22*4],eax + mov ax,[edi+2*6] + mov [PSampleBuf+9*4+%1*22*4],eax + mov ax,[edi+2*7] + mov [PSampleBuf+10*4+%1*22*4],eax + mov ax,[edi+2*8] + mov [PSampleBuf+11*4+%1*22*4],eax + mov ax,[edi+2*9] + mov [PSampleBuf+12*4+%1*22*4],eax + mov ax,[edi+2*10] + mov [PSampleBuf+13*4+%1*22*4],eax + mov ax,[edi+2*11] + mov [PSampleBuf+14*4+%1*22*4],eax + mov ax,[edi+2*12] + mov [PSampleBuf+15*4+%1*22*4],eax + mov ax,[edi+2*13] + mov [PSampleBuf+16*4+%1*22*4],eax + mov [PSampleBuf+19*4+%1*22*4],eax + mov ax,[edi+2*14] + mov [PSampleBuf+17*4+%1*22*4],eax + mov [PSampleBuf+20*4+%1*22*4],eax + mov ax,[edi+2*15] + mov [PSampleBuf+18*4+%1*22*4],eax + mov [PSampleBuf+21*4+%1*22*4],eax + +; cmp byte[VoiceNoiseEn+%1],10 +; je %%notinterpsound5 + cmp byte [InterSound],1 + jne %%notinterpsound5 + cmp byte [StereoSound],1 + je near %%NextSampleSi + jmp %%NextSamplei +%%notinterpsound5 + cmp byte [StereoSound],1 + je near %%NextSampleS + jmp %%NextSample +%%convertBRR + mov eax,[spcRam+esi] + mov ebx,[spcRam+esi+4] + mov [spcRamcmp+esi],eax + mov [spcRamcmp+esi+4],ebx + mov al,[spcRam+esi+8] + mov [spcRamcmp+esi+8],al +%%convertBRR2 + mov edi,esi + inc edi + shl edi,2 + add esi,spcRam + add edi,[spcBuffera] + mov eax,[Voice0Prev0+%1*4] + mov [Voice0BufPtr+%1*4],edi + mov dword [prev0],eax + mov eax,[Voice0Prev1+%1*4] + mov dword [prev1],eax + mov ecx,%1 + call BRRDecode + pop esi + mov edi,[Voice0BufPtr+%1*4] + + mov ax,[edi] + mov [PSampleBuf+3*4+%1*22*4],eax + mov ax,[edi+2*1] + mov [PSampleBuf+4*4+%1*22*4],eax + mov ax,[edi+2*2] + mov [PSampleBuf+5*4+%1*22*4],eax + mov ax,[edi+2*3] + mov [PSampleBuf+6*4+%1*22*4],eax + mov ax,[edi+2*4] + mov [PSampleBuf+7*4+%1*22*4],eax + mov ax,[edi+2*5] + mov [PSampleBuf+8*4+%1*22*4],eax + mov ax,[edi+2*6] + mov [PSampleBuf+9*4+%1*22*4],eax + mov ax,[edi+2*7] + mov [PSampleBuf+10*4+%1*22*4],eax + mov ax,[edi+2*8] + mov [PSampleBuf+11*4+%1*22*4],eax + mov ax,[edi+2*9] + mov [PSampleBuf+12*4+%1*22*4],eax + mov ax,[edi+2*10] + mov [PSampleBuf+13*4+%1*22*4],eax + mov ax,[edi+2*11] + mov [PSampleBuf+14*4+%1*22*4],eax + mov ax,[edi+2*12] + mov [PSampleBuf+15*4+%1*22*4],eax + mov ax,[edi+2*13] + mov [PSampleBuf+16*4+%1*22*4],eax + mov [PSampleBuf+19*4+%1*22*4],eax + mov ax,[edi+2*14] + mov [PSampleBuf+17*4+%1*22*4],eax + mov [PSampleBuf+20*4+%1*22*4],eax + mov ax,[edi+2*15] + mov [PSampleBuf+18*4+%1*22*4],eax + mov [PSampleBuf+21*4+%1*22*4],eax + + mov eax,dword [prev0] + mov [Voice0Prev0+%1*4],eax + mov eax,dword [prev1] + mov [Voice0Prev1+%1*4],eax + mov al,[loopbl] + mov [Voice0Loop+%1],al + mov al,[lastbl] + mov [Voice0End+%1],al + mov ebx,[Voice0Freq+%1*4] + add dword [Voice0Ptr+%1*4],9 +; cmp byte[VoiceNoiseEn+%1],10 +; je %%notinterpsound6 + cmp byte [InterSound],1 + jne %%notinterpsound6 + cmp byte [StereoSound],1 + je near %%NextSampleSi + jmp %%NextSamplei +%%notinterpsound6 + cmp byte [StereoSound],1 + je near %%NextSampleS + jmp %%NextSample +%%noDecode1Block +; and byte [DSPMem+5Ch],%4 +; and byte [DSPMem+4Ch],%4 +; mov byte[Voice0Looped+%1],0 + cmp byte [Voice0Loop+%1],1 + jne near %%EndSample +; mov byte[Voice0Looped+%1],1 + mov byte[SoundLooped0+%1],1 + cmp byte[CNetType],20 + je %%SkipStuff3 + or byte [DSPMem+7Ch],%3 +%%SkipStuff3 +; mov dword[Voice0Prev0+%1*4],0 +; mov dword[Voice0Prev1+%1*4],0 + +; push eax +; push edx +; push ebx +; mov edx,[DSPMem+04h+%1*10h] +; and edx,0ffh +; shl edx,2 +; xor eax,eax +; mov ah,[DSPMem+5Dh] +; add ax,dx +; xor ebx,ebx +; mov bx,[spcRam+eax] +; mov dword[Voice0Ptr+%1*4],ebx +; xor ebx,ebx +; mov bx,[spcRam+eax+2] +; mov dword[Voice0LoopPtr+%1*4],ebx +; pop ebx +; pop edx +; pop eax + + mov eax,[Voice0LoopPtr+%1*4] + mov [Voice0Ptr+%1*4],eax +; mov eax,[Voice0Prev0+%1*4] +; mov [Voice0Prev1+%1*4],eax + jmp %%Decode1Block +%%EndSample + cmp byte[CNetType],20 + je %%SkipStuff4 + or byte [DSPMem+7Ch],%3 + mov byte [DSPMem+08h+%1*10h],0 +%%SkipStuff4 +; and byte [DSPMem+5Ch],%4 + mov dword[Voice0EnvInc+%1*4],0 + mov dword[Voice0IncNumber+%1*4],0 + mov byte [Voice0Status+%1],0 +; mov byte [DSPMem+09h+%1*10h],0h + jmp %2 +%%ProcessVoice1 + jmp %2 +%endmacro + +%macro ProcessVoiceHandler16 4 + cmp byte [Voice0Disable+%1],1 + jne near %2 + cmp byte [Voice0Status+%1],1 + jne near %2 + cmp byte[PitchModEn],0 +; je .nopitchmod + mov eax,%1 + dec al + cmp al,0FFh + je .nopitchmod +; cmp byte[DSPMem+%1*10h-10h+8h],40h +; jae .noch6dis +; jmp .nopitchmod +; cmp al,6 +; je .nopitchmod +;.noch6dis + cmp byte [Voice0Disable+eax],1 + jne .nopitchmod + cmp byte [Voice0Status+eax],1 + jne .nopitchmod + + test byte [DSPMem+2Dh],%3 + jnz near .pitchmod +.nopitchmod + test byte [DSPMem+3Dh],%3 + jnz .NoEcho + cmp byte[echoon0+%1],1 + je near .echostuff +.NoEcho + ProcessVoiceStuff %1, %2, %3, %4, NonEchoMono, NonEchoStereo, NonEchoMonoInterpolated, NonEchoStereoInterpolated + ; Process Echo +.echostuff + ProcessVoiceStuff %1, %2, %3, %4, EchoMono, EchoStereo, EchoMonoInterpolated, EchoStereoInterpolated +.pitchmod + mov al,[DSPMem+4+%1*10h] + cmp al,[DSPMem+4+%1*10h-10h] + je near .nopitchmod + test byte [DSPMem+3Dh],%3 + jnz .NoEchopm + cmp byte[echoon0+%1],1 + je near .echopm +.NoEchopm + ProcessVoiceStuff %1, %2, %3, %4, NonEchoMonoPM, NonEchoStereoPM, NonEchoMonoPM, NonEchoStereoPM +.echopm + ProcessVoiceStuff %1, %2, %3, %4, EchoMonoPM, EchoStereoPM, EchoMonoPM, EchoStereoPM +%endmacro + +%macro FiltTapProc 1 + sub edx,2 + mov eax,dword[FIRTAPVal0+%1*4] + and edx,0Fh + mov ebx,[FiltLoop+edx*4] + imul eax,ebx + sar eax,7 + add ecx,eax +%endmacro + +%macro FiltTapProcR 1 + sub edx,2 + mov eax,dword[FIRTAPVal0+%1*4] + and edx,0Fh + mov ebx,[FiltLoopR+edx*4] + imul eax,ebx + sar eax,7 + add ecx,eax +%endmacro + +%macro MixEcho 0 + mov al,[EchoVL] + mov bl,[EchoVR] + cmp bl,al + ja .novol + mov bl,al +.novol + mov [EchoT],bl + + ; Copy echobuf to DSPBuffer, EchoBuffer to echobuf + cmp byte[StereoSound],1 + je near .Stereo + mov esi,[CEchoPtr] + xor edi,edi +.next + ; Get current echo buffer + mov ebx,[echobuf+esi*4] + ; Process FIR Filter + mov edx,[CurFiltPtr] + mov eax,ebx + mov [FiltLoop+edx*4],ebx + mov ecx,[FIRTAPVal0] + imul eax,ecx + sar eax,7 + mov ecx,eax + FiltTapProc 1 + FiltTapProc 2 + FiltTapProc 3 + FiltTapProc 4 + FiltTapProc 5 + FiltTapProc 6 + FiltTapProc 7 + inc dword[CurFiltPtr] + and byte[CurFiltPtr],0Fh + ; Set feedback on previous echo + mov eax,[EchoFB] + imul eax,ecx + sar eax,7 + ; Add in new echo/Store into Echo Buffer + mov ecx,eax + xor ebx,ebx + add [DSPBuffer+edi*4],ecx + mov eax,[EchoBuffer+edi*4] + mov bl,[EchoT] + mul ebx + sar eax,7 + add eax,ecx + mov [echobuf+esi*4],eax + inc esi + cmp esi,[MaxEcho] + jb .nexte + xor esi,esi +.nexte + inc edi + cmp edi,[BufferSizeB] + jne near .next + mov [CEchoPtr],esi + jmp .Mono + +.Stereo + mov esi,[CEchoPtr] + xor edi,edi +.nexts + ; Get current echo buffer + mov ebx,[echobuf+esi*4] + ; Process FIR Filter + mov edx,[CurFiltPtr] + mov eax,ebx + mov [FiltLoop+edx*4],ebx + mov ecx,[FIRTAPVal0] + imul eax,ecx + sar eax,7 + mov ecx,eax + FiltTapProc 1 + FiltTapProc 2 + FiltTapProc 3 + FiltTapProc 4 + FiltTapProc 5 + FiltTapProc 6 + FiltTapProc 7 + add [DSPBuffer+edi*4],ecx + ; Set feedback on previous echo + mov eax,[EchoFB] + imul eax,ecx + sar eax,7 + + ; Add in new echo/Store into Echo Buffer + + mov ecx,eax + xor ebx,ebx + mov eax,[EchoBuffer+edi*4] + mov bl,[EchoVL] + mul ebx + sar eax,7 + add eax,ecx + + mov [echobuf+esi*4],eax + inc esi + inc edi + + ; Get current echo buffer + mov ebx,[echobuf+esi*4] + ; Process FIR Filter + mov edx,[CurFiltPtr] + mov eax,ebx + mov [FiltLoopR+edx*4],ebx + mov ecx,[FIRTAPVal0] + imul eax,ecx + sar eax,7 + mov ecx,eax + FiltTapProcR 1 + FiltTapProcR 2 + FiltTapProcR 3 + FiltTapProcR 4 + FiltTapProcR 5 + FiltTapProcR 6 + FiltTapProcR 7 + add [DSPBuffer+edi*4],ecx + inc dword[CurFiltPtr] + and byte[CurFiltPtr],0Fh + ; Set feedback on previous echo + mov eax,[EchoFB] + imul eax,ecx + sar eax,7 + ; Add in new echo/Store into Echo Buffer + mov ecx,eax + xor ebx,ebx + mov eax,[EchoBuffer+edi*4] + mov bl,[EchoVR] + mul ebx + sar eax,7 + add eax,ecx + mov [echobuf+esi*4],eax + + mov eax,[MaxEcho] + inc esi + add eax,eax + cmp esi,eax + jb .nextes + xor esi,esi +.nextes + inc edi + cmp edi,[BufferSizeB] + jne near .nexts + mov [CEchoPtr],esi +.Mono +%endmacro + +%macro MixEcho2 0 + mov al,[EchoVL] + mov bl,[EchoVR] + cmp bl,al + ja %%novol + mov bl,al +%%novol + mov [EchoT],bl + + ; Copy echobuf to DSPBuffer, EchoBuffer to echobuf + cmp byte[StereoSound],1 + je near %%Stereo + mov esi,[CEchoPtr] + xor edi,edi +%%next + ; Get current echo buffer + mov ebx,[echobuf+esi*4] + mov eax,[EchoFB] + add [DSPBuffer+edi*4],ebx + imul eax,ebx + sar eax,7 + ; Add in new echo/Store into Echo Buffer + mov ecx,eax + xor ebx,ebx + mov eax,[EchoBuffer+edi*4] + mov bl,[EchoT] + mul ebx + sar eax,7 + add eax,ecx + mov [echobuf+esi*4],eax + inc esi + cmp esi,[MaxEcho] + jae %%echowrap +%%nexte + inc edi + cmp edi,[BufferSizeB] + jne %%next + mov [CEchoPtr],esi + jmp %%Mono +%%echowrap + xor esi,esi + jmp %%nexte + +%%Stereo + mov esi,[CEchoPtr] + xor edi,edi +%%nexts + ; Get current echo buffer + mov ecx,[echobuf+esi*4] + mov eax,[EchoFB] + add [DSPBuffer+edi*4],ecx + imul eax,ecx + sar eax,7 + ; Add in new echo/Store into Echo Buffer + mov ecx,eax + xor ebx,ebx + mov eax,[EchoBuffer+edi*4] + mov bl,[EchoVL] + mul ebx + sar eax,7 + add eax,ecx + mov [echobuf+esi*4],eax + inc esi + inc edi + + ; Get current echo buffer + mov ecx,[echobuf+esi*4] + mov eax,[EchoFB] + add [DSPBuffer+edi*4],ecx + imul eax,ecx + sar eax,7 + ; Add in new echo/Store into Echo Buffer + mov ecx,eax + xor ebx,ebx + mov eax,[EchoBuffer+edi*4] + mov bl,[EchoVR] + mul ebx + sar eax,7 + add eax,ecx + mov [echobuf+esi*4],eax + + mov eax,[MaxEcho] + inc esi + add eax,eax + cmp esi,eax + jae %%echowrap2 +%%nextes + inc edi + cmp edi,[BufferSizeB] + jne near %%nexts + mov [CEchoPtr],esi + jmp %%Mono +%%echowrap2 + xor esi,esi + jmp %%nextes +%%Mono +%endmacro + +NEWSYM SBHandler + cli + push ds + push eax + + +NEWSYM handlersbseg + mov ax,[cs:dssel] + mov ds,ax + + cmp byte[SBHDMA],0 + jne near SBHandler16 + push ebx + push ecx + push edx + push edi + push esi + push es + + call GetCDMAPos + + cmp byte[csounddisable],1 + je near stopsbsound + test byte[DSPMem+6Ch],11000000b + jnz near stopsbsound + + ; Process the sound :I + + mov es,[sbselec] + cmp byte[SBswitch],0 + jne .2ndblock + mov edi,[sbpmofs] + jmp .startblockcopy +.2ndblock + ; copy to 2nd block + ; clear memory + mov edi,[sbpmofs] + add edi,[BufferSizeB] +.startblockcopy + + mov esi,DSPBuffer + mov ecx,[BufferSizeB] + cmp byte[Surround],0 + je .nosurround + cmp byte[StereoSound],0 + jne near .surroundstereo +; jmp .surroundmono +.nosurround +.loopb + mov eax,[esi] + cmp eax,-32768 + jge .noneg3 + mov eax,-32768 +.noneg3 + cmp eax,32767 + jle .noneg4 + mov eax,32767 +.noneg4 + xor ah,80h + mov [es:edi],ah + add esi,4 + inc edi + dec ecx + jnz .loopb + jmp .sbend +.surroundstereo + shr ecx,1 +.loopbs + mov eax,[esi] + cmp eax,-32768 + jge .noneg3s + mov eax,-32768 +.noneg3s + cmp eax,32767 + jle .noneg4s + mov eax,32767 +.noneg4s + xor ah,80h + mov [es:edi],ah + mov eax,[esi+4] + cmp eax,-32768 + jge .noneg3s2 + mov eax,-32768 +.noneg3s2 + cmp eax,32767 + jle .noneg4s2 + mov eax,32767 +.noneg4s2 + neg ah + xor ah,80h + mov [es:edi+1],ah + add esi,8 + add edi,2 + dec ecx + jnz .loopbs + jmp .sbend +.surroundmono + cmp byte[SBswitch],0 + je .1stblock + add edi,[BufferSizeB] +.1stblock +.loopbm + mov eax,[esi] + cmp eax,-32768 + jge .noneg3m + mov eax,-32768 +.noneg3m + cmp eax,32767 + jle .noneg4m + mov eax,32767 +.noneg4m + xor ah,80h + mov [es:edi],ah + xor ah,80h + neg ah + xor ah,80h + mov [es:edi+1],ah + add esi,4 + add edi,2 + dec ecx + jnz .loopbm +.sbend + xor byte [SBswitch],1 + + ; move the good data at spcRam+0f3h + xor eax,eax + mov al,[spcRam+0F2h] + mov bl,[DSPMem+eax] + mov [spcRam+0F3h],bl + ; acknowledge SB for IRQing + mov dx,[SBPort] + add dl,0Eh + in al,dx + mov al,20h + out 20h,al + cmp byte[SBIrq],7 + jbe .nohighirq + mov al,20h + out 0A0h,al +.nohighirq + sti + jmp Startprocsbdata + +echowrittento db 0 + +NEWSYM stopsbsound +; mov byte[Voice0Status],0 +; mov byte[Voice1Status],0 +; mov byte[Voice2Status],0 +; mov byte[Voice3Status],0 +; mov byte[Voice4Status],0 +; mov byte[Voice5Status],0 +; mov byte[Voice6Status],0 +; mov byte[Voice7Status],0 + + mov ax,ds + mov es,ax + mov edi,DSPBuffer + mov ecx,[BufferSizeB] + xor eax,eax + rep stosd + + cmp byte[SBswitch],0 + jne near .2ndblock + + ; clear block + mov es,[sbselec] + mov edi,[sbpmofs] + mov ecx,[BufferSizeB] + shr ecx,2 +.loopa + mov dword[es:edi],80808080h + add edi,4 + dec ecx + jnz .loopa + jmp .sbend +.2ndblock + ; copy to 2nd block + ; clear memory + mov es,[sbselec] + mov edi,[sbpmofs] + add edi,[BufferSizeB] + mov ecx,[BufferSizeB] + shr ecx,2 +.loopb + mov dword[es:edi],80808080h + add edi,4 + dec ecx + jnz .loopb +.sbend + xor byte [SBswitch],1 + + ; acknowledge SB for IRQing + mov dx,[SBPort] + add dl,0Eh + in al,dx + mov al,20h + out 20h,al + cmp byte[SBIrq],7 + jbe .nohighirq + mov al,20h + out 0A0h,al +.nohighirq + + pop es + pop esi + pop edi + pop edx + pop ecx + pop ebx + pop eax + pop ds + sti + iretd + +NEWSYM sbhandexec, dd 0 + +; Process 20 blocks * 8 voices (no pitch yet) +NEWSYM SBHandler16 + push ebx + push ecx + push edx + push edi + push esi + push es + inc dword[sbhandexec] + + call GetCDMAPos + + cmp byte[csounddisable],1 + je near stopsbsound16 + test byte[DSPMem+6Ch],11000000b + jnz near stopsbsound16 + + mov es,[sbselec] + + cmp byte[SBswitch],0 + jne near .2ndblock + mov edi,[sbpmofs] + jmp .doneblock +.2ndblock + ; copy to 2nd block + ; clear memory + mov edi,[sbpmofs] + add edi,[BufferSizeW] +.doneblock + mov esi,DSPBuffer + mov ecx,[BufferSizeB] + cmp byte[Surround],0 + je .nosurround + cmp byte[StereoSound],0 + jne near .surroundstereo +; jmp .surroundmono +.nosurround +.loopb + mov eax,[esi] + cmp eax,-32768 + jge .noneg5 + mov eax,-32768 +.noneg5 + cmp eax,32767 + jle .noneg6 + mov eax,32767 +.noneg6 + mov [es:edi],ax + add esi,4 + add edi,2 + dec ecx + jnz .loopb + jmp .sbend +.surroundstereo + shr ecx,1 +.loopbs + mov eax,[esi] + cmp eax,-32768 + jge .noneg5s + mov eax,-32768 +.noneg5s + cmp eax,32767 + jle .noneg6s + mov eax,32767 +.noneg6s + mov [es:edi],ax + mov eax,[esi+4] + cmp eax,-32768 + jge .noneg5s2 + mov eax,-32768 +.noneg5s2 + cmp eax,32767 + jle .noneg6s2 + mov eax,32767 +.noneg6s2 + neg ax + mov [es:edi+2],ax + add esi,8 + add edi,4 + dec ecx + jnz .loopbs + jmp .sbend +.surroundmono + cmp byte[SBswitch],0 + je .1stblock + add edi,[BufferSizeW] +.1stblock +.loopbm + mov eax,[esi] + cmp eax,-32768 + jge .noneg5m + mov eax,-32768 +.noneg5m + cmp eax,32767 + jle .noneg6m + mov eax,32767 +.noneg6m + mov [es:edi],ax + neg ax + mov [es:edi+2],ax + add esi,4 + add edi,4 + dec ecx + jnz .loopbm +.sbend + xor byte [SBswitch],1 + + ; acknowledge SB for IRQing + mov dx,[SBPort] + add dl,0Fh + in al,dx + mov al,20h + out 20h,al + cmp byte[SBIrq],7 + jbe .nohighirq + mov al,20h + out 0A0h,al +.nohighirq + sti + + +Startprocsbdata: + call ProcessSoundBuffer + + pop es + pop esi + pop edi + pop edx + pop ecx + pop ebx + pop eax + pop ds + iretd + +NEWSYM ProcessSoundBuffer + ; Clear the DSP Buffer + mov edi,DSPBuffer + mov ax,ds + mov es,ax + xor eax,eax + mov ecx,[BufferSizeB] + rep stosd + + ; Clear Echo Buffer + cmp byte[cfgecho],1 + je .nowriteecho + test byte[DSPMem+6Ch],20h + jnz .nowriteecho + mov edi,EchoBuffer + mov ecx,[BufferSizeB] + rep stosd +.nowriteecho + + ; Process the sound :I + + ProcessVoiceHandler16 0,ProcessVoice116,1,254 +NEWSYM ProcessVoice116 + ProcessVoiceHandler16 1,ProcessVoice216,2,253 +NEWSYM ProcessVoice216 + ProcessVoiceHandler16 2,ProcessVoice316,4,251 +NEWSYM ProcessVoice316 + ProcessVoiceHandler16 3,ProcessVoice416,8,247 +NEWSYM ProcessVoice416 + ProcessVoiceHandler16 4,ProcessVoice516,16,239 +NEWSYM ProcessVoice516 + ProcessVoiceHandler16 5,ProcessVoice616,32,223 +NEWSYM ProcessVoice616 + ProcessVoiceHandler16 6,ProcessVoice716,64,191 +NEWSYM ProcessVoice716 + ProcessVoiceHandler16 7,ProcessVoice816,128,127 +NEWSYM ProcessVoice816 + + cmp byte[cfgecho],1 + je near .echowritten + test byte[DSPMem+6Ch],20h + jnz near .nowriteecho2 + mov byte[echowrittento],1 + ; Mix Echo with DSP Buffer + cmp dword[FIRTAPVal0],7Fh + jne near .echonotokay + cmp dword[FIRTAPVal1],0 + jne near .echonotokay + cmp dword[FIRTAPVal2],0 + jne near .echonotokay + cmp dword[FIRTAPVal3],0 + jne near .echonotokay + cmp dword[FIRTAPVal4],0 + jne near .echonotokay + cmp dword[FIRTAPVal5],0 + jne near .echonotokay + cmp dword[FIRTAPVal6],0 + jne near .echonotokay + cmp dword[FIRTAPVal7],0 + jne near .echonotokay + MixEcho2 + jmp .echowritten +.echonotokay + MixEcho + jmp .echowritten +.nowriteecho2 + cmp byte[echowrittento],0 + je .echowritten + mov edi,echobuf + mov ecx,[MaxEcho] + cmp byte[StereoSound],1 + jne .noechostereo + add ecx,ecx +.noechostereo + xor eax,eax + rep stosd + mov byte[echowrittento],0 +.echowritten + cmp byte[CNetType],20 + je .clearendx + cmp byte[MovieProcessing],0 + je .skipendxclear +.clearendx + mov byte[DSPMem+7Ch],0 +.skipendxclear + + cmp byte[RevStereo],0 + je .norevstereo + mov edi,DSPBuffer + mov ax,ds + mov es,ax + xor eax,eax + mov ecx,[BufferSizeB] + shr ecx,1 +.revstloop + mov eax,[edi] + mov ebx,[edi+4] + mov [edi],ebx + mov [edi+4],eax + add edi,8 + loop .revstloop +.norevstereo + + cmp byte[LowPassFilter],0 + je near LPFexit + mov esi,DSPBuffer + cmp byte[StereoSound],1 + jz near LPFstereo + mov ecx, [BufferSizeB] + shr ecx,1 + mov ebx,[LPFsample1] +NEWSYM LPFmonoloop + mov eax,[esi] + sar eax,1 + add ebx,eax + mov [esi],ebx + add esi,4 + mov ebx,[esi] + sar ebx,1 + add eax,ebx + mov [esi],eax + add esi,4 + dec ecx + jnz near LPFmonoloop + mov [LPFsample1],ebx + jmp LPFexit + +NEWSYM LPFstereo + mov ecx, [BufferSizeB] + shr ecx,2 +; mov ecx, <------------------- # of samples to mix / 4 + mov ebx,[LPFsample1] + mov edx,[LPFsample2] +NEWSYM LPFstereoloop + push ecx + mov eax,[esi] + sar eax,1 + add ebx,eax + mov [esi],ebx + mov ecx,[esi+4] + sar ecx,1 + add edx,ecx + mov [esi+4],edx + add esi,8 + mov ebx,[esi] + sar ebx,1 + add eax,ebx + mov [esi],eax + mov edx,[esi+4] + sar edx,1 + add ecx,edx + mov [esi+4],ecx + add esi,8 + pop ecx + dec ecx + jnz near LPFstereoloop + mov [LPFsample1],ebx + mov [LPFsample2],edx +NEWSYM LPFexit + ret + +NEWSYM stopsbsound16 +; mov byte[Voice0Status],0 +; mov byte[Voice1Status],0 +; mov byte[Voice2Status],0 +; mov byte[Voice3Status],0 +; mov byte[Voice4Status],0 +; mov byte[Voice5Status],0 +; mov byte[Voice6Status],0 +; mov byte[Voice7Status],0 + + mov ax,ds + mov es,ax + mov edi,DSPBuffer + mov ecx,[BufferSizeB] + xor eax,eax + rep stosd + + cmp byte[SBswitch],0 + jne near .2ndblock + + ; clear block + mov es,[sbselec] + mov edi,[sbpmofs] + mov ecx,[BufferSizeB] + shr ecx,1 +.loopa + mov dword[es:edi],00000000h + add edi,4 + dec ecx + jnz .loopa + jmp .sbend +.2ndblock + ; copy to 2nd block + ; clear memory + mov es,[sbselec] + mov edi,[sbpmofs] + add edi,[BufferSizeW] + mov ecx,[BufferSizeB] + shr ecx,1 +.loopb + mov dword[es:edi],00000000h + add edi,4 + dec ecx + jnz .loopb +.sbend + xor byte [SBswitch],1 + + ; acknowledge SB for IRQing + mov dx,[SBPort] + add dl,0Fh + in al,dx + mov al,20h + out 20h,al + cmp byte[SBIrq],7 + jbe .nohighirq + mov al,20h + out 0A0h,al +.nohighirq + + pop es + pop esi + pop edi + pop edx + pop ecx + pop ebx + pop eax + pop ds + sti + iretd + +;**************************************************** +; Sound Blaster Initialization Stuff +;**************************************************** + +NEWSYM memoryloc, dd 0 ; Memory offset in conventional memory +NEWSYM memoryloc2, dd 0 ; Memory offset in conventional memory +NEWSYM sbselec, dw 0 ; Selector of Memory location +NEWSYM sbpmofs, dd 0 ; offset of Memory location +SBDeinitType db 0 + +NEWSYM initSB + mov eax,[SoundQuality] + cmp byte[StereoSound],1 + jne .nostereobuf + mov ax,[BufferSizes+eax*2] + jmp .skipstereobuf +.nostereobuf + mov ax,[BufferSize+eax*2] +.skipstereobuf + + mov [BufferSizeB],ax + add ax,ax + mov [BufferSizeW],ax + + mov byte [SBswitch],0 + ; Allocate pointer + ; Set up SB + call ResetSBDSP + + cmp byte [SBHDMA],0 + je .no16bit + cmp byte [SBHDMA],4 + jb near .init16bitlowhdma + jmp .init16bit +.no16bit + + ; Determine Version # + mov al,0E1h + call WriteDSP + call ReadDSP + mov [.Versionnum],al + call ReadDSP + mov [.Versionnum+1],al + + ; Turn on speakers + mov al,0D1h + call WriteDSP + + ; Set Time-Constant Data ( = 256 - (1000000/sampling rate) ) + ; 8000=131, 22050=210, 44100=233, 11025=165 + mov al,40h + call WriteDSP + + cmp byte[Surround],0 +; jne .surround8b + cmp byte[StereoSound],1 + jne .nostereo8b +.surround8b + mov eax,[SoundQuality] + cmp eax,2 + jbe .okay + mov eax,2 +.okay + mov al,byte [SoundSpeedt+eax] + call WriteDSP + ; Set Stereo + mov dx, [SBPort] + add dx, 04h + mov al,0Eh + out dx,al + inc dx + in al,dx + or al,022h + out dx,al + jmp .donestereo +.nostereo8b + mov eax,[SoundQuality] + mov al,byte [SoundSpeeds+eax] + call WriteDSP +.donestereo + + cmp byte[StereoSound],1 + je .highmode + mov eax,[SoundQuality] + cmp byte [SoundSpeeds+eax],211 + ja .highmode + mov byte[.Versionnum],1 +.highmode + ; Setup DMA + ; Select DMA channel + mov al,[SBDMA] + add al,4 + mov dx,000Ah + out dx,al + ; Clear DMA + mov al,00h + mov dx,000Ch + out dx,al + ; Set autoinit/write (set as DAC) + mov al,58h + add al,[SBDMA] + mov dx,000Bh + out dx,al + ; Send Offset Address + mov al,[memoryloc] + mov dl,[SBDMA] + shl dl,1 + out dx,al + mov al,[memoryloc+1] + out dx,al + ; Send length of entire block + mov ax,[BufferSizeW] + dec ax + inc dx + out dx,al + mov al,ah + out dx,al + ; Send page # (address/65536) + mov al,[memoryloc+2] + mov dl,[SBDMAPage] + out dx,al + ; turn on DMA + mov al,[SBDMA] + mov dx,000Ah + out dx,al + + ; Prepare SB for the first block + ; 8-bit auto-init, mono, unsigned + mov al,048h ; Sb 2.0 version... + call WriteDSP + + ; Send Length-1 to DSP port + mov ax,[BufferSizeB] + dec ax + call WriteDSP + mov al,ah + call WriteDSP + mov byte[SBDeinitType],1 + mov al,090h ; Sb 2.0 version... + cmp byte[.Versionnum],2 + jne .noversion2 + cmp byte[.Versionnum+1],0 + je .slowspeed +.noversion2 + cmp byte[.Versionnum],1 + ja .notversion1 +.slowspeed + mov byte[SBDeinitType],0 + mov al,1Ch +.notversion1 + call WriteDSP + jmp .fixsurround + +.Versionnum dw 0 + +.init16bitlowhdma + ; Set Time-Constant Data ( = 256 - (1000000/sampling rate) ) + ; 8000=131, 22050=210, 44100=233, 11025=165 + mov al,40h + call WriteDSP + + push ecx + mov ecx,[SoundQuality] + mov al,byte [SoundSpeeds+ecx] + pop ecx + call WriteDSP + + mov edx,[memoryloc] + shr edx,1 + mov [memoryloc2],edx + + ; Setup DMA + + ; turn off DMA +; mov al,[SBHDMA] +; and al,03h +; or al,04h +; mov dx,00D4h +; out dx,al + + ; Setup DMA + ; Select DMA channel + mov al,[SBHDMA] + and al,03h + or al,04h + mov dx,000Ah + out dx,al + + ; clear flip-flop + mov dx,00D8h + xor al,al + out dx,al + + ; Set autoinit/write (set as DAC) + mov al,[SBHDMA] + and al,3 + add al,58h + mov dx,00D6h + out dx,al + + ; Send Offset Address +; mov al,[memoryloc2] +; mov dl,[SBHDMA] +; and dl,3 +; shl dl,2 +; add dl,0C0h +; out dx,al +; mov al,[memoryloc2+1] +; out dx,al + + ; Send Offset Address + mov al,[memoryloc] + mov dl,[SBDMA] + shl dl,1 + out dx,al + mov al,[memoryloc+1] + out dx,al + + ; Send length of entire block + mov ax,[BufferSizeW] + dec ax + add dx,2 + out dx,al + mov al,ah + out dx,al + + ; Send page # (address/65536) + mov al,[memoryloc+2] + mov dl,[SBHDMAPage] + out dx,al + + ; Prepare SB for the first block + ; 16-bit auto-init, mono, unsigned + mov al,0B6h ; Sb 16 version (DSP 4) + call WriteDSP +; cmp byte[Surround],0 +; jne .surroundl + cmp byte[StereoSound],1 + jne .Monol +.surroundl + mov al,30h ; stereo/signed + call WriteDSP + jmp .AfterStereol +.Monol + mov al,10h ; mono/signed + call WriteDSP +.AfterStereol + + ; Send Length-1 to DSP port + mov ax,[BufferSizeB] + dec ax + call WriteDSP + mov al,ah + call WriteDSP + + ; turn on DMA +; mov al,[SBHDMA] +; and al,03h +; mov dx,00D4h +; out dx,al + + ; Setup DMA + ; Select DMA channel + mov al,[SBHDMA] + and al,03h + mov dx,000Ah + out dx,al + + ; Turn on speakers + mov al,0D1h + call WriteDSP + jmp .fixsurround + +.init16bit + ; Set Time-Constant Data ( = 256 - (1000000/sampling rate) ) + ; 8000=131, 22050=210, 44100=233, 11025=165 + mov al,41h + call WriteDSP + push ecx + mov ecx,[SoundQuality] + mov al,byte [SBToSPCSpeeds2+ecx*4+1] + pop ecx + call WriteDSP + push ecx + mov ecx,[SoundQuality] + mov al,byte [SBToSPCSpeeds2+ecx*4] + pop ecx + call WriteDSP + + mov edx,[memoryloc] + shr edx,1 + mov [memoryloc2],edx + + ; Setup DMA + + ; turn off DMA + mov al,[SBHDMA] + and al,03h + or al,04h + mov dx,00D4h + out dx,al + + ; clear flip-flop + mov dx,00D8h + xor al,al + out dx,al + + ; Set autoinit/write (set as DAC) + mov al,[SBHDMA] + and al,3 + add al,58h + mov dx,00D6h + out dx,al + + ; Send Offset Address + mov al,[memoryloc2] + mov dl,[SBHDMA] + and dl,3 + shl dl,2 + add dl,0C0h + out dx,al + mov al,[memoryloc2+1] + out dx,al + + ; Send length of entire block + mov ax,[BufferSizeW] + dec ax + add dx,2 + out dx,al + mov al,ah + out dx,al + + ; Send page # (address/65536) + mov al,[memoryloc+2] + mov dl,[SBHDMAPage] + out dx,al + + ; Prepare SB for the first block + ; 16-bit auto-init, mono, unsigned + mov al,0B6h ; Sb 16 version (DSP 4) + call WriteDSP +; cmp byte[Surround],0 +; jne .surround + cmp byte[StereoSound],1 + jne .Mono +.surround + mov al,30h ; stereo/signed + call WriteDSP + jmp .AfterStereo +.Mono + mov al,10h ; mono/signed + call WriteDSP +.AfterStereo + + ; Send Length-1 to DSP port + mov ax,[BufferSizeB] + dec ax + call WriteDSP + mov al,ah + call WriteDSP + + ; turn on DMA + mov al,[SBHDMA] + and al,03h + mov dx,00D4h + out dx,al + + ; Turn on speakers + mov al,0D1h + call WriteDSP + +.fixsurround + + ; Adjust byte lengths for mono surround sound + cmp byte[Surround],0 + je .nosurroundadj + cmp byte[StereoSound],0 + jne .nosurroundadj +; shr word[BufferSizeB],1 +; shr word[BufferSizeW],1 +.nosurroundadj + ret + + +GetCDMAPos: + ; clear flipflop + xor ebx,ebx + mov bl,[SBDMA] + cmp byte[SBHDMA],4 + jb .nohdma + mov bl,[SBHDMA] + mov dx,0Ch +.nohdma + mov dx,0D8h + xor al,al + out dx,al + nop + nop + nop + nop + mov dx,[.wordcountport+ebx*2] + + in al,dx + nop + nop + mov bl,al + in al,dx + nop + nop + nop + nop + mov bh,al + cmp byte[SBHDMA],4 + jb .ldma2 + add bx,bx +.ldma2 + ; value returned = bx, # of bytes left for transfer + mov cx,[BufferSizeB] + mov dx,cx + add cx,cx + cmp byte[SBHDMA],4 + jb .ldmab + add cx,cx + add dx,dx +.ldmab + sub cx,bx + mov byte[SBswitch],1 + cmp cx,dx + jb .parta + mov byte[SBswitch],0 +.parta + ret +.wordcountport dw 1,3,5,7,0C2h,0C6h,0CAh,0CEh + +; old routines, doesn't work w/ sb live! + jmp .fin + +.loop + in al,dx + nop + nop + mov cl,al + in al,dx + nop + nop + nop + nop + mov ch,al + in al,dx + nop + nop + mov bl,al + in al,dx + mov bh,al + sub cx,bx + test cx,8000h + jz .notneg + neg cx +.notneg + cmp byte[SBHDMA],4 + jb .ldma + add cx,cx + add bx,bx +.ldma + cmp cx,4 + ja .loop + +.fin + \ No newline at end of file diff --git a/zsnes/src/cpu/e65816.inc b/zsnes/src/cpu/e65816.inc new file mode 100644 index 00000000..1348ff24 --- /dev/null +++ b/zsnes/src/cpu/e65816.inc @@ -0,0 +1,1995 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM brkv,brkv8,changeexecloop,copv,copv8,curexecstate,curnmi,execloop +EXTSYM initaddrl,membank0r16,membank0r8 +EXTSYM membank0w16,membank0w8,memtabler16,memtabler8,memtablew16,memtablew8 +EXTSYM nmistatus,regaccessbankr8,snesmap2,snesmmap,stackand,stackor,tablead +EXTSYM wramdata,xa,xd,xdb,xe,xirqb,xpb,xpc,xs,xx,xy +EXTSYM switchtovirq,intrset,UpdateDPage +EXTSYM switchtovirqret +EXTSYM debstop3 + + + + + + +; B = ( or ) +; C = , +; L = [ or ] +; I = # + + +COp61m8nd: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bnd +COp61m16nd: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bnd +COp61m8d: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bd +COp61m16d: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bd +COp63m8nd: ; ADC d,s + addr_dCs_8br + ADCMacro8bnd +COp63m16nd: ; ADC d,s + addr_dCs_16br + ADCMacro16bnd +COp63m8d: ; ADC d,s + addr_dCs_8br + ADCMacro8bd +COp63m16d: ; ADC d,s + addr_dCs_16br + ADCMacro16bd +COp65m8nd: ; ADC d + addr_d_8br + ADCMacro8bnd +COp65m16nd: ; ADC d + addr_d_16br + ADCMacro16bnd +COp65m8d: ; ADC d + addr_d_8br + ADCMacro8bd +COp65m16d: ; ADC d + addr_d_16br + ADCMacro16bd +COp67m8nd: ; ADC [d] + addr_LdL_8br + ADCMacro8bnd +COp67m16nd: ; ADC [d] + addr_LdL_16br + ADCMacro16bnd +COp67m8d: ; ADC [d] + addr_LdL_8br + ADCMacro8bd +COp67m16d: ; ADC [d] + addr_LdL_16br + ADCMacro16bd +COp69m8nd: ; ADC # + addr_I_8br + ADCMacro8bnd +COp69m16nd: ; ADC # + addr_I_16br + ADCMacro16bnd +COp69m8d: ; ADC # + addr_I_8br + ADCMacro8bd +COp69m16d: ; ADC # + addr_I_16br + ADCMacro16bd +COp6Dm8nd: ; ADC a + addr_a_8br + ADCMacro8bnd +COp6Dm16nd: ; ADC a + addr_a_16br + ADCMacro16bnd +COp6Dm8d: ; ADC a + addr_a_8br + ADCMacro8bd +COp6Dm16d: ; ADC a + addr_a_16br + ADCMacro16bd +COp6Fm8nd: ; ADC al + addr_al_8br + ADCMacro8bnd +COp6Fm16nd: ; ADC al + addr_al_16br + ADCMacro16bnd +COp6Fm8d: ; ADC al + addr_al_8br + ADCMacro8bd +COp6Fm16d: ; ADC al + addr_al_16br + ADCMacro16bd +COp71m8nd: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bnd +COp71m16nd: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bnd +COp71m8d: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bd +COp71m16d: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bd +COp72m8nd: ; ADC (d) + addr_BdB_8br + ADCMacro8bnd +COp72m16nd: ; ADC (d) + addr_BdB_16br + ADCMacro16bnd +COp72m8d: ; ADC (d) + addr_BdB_8br + ADCMacro8bd +COp72m16d: ; ADC (d) + addr_BdB_16br + ADCMacro16bd +COp73m8nd: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bnd +COp73m16nd: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bnd +COp73m8d: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bd +COp73m16d: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bd +COp75m8nd: ; ADC d,x + addr_dCx_8br + ADCMacro8bnd +COp75m16nd: ; ADC d,x + addr_dCx_16br + ADCMacro16bnd +COp75m8d: ; ADC d,x + addr_dCx_8br + ADCMacro8bd +COp75m16d: ; ADC d,x + addr_dCx_16br + ADCMacro16bd +COp77m8nd: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bnd +COp77m16nd: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bnd +COp77m8d: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bd +COp77m16d: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bd +COp79m8nd: ; ADC a,y + addr_aCy_8br + ADCMacro8bnd +COp79m16nd: ; ADC a,y + addr_aCy_16br + ADCMacro16bnd +COp79m8d: ; ADC a,y + addr_aCy_8br + ADCMacro8bd +COp79m16d: ; ADC a,y + addr_aCy_16br + ADCMacro16bd +COp7Dm8nd: ; ADC a,x + addr_aCx_8br + ADCMacro8bnd +COp7Dm16nd: ; ADC a,x + addr_aCx_16br + ADCMacro16bnd +COp7Dm8d: ; ADC a,x + addr_aCx_8br + ADCMacro8bd +COp7Dm16d: ; ADC a,x + addr_aCx_16br + ADCMacro16bd +COp7Fm8nd: ; ADC al,x + addr_alCx_8br + ADCMacro8bnd +COp7Fm16nd: ; ADC al,x + addr_alCx_16br + ADCMacro16bnd +COp7Fm8d: ; ADC al,x + addr_alCx_8br + ADCMacro8bd +COp7Fm16d: ; ADC al,x + addr_alCx_16br + ADCMacro16bd + +COp21m8: ; AND(d,x) + addr_BdCxB_8br + ANDMacro8b +COp21m16:; AND(d,x) + addr_BdCxB_16br + ANDMacro16b +COp23m8: ; AND d,s + addr_dCs_8br + ANDMacro8b +COp23m16:; AND d,s + addr_dCs_16br + ANDMacro16b +COp25m8: ; AND d + addr_d_8br + ANDMacro8b +COp25m16:; AND d + addr_d_16br + ANDMacro16b +COp27m8: ; AND [d] + addr_LdL_8br + ANDMacro8b +COp27m16:; AND [d] + addr_LdL_16br + ANDMacro16b +COp29m8: ; AND # + addr_I_8br + ANDMacro8b +COp29m16:; AND # + addr_I_16br + ANDMacro16b +COp2Dm8: ; AND a + addr_a_8br + ANDMacro8b +COp2Dm16:; AND a + addr_a_16br + ANDMacro16b +COp2Fm8: ; AND al + addr_al_8br + ANDMacro8b +COp2Fm16:; AND al + addr_al_16br + ANDMacro16b +COp31m8: ; AND(d),y + addr_BdBCy_8br + ANDMacro8b +COp31m16:; AND(d),y + addr_BdBCy_16br + ANDMacro16b +COp32m8: ; AND (d) + addr_BdB_8br + ANDMacro8b +COp32m16:; AND (d) + addr_BdB_16br + ANDMacro16b +COp33m8: ; AND(d,s),y + addr_BdCsBCy_8br + ANDMacro8b +COp33m16:; AND(d,s),y + addr_BdCsBCy_16br + ANDMacro16b +COp35m8: ; AND d,x + addr_dCx_8br + ANDMacro8b +COp35m16:; AND d,x + addr_dCx_16br + ANDMacro16b +COp37m8: ; AND [d],y + addr_LdLCy_8br + ANDMacro8b +COp37m16:; AND [d],y + addr_LdLCy_16br + ANDMacro16b +COp39m8: ; AND a,y + addr_aCy_8br + ANDMacro8b +COp39m16:; AND a,y + addr_aCy_16br + ANDMacro16b +COp3Dm8: ; AND a,x + addr_aCx_8br + ANDMacro8b +COp3Dm16:; AND a,x + addr_aCx_16br + ANDMacro16b +COp3Fm8: ; AND al,x + addr_alCx_8br + ANDMacro8b +COp3Fm16:; AND al,x + addr_alCx_16br + ANDMacro16b + +COp06m8: ; ASL d + addr_d_8brni + ASLMacro8b + addr_d_8bw + endloop +COp06m16:; ASL d + addr_d_16brni + ASLMacro16b + addr_d_16bw + endloop +COp0Am8: ; ASL A + addr_A_8brni + ASLMacro8b + addr_A_8bw + endloop +COp0Am16:; ASL A + addr_A_16brni + ASLMacro16b + addr_A_16bw + endloop +COp0Em8: ; ASL a + addr_a_8brni + ASLMacro8b + addr_a_8bw + endloop +COp0Em16:; ASL a + addr_a_16brni + ASLMacro16b + addr_a_16bw + endloop +COp16m8: ; ASL d,x + addr_dCx_8brni + ASLMacro8b + addr_dCx_8bw + endloop +COp16m16:; ASL d,x + addr_dCx_16brni + ASLMacro16b + addr_dCx_16bw + endloop +COp1Em8: ; ASL a,x + addr_aCx_8brni + ASLMacro8b + addr_aCx_8bw + endloop +COp1Em16:; ASL a,x + addr_aCx_16brni + ASLMacro16b + addr_aCx_16bw + endloop + +COp90: ; BCC r + test byte[flagc],01h + jnz .skip + JumpMacro +COpB0: ; BCS r + test byte[flagc],01h + jz .skip + JumpMacro +COpF0: ; BEQ r + test dword[flagnz],0FFFFh + jnz .skip + JumpMacro +COp30: ; BMI r + test dword[flagnz],018000h + jz .skip + JumpMacro +COpD0: ; BNE r + test dword[flagnz],0FFFFh + jz .skip + JumpMacro +COp10: ; BPL r + test dword[flagnz],018000h + jnz .skip + JumpMacro +COp80: ; BRA r + movsx eax,byte[esi] + inc esi + add esi,eax + endloop +COp50: ; BVC r + test dword[flago],0FFh + jnz .skip + JumpMacro +COp70: ; BVS r + test dword[flago],0FFh + jz .skip + JumpMacro + +; BIT instruction does not affect N and V flags when using immediate +; addressing mode. When using other addressing modes, the N and V flags + +COp89m8: ; BIT # + BITMacroim8b +COp89m16:; BIT # + BITMacroim16b + +COp24m8: ; BIT d + addr_d_8br + BITMacro8b +COp24m16:; BIT d + addr_d_16br + BITMacro16b +COp2Cm8: ; BIT a + addr_a_8br + BITMacro8b +COp2Cm16:; BIT a + addr_a_16br + BITMacro16b +COp34m8: ; BIT d,x + addr_dCx_8br + BITMacro8b +COp34m16:; BIT d,x + addr_dCx_16br + BITMacro16b +COp3Cm8: ; BIT a,x + addr_aCx_8br + BITMacro8b +COp3Cm16:; BIT a,x + addr_aCx_16br + BITMacro16b + +COp00: ; BRK s + BRKMacro + +COp82: ; BRL rl + BRLMacro + +COp18: ; CLC i + mov dword[flagc],0 + endloop +COpD8: ; CLD i + and dl,0F7h + mov bl,dl + mov edi,[tablead+ebx*4] + endloop +COp58: ; CLI i + and dl,0FBh + cmp byte[doirqnext],0 + je .noirqexec + mov byte[doirqnext],0 + call switchtovirqret +.noirqexec + endloop +COpB8: ; CLV i + mov dword[flago],0 + endloop + +COpC1m8: ; CMP(d,x) + addr_BdCxB_8br + CMPMacro8b +COpC1m16:; CMP(d,x) + addr_BdCxB_16br + CMPMacro16b +COpC3m8: ; CMP d,s + addr_dCs_8br + CMPMacro8b +COpC3m16:; CMP d,s + addr_dCs_16br + CMPMacro16b +COpC5m8: ; CMP d + addr_d_8br + CMPMacro8b +COpC5m16:; CMP d + addr_d_16br + CMPMacro16b +COpC7m8: ; CMP [d] + addr_LdL_8br + CMPMacro8b +COpC7m16:; CMP [d] + addr_LdL_16br + CMPMacro16b +COpC9m8: ; CMP # + addr_I_8br + CMPMacro8b +COpC9m16:; CMP # + addr_I_16br + CMPMacro16b +COpCDm8: ; CMP a + addr_a_8br + CMPMacro8b +COpCDm16:; CMP a + addr_a_16br + CMPMacro16b +COpCFm8: ; CMP al + addr_al_8br + CMPMacro8b +COpCFm16:; CMP al + addr_al_16br + CMPMacro16b +COpD1m8: ; CMP(d),y + addr_BdBCy_8br + CMPMacro8b +COpD1m16:; CMP(d),y + addr_BdBCy_16br + CMPMacro16b +COpD2m8: ; CMP (d) + addr_BdB_8br + CMPMacro8b +COpD2m16:; CMP (d) + addr_BdB_16br + CMPMacro16b +COpD3m8: ; CMP(d,s),y + addr_BdCsBCy_8br + CMPMacro8b +COpD3m16:; CMP(d,s),y + addr_BdCsBCy_16br + CMPMacro16b +COpD5m8: ; CMP d,x + addr_dCx_8br + CMPMacro8b +COpD5m16:; CMP d,x + addr_dCx_16br + CMPMacro16b +COpD7m8: ; CMP [d],y + addr_LdLCy_8br + CMPMacro8b +COpD7m16:; CMP [d],y + addr_LdLCy_16br + CMPMacro16b +COpD9m8: ; CMP a,y + addr_aCy_8br + CMPMacro8b +COpD9m16:; CMP a,y + addr_aCy_16br + CMPMacro16b +COpDDm8: ; CMP a,x + addr_aCx_8br + CMPMacro8b +COpDDm16:; CMP a,x + addr_aCx_16br + CMPMacro16b +COpDFm8: ; CMP al,x + addr_alCx_8br + CMPMacro8b +COpDFm16:; CMP al,x + addr_alCx_16br + CMPMacro16b + +COp02: ; COP s + COPMacro + +COpE0x8: ; CPX # + addr_I_8br + CPXMacro8b +COpE0x16:; CPX # + addr_I_16br + CPXMacro16b +COpE4x8: ; CPX d + addr_d_8br + CPXMacro8b +COpE4x16:; CPX d + addr_d_16br + CPXMacro16b +COpECx8: ; CPX a + addr_a_8br + CPXMacro8b +COpECx16:; CPX a + addr_a_16br + CPXMacro16b + +COpC0x8: ; CPY # + addr_I_8br + CPYMacro8b +COpC0x16:; CPY # + addr_I_16br + CPYMacro16b +COpC4x8: ; CPY d + addr_d_8br + CPYMacro8b +COpC4x16:; CPY d + addr_d_16br + CPYMacro16b +COpCCx8: ; CPY a + addr_a_8br + CPYMacro8b +COpCCx16:; CPY a + addr_a_16br + CPYMacro16b + +COp3Am8: ; DEC A + addr_A_8brni + dec al + flagsetnz8bnel + addr_A_8bw + endloop +COp3Am16:; DEC A + addr_A_16brni + dec ax + flagsetnz16bnel + addr_A_16bw + endloop +COpCEm8: ; DEC a + addr_a_8brni + dec al + flagsetnz8bnel + addr_a_8bw + endloop +COpCEm16:; DEC a + addr_a_16brni + dec ax + flagsetnz16bnel + addr_a_16bw + endloop +COpC6m8: ; DEC d + addr_d_8brni + dec al + flagsetnz8bnel + addr_d_8bw + endloop +COpC6m16:; DEC d + addr_d_16brni + dec ax + flagsetnz16bnel + addr_d_16bw + endloop +COpD6m8: ; DEC d,x + addr_dCx_8brni + dec al + flagsetnz8bnel + addr_dCx_8bw + endloop +COpD6m16:; DEC d,x + addr_dCx_16brni + dec ax + flagsetnz16bnel + addr_dCx_16bw + endloop +COpDEm8: ; DEC a,x + addr_aCx_8brni + dec al + flagsetnz8bnel + addr_aCx_8bw + endloop +COpDEm16:; DEC a,x + addr_aCx_16brni + dec ax + flagsetnz16bnel + addr_aCx_16bw + endloop + +COpCAx8: ; DEX i + dec byte[xx] + mov al,[xx] + flagsetnz8b + endloop +COpCAx16:; DEX i + dec word[xx] + mov ax,[xx] + flagsetnz16b + endloop +COp88x8: ; DEY i + dec byte[xy] + mov al,[xy] + flagsetnz8b + endloop +COp88x16:; DEY i + dec word[xy] + mov ax,[xy] + flagsetnz16b + endloop + +COp41m8: ; EOR(d,x) + addr_BdCxB_8br + EORMacro8b +COp41m16:; EOR(d,x) + addr_BdCxB_16br + EORMacro16b +COp43m8: ; EOR d,s + addr_dCs_8br + EORMacro8b +COp43m16:; EOR d,s + addr_dCs_16br + EORMacro16b +COp45m8: ; EOR d + addr_d_8br + EORMacro8b +COp45m16:; EOR d + addr_d_16br + EORMacro16b +COp47m8: ; EOR [d] + addr_LdL_8br + EORMacro8b +COp47m16:; EOR [d] + addr_LdL_16br + EORMacro16b +COp49m8: ; EOR # + addr_I_8br + EORMacro8b +COp49m16:; EOR # + addr_I_16br + EORMacro16b +COp4Dm8: ; EOR a + addr_a_8br + EORMacro8b +COp4Dm16:; EOR a + addr_a_16br + EORMacro16b +COp4Fm8: ; EOR al + addr_al_8br + EORMacro8b +COp4Fm16:; EOR al + addr_al_16br + EORMacro16b +COp51m8: ; EOR(d),y + addr_BdBCy_8br + EORMacro8b +COp51m16:; EOR(d),y + addr_BdBCy_16br + EORMacro16b +COp52m8: ; EOR (d) + addr_BdB_8br + EORMacro8b +COp52m16:; EOR (d) + addr_BdB_16br + EORMacro16b +COp53m8: ; EOR(d,s),y + addr_BdCsBCy_8br + EORMacro8b +COp53m16:; EOR(d,s),y + addr_BdCsBCy_16br + EORMacro16b +COp55m8: ; EOR d,x + addr_dCx_8br + EORMacro8b +COp55m16:; EOR d,x + addr_dCx_16br + EORMacro16b +COp57m8: ; EOR [d],y + addr_LdLCy_8br + EORMacro8b +COp57m16:; EOR [d],y + addr_LdLCy_16br + EORMacro16b +COp59m8: ; EOR a,y + addr_aCy_8br + EORMacro8b +COp59m16:; EOR a,y + addr_aCy_16br + EORMacro16b +COp5Dm8: ; EORa,x + addr_aCx_8br + EORMacro8b +COp5Dm16:; EORa,x + addr_aCx_16br + EORMacro16b +COp5Fm8: ; EOR al,x + addr_alCx_8br + EORMacro8b +COp5Fm16:; EOR al,x + addr_alCx_16br + EORMacro16b + + +COp1Am8: ; INC A + addr_A_8brni + inc al + flagsetnz8bnel + addr_A_8bw + endloop +COp1Am16:; INC A + addr_A_16brni + inc ax + flagsetnz16bnel + addr_A_16bw + endloop +COpEEm8: ; INC a + addr_a_8brni + inc al + flagsetnz8bnel + addr_a_8bw + endloop +COpEEm16:; INC a + addr_a_16brni + inc ax + flagsetnz16bnel + addr_a_16bw + endloop +COpE6m8: ; INC d + addr_d_8brni + inc al + flagsetnz8bnel + addr_d_8bw + endloop +COpE6m16:; INC d + addr_d_16brni + inc ax + flagsetnz16bnel + addr_d_16bw + endloop +COpF6m8: ; INC d,x + addr_dCx_8brni + inc al + flagsetnz8bnel + addr_dCx_8bw + endloop +COpF6m16:; INC d,x + addr_dCx_16brni + inc ax + flagsetnz16bnel + addr_dCx_16bw + endloop +COpFEm8: ; INC a,x + addr_aCx_8brni + inc al + flagsetnz8bnel + addr_aCx_8bw + endloop +COpFEm16:; INC a,x + addr_aCx_16brni + inc ax + flagsetnz16bnel + addr_aCx_16bw + endloop + + +COpE8x8: ; INX i + inc byte[xx] + mov al,[xx] + flagsetnz8b + endloop +COpE8x16:; INX i + inc word[xx] + mov ax,[xx] + flagsetnz16b + endloop +COpC8x8: ; INY i + inc byte[xy] + mov al,[xy] + flagsetnz8b + endloop +COpC8x16:; INY i + inc word[xy] + mov ax,[xy] + flagsetnz16b + endloop + +COpDC: ; JML (a) + JMLMacro +COp4C: ; JMP a + JMPMacro4C +COp6C: ; JMP (a) + JMPMacro6C +COp7C: ; JMP(a,x) + JMPMacro7C +COp5C: ; JMP al + JMPMacro5C + +COp22: ; JSL al + JSLMacro +COp20: ; JSR a + JSRMacro20 +COpFC: ; JSR(a,x) + JSRMacroFC + +COpA1m8: ; LDA(d,x) + addr_BdCxB_8br + LDAMacro8b +COpA1m16:; LDA(d,x) + addr_BdCxB_16br + LDAMacro16b +COpA3m8: ; LDA d,s + addr_dCs_8br + LDAMacro8b +COpA3m16:; LDA d,s + addr_dCs_16br + LDAMacro16b +COpA5m8: ; LDA d + addr_d_8br + LDAMacro8b +COpA5m16:; LDA d + addr_d_16br + LDAMacro16b +COpA7m8: ; LDA [d] + addr_LdL_8br + LDAMacro8b +COpA7m16:; LDA [d] + addr_LdL_16br + LDAMacro16b +COpA9m8: ; LDA # + addr_I_8br + LDAMacro8b +COpA9m16:; LDA # + addr_I_16br + LDAMacro16b +COpADm8: ; LDA a + addr_a_8br + LDAMacro8b +COpADm16:; LDA a + addr_a_16br + LDAMacro16b +COpAFm8: ; LDA al + addr_al_8br + LDAMacro8b +COpAFm16:; LDA al + addr_al_16br + LDAMacro16b +COpB1m8: ; LDA(d),y + addr_BdBCy_8br + LDAMacro8b +COpB1m16:; LDA(d),y + addr_BdBCy_16br + LDAMacro16b +COpB2m8: ; LDA (d) + addr_BdB_8br + LDAMacro8b +COpB2m16:; LDA (d) + addr_BdB_16br + LDAMacro16b +COpB3m8: ; LDA(d,s),y + addr_BdCsBCy_8br + LDAMacro8b +COpB3m16:; LDA(d,s),y + addr_BdCsBCy_16br + LDAMacro16b +COpB5m8: ; LDA d,x + addr_dCx_8br + LDAMacro8b +COpB5m16:; LDA d,x + addr_dCx_16br + LDAMacro16b +COpB7m8: ; LDA [d],y + addr_LdLCy_8br + LDAMacro8b +COpB7m16:; LDA [d],y + addr_LdLCy_16br + LDAMacro16b +COpB9m8: ; LDA a,y + addr_aCy_8br + LDAMacro8b +COpB9m16:; LDA a,y + addr_aCy_16br + LDAMacro16b +COpBDm8: ; LDA a,x + addr_aCx_8br + LDAMacro8b +COpBDm16:; LDA a,x + addr_aCx_16br + LDAMacro16b +COpBFm8: ; LDA al,x + addr_alCx_8br + LDAMacro8b +COpBFm16:; LDA al,x + addr_alCx_16br + LDAMacro16b + +COpA2x8: ; LDX # + addr_I_8br + LDXMacro8b +COpA2x16:; LDX # + addr_I_16br + LDXMacro16b +COpA6x8: ; LDX d + addr_d_8br + LDXMacro8b +COpA6x16:; LDX d + addr_d_16br + LDXMacro16b +COpAEx8: ; LDX a + addr_a_8br + LDXMacro8b +COpAEx16:; LDX a + addr_a_16br + LDXMacro16b +COpB6x8: ; LDX d,y + addr_dCy_8br + LDXMacro8b +COpB6x16:; LDX d,y + addr_dCy_16br + LDXMacro16b +COpBEx8: ; LDX a,y + addr_aCy_8br + LDXMacro8b +COpBEx16:; LDX a,y + addr_aCy_16br + LDXMacro16b + +COpA0x8: ; LDY # + addr_I_8br + LDYMacro8b +COpA0x16:; LDY # + addr_I_16br + LDYMacro16b +COpA4x8: ; LDY d + addr_d_8br + LDYMacro8b +COpA4x16:; LDY d + addr_d_16br + LDYMacro16b +COpACx8: ; LDY a + addr_a_8br + LDYMacro8b +COpACx16:; LDY a + addr_a_16br + LDYMacro16b +COpB4x8: ; LDY d,x + addr_dCx_8br + LDYMacro8b +COpB4x16:; LDY d,x + addr_dCx_16br + LDYMacro16b +COpBCx8: ; LDY a,x + addr_aCx_8br + LDYMacro8b +COpBCx16:; LDY a,x + addr_aCx_16br + LDYMacro16b + +COp46m8: ; LSR d + addr_d_8brni + LSRMacro8b + addr_d_8bw + endloop +COp46m16:; LSR d + addr_d_16brni + LSRMacro16b + addr_d_16bw + endloop +COp4Am8: ; LSR A + addr_A_8brni + LSRMacro8b + addr_A_8bw + endloop +COp4Am16:; LSR A + addr_A_16brni + LSRMacro16b + addr_A_16bw + endloop +COp4Em8: ; LSR a + addr_a_8brni + LSRMacro8b + addr_a_8bw + endloop +COp4Em16:; LSR a + addr_a_16brni + LSRMacro16b + addr_a_16bw + endloop +COp56m8: ; LSR d,x + addr_dCx_8brni + LSRMacro8b + addr_dCx_8bw + endloop +COp56m16:; LSR d,x + addr_dCx_16brni + LSRMacro16b + addr_dCx_16bw + endloop +COp5Em8: ; LSRa,x + addr_aCx_8brni + LSRMacro8b + addr_aCx_8bw + endloop +COp5Em16:; LSRa,x + addr_aCx_16brni + LSRMacro16b + addr_aCx_16bw + endloop + +COp54: ; MVN xya + MVNMacro +COp44: ; MVP xya + MVPMacro + +COpEA: ; NOP i + endloop + +COp01m8: ; ORA(d,x) + addr_BdCxB_8br + ORAMacro8b +COp01m16:; ORA(d,x) + addr_BdCxB_16br + ORAMacro16b +COp03m8: ; ORA d,s + addr_dCs_8br + ORAMacro8b +COp03m16:; ORA d,s + addr_dCs_16br + ORAMacro16b +COp05m8: ; ORA d + addr_d_8br + ORAMacro8b +COp05m16:; ORA d + addr_d_16br + ORAMacro16b +COp07m8: ; ORA [d] + addr_LdL_8br + ORAMacro8b +COp07m16:; ORA [d] + addr_LdL_16br + ORAMacro16b +COp09m8: ; ORA # + addr_I_8br + ORAMacro8b +COp09m16:; ORA # + addr_I_16br + ORAMacro16b +COp0Dm8: ; ORA a + addr_a_8br + ORAMacro8b +COp0Dm16:; ORA a + addr_a_16br + ORAMacro16b +COp0Fm8: ; ORA al + addr_al_8br + ORAMacro8b +COp0Fm16:; ORA al + addr_al_16br + ORAMacro16b +COp11m8: ; ORA(d),y + addr_BdBCy_8br + ORAMacro8b +COp11m16:; ORA(d),y + addr_BdBCy_16br + ORAMacro16b +COp12m8: ; ORA(d) + addr_BdB_8br + ORAMacro8b +COp12m16:; ORA(d) + addr_BdB_16br + ORAMacro16b +COp13m8: ; ORA(d,s),y + addr_BdCsBCy_8br + ORAMacro8b +COp13m16:; ORA(d,s),y + addr_BdCsBCy_16br + ORAMacro16b +COp15m8: ; ORA d,x + addr_dCx_8br + ORAMacro8b +COp15m16:; ORA d,x + addr_dCx_16br + ORAMacro16b +COp17m8: ; ORA [d],y + addr_LdLCy_8br + ORAMacro8b +COp17m16:; ORA [d],y + addr_LdLCy_16br + ORAMacro16b +COp19m8: ; ORA a,y + addr_aCy_8br + ORAMacro8b +COp19m16:; ORA a,y + addr_aCy_16br + ORAMacro16b +COp1Dm8: ; ORA a,x + addr_aCx_8br + ORAMacro8b +COp1Dm16:; ORA a,x + addr_aCx_16br + ORAMacro16b +COp1Fm8: ; ORA al,x + addr_alCx_8br + ORAMacro8b +COp1Fm16:; ORA al,x + addr_alCx_16br + ORAMacro16b + +COpF4: ; PEA s + PEAMacro +COpD4: ; PEI s + PEIMacro +COp62: ; PER s + PERMacro + +COp48m8: ; PHA s + PUSHMacro8b [xa] +COp48m16:; PHA s + PUSHMacro16b [xa], [xa+1] +COp8B: ; PHB s + PUSHMacro8b [xdb] +COp0B: ; PHD s + PUSHMacro16b [xd], [xd+1] +COp4B: ; PHK s + PUSHMacro8b [xpb] +COp08: ; PHP s + PUSHMacro8bp +COpDAx8: ; PHX s + PUSHMacro8b [xx] +COpDAx16:; PHX s + PUSHMacro16b [xx], [xx+1] +COp5Ax8: ; PHY s + PUSHMacro8b [xy] +COp5Ax16:; PHY s + PUSHMacro16b [xy], [xy+1] + +COp68m8: ; PLA s + POPMacro8b [xa] +COp68m16:; PLA s + POPMacro16b [xa], [xa+1] +COpAB: ; PLB s + POPMacro8b [xdb] +COp2B: ; PLD s + POPMacro16bd [xd], [xd+1] +COp28: ; PLP s + POPMacroP +COpFAx8: ; PLX s + POPMacro8b [xx] +COpFAx16:; PLX s + POPMacro16b [xx], [xx+1] +COp7Ax8: ; PLY s + POPMacro8b [xy] +COp7Ax16:; PLY s + POPMacro16b [xy], [xy+1] + +COpC2: ; REP # + REPMacro + +COp26m8: ; ROL d + addr_d_8brni + ROLMacro8b + addr_d_8bw + endloop +COp26m16:; ROL d + addr_d_16brni + ROLMacro16b + addr_d_16bw + endloop +COp2Am8: ; ROL A + addr_A_8brni + ROLMacro8b + addr_A_8bw + endloop +COp2Am16:; ROL A + addr_A_16brni + ROLMacro16b + addr_A_16bw + endloop +COp2Em8: ; ROL a + addr_a_8brni + ROLMacro8b + addr_a_8bw + endloop +COp2Em16:; ROL a + addr_a_16brni + ROLMacro16b + addr_a_16bw + endloop +COp36m8: ; ROL d,x + addr_dCx_8brni + ROLMacro8b + addr_dCx_8bw + endloop +COp36m16:; ROL d,x + addr_dCx_16brni + ROLMacro16b + addr_dCx_16bw + endloop +COp3Em8: ; ROL a,x + addr_aCx_8brni + ROLMacro8b + addr_aCx_8bw + endloop +COp3Em16:; ROL a,x + addr_aCx_16brni + ROLMacro16b + addr_aCx_16bw + endloop + +COp66m8: ; ROR d + addr_d_8brni + RORMacro8b + addr_d_8bw + endloop +COp66m16:; ROR d + addr_d_16brni + RORMacro16b + addr_d_16bw + endloop +COp6Am8: ; ROR A + addr_A_8brni + RORMacro8b + addr_A_8bw + endloop +COp6Am16:; ROR A + addr_A_16brni + RORMacro16b + addr_A_16bw + endloop +COp6Em8: ; ROR a + addr_a_8brni + RORMacro8b + addr_a_8bw + endloop +COp6Em16:; ROR a + addr_a_16brni + RORMacro16b + addr_a_16bw + endloop +COp76m8: ; ROR d,x + addr_dCx_8brni + RORMacro8b + addr_dCx_8bw + endloop +COp76m16:; ROR d,x + addr_dCx_16brni + RORMacro16b + addr_dCx_16bw + endloop +COp7Em8: ; ROR a,x + addr_aCx_8brni + RORMacro8b + addr_aCx_8bw + endloop +COp7Em16:; ROR a,x + addr_aCx_16brni + RORMacro16b + addr_aCx_16bw + endloop + +COp40: ; RTI s + RTIMacro +COp6B: ; RTL s + RTLMacro +COp60: ; RTS s + RTSMacro + +COpE1m8nd: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bnd +COpE1m16nd: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bnd +COpE1m8d: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bd +COpE1m16d: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bd +COpE3m8nd: ; SBC d,s + addr_dCs_8br + SBCMacro8bnd +COpE3m16nd: ; SBC d,s + addr_dCs_16br + SBCMacro16bnd +COpE3m8d: ; SBC d,s + addr_dCs_8br + SBCMacro8bd +COpE3m16d: ; SBC d,s + addr_dCs_16br + SBCMacro16bd +COpE5m8nd: ; SBC d + addr_d_8br + SBCMacro8bnd +COpE5m16nd: ; SBC d + addr_d_16br + SBCMacro16bnd +COpE5m8d: ; SBC d + addr_d_8br + SBCMacro8bd +COpE5m16d: ; SBC d + addr_d_16br + SBCMacro16bd +COpE7m8nd: ; SBC [d] + addr_LdL_8br + SBCMacro8bnd +COpE7m16nd: ; SBC [d] + addr_LdL_16br + SBCMacro16bnd +COpE7m8d: ; SBC [d] + addr_LdL_8br + SBCMacro8bd +COpE7m16d: ; SBC [d] + addr_LdL_16br + SBCMacro16bd +COpE9m8nd: ; SBC # + addr_I_8br + SBCMacro8bnd +COpE9m16nd: ; SBC # + addr_I_16br + SBCMacro16bnd +COpE9m8d: ; SBC # + addr_I_8br + SBCMacro8bd +COpE9m16d: ; SBC # + addr_I_16br + SBCMacro16bd +COpEDm8nd: ; SBC a + addr_a_8br + SBCMacro8bnd +COpEDm16nd: ; SBC a + addr_a_16br + SBCMacro16bnd +COpEDm8d: ; SBC a + addr_a_8br + SBCMacro8bd +COpEDm16d: ; SBC a + addr_a_16br + SBCMacro16bd +COpEFm8nd: ; SBC al + addr_al_8br + SBCMacro8bnd +COpEFm16nd: ; SBC al + addr_al_16br + SBCMacro16bnd +COpEFm8d: ; SBC al + addr_al_8br + SBCMacro8bd +COpEFm16d: ; SBC al + addr_al_16br + SBCMacro16bd +COpF1m8nd: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bnd +COpF1m16nd: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bnd +COpF1m8d: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bd +COpF1m16d: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bd +COpF2m8nd: ; SBC (d) + addr_BdB_8br + SBCMacro8bnd +COpF2m16nd: ; SBC (d) + addr_BdB_16br + SBCMacro16bnd +COpF2m8d: ; SBC (d) + addr_BdB_8br + SBCMacro8bd +COpF2m16d: ; SBC (d) + addr_BdB_16br + SBCMacro16bd +COpF3m8nd: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bnd +COpF3m16nd: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bnd +COpF3m8d: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bd +COpF3m16d: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bd +COpF5m8nd: ; SBC d,x + addr_dCx_8br + SBCMacro8bnd +COpF5m16nd: ; SBC d,x + addr_dCx_16br + SBCMacro16bnd +COpF5m8d: ; SBC d,x + addr_dCx_8br + SBCMacro8bd +COpF5m16d: ; SBC d,x + addr_dCx_16br + SBCMacro16bd +COpF7m8nd: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bnd +COpF7m16nd: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bnd +COpF7m8d: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bd +COpF7m16d: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bd +COpF9m8nd: ; SBC a,y + addr_aCy_8br + SBCMacro8bnd +COpF9m16nd: ; SBC a,y + addr_aCy_16br + SBCMacro16bnd +COpF9m8d: ; SBC a,y + addr_aCy_8br + SBCMacro8bd +COpF9m16d: ; SBC a,y + addr_aCy_16br + SBCMacro16bd +COpFDm8nd: ; SBC a,x + addr_aCx_8br + SBCMacro8bnd +COpFDm16nd: ; SBC a,x + addr_aCx_16br + SBCMacro16bnd +COpFDm8d: ; SBC a,x + addr_aCx_8br + SBCMacro8bd +COpFDm16d: ; SBC a,x + addr_aCx_16br + SBCMacro16bd +COpFFm8nd: ; SBC al,x + addr_alCx_8br + SBCMacro8bnd +COpFFm16nd: ; SBC al,x + addr_alCx_16br + SBCMacro16bnd +COpFFm8d: ; SBC al,x + addr_alCx_8br + SBCMacro8bd +COpFFm16d: ; SBC al,x + addr_alCx_16br + SBCMacro16bd + +COp38: ; SEC i + mov dword[flagc],0FFh + endloop +COpF8: ; SED i + or dl,08h + mov bl,dl + mov edi,[tablead+ebx*4] + endloop +COp78: ; SEI i + or dl,04h + endloop + +COpE2: ; SEP # + SEPMacro + +COp81m8: ; STA(d,x) + STAMacro8b + addr_BdCxB_8bw + endloop +COp81m16:; STA(d,x) + STAMacro16b + addr_BdCxB_16bw + endloop +COp83m8: ; STA d,s + STAMacro8b + addr_dCs_8bw + endloop +COp83m16:; STA d,s + STAMacro16b + addr_dCs_16bw + endloop +COp85m8: ; STA d + STAMacro8b + addr_d_8bw + endloop +COp85m16:; STA d + STAMacro16b + addr_d_16bw + endloop +COp87m8: ; STA [d] + STAMacro8b + addr_LdL_8bw + endloop +COp87m16:; STA [d] + STAMacro16b + addr_LdL_16bw + endloop +COp8Dm8: ; STA a + STAMacro8b + addr_a_8bw + endloop +COp8Dm16:; STA a + STAMacro16b + addr_a_16bw + endloop +COp8Fm8: ; STA al + STAMacro8b + addr_al_8bw + endloop +COp8Fm16:; STA al + STAMacro16b + addr_al_16bw + endloop +COp91m8: ; STA(d),y + STAMacro8b + addr_BdBCy_8bw + endloop +COp91m16:; STA(d),y + STAMacro16b + addr_BdBCy_16bw + endloop +COp92m8: ; STA (d) + STAMacro8b + addr_BdB_8bw + endloop +COp92m16:; STA (d) + STAMacro16b + addr_BdB_16bw + endloop +COp93m8: ; STA(d,s),y + STAMacro8b + addr_BdCsBCy_8bw + endloop +COp93m16:; STA(d,s),y + STAMacro16b + addr_BdCsBCy_16bw + endloop +COp95m8: ; STA d,x + STAMacro8b + addr_dCx_8bw + endloop +COp95m16:; STA d,x + STAMacro16b + addr_dCx_16bw + endloop +COp97m8: ; STA [d],y + STAMacro8b + addr_LdLCy_8bw + endloop +COp97m16:; STA [d],y + STAMacro16b + addr_LdLCy_16bw + endloop +COp99m8: ; STA a,y + STAMacro8b + addr_aCy_8bw + endloop +COp99m16:; STA a,y + STAMacro16b + addr_aCy_16bw + endloop +COp9Dm8: ; STA a,x + STAMacro8b + addr_aCx_8bw + endloop +COp9Dm16:; STA a,x + STAMacro16b + addr_aCx_16bw + endloop +COp9Fm8: ; STA al,x + STAMacro8b + addr_alCx_8bw + endloop +COp9Fm16:; STA al,x + STAMacro16b + addr_alCx_16bw + endloop + +COp86x8: ; STX d + STXMacro8b + addr_d_8bw + endloop +COp86x16:; STX d + STXMacro16b + addr_d_16bw + endloop +COp8Ex8: ; STX a + STXMacro8b + addr_a_8bw + endloop +COp8Ex16:; STX a + STXMacro16b + addr_a_16bw + endloop +COp96x8: ; STX d,y + STXMacro8b + addr_dCy_8bw + endloop +COp96x16:; STX d,y + STXMacro16b + addr_dCy_16bw + endloop + +COp84x8: ; STY d + STYMacro8b + addr_d_8bw + endloop +COp84x16:; STY d + STYMacro16b + addr_d_16bw + endloop +COp8Cx8: ; STY a + STYMacro8b + addr_a_8bw + endloop +COp8Cx16:; STY a + STYMacro16b + addr_a_16bw + endloop +COp94x8: ; STYd,x + STYMacro8b + addr_dCx_8bw + endloop +COp94x16:; STYd,x + STYMacro16b + addr_dCx_16bw + endloop + +COpDB: ; STP i + dec esi + endloop + +COp64m8: ; STZ d + xor al,al + addr_d_8bw + endloop +COp64m16:; STZ d + xor eax,eax + addr_d_16bw + endloop +COp74m8: ; STZ d,x + xor al,al + addr_dCx_8bw + endloop +COp74m16:; STZ d,x + xor eax,eax + addr_dCx_16bw + endloop +COp9Cm8: ; STZ a + xor al,al + addr_a_8bw + endloop +COp9Cm16:; STZ a + xor eax,eax + addr_a_16bw + endloop +COp9Em8: ; STZ a,x + xor al,al + addr_aCx_8bw + endloop +COp9Em16:; STZ a,x + xor eax,eax + addr_aCx_16bw + endloop + +COp14m8: ; TRB d + addr_d_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cl,al + jz .zero + mov word[flagnz],1 + not cl + and al,cl + addr_d_8bw + endloop +.zero + mov word[flagnz],0 + not cl + and al,cl + addr_d_8bw + endloop +COp14m16:; TRB d + addr_d_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[flagnz],1 + not cx + and ax,cx + addr_d_16bw + endloop +.zero + mov word[flagnz],0 + not cx + and ax,cx + addr_d_16bw + endloop +COp1Cm8: ; TRB a + addr_a_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cl,al + jz .zero + mov word[flagnz],1 + not cl + and al,cl + addr_a_8bw + endloop +.zero + mov word[flagnz],0 + not cl + and al,cl + addr_a_8bw + endloop +COp1Cm16:; TRB a + addr_a_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[flagnz],1 + not cx + and ax,cx + addr_a_16bw + endloop +.zero + mov word[flagnz],0 + not cx + and ax,cx + addr_a_16bw + endloop + +COp04m8: ; TSB d + addr_d_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test al,cl + jz .zero + mov word[flagnz],1 + or al,cl + addr_d_8bw + endloop +.zero + mov word[flagnz],0 + or al,cl + addr_d_8bw + endloop +COp04m16:; TSB d + addr_d_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[flagnz],1 + or ax,cx + addr_d_16bw + endloop +.zero + mov word[flagnz],0 + or ax,cx + addr_d_16bw + endloop +COp0Cm8: ; TSB a + addr_a_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test al,cl + jz .zero + mov word[flagnz],1 + or al,cl + addr_a_8bw + endloop +.zero + mov word[flagnz],0 + or al,cl + addr_a_8bw + endloop +COp0Cm16:; TSB a + addr_a_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[flagnz],1 + or ax,cx + addr_a_16bw + endloop +.zero + mov word[flagnz],0 + or ax,cx + addr_a_16bw + endloop + +COpAAx8: ; TAX i + mov al,[xa] + mov [xx],al + flagsetnz8b + endloop +COpAAx16:; TAX i + mov ax,[xa] + mov [xx],ax + flagsetnz16b + endloop +COpA8x8: ; TAY i + mov al,[xa] + mov [xy],al + flagsetnz8b + endloop +COpA8x16:; TAY i + mov ax,[xa] + mov [xy],ax + flagsetnz16b + endloop +COp5B: ; TCD i + mov ax,[xa] + mov [xd],ax + call UpdateDPage + flagsetnz16b + endloop +COp1B: ; TCS i + mov ax,[xa] + mov [xs],ax + endloop +COp7B: ; TDC i + mov ax,[xd] + mov [xa],ax + flagsetnz16b + endloop +COp3B: ; TSC i + mov ax,[xs] + mov [xa],ax + flagsetnz16b + endloop +COpBAx8: ; TSX i + mov al,[xs] + mov [xx],al + flagsetnz8b + endloop +COpBAx16:; TSX i + mov ax,[xs] + mov [xx],ax + flagsetnz16b + endloop +COp8Am8: ; TXA i + mov al,[xx] + mov [xa],al + flagsetnz8b + endloop +COp8Am16:; TXA i + mov ax,[xx] + mov [xa],ax + flagsetnz16b + endloop +COp9A: ; TXS i + mov ax,[xx] + mov [xs],ax + test byte[xe],1 + jnz .emul + endloop +.emul + mov byte[xs+1],1 + endloop +COp9Bx8: ; TXY i + mov al,[xx] + mov [xy],al + flagsetnz8b + endloop +COp9Bx16:; TXY i + mov ax,[xx] + mov [xy],ax + flagsetnz16b + endloop +COp98m8: ; TYA i + mov al,[xy] + mov [xa],al + flagsetnz8b + endloop +COp98m16:; TYA i + mov ax,[xy] + mov [xa],ax + flagsetnz16b + endloop +COpBBx8: ; TYX i + mov al,[xy] + mov [xx],al + flagsetnz8b + endloop +COpBBx16:; TYX i + mov ax,[xy] + mov [xx],ax + flagsetnz16b + endloop + +COpCB: ; WAI i + mov byte[debstop3],1 + WAIMacro + +COpEB: ; XBA i + mov ah,[xa] + mov al,[xa+1] + mov [xa],ax + flagsetnz8b + endloop + +COpFB: ; XCE i + XCEMacro + +COp42: ; WDM + inc esi + endloop + \ No newline at end of file diff --git a/zsnes/src/cpu/e65816b.inc b/zsnes/src/cpu/e65816b.inc new file mode 100644 index 00000000..48c55f2b --- /dev/null +++ b/zsnes/src/cpu/e65816b.inc @@ -0,0 +1,1987 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM brkv,brkv8,changeexecloop,copv,copv8,curexecstate,curnmi,execloop +EXTSYM initaddrl,membank0r16,membank0r8 +EXTSYM membank0w16,membank0w8,memtabler16,memtabler8,memtablew16,memtablew8 +EXTSYM nmistatus,regaccessbankr8,snesmap2,snesmmap,stackand,stackor +EXTSYM wramdata,xa,xd,xdb,xe,xirqb,xpb,xpc,xs,xx,xy +EXTSYM switchtovirq,intrset,UpdateDPage +EXTSYM DPageR8,DPageW8,DPageR16,DPageW16 + + + + + +; B = ( or ) +; C = , +; L = [ or ] +; I = # + + +COp61m8nd: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bnd +COp61m16nd: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bnd +COp61m8d: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bd +COp61m16d: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bd +COp63m8nd: ; ADC d,s + addr_dCs_8br + ADCMacro8bnd +COp63m16nd: ; ADC d,s + addr_dCs_16br + ADCMacro16bnd +COp63m8d: ; ADC d,s + addr_dCs_8br + ADCMacro8bd +COp63m16d: ; ADC d,s + addr_dCs_16br + ADCMacro16bd +COp65m8nd: ; ADC d + addr_d_8br + ADCMacro8bnd +COp65m16nd: ; ADC d + addr_d_16br + ADCMacro16bnd +COp65m8d: ; ADC d + addr_d_8br + ADCMacro8bd +COp65m16d: ; ADC d + addr_d_16br + ADCMacro16bd +COp67m8nd: ; ADC [d] + addr_LdL_8br + ADCMacro8bnd +COp67m16nd: ; ADC [d] + addr_LdL_16br + ADCMacro16bnd +COp67m8d: ; ADC [d] + addr_LdL_8br + ADCMacro8bd +COp67m16d: ; ADC [d] + addr_LdL_16br + ADCMacro16bd +COp69m8nd: ; ADC # + addr_I_8br + ADCMacro8bnd +COp69m16nd: ; ADC # + addr_I_16br + ADCMacro16bnd +COp69m8d: ; ADC # + addr_I_8br + ADCMacro8bd +COp69m16d: ; ADC # + addr_I_16br + ADCMacro16bd +COp6Dm8nd: ; ADC a + addr_a_8br + ADCMacro8bnd +COp6Dm16nd: ; ADC a + addr_a_16br + ADCMacro16bnd +COp6Dm8d: ; ADC a + addr_a_8br + ADCMacro8bd +COp6Dm16d: ; ADC a + addr_a_16br + ADCMacro16bd +COp6Fm8nd: ; ADC al + addr_al_8br + ADCMacro8bnd +COp6Fm16nd: ; ADC al + addr_al_16br + ADCMacro16bnd +COp6Fm8d: ; ADC al + addr_al_8br + ADCMacro8bd +COp6Fm16d: ; ADC al + addr_al_16br + ADCMacro16bd +COp71m8nd: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bnd +COp71m16nd: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bnd +COp71m8d: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bd +COp71m16d: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bd +COp72m8nd: ; ADC (d) + addr_BdB_8br + ADCMacro8bnd +COp72m16nd: ; ADC (d) + addr_BdB_16br + ADCMacro16bnd +COp72m8d: ; ADC (d) + addr_BdB_8br + ADCMacro8bd +COp72m16d: ; ADC (d) + addr_BdB_16br + ADCMacro16bd +COp73m8nd: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bnd +COp73m16nd: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bnd +COp73m8d: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bd +COp73m16d: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bd +COp75m8nd: ; ADC d,x + addr_dCx_8br + ADCMacro8bnd +COp75m16nd: ; ADC d,x + addr_dCx_16br + ADCMacro16bnd +COp75m8d: ; ADC d,x + addr_dCx_8br + ADCMacro8bd +COp75m16d: ; ADC d,x + addr_dCx_16br + ADCMacro16bd +COp77m8nd: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bnd +COp77m16nd: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bnd +COp77m8d: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bd +COp77m16d: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bd +COp79m8nd: ; ADC a,y + addr_aCy_8br + ADCMacro8bnd +COp79m16nd: ; ADC a,y + addr_aCy_16br + ADCMacro16bnd +COp79m8d: ; ADC a,y + addr_aCy_8br + ADCMacro8bd +COp79m16d: ; ADC a,y + addr_aCy_16br + ADCMacro16bd +COp7Dm8nd: ; ADC a,x + addr_aCx_8br + ADCMacro8bnd +COp7Dm16nd: ; ADC a,x + addr_aCx_16br + ADCMacro16bnd +COp7Dm8d: ; ADC a,x + addr_aCx_8br + ADCMacro8bd +COp7Dm16d: ; ADC a,x + addr_aCx_16br + ADCMacro16bd +COp7Fm8nd: ; ADC al,x + addr_alCx_8br + ADCMacro8bnd +COp7Fm16nd: ; ADC al,x + addr_alCx_16br + ADCMacro16bnd +COp7Fm8d: ; ADC al,x + addr_alCx_8br + ADCMacro8bd +COp7Fm16d: ; ADC al,x + addr_alCx_16br + ADCMacro16bd + +COp21m8: ; AND(d,x) + addr_BdCxB_8br + ANDMacro8b +COp21m16:; AND(d,x) + addr_BdCxB_16br + ANDMacro16b +COp23m8: ; AND d,s + addr_dCs_8br + ANDMacro8b +COp23m16:; AND d,s + addr_dCs_16br + ANDMacro16b +COp25m8: ; AND d + addr_d_8br + ANDMacro8b +COp25m16:; AND d + addr_d_16br + ANDMacro16b +COp27m8: ; AND [d] + addr_LdL_8br + ANDMacro8b +COp27m16:; AND [d] + addr_LdL_16br + ANDMacro16b +COp29m8: ; AND # + addr_I_8br + ANDMacro8b +COp29m16:; AND # + addr_I_16br + ANDMacro16b +COp2Dm8: ; AND a + addr_a_8br + ANDMacro8b +COp2Dm16:; AND a + addr_a_16br + ANDMacro16b +COp2Fm8: ; AND al + addr_al_8br + ANDMacro8b +COp2Fm16:; AND al + addr_al_16br + ANDMacro16b +COp31m8: ; AND(d),y + addr_BdBCy_8br + ANDMacro8b +COp31m16:; AND(d),y + addr_BdBCy_16br + ANDMacro16b +COp32m8: ; AND (d) + addr_BdB_8br + ANDMacro8b +COp32m16:; AND (d) + addr_BdB_16br + ANDMacro16b +COp33m8: ; AND(d,s),y + addr_BdCsBCy_8br + ANDMacro8b +COp33m16:; AND(d,s),y + addr_BdCsBCy_16br + ANDMacro16b +COp35m8: ; AND d,x + addr_dCx_8br + ANDMacro8b +COp35m16:; AND d,x + addr_dCx_16br + ANDMacro16b +COp37m8: ; AND [d],y + addr_LdLCy_8br + ANDMacro8b +COp37m16:; AND [d],y + addr_LdLCy_16br + ANDMacro16b +COp39m8: ; AND a,y + addr_aCy_8br + ANDMacro8b +COp39m16:; AND a,y + addr_aCy_16br + ANDMacro16b +COp3Dm8: ; AND a,x + addr_aCx_8br + ANDMacro8b +COp3Dm16:; AND a,x + addr_aCx_16br + ANDMacro16b +COp3Fm8: ; AND al,x + addr_alCx_8br + ANDMacro8b +COp3Fm16:; AND al,x + addr_alCx_16br + ANDMacro16b + +COp06m8: ; ASL d + addr_d_8brni + ASLMacro8b + addr_d_8bw + endloop +COp06m16:; ASL d + addr_d_16brni + ASLMacro16b + addr_d_16bw + endloop +COp0Am8: ; ASL A + addr_A_8brni + ASLMacro8b + addr_A_8bw + endloop +COp0Am16:; ASL A + addr_A_16brni + ASLMacro16b + addr_A_16bw + endloop +COp0Em8: ; ASL a + addr_a_8brni + ASLMacro8b + addr_a_8bw + endloop +COp0Em16:; ASL a + addr_a_16brni + ASLMacro16b + addr_a_16bw + endloop +COp16m8: ; ASL d,x + addr_dCx_8brni + ASLMacro8b + addr_dCx_8bw + endloop +COp16m16:; ASL d,x + addr_dCx_16brni + ASLMacro16b + addr_dCx_16bw + endloop +COp1Em8: ; ASL a,x + addr_aCx_8brni + ASLMacro8b + addr_aCx_8bw + endloop +COp1Em16:; ASL a,x + addr_aCx_16brni + ASLMacro16b + addr_aCx_16bw + endloop + +COp90: ; BCC r + test byte[flagc],01h + jnz .skip + JumpMacro +COpB0: ; BCS r + test byte[flagc],01h + jz .skip + JumpMacro +COpF0: ; BEQ r + test dword[flagnz],0FFFFh + jnz .skip + JumpMacro +COp30: ; BMI r + test dword[flagnz],018000h + jz .skip + JumpMacro +COpD0: ; BNE r + test dword[flagnz],0FFFFh + jz .skip + JumpMacro +COp10: ; BPL r + test dword[flagnz],018000h + jnz .skip + JumpMacro +COp80: ; BRA r + movsx eax,byte[esi] + inc esi + add esi,eax + endloop +COp50: ; BVC r + test dword[flago],0FFh + jnz .skip + JumpMacro +COp70: ; BVS r + test dword[flago],0FFh + jz .skip + JumpMacro + +; BIT instruction does not affect N and V flags when using immediate +; addressing mode. When using other addressing modes, the N and V flags + +COp89m8: ; BIT # + BITMacroim8b +COp89m16:; BIT # + BITMacroim16b + +COp24m8: ; BIT d + addr_d_8br + BITMacro8b +COp24m16:; BIT d + addr_d_16br + BITMacro16b +COp2Cm8: ; BIT a + addr_a_8br + BITMacro8b +COp2Cm16:; BIT a + addr_a_16br + BITMacro16b +COp34m8: ; BIT d,x + addr_dCx_8br + BITMacro8b +COp34m16:; BIT d,x + addr_dCx_16br + BITMacro16b +COp3Cm8: ; BIT a,x + addr_aCx_8br + BITMacro8b +COp3Cm16:; BIT a,x + addr_aCx_16br + BITMacro16b + +COp00: ; BRK s + BRKMacro + +COp82: ; BRL rl + BRLMacro + +COp18: ; CLC i + mov dword[flagc],0 + endloop +COpD8: ; CLD i + and dl,0F7h + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop +COp58: ; CLI i + and dl,0FBh + endloop +COpB8: ; CLV i + mov dword[flago],0 + endloop + +COpC1m8: ; CMP(d,x) + addr_BdCxB_8br + CMPMacro8b +COpC1m16:; CMP(d,x) + addr_BdCxB_16br + CMPMacro16b +COpC3m8: ; CMP d,s + addr_dCs_8br + CMPMacro8b +COpC3m16:; CMP d,s + addr_dCs_16br + CMPMacro16b +COpC5m8: ; CMP d + addr_d_8br + CMPMacro8b +COpC5m16:; CMP d + addr_d_16br + CMPMacro16b +COpC7m8: ; CMP [d] + addr_LdL_8br + CMPMacro8b +COpC7m16:; CMP [d] + addr_LdL_16br + CMPMacro16b +COpC9m8: ; CMP # + addr_I_8br + CMPMacro8b +COpC9m16:; CMP # + addr_I_16br + CMPMacro16b +COpCDm8: ; CMP a + addr_a_8br + CMPMacro8b +COpCDm16:; CMP a + addr_a_16br + CMPMacro16b +COpCFm8: ; CMP al + addr_al_8br + CMPMacro8b +COpCFm16:; CMP al + addr_al_16br + CMPMacro16b +COpD1m8: ; CMP(d),y + addr_BdBCy_8br + CMPMacro8b +COpD1m16:; CMP(d),y + addr_BdBCy_16br + CMPMacro16b +COpD2m8: ; CMP (d) + addr_BdB_8br + CMPMacro8b +COpD2m16:; CMP (d) + addr_BdB_16br + CMPMacro16b +COpD3m8: ; CMP(d,s),y + addr_BdCsBCy_8br + CMPMacro8b +COpD3m16:; CMP(d,s),y + addr_BdCsBCy_16br + CMPMacro16b +COpD5m8: ; CMP d,x + addr_dCx_8br + CMPMacro8b +COpD5m16:; CMP d,x + addr_dCx_16br + CMPMacro16b +COpD7m8: ; CMP [d],y + addr_LdLCy_8br + CMPMacro8b +COpD7m16:; CMP [d],y + addr_LdLCy_16br + CMPMacro16b +COpD9m8: ; CMP a,y + addr_aCy_8br + CMPMacro8b +COpD9m16:; CMP a,y + addr_aCy_16br + CMPMacro16b +COpDDm8: ; CMP a,x + addr_aCx_8br + CMPMacro8b +COpDDm16:; CMP a,x + addr_aCx_16br + CMPMacro16b +COpDFm8: ; CMP al,x + addr_alCx_8br + CMPMacro8b +COpDFm16:; CMP al,x + addr_alCx_16br + CMPMacro16b + +COp02: ; COP s + COPMacro + +COpE0x8: ; CPX # + addr_I_8br + CPXMacro8b +COpE0x16:; CPX # + addr_I_16br + CPXMacro16b +COpE4x8: ; CPX d + addr_d_8br + CPXMacro8b +COpE4x16:; CPX d + addr_d_16br + CPXMacro16b +COpECx8: ; CPX a + addr_a_8br + CPXMacro8b +COpECx16:; CPX a + addr_a_16br + CPXMacro16b + +COpC0x8: ; CPY # + addr_I_8br + CPYMacro8b +COpC0x16:; CPY # + addr_I_16br + CPYMacro16b +COpC4x8: ; CPY d + addr_d_8br + CPYMacro8b +COpC4x16:; CPY d + addr_d_16br + CPYMacro16b +COpCCx8: ; CPY a + addr_a_8br + CPYMacro8b +COpCCx16:; CPY a + addr_a_16br + CPYMacro16b + +COp3Am8: ; DEC A + addr_A_8brni + dec al + flagsetnz8bnel + addr_A_8bw + endloop +COp3Am16:; DEC A + addr_A_16brni + dec ax + flagsetnz16bnel + addr_A_16bw + endloop +COpCEm8: ; DEC a + addr_a_8brni + dec al + flagsetnz8bnel + addr_a_8bw + endloop +COpCEm16:; DEC a + addr_a_16brni + dec ax + flagsetnz16bnel + addr_a_16bw + endloop +COpC6m8: ; DEC d + addr_d_8brni + dec al + flagsetnz8bnel + addr_d_8bw + endloop +COpC6m16:; DEC d + addr_d_16brni + dec ax + flagsetnz16bnel + addr_d_16bw + endloop +COpD6m8: ; DEC d,x + addr_dCx_8brni + dec al + flagsetnz8bnel + addr_dCx_8bw + endloop +COpD6m16:; DEC d,x + addr_dCx_16brni + dec ax + flagsetnz16bnel + addr_dCx_16bw + endloop +COpDEm8: ; DEC a,x + addr_aCx_8brni + dec al + flagsetnz8bnel + addr_aCx_8bw + endloop +COpDEm16:; DEC a,x + addr_aCx_16brni + dec ax + flagsetnz16bnel + addr_aCx_16bw + endloop + +COpCAx8: ; DEX i + dec byte[xx] + mov al,[xx] + flagsetnz8b + endloop +COpCAx16:; DEX i + dec word[xx] + mov ax,[xx] + flagsetnz16b + endloop +COp88x8: ; DEY i + dec byte[xy] + mov al,[xy] + flagsetnz8b + endloop +COp88x16:; DEY i + dec word[xy] + mov ax,[xy] + flagsetnz16b + endloop + +COp41m8: ; EOR(d,x) + addr_BdCxB_8br + EORMacro8b +COp41m16:; EOR(d,x) + addr_BdCxB_16br + EORMacro16b +COp43m8: ; EOR d,s + addr_dCs_8br + EORMacro8b +COp43m16:; EOR d,s + addr_dCs_16br + EORMacro16b +COp45m8: ; EOR d + addr_d_8br + EORMacro8b +COp45m16:; EOR d + addr_d_16br + EORMacro16b +COp47m8: ; EOR [d] + addr_LdL_8br + EORMacro8b +COp47m16:; EOR [d] + addr_LdL_16br + EORMacro16b +COp49m8: ; EOR # + addr_I_8br + EORMacro8b +COp49m16:; EOR # + addr_I_16br + EORMacro16b +COp4Dm8: ; EOR a + addr_a_8br + EORMacro8b +COp4Dm16:; EOR a + addr_a_16br + EORMacro16b +COp4Fm8: ; EOR al + addr_al_8br + EORMacro8b +COp4Fm16:; EOR al + addr_al_16br + EORMacro16b +COp51m8: ; EOR(d),y + addr_BdBCy_8br + EORMacro8b +COp51m16:; EOR(d),y + addr_BdBCy_16br + EORMacro16b +COp52m8: ; EOR (d) + addr_BdB_8br + EORMacro8b +COp52m16:; EOR (d) + addr_BdB_16br + EORMacro16b +COp53m8: ; EOR(d,s),y + addr_BdCsBCy_8br + EORMacro8b +COp53m16:; EOR(d,s),y + addr_BdCsBCy_16br + EORMacro16b +COp55m8: ; EOR d,x + addr_dCx_8br + EORMacro8b +COp55m16:; EOR d,x + addr_dCx_16br + EORMacro16b +COp57m8: ; EOR [d],y + addr_LdLCy_8br + EORMacro8b +COp57m16:; EOR [d],y + addr_LdLCy_16br + EORMacro16b +COp59m8: ; EOR a,y + addr_aCy_8br + EORMacro8b +COp59m16:; EOR a,y + addr_aCy_16br + EORMacro16b +COp5Dm8: ; EORa,x + addr_aCx_8br + EORMacro8b +COp5Dm16:; EORa,x + addr_aCx_16br + EORMacro16b +COp5Fm8: ; EOR al,x + addr_alCx_8br + EORMacro8b +COp5Fm16:; EOR al,x + addr_alCx_16br + EORMacro16b + + +COp1Am8: ; INC A + addr_A_8brni + inc al + flagsetnz8bnel + addr_A_8bw + endloop +COp1Am16:; INC A + addr_A_16brni + inc ax + flagsetnz16bnel + addr_A_16bw + endloop +COpEEm8: ; INC a + addr_a_8brni + inc al + flagsetnz8bnel + addr_a_8bw + endloop +COpEEm16:; INC a + addr_a_16brni + inc ax + flagsetnz16bnel + addr_a_16bw + endloop +COpE6m8: ; INC d + addr_d_8brni + inc al + flagsetnz8bnel + addr_d_8bw + endloop +COpE6m16:; INC d + addr_d_16brni + inc ax + flagsetnz16bnel + addr_d_16bw + endloop +COpF6m8: ; INC d,x + addr_dCx_8brni + inc al + flagsetnz8bnel + addr_dCx_8bw + endloop +COpF6m16:; INC d,x + addr_dCx_16brni + inc ax + flagsetnz16bnel + addr_dCx_16bw + endloop +COpFEm8: ; INC a,x + addr_aCx_8brni + inc al + flagsetnz8bnel + addr_aCx_8bw + endloop +COpFEm16:; INC a,x + addr_aCx_16brni + inc ax + flagsetnz16bnel + addr_aCx_16bw + endloop + + +COpE8x8: ; INX i + inc byte[xx] + mov al,[xx] + flagsetnz8b + endloop +COpE8x16:; INX i + inc word[xx] + mov ax,[xx] + flagsetnz16b + endloop +COpC8x8: ; INY i + inc byte[xy] + mov al,[xy] + flagsetnz8b + endloop +COpC8x16:; INY i + inc word[xy] + mov ax,[xy] + flagsetnz16b + endloop + +COpDC: ; JML (a) + JMLMacro +COp4C: ; JMP a + JMPMacro4C +COp6C: ; JMP (a) + JMPMacro6C +COp7C: ; JMP(a,x) + JMPMacro7C +COp5C: ; JMP al + JMPMacro5C + +COp22: ; JSL al + JSLMacro +COp20: ; JSR a + JSRMacro20 +COpFC: ; JSR(a,x) + JSRMacroFC + +COpA1m8: ; LDA(d,x) + addr_BdCxB_8br + LDAMacro8b +COpA1m16:; LDA(d,x) + addr_BdCxB_16br + LDAMacro16b +COpA3m8: ; LDA d,s + addr_dCs_8br + LDAMacro8b +COpA3m16:; LDA d,s + addr_dCs_16br + LDAMacro16b +COpA5m8: ; LDA d + addr_d_8br + LDAMacro8b +COpA5m16:; LDA d + addr_d_16br + LDAMacro16b +COpA7m8: ; LDA [d] + addr_LdL_8br + LDAMacro8b +COpA7m16:; LDA [d] + addr_LdL_16br + LDAMacro16b +COpA9m8: ; LDA # + addr_I_8br + LDAMacro8b +COpA9m16:; LDA # + addr_I_16br + LDAMacro16b +COpADm8: ; LDA a + addr_a_8br + LDAMacro8b +COpADm16:; LDA a + addr_a_16br + LDAMacro16b +COpAFm8: ; LDA al + addr_al_8br + LDAMacro8b +COpAFm16:; LDA al + addr_al_16br + LDAMacro16b +COpB1m8: ; LDA(d),y + addr_BdBCy_8br + LDAMacro8b +COpB1m16:; LDA(d),y + addr_BdBCy_16br + LDAMacro16b +COpB2m8: ; LDA (d) + addr_BdB_8br + LDAMacro8b +COpB2m16:; LDA (d) + addr_BdB_16br + LDAMacro16b +COpB3m8: ; LDA(d,s),y + addr_BdCsBCy_8br + LDAMacro8b +COpB3m16:; LDA(d,s),y + addr_BdCsBCy_16br + LDAMacro16b +COpB5m8: ; LDA d,x + addr_dCx_8br + LDAMacro8b +COpB5m16:; LDA d,x + addr_dCx_16br + LDAMacro16b +COpB7m8: ; LDA [d],y + addr_LdLCy_8br + LDAMacro8b +COpB7m16:; LDA [d],y + addr_LdLCy_16br + LDAMacro16b +COpB9m8: ; LDA a,y + addr_aCy_8br + LDAMacro8b +COpB9m16:; LDA a,y + addr_aCy_16br + LDAMacro16b +COpBDm8: ; LDA a,x + addr_aCx_8br + LDAMacro8b +COpBDm16:; LDA a,x + addr_aCx_16br + LDAMacro16b +COpBFm8: ; LDA al,x + addr_alCx_8br + LDAMacro8b +COpBFm16:; LDA al,x + addr_alCx_16br + LDAMacro16b + +COpA2x8: ; LDX # + addr_I_8br + LDXMacro8b +COpA2x16:; LDX # + addr_I_16br + LDXMacro16b +COpA6x8: ; LDX d + addr_d_8br + LDXMacro8b +COpA6x16:; LDX d + addr_d_16br + LDXMacro16b +COpAEx8: ; LDX a + addr_a_8br + LDXMacro8b +COpAEx16:; LDX a + addr_a_16br + LDXMacro16b +COpB6x8: ; LDX d,y + addr_dCy_8br + LDXMacro8b +COpB6x16:; LDX d,y + addr_dCy_16br + LDXMacro16b +COpBEx8: ; LDX a,y + addr_aCy_8br + LDXMacro8b +COpBEx16:; LDX a,y + addr_aCy_16br + LDXMacro16b + +COpA0x8: ; LDY # + addr_I_8br + LDYMacro8b +COpA0x16:; LDY # + addr_I_16br + LDYMacro16b +COpA4x8: ; LDY d + addr_d_8br + LDYMacro8b +COpA4x16:; LDY d + addr_d_16br + LDYMacro16b +COpACx8: ; LDY a + addr_a_8br + LDYMacro8b +COpACx16:; LDY a + addr_a_16br + LDYMacro16b +COpB4x8: ; LDY d,x + addr_dCx_8br + LDYMacro8b +COpB4x16:; LDY d,x + addr_dCx_16br + LDYMacro16b +COpBCx8: ; LDY a,x + addr_aCx_8br + LDYMacro8b +COpBCx16:; LDY a,x + addr_aCx_16br + LDYMacro16b + +COp46m8: ; LSR d + addr_d_8brni + LSRMacro8b + addr_d_8bw + endloop +COp46m16:; LSR d + addr_d_16brni + LSRMacro16b + addr_d_16bw + endloop +COp4Am8: ; LSR A + addr_A_8brni + LSRMacro8b + addr_A_8bw + endloop +COp4Am16:; LSR A + addr_A_16brni + LSRMacro16b + addr_A_16bw + endloop +COp4Em8: ; LSR a + addr_a_8brni + LSRMacro8b + addr_a_8bw + endloop +COp4Em16:; LSR a + addr_a_16brni + LSRMacro16b + addr_a_16bw + endloop +COp56m8: ; LSR d,x + addr_dCx_8brni + LSRMacro8b + addr_dCx_8bw + endloop +COp56m16:; LSR d,x + addr_dCx_16brni + LSRMacro16b + addr_dCx_16bw + endloop +COp5Em8: ; LSRa,x + addr_aCx_8brni + LSRMacro8b + addr_aCx_8bw + endloop +COp5Em16:; LSRa,x + addr_aCx_16brni + LSRMacro16b + addr_aCx_16bw + endloop + +COp54: ; MVN xya + MVNMacro +COp44: ; MVP xya + MVPMacro + +COpEA: ; NOP i + endloop + +COp01m8: ; ORA(d,x) + addr_BdCxB_8br + ORAMacro8b +COp01m16:; ORA(d,x) + addr_BdCxB_16br + ORAMacro16b +COp03m8: ; ORA d,s + addr_dCs_8br + ORAMacro8b +COp03m16:; ORA d,s + addr_dCs_16br + ORAMacro16b +COp05m8: ; ORA d + addr_d_8br + ORAMacro8b +COp05m16:; ORA d + addr_d_16br + ORAMacro16b +COp07m8: ; ORA [d] + addr_LdL_8br + ORAMacro8b +COp07m16:; ORA [d] + addr_LdL_16br + ORAMacro16b +COp09m8: ; ORA # + addr_I_8br + ORAMacro8b +COp09m16:; ORA # + addr_I_16br + ORAMacro16b +COp0Dm8: ; ORA a + addr_a_8br + ORAMacro8b +COp0Dm16:; ORA a + addr_a_16br + ORAMacro16b +COp0Fm8: ; ORA al + addr_al_8br + ORAMacro8b +COp0Fm16:; ORA al + addr_al_16br + ORAMacro16b +COp11m8: ; ORA(d),y + addr_BdBCy_8br + ORAMacro8b +COp11m16:; ORA(d),y + addr_BdBCy_16br + ORAMacro16b +COp12m8: ; ORA(d) + addr_BdB_8br + ORAMacro8b +COp12m16:; ORA(d) + addr_BdB_16br + ORAMacro16b +COp13m8: ; ORA(d,s),y + addr_BdCsBCy_8br + ORAMacro8b +COp13m16:; ORA(d,s),y + addr_BdCsBCy_16br + ORAMacro16b +COp15m8: ; ORA d,x + addr_dCx_8br + ORAMacro8b +COp15m16:; ORA d,x + addr_dCx_16br + ORAMacro16b +COp17m8: ; ORA [d],y + addr_LdLCy_8br + ORAMacro8b +COp17m16:; ORA [d],y + addr_LdLCy_16br + ORAMacro16b +COp19m8: ; ORA a,y + addr_aCy_8br + ORAMacro8b +COp19m16:; ORA a,y + addr_aCy_16br + ORAMacro16b +COp1Dm8: ; ORA a,x + addr_aCx_8br + ORAMacro8b +COp1Dm16:; ORA a,x + addr_aCx_16br + ORAMacro16b +COp1Fm8: ; ORA al,x + addr_alCx_8br + ORAMacro8b +COp1Fm16:; ORA al,x + addr_alCx_16br + ORAMacro16b + +COpF4: ; PEA s + PEAMacro +COpD4: ; PEI s + PEIMacro +COp62: ; PER s + PERMacro + +COp48m8: ; PHA s + PUSHMacro8b [xa] +COp48m16:; PHA s + PUSHMacro16b [xa], [xa+1] +COp8B: ; PHB s + PUSHMacro8b [xdb] +COp0B: ; PHD s + PUSHMacro16b [xd], [xd+1] +COp4B: ; PHK s + PUSHMacro8b [xpb] +COp08: ; PHP s + PUSHMacro8bp +COpDAx8: ; PHX s + PUSHMacro8b [xx] +COpDAx16:; PHX s + PUSHMacro16b [xx], [xx+1] +COp5Ax8: ; PHY s + PUSHMacro8b [xy] +COp5Ax16:; PHY s + PUSHMacro16b [xy], [xy+1] + +COp68m8: ; PLA s + POPMacro8b [xa] +COp68m16:; PLA s + POPMacro16b [xa], [xa+1] +COpAB: ; PLB s + POPMacro8b [xdb] +COp2B: ; PLD s + POPMacro16bd [xd], [xd+1] +COp28: ; PLP s + POPMacroP +COpFAx8: ; PLX s + POPMacro8b [xx] +COpFAx16:; PLX s + POPMacro16b [xx], [xx+1] +COp7Ax8: ; PLY s + POPMacro8b [xy] +COp7Ax16:; PLY s + POPMacro16b [xy], [xy+1] + +COpC2: ; REP # + REPMacro + +COp26m8: ; ROL d + addr_d_8brni + ROLMacro8b + addr_d_8bw + endloop +COp26m16:; ROL d + addr_d_16brni + ROLMacro16b + addr_d_16bw + endloop +COp2Am8: ; ROL A + addr_A_8brni + ROLMacro8b + addr_A_8bw + endloop +COp2Am16:; ROL A + addr_A_16brni + ROLMacro16b + addr_A_16bw + endloop +COp2Em8: ; ROL a + addr_a_8brni + ROLMacro8b + addr_a_8bw + endloop +COp2Em16:; ROL a + addr_a_16brni + ROLMacro16b + addr_a_16bw + endloop +COp36m8: ; ROL d,x + addr_dCx_8brni + ROLMacro8b + addr_dCx_8bw + endloop +COp36m16:; ROL d,x + addr_dCx_16brni + ROLMacro16b + addr_dCx_16bw + endloop +COp3Em8: ; ROL a,x + addr_aCx_8brni + ROLMacro8b + addr_aCx_8bw + endloop +COp3Em16:; ROL a,x + addr_aCx_16brni + ROLMacro16b + addr_aCx_16bw + endloop + +COp66m8: ; ROR d + addr_d_8brni + RORMacro8b + addr_d_8bw + endloop +COp66m16:; ROR d + addr_d_16brni + RORMacro16b + addr_d_16bw + endloop +COp6Am8: ; ROR A + addr_A_8brni + RORMacro8b + addr_A_8bw + endloop +COp6Am16:; ROR A + addr_A_16brni + RORMacro16b + addr_A_16bw + endloop +COp6Em8: ; ROR a + addr_a_8brni + RORMacro8b + addr_a_8bw + endloop +COp6Em16:; ROR a + addr_a_16brni + RORMacro16b + addr_a_16bw + endloop +COp76m8: ; ROR d,x + addr_dCx_8brni + RORMacro8b + addr_dCx_8bw + endloop +COp76m16:; ROR d,x + addr_dCx_16brni + RORMacro16b + addr_dCx_16bw + endloop +COp7Em8: ; ROR a,x + addr_aCx_8brni + RORMacro8b + addr_aCx_8bw + endloop +COp7Em16:; ROR a,x + addr_aCx_16brni + RORMacro16b + addr_aCx_16bw + endloop + +COp40: ; RTI s + RTIMacro +COp6B: ; RTL s + RTLMacro +COp60: ; RTS s + RTSMacro + +COpE1m8nd: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bnd +COpE1m16nd: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bnd +COpE1m8d: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bd +COpE1m16d: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bd +COpE3m8nd: ; SBC d,s + addr_dCs_8br + SBCMacro8bnd +COpE3m16nd: ; SBC d,s + addr_dCs_16br + SBCMacro16bnd +COpE3m8d: ; SBC d,s + addr_dCs_8br + SBCMacro8bd +COpE3m16d: ; SBC d,s + addr_dCs_16br + SBCMacro16bd +COpE5m8nd: ; SBC d + addr_d_8br + SBCMacro8bnd +COpE5m16nd: ; SBC d + addr_d_16br + SBCMacro16bnd +COpE5m8d: ; SBC d + addr_d_8br + SBCMacro8bd +COpE5m16d: ; SBC d + addr_d_16br + SBCMacro16bd +COpE7m8nd: ; SBC [d] + addr_LdL_8br + SBCMacro8bnd +COpE7m16nd: ; SBC [d] + addr_LdL_16br + SBCMacro16bnd +COpE7m8d: ; SBC [d] + addr_LdL_8br + SBCMacro8bd +COpE7m16d: ; SBC [d] + addr_LdL_16br + SBCMacro16bd +COpE9m8nd: ; SBC # + addr_I_8br + SBCMacro8bnd +COpE9m16nd: ; SBC # + addr_I_16br + SBCMacro16bnd +COpE9m8d: ; SBC # + addr_I_8br + SBCMacro8bd +COpE9m16d: ; SBC # + addr_I_16br + SBCMacro16bd +COpEDm8nd: ; SBC a + addr_a_8br + SBCMacro8bnd +COpEDm16nd: ; SBC a + addr_a_16br + SBCMacro16bnd +COpEDm8d: ; SBC a + addr_a_8br + SBCMacro8bd +COpEDm16d: ; SBC a + addr_a_16br + SBCMacro16bd +COpEFm8nd: ; SBC al + addr_al_8br + SBCMacro8bnd +COpEFm16nd: ; SBC al + addr_al_16br + SBCMacro16bnd +COpEFm8d: ; SBC al + addr_al_8br + SBCMacro8bd +COpEFm16d: ; SBC al + addr_al_16br + SBCMacro16bd +COpF1m8nd: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bnd +COpF1m16nd: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bnd +COpF1m8d: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bd +COpF1m16d: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bd +COpF2m8nd: ; SBC (d) + addr_BdB_8br + SBCMacro8bnd +COpF2m16nd: ; SBC (d) + addr_BdB_16br + SBCMacro16bnd +COpF2m8d: ; SBC (d) + addr_BdB_8br + SBCMacro8bd +COpF2m16d: ; SBC (d) + addr_BdB_16br + SBCMacro16bd +COpF3m8nd: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bnd +COpF3m16nd: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bnd +COpF3m8d: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bd +COpF3m16d: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bd +COpF5m8nd: ; SBC d,x + addr_dCx_8br + SBCMacro8bnd +COpF5m16nd: ; SBC d,x + addr_dCx_16br + SBCMacro16bnd +COpF5m8d: ; SBC d,x + addr_dCx_8br + SBCMacro8bd +COpF5m16d: ; SBC d,x + addr_dCx_16br + SBCMacro16bd +COpF7m8nd: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bnd +COpF7m16nd: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bnd +COpF7m8d: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bd +COpF7m16d: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bd +COpF9m8nd: ; SBC a,y + addr_aCy_8br + SBCMacro8bnd +COpF9m16nd: ; SBC a,y + addr_aCy_16br + SBCMacro16bnd +COpF9m8d: ; SBC a,y + addr_aCy_8br + SBCMacro8bd +COpF9m16d: ; SBC a,y + addr_aCy_16br + SBCMacro16bd +COpFDm8nd: ; SBC a,x + addr_aCx_8br + SBCMacro8bnd +COpFDm16nd: ; SBC a,x + addr_aCx_16br + SBCMacro16bnd +COpFDm8d: ; SBC a,x + addr_aCx_8br + SBCMacro8bd +COpFDm16d: ; SBC a,x + addr_aCx_16br + SBCMacro16bd +COpFFm8nd: ; SBC al,x + addr_alCx_8br + SBCMacro8bnd +COpFFm16nd: ; SBC al,x + addr_alCx_16br + SBCMacro16bnd +COpFFm8d: ; SBC al,x + addr_alCx_8br + SBCMacro8bd +COpFFm16d: ; SBC al,x + addr_alCx_16br + SBCMacro16bd + +COp38: ; SEC i + mov dword[flagc],0FFh + endloop +COpF8: ; SED i + or dl,08h + mov bl,dl + mov edi,[tableadb+ebx*4] + endloop +COp78: ; SEI i + or dl,04h + endloop + +COpE2: ; SEP # + SEPMacro + +COp81m8: ; STA(d,x) + STAMacro8b + addr_BdCxB_8bw + endloop +COp81m16:; STA(d,x) + STAMacro16b + addr_BdCxB_16bw + endloop +COp83m8: ; STA d,s + STAMacro8b + addr_dCs_8bw + endloop +COp83m16:; STA d,s + STAMacro16b + addr_dCs_16bw + endloop +COp85m8: ; STA d + STAMacro8b + addr_d_8bw + endloop +COp85m16:; STA d + STAMacro16b + addr_d_16bw + endloop +COp87m8: ; STA [d] + STAMacro8b + addr_LdL_8bw + endloop +COp87m16:; STA [d] + STAMacro16b + addr_LdL_16bw + endloop +COp8Dm8: ; STA a + STAMacro8b + addr_a_8bw + endloop +COp8Dm16:; STA a + STAMacro16b + addr_a_16bw + endloop +COp8Fm8: ; STA al + STAMacro8b + addr_al_8bw + endloop +COp8Fm16:; STA al + STAMacro16b + addr_al_16bw + endloop +COp91m8: ; STA(d),y + STAMacro8b + addr_BdBCy_8bw + endloop +COp91m16:; STA(d),y + STAMacro16b + addr_BdBCy_16bw + endloop +COp92m8: ; STA (d) + STAMacro8b + addr_BdB_8bw + endloop +COp92m16:; STA (d) + STAMacro16b + addr_BdB_16bw + endloop +COp93m8: ; STA(d,s),y + STAMacro8b + addr_BdCsBCy_8bw + endloop +COp93m16:; STA(d,s),y + STAMacro16b + addr_BdCsBCy_16bw + endloop +COp95m8: ; STA d,x + STAMacro8b + addr_dCx_8bw + endloop +COp95m16:; STA d,x + STAMacro16b + addr_dCx_16bw + endloop +COp97m8: ; STA [d],y + STAMacro8b + addr_LdLCy_8bw + endloop +COp97m16:; STA [d],y + STAMacro16b + addr_LdLCy_16bw + endloop +COp99m8: ; STA a,y + STAMacro8b + addr_aCy_8bw + endloop +COp99m16:; STA a,y + STAMacro16b + addr_aCy_16bw + endloop +COp9Dm8: ; STA a,x + STAMacro8b + addr_aCx_8bw + endloop +COp9Dm16:; STA a,x + STAMacro16b + addr_aCx_16bw + endloop +COp9Fm8: ; STA al,x + STAMacro8b + addr_alCx_8bw + endloop +COp9Fm16:; STA al,x + STAMacro16b + addr_alCx_16bw + endloop + +COp86x8: ; STX d + STXMacro8b + addr_d_8bw + endloop +COp86x16:; STX d + STXMacro16b + addr_d_16bw + endloop +COp8Ex8: ; STX a + STXMacro8b + addr_a_8bw + endloop +COp8Ex16:; STX a + STXMacro16b + addr_a_16bw + endloop +COp96x8: ; STX d,y + STXMacro8b + addr_dCy_8bw + endloop +COp96x16:; STX d,y + STXMacro16b + addr_dCy_16bw + endloop + +COp84x8: ; STY d + STYMacro8b + addr_d_8bw + endloop +COp84x16:; STY d + STYMacro16b + addr_d_16bw + endloop +COp8Cx8: ; STY a + STYMacro8b + addr_a_8bw + endloop +COp8Cx16:; STY a + STYMacro16b + addr_a_16bw + endloop +COp94x8: ; STYd,x + STYMacro8b + addr_dCx_8bw + endloop +COp94x16:; STYd,x + STYMacro16b + addr_dCx_16bw + endloop + +COpDB: ; STP i + dec esi + endloop + +COp64m8: ; STZ d + xor al,al + addr_d_8bw + endloop +COp64m16:; STZ d + xor eax,eax + addr_d_16bw + endloop +COp74m8: ; STZ d,x + xor al,al + addr_dCx_8bw + endloop +COp74m16:; STZ d,x + xor eax,eax + addr_dCx_16bw + endloop +COp9Cm8: ; STZ a + xor al,al + addr_a_8bw + endloop +COp9Cm16:; STZ a + xor eax,eax + addr_a_16bw + endloop +COp9Em8: ; STZ a,x + xor al,al + addr_aCx_8bw + endloop +COp9Em16:; STZ a,x + xor eax,eax + addr_aCx_16bw + endloop + +COp14m8: ; TRB d + addr_d_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cl,al + jz .zero + mov word[flagnz],1 + not cl + and al,cl + addr_d_8bw + endloop +.zero + mov word[flagnz],0 + not cl + and al,cl + addr_d_8bw + endloop +COp14m16:; TRB d + addr_d_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[flagnz],1 + not cx + and ax,cx + addr_d_16bw + endloop +.zero + mov word[flagnz],0 + not cx + and ax,cx + addr_d_16bw + endloop +COp1Cm8: ; TRB a + addr_a_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cl,al + jz .zero + mov word[flagnz],1 + not cl + and al,cl + addr_a_8bw + endloop +.zero + mov word[flagnz],0 + not cl + and al,cl + addr_a_8bw + endloop +COp1Cm16:; TRB a + addr_a_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[flagnz],1 + not cx + and ax,cx + addr_a_16bw + endloop +.zero + mov word[flagnz],0 + not cx + and ax,cx + addr_a_16bw + endloop + +COp04m8: ; TSB d + addr_d_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test al,cl + jz .zero + mov word[flagnz],1 + or al,cl + addr_d_8bw + endloop +.zero + mov word[flagnz],0 + or al,cl + addr_d_8bw + endloop +COp04m16:; TSB d + addr_d_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[flagnz],1 + or ax,cx + addr_d_16bw + endloop +.zero + mov word[flagnz],0 + or ax,cx + addr_d_16bw + endloop +COp0Cm8: ; TSB a + addr_a_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test al,cl + jz .zero + mov word[flagnz],1 + or al,cl + addr_a_8bw + endloop +.zero + mov word[flagnz],0 + or al,cl + addr_a_8bw + endloop +COp0Cm16:; TSB a + addr_a_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[flagnz],1 + or ax,cx + addr_a_16bw + endloop +.zero + mov word[flagnz],0 + or ax,cx + addr_a_16bw + endloop + +COpAAx8: ; TAX i + mov al,[xa] + mov [xx],al + flagsetnz8b + endloop +COpAAx16:; TAX i + mov ax,[xa] + mov [xx],ax + flagsetnz16b + endloop +COpA8x8: ; TAY i + mov al,[xa] + mov [xy],al + flagsetnz8b + endloop +COpA8x16:; TAY i + mov ax,[xa] + mov [xy],ax + flagsetnz16b + endloop +COp5B: ; TCD i + mov ax,[xa] + mov [xd],ax + call UpdateDPage + flagsetnz16b + endloop +COp1B: ; TCS i + mov ax,[xa] + mov [xs],ax + endloop +COp7B: ; TDC i + mov ax,[xd] + mov [xa],ax + flagsetnz16b + endloop +COp3B: ; TSC i + mov ax,[xs] + mov [xa],ax + flagsetnz16b + endloop +COpBAx8: ; TSX i + mov al,[xs] + mov [xx],al + flagsetnz8b + endloop +COpBAx16:; TSX i + mov ax,[xs] + mov [xx],ax + flagsetnz16b + endloop +COp8Am8: ; TXA i + mov al,[xx] + mov [xa],al + flagsetnz8b + endloop +COp8Am16:; TXA i + mov ax,[xx] + mov [xa],ax + flagsetnz16b + endloop +COp9A: ; TXS i + mov ax,[xx] + mov [xs],ax + test byte[xe],1 + jnz .emul + endloop +.emul + mov byte[xs+1],1 + endloop +COp9Bx8: ; TXY i + mov al,[xx] + mov [xy],al + flagsetnz8b + endloop +COp9Bx16:; TXY i + mov ax,[xx] + mov [xy],ax + flagsetnz16b + endloop +COp98m8: ; TYA i + mov al,[xy] + mov [xa],al + flagsetnz8b + endloop +COp98m16:; TYA i + mov ax,[xy] + mov [xa],ax + flagsetnz16b + endloop +COpBBx8: ; TYX i + mov al,[xy] + mov [xx],al + flagsetnz8b + endloop +COpBBx16:; TYX i + mov ax,[xy] + mov [xx],ax + flagsetnz16b + endloop + +COpCB: ; WAI i + WAIMacro + +COpEB: ; XBA i + mov ah,[xa] + mov al,[xa+1] + mov [xa],ax + flagsetnz8b + endloop + +COpFB: ; XCE i + XCEMacro + +COp42: ; WDM + inc esi + endloop + \ No newline at end of file diff --git a/zsnes/src/cpu/e65816c.inc b/zsnes/src/cpu/e65816c.inc new file mode 100644 index 00000000..7beeccd4 --- /dev/null +++ b/zsnes/src/cpu/e65816c.inc @@ -0,0 +1,1987 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM brkv,brkv8,changeexecloop,copv,copv8,curexecstate,curnmi,execloop +EXTSYM initaddrl,intrset,membank0r16,membank0r8 +EXTSYM membank0w16,membank0w8,memtabler16,memtabler8,memtablew16,memtablew8 +EXTSYM nmistatus,regaccessbankr8,snesmap2,snesmmap,stackand,stackor +EXTSYM wramdata,xa,xd,xdb,xe,xirqb,xpb,xpc,xs,xx,xy +EXTSYM switchtovirq,UpdateDPage +EXTSYM DPageR8,DPageW8,DPageR16,DPageW16 + + + + + +; B = ( or ) +; C = , +; L = [ or ] +; I = # + + +COp61m8nd: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bnd +COp61m16nd: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bnd +COp61m8d: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bd +COp61m16d: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bd +COp63m8nd: ; ADC d,s + addr_dCs_8br + ADCMacro8bnd +COp63m16nd: ; ADC d,s + addr_dCs_16br + ADCMacro16bnd +COp63m8d: ; ADC d,s + addr_dCs_8br + ADCMacro8bd +COp63m16d: ; ADC d,s + addr_dCs_16br + ADCMacro16bd +COp65m8nd: ; ADC d + addr_d_8br + ADCMacro8bnd +COp65m16nd: ; ADC d + addr_d_16br + ADCMacro16bnd +COp65m8d: ; ADC d + addr_d_8br + ADCMacro8bd +COp65m16d: ; ADC d + addr_d_16br + ADCMacro16bd +COp67m8nd: ; ADC [d] + addr_LdL_8br + ADCMacro8bnd +COp67m16nd: ; ADC [d] + addr_LdL_16br + ADCMacro16bnd +COp67m8d: ; ADC [d] + addr_LdL_8br + ADCMacro8bd +COp67m16d: ; ADC [d] + addr_LdL_16br + ADCMacro16bd +COp69m8nd: ; ADC # + addr_I_8br + ADCMacro8bnd +COp69m16nd: ; ADC # + addr_I_16br + ADCMacro16bnd +COp69m8d: ; ADC # + addr_I_8br + ADCMacro8bd +COp69m16d: ; ADC # + addr_I_16br + ADCMacro16bd +COp6Dm8nd: ; ADC a + addr_a_8br + ADCMacro8bnd +COp6Dm16nd: ; ADC a + addr_a_16br + ADCMacro16bnd +COp6Dm8d: ; ADC a + addr_a_8br + ADCMacro8bd +COp6Dm16d: ; ADC a + addr_a_16br + ADCMacro16bd +COp6Fm8nd: ; ADC al + addr_al_8br + ADCMacro8bnd +COp6Fm16nd: ; ADC al + addr_al_16br + ADCMacro16bnd +COp6Fm8d: ; ADC al + addr_al_8br + ADCMacro8bd +COp6Fm16d: ; ADC al + addr_al_16br + ADCMacro16bd +COp71m8nd: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bnd +COp71m16nd: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bnd +COp71m8d: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bd +COp71m16d: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bd +COp72m8nd: ; ADC (d) + addr_BdB_8br + ADCMacro8bnd +COp72m16nd: ; ADC (d) + addr_BdB_16br + ADCMacro16bnd +COp72m8d: ; ADC (d) + addr_BdB_8br + ADCMacro8bd +COp72m16d: ; ADC (d) + addr_BdB_16br + ADCMacro16bd +COp73m8nd: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bnd +COp73m16nd: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bnd +COp73m8d: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bd +COp73m16d: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bd +COp75m8nd: ; ADC d,x + addr_dCx_8br + ADCMacro8bnd +COp75m16nd: ; ADC d,x + addr_dCx_16br + ADCMacro16bnd +COp75m8d: ; ADC d,x + addr_dCx_8br + ADCMacro8bd +COp75m16d: ; ADC d,x + addr_dCx_16br + ADCMacro16bd +COp77m8nd: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bnd +COp77m16nd: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bnd +COp77m8d: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bd +COp77m16d: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bd +COp79m8nd: ; ADC a,y + addr_aCy_8br + ADCMacro8bnd +COp79m16nd: ; ADC a,y + addr_aCy_16br + ADCMacro16bnd +COp79m8d: ; ADC a,y + addr_aCy_8br + ADCMacro8bd +COp79m16d: ; ADC a,y + addr_aCy_16br + ADCMacro16bd +COp7Dm8nd: ; ADC a,x + addr_aCx_8br + ADCMacro8bnd +COp7Dm16nd: ; ADC a,x + addr_aCx_16br + ADCMacro16bnd +COp7Dm8d: ; ADC a,x + addr_aCx_8br + ADCMacro8bd +COp7Dm16d: ; ADC a,x + addr_aCx_16br + ADCMacro16bd +COp7Fm8nd: ; ADC al,x + addr_alCx_8br + ADCMacro8bnd +COp7Fm16nd: ; ADC al,x + addr_alCx_16br + ADCMacro16bnd +COp7Fm8d: ; ADC al,x + addr_alCx_8br + ADCMacro8bd +COp7Fm16d: ; ADC al,x + addr_alCx_16br + ADCMacro16bd + +COp21m8: ; AND(d,x) + addr_BdCxB_8br + ANDMacro8b +COp21m16:; AND(d,x) + addr_BdCxB_16br + ANDMacro16b +COp23m8: ; AND d,s + addr_dCs_8br + ANDMacro8b +COp23m16:; AND d,s + addr_dCs_16br + ANDMacro16b +COp25m8: ; AND d + addr_d_8br + ANDMacro8b +COp25m16:; AND d + addr_d_16br + ANDMacro16b +COp27m8: ; AND [d] + addr_LdL_8br + ANDMacro8b +COp27m16:; AND [d] + addr_LdL_16br + ANDMacro16b +COp29m8: ; AND # + addr_I_8br + ANDMacro8b +COp29m16:; AND # + addr_I_16br + ANDMacro16b +COp2Dm8: ; AND a + addr_a_8br + ANDMacro8b +COp2Dm16:; AND a + addr_a_16br + ANDMacro16b +COp2Fm8: ; AND al + addr_al_8br + ANDMacro8b +COp2Fm16:; AND al + addr_al_16br + ANDMacro16b +COp31m8: ; AND(d),y + addr_BdBCy_8br + ANDMacro8b +COp31m16:; AND(d),y + addr_BdBCy_16br + ANDMacro16b +COp32m8: ; AND (d) + addr_BdB_8br + ANDMacro8b +COp32m16:; AND (d) + addr_BdB_16br + ANDMacro16b +COp33m8: ; AND(d,s),y + addr_BdCsBCy_8br + ANDMacro8b +COp33m16:; AND(d,s),y + addr_BdCsBCy_16br + ANDMacro16b +COp35m8: ; AND d,x + addr_dCx_8br + ANDMacro8b +COp35m16:; AND d,x + addr_dCx_16br + ANDMacro16b +COp37m8: ; AND [d],y + addr_LdLCy_8br + ANDMacro8b +COp37m16:; AND [d],y + addr_LdLCy_16br + ANDMacro16b +COp39m8: ; AND a,y + addr_aCy_8br + ANDMacro8b +COp39m16:; AND a,y + addr_aCy_16br + ANDMacro16b +COp3Dm8: ; AND a,x + addr_aCx_8br + ANDMacro8b +COp3Dm16:; AND a,x + addr_aCx_16br + ANDMacro16b +COp3Fm8: ; AND al,x + addr_alCx_8br + ANDMacro8b +COp3Fm16:; AND al,x + addr_alCx_16br + ANDMacro16b + +COp06m8: ; ASL d + addr_d_8brni + ASLMacro8b + addr_d_8bw + endloop +COp06m16:; ASL d + addr_d_16brni + ASLMacro16b + addr_d_16bw + endloop +COp0Am8: ; ASL A + addr_A_8brni + ASLMacro8b + addr_A_8bw + endloop +COp0Am16:; ASL A + addr_A_16brni + ASLMacro16b + addr_A_16bw + endloop +COp0Em8: ; ASL a + addr_a_8brni + ASLMacro8b + addr_a_8bw + endloop +COp0Em16:; ASL a + addr_a_16brni + ASLMacro16b + addr_a_16bw + endloop +COp16m8: ; ASL d,x + addr_dCx_8brni + ASLMacro8b + addr_dCx_8bw + endloop +COp16m16:; ASL d,x + addr_dCx_16brni + ASLMacro16b + addr_dCx_16bw + endloop +COp1Em8: ; ASL a,x + addr_aCx_8brni + ASLMacro8b + addr_aCx_8bw + endloop +COp1Em16:; ASL a,x + addr_aCx_16brni + ASLMacro16b + addr_aCx_16bw + endloop + +COp90: ; BCC r + test byte[flagc],01h + jnz .skip + JumpMacro +COpB0: ; BCS r + test byte[flagc],01h + jz .skip + JumpMacro +COpF0: ; BEQ r + test dword[flagnz],0FFFFh + jnz .skip + JumpMacro +COp30: ; BMI r + test dword[flagnz],018000h + jz .skip + JumpMacro +COpD0: ; BNE r + test dword[flagnz],0FFFFh + jz .skip + JumpMacro +COp10: ; BPL r + test dword[flagnz],018000h + jnz .skip + JumpMacro +COp80: ; BRA r + movsx eax,byte[esi] + inc esi + add esi,eax + endloop +COp50: ; BVC r + test dword[flago],0FFh + jnz .skip + JumpMacro +COp70: ; BVS r + test dword[flago],0FFh + jz .skip + JumpMacro + +; BIT instruction does not affect N and V flags when using immediate +; addressing mode. When using other addressing modes, the N and V flags + +COp89m8: ; BIT # + BITMacroim8b +COp89m16:; BIT # + BITMacroim16b + +COp24m8: ; BIT d + addr_d_8br + BITMacro8b +COp24m16:; BIT d + addr_d_16br + BITMacro16b +COp2Cm8: ; BIT a + addr_a_8br + BITMacro8b +COp2Cm16:; BIT a + addr_a_16br + BITMacro16b +COp34m8: ; BIT d,x + addr_dCx_8br + BITMacro8b +COp34m16:; BIT d,x + addr_dCx_16br + BITMacro16b +COp3Cm8: ; BIT a,x + addr_aCx_8br + BITMacro8b +COp3Cm16:; BIT a,x + addr_aCx_16br + BITMacro16b + +COp00: ; BRK s + BRKMacro + +COp82: ; BRL rl + BRLMacro + +COp18: ; CLC i + mov dword[flagc],0 + endloop +COpD8: ; CLD i + and dl,0F7h + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop +COp58: ; CLI i + and dl,0FBh + endloop +COpB8: ; CLV i + mov dword[flago],0 + endloop + +COpC1m8: ; CMP(d,x) + addr_BdCxB_8br + CMPMacro8b +COpC1m16:; CMP(d,x) + addr_BdCxB_16br + CMPMacro16b +COpC3m8: ; CMP d,s + addr_dCs_8br + CMPMacro8b +COpC3m16:; CMP d,s + addr_dCs_16br + CMPMacro16b +COpC5m8: ; CMP d + addr_d_8br + CMPMacro8b +COpC5m16:; CMP d + addr_d_16br + CMPMacro16b +COpC7m8: ; CMP [d] + addr_LdL_8br + CMPMacro8b +COpC7m16:; CMP [d] + addr_LdL_16br + CMPMacro16b +COpC9m8: ; CMP # + addr_I_8br + CMPMacro8b +COpC9m16:; CMP # + addr_I_16br + CMPMacro16b +COpCDm8: ; CMP a + addr_a_8br + CMPMacro8b +COpCDm16:; CMP a + addr_a_16br + CMPMacro16b +COpCFm8: ; CMP al + addr_al_8br + CMPMacro8b +COpCFm16:; CMP al + addr_al_16br + CMPMacro16b +COpD1m8: ; CMP(d),y + addr_BdBCy_8br + CMPMacro8b +COpD1m16:; CMP(d),y + addr_BdBCy_16br + CMPMacro16b +COpD2m8: ; CMP (d) + addr_BdB_8br + CMPMacro8b +COpD2m16:; CMP (d) + addr_BdB_16br + CMPMacro16b +COpD3m8: ; CMP(d,s),y + addr_BdCsBCy_8br + CMPMacro8b +COpD3m16:; CMP(d,s),y + addr_BdCsBCy_16br + CMPMacro16b +COpD5m8: ; CMP d,x + addr_dCx_8br + CMPMacro8b +COpD5m16:; CMP d,x + addr_dCx_16br + CMPMacro16b +COpD7m8: ; CMP [d],y + addr_LdLCy_8br + CMPMacro8b +COpD7m16:; CMP [d],y + addr_LdLCy_16br + CMPMacro16b +COpD9m8: ; CMP a,y + addr_aCy_8br + CMPMacro8b +COpD9m16:; CMP a,y + addr_aCy_16br + CMPMacro16b +COpDDm8: ; CMP a,x + addr_aCx_8br + CMPMacro8b +COpDDm16:; CMP a,x + addr_aCx_16br + CMPMacro16b +COpDFm8: ; CMP al,x + addr_alCx_8br + CMPMacro8b +COpDFm16:; CMP al,x + addr_alCx_16br + CMPMacro16b + +COp02: ; COP s + COPMacro + +COpE0x8: ; CPX # + addr_I_8br + CPXMacro8b +COpE0x16:; CPX # + addr_I_16br + CPXMacro16b +COpE4x8: ; CPX d + addr_d_8br + CPXMacro8b +COpE4x16:; CPX d + addr_d_16br + CPXMacro16b +COpECx8: ; CPX a + addr_a_8br + CPXMacro8b +COpECx16:; CPX a + addr_a_16br + CPXMacro16b + +COpC0x8: ; CPY # + addr_I_8br + CPYMacro8b +COpC0x16:; CPY # + addr_I_16br + CPYMacro16b +COpC4x8: ; CPY d + addr_d_8br + CPYMacro8b +COpC4x16:; CPY d + addr_d_16br + CPYMacro16b +COpCCx8: ; CPY a + addr_a_8br + CPYMacro8b +COpCCx16:; CPY a + addr_a_16br + CPYMacro16b + +COp3Am8: ; DEC A + addr_A_8brni + dec al + flagsetnz8bnel + addr_A_8bw + endloop +COp3Am16:; DEC A + addr_A_16brni + dec ax + flagsetnz16bnel + addr_A_16bw + endloop +COpCEm8: ; DEC a + addr_a_8brni + dec al + flagsetnz8bnel + addr_a_8bw + endloop +COpCEm16:; DEC a + addr_a_16brni + dec ax + flagsetnz16bnel + addr_a_16bw + endloop +COpC6m8: ; DEC d + addr_d_8brni + dec al + flagsetnz8bnel + addr_d_8bw + endloop +COpC6m16:; DEC d + addr_d_16brni + dec ax + flagsetnz16bnel + addr_d_16bw + endloop +COpD6m8: ; DEC d,x + addr_dCx_8brni + dec al + flagsetnz8bnel + addr_dCx_8bw + endloop +COpD6m16:; DEC d,x + addr_dCx_16brni + dec ax + flagsetnz16bnel + addr_dCx_16bw + endloop +COpDEm8: ; DEC a,x + addr_aCx_8brni + dec al + flagsetnz8bnel + addr_aCx_8bw + endloop +COpDEm16:; DEC a,x + addr_aCx_16brni + dec ax + flagsetnz16bnel + addr_aCx_16bw + endloop + +COpCAx8: ; DEX i + dec byte[xx] + mov al,[xx] + flagsetnz8b + endloop +COpCAx16:; DEX i + dec word[xx] + mov ax,[xx] + flagsetnz16b + endloop +COp88x8: ; DEY i + dec byte[xy] + mov al,[xy] + flagsetnz8b + endloop +COp88x16:; DEY i + dec word[xy] + mov ax,[xy] + flagsetnz16b + endloop + +COp41m8: ; EOR(d,x) + addr_BdCxB_8br + EORMacro8b +COp41m16:; EOR(d,x) + addr_BdCxB_16br + EORMacro16b +COp43m8: ; EOR d,s + addr_dCs_8br + EORMacro8b +COp43m16:; EOR d,s + addr_dCs_16br + EORMacro16b +COp45m8: ; EOR d + addr_d_8br + EORMacro8b +COp45m16:; EOR d + addr_d_16br + EORMacro16b +COp47m8: ; EOR [d] + addr_LdL_8br + EORMacro8b +COp47m16:; EOR [d] + addr_LdL_16br + EORMacro16b +COp49m8: ; EOR # + addr_I_8br + EORMacro8b +COp49m16:; EOR # + addr_I_16br + EORMacro16b +COp4Dm8: ; EOR a + addr_a_8br + EORMacro8b +COp4Dm16:; EOR a + addr_a_16br + EORMacro16b +COp4Fm8: ; EOR al + addr_al_8br + EORMacro8b +COp4Fm16:; EOR al + addr_al_16br + EORMacro16b +COp51m8: ; EOR(d),y + addr_BdBCy_8br + EORMacro8b +COp51m16:; EOR(d),y + addr_BdBCy_16br + EORMacro16b +COp52m8: ; EOR (d) + addr_BdB_8br + EORMacro8b +COp52m16:; EOR (d) + addr_BdB_16br + EORMacro16b +COp53m8: ; EOR(d,s),y + addr_BdCsBCy_8br + EORMacro8b +COp53m16:; EOR(d,s),y + addr_BdCsBCy_16br + EORMacro16b +COp55m8: ; EOR d,x + addr_dCx_8br + EORMacro8b +COp55m16:; EOR d,x + addr_dCx_16br + EORMacro16b +COp57m8: ; EOR [d],y + addr_LdLCy_8br + EORMacro8b +COp57m16:; EOR [d],y + addr_LdLCy_16br + EORMacro16b +COp59m8: ; EOR a,y + addr_aCy_8br + EORMacro8b +COp59m16:; EOR a,y + addr_aCy_16br + EORMacro16b +COp5Dm8: ; EORa,x + addr_aCx_8br + EORMacro8b +COp5Dm16:; EORa,x + addr_aCx_16br + EORMacro16b +COp5Fm8: ; EOR al,x + addr_alCx_8br + EORMacro8b +COp5Fm16:; EOR al,x + addr_alCx_16br + EORMacro16b + + +COp1Am8: ; INC A + addr_A_8brni + inc al + flagsetnz8bnel + addr_A_8bw + endloop +COp1Am16:; INC A + addr_A_16brni + inc ax + flagsetnz16bnel + addr_A_16bw + endloop +COpEEm8: ; INC a + addr_a_8brni + inc al + flagsetnz8bnel + addr_a_8bw + endloop +COpEEm16:; INC a + addr_a_16brni + inc ax + flagsetnz16bnel + addr_a_16bw + endloop +COpE6m8: ; INC d + addr_d_8brni + inc al + flagsetnz8bnel + addr_d_8bw + endloop +COpE6m16:; INC d + addr_d_16brni + inc ax + flagsetnz16bnel + addr_d_16bw + endloop +COpF6m8: ; INC d,x + addr_dCx_8brni + inc al + flagsetnz8bnel + addr_dCx_8bw + endloop +COpF6m16:; INC d,x + addr_dCx_16brni + inc ax + flagsetnz16bnel + addr_dCx_16bw + endloop +COpFEm8: ; INC a,x + addr_aCx_8brni + inc al + flagsetnz8bnel + addr_aCx_8bw + endloop +COpFEm16:; INC a,x + addr_aCx_16brni + inc ax + flagsetnz16bnel + addr_aCx_16bw + endloop + + +COpE8x8: ; INX i + inc byte[xx] + mov al,[xx] + flagsetnz8b + endloop +COpE8x16:; INX i + inc word[xx] + mov ax,[xx] + flagsetnz16b + endloop +COpC8x8: ; INY i + inc byte[xy] + mov al,[xy] + flagsetnz8b + endloop +COpC8x16:; INY i + inc word[xy] + mov ax,[xy] + flagsetnz16b + endloop + +COpDC: ; JML (a) + JMLMacro +COp4C: ; JMP a + JMPMacro4C +COp6C: ; JMP (a) + JMPMacro6C +COp7C: ; JMP(a,x) + JMPMacro7C +COp5C: ; JMP al + JMPMacro5C + +COp22: ; JSL al + JSLMacro +COp20: ; JSR a + JSRMacro20 +COpFC: ; JSR(a,x) + JSRMacroFC + +COpA1m8: ; LDA(d,x) + addr_BdCxB_8br + LDAMacro8b +COpA1m16:; LDA(d,x) + addr_BdCxB_16br + LDAMacro16b +COpA3m8: ; LDA d,s + addr_dCs_8br + LDAMacro8b +COpA3m16:; LDA d,s + addr_dCs_16br + LDAMacro16b +COpA5m8: ; LDA d + addr_d_8br + LDAMacro8b +COpA5m16:; LDA d + addr_d_16br + LDAMacro16b +COpA7m8: ; LDA [d] + addr_LdL_8br + LDAMacro8b +COpA7m16:; LDA [d] + addr_LdL_16br + LDAMacro16b +COpA9m8: ; LDA # + addr_I_8br + LDAMacro8b +COpA9m16:; LDA # + addr_I_16br + LDAMacro16b +COpADm8: ; LDA a + addr_a_8br + LDAMacro8b +COpADm16:; LDA a + addr_a_16br + LDAMacro16b +COpAFm8: ; LDA al + addr_al_8br + LDAMacro8b +COpAFm16:; LDA al + addr_al_16br + LDAMacro16b +COpB1m8: ; LDA(d),y + addr_BdBCy_8br + LDAMacro8b +COpB1m16:; LDA(d),y + addr_BdBCy_16br + LDAMacro16b +COpB2m8: ; LDA (d) + addr_BdB_8br + LDAMacro8b +COpB2m16:; LDA (d) + addr_BdB_16br + LDAMacro16b +COpB3m8: ; LDA(d,s),y + addr_BdCsBCy_8br + LDAMacro8b +COpB3m16:; LDA(d,s),y + addr_BdCsBCy_16br + LDAMacro16b +COpB5m8: ; LDA d,x + addr_dCx_8br + LDAMacro8b +COpB5m16:; LDA d,x + addr_dCx_16br + LDAMacro16b +COpB7m8: ; LDA [d],y + addr_LdLCy_8br + LDAMacro8b +COpB7m16:; LDA [d],y + addr_LdLCy_16br + LDAMacro16b +COpB9m8: ; LDA a,y + addr_aCy_8br + LDAMacro8b +COpB9m16:; LDA a,y + addr_aCy_16br + LDAMacro16b +COpBDm8: ; LDA a,x + addr_aCx_8br + LDAMacro8b +COpBDm16:; LDA a,x + addr_aCx_16br + LDAMacro16b +COpBFm8: ; LDA al,x + addr_alCx_8br + LDAMacro8b +COpBFm16:; LDA al,x + addr_alCx_16br + LDAMacro16b + +COpA2x8: ; LDX # + addr_I_8br + LDXMacro8b +COpA2x16:; LDX # + addr_I_16br + LDXMacro16b +COpA6x8: ; LDX d + addr_d_8br + LDXMacro8b +COpA6x16:; LDX d + addr_d_16br + LDXMacro16b +COpAEx8: ; LDX a + addr_a_8br + LDXMacro8b +COpAEx16:; LDX a + addr_a_16br + LDXMacro16b +COpB6x8: ; LDX d,y + addr_dCy_8br + LDXMacro8b +COpB6x16:; LDX d,y + addr_dCy_16br + LDXMacro16b +COpBEx8: ; LDX a,y + addr_aCy_8br + LDXMacro8b +COpBEx16:; LDX a,y + addr_aCy_16br + LDXMacro16b + +COpA0x8: ; LDY # + addr_I_8br + LDYMacro8b +COpA0x16:; LDY # + addr_I_16br + LDYMacro16b +COpA4x8: ; LDY d + addr_d_8br + LDYMacro8b +COpA4x16:; LDY d + addr_d_16br + LDYMacro16b +COpACx8: ; LDY a + addr_a_8br + LDYMacro8b +COpACx16:; LDY a + addr_a_16br + LDYMacro16b +COpB4x8: ; LDY d,x + addr_dCx_8br + LDYMacro8b +COpB4x16:; LDY d,x + addr_dCx_16br + LDYMacro16b +COpBCx8: ; LDY a,x + addr_aCx_8br + LDYMacro8b +COpBCx16:; LDY a,x + addr_aCx_16br + LDYMacro16b + +COp46m8: ; LSR d + addr_d_8brni + LSRMacro8b + addr_d_8bw + endloop +COp46m16:; LSR d + addr_d_16brni + LSRMacro16b + addr_d_16bw + endloop +COp4Am8: ; LSR A + addr_A_8brni + LSRMacro8b + addr_A_8bw + endloop +COp4Am16:; LSR A + addr_A_16brni + LSRMacro16b + addr_A_16bw + endloop +COp4Em8: ; LSR a + addr_a_8brni + LSRMacro8b + addr_a_8bw + endloop +COp4Em16:; LSR a + addr_a_16brni + LSRMacro16b + addr_a_16bw + endloop +COp56m8: ; LSR d,x + addr_dCx_8brni + LSRMacro8b + addr_dCx_8bw + endloop +COp56m16:; LSR d,x + addr_dCx_16brni + LSRMacro16b + addr_dCx_16bw + endloop +COp5Em8: ; LSRa,x + addr_aCx_8brni + LSRMacro8b + addr_aCx_8bw + endloop +COp5Em16:; LSRa,x + addr_aCx_16brni + LSRMacro16b + addr_aCx_16bw + endloop + +COp54: ; MVN xya + MVNMacro +COp44: ; MVP xya + MVPMacro + +COpEA: ; NOP i + endloop + +COp01m8: ; ORA(d,x) + addr_BdCxB_8br + ORAMacro8b +COp01m16:; ORA(d,x) + addr_BdCxB_16br + ORAMacro16b +COp03m8: ; ORA d,s + addr_dCs_8br + ORAMacro8b +COp03m16:; ORA d,s + addr_dCs_16br + ORAMacro16b +COp05m8: ; ORA d + addr_d_8br + ORAMacro8b +COp05m16:; ORA d + addr_d_16br + ORAMacro16b +COp07m8: ; ORA [d] + addr_LdL_8br + ORAMacro8b +COp07m16:; ORA [d] + addr_LdL_16br + ORAMacro16b +COp09m8: ; ORA # + addr_I_8br + ORAMacro8b +COp09m16:; ORA # + addr_I_16br + ORAMacro16b +COp0Dm8: ; ORA a + addr_a_8br + ORAMacro8b +COp0Dm16:; ORA a + addr_a_16br + ORAMacro16b +COp0Fm8: ; ORA al + addr_al_8br + ORAMacro8b +COp0Fm16:; ORA al + addr_al_16br + ORAMacro16b +COp11m8: ; ORA(d),y + addr_BdBCy_8br + ORAMacro8b +COp11m16:; ORA(d),y + addr_BdBCy_16br + ORAMacro16b +COp12m8: ; ORA(d) + addr_BdB_8br + ORAMacro8b +COp12m16:; ORA(d) + addr_BdB_16br + ORAMacro16b +COp13m8: ; ORA(d,s),y + addr_BdCsBCy_8br + ORAMacro8b +COp13m16:; ORA(d,s),y + addr_BdCsBCy_16br + ORAMacro16b +COp15m8: ; ORA d,x + addr_dCx_8br + ORAMacro8b +COp15m16:; ORA d,x + addr_dCx_16br + ORAMacro16b +COp17m8: ; ORA [d],y + addr_LdLCy_8br + ORAMacro8b +COp17m16:; ORA [d],y + addr_LdLCy_16br + ORAMacro16b +COp19m8: ; ORA a,y + addr_aCy_8br + ORAMacro8b +COp19m16:; ORA a,y + addr_aCy_16br + ORAMacro16b +COp1Dm8: ; ORA a,x + addr_aCx_8br + ORAMacro8b +COp1Dm16:; ORA a,x + addr_aCx_16br + ORAMacro16b +COp1Fm8: ; ORA al,x + addr_alCx_8br + ORAMacro8b +COp1Fm16:; ORA al,x + addr_alCx_16br + ORAMacro16b + +COpF4: ; PEA s + PEAMacro +COpD4: ; PEI s + PEIMacro +COp62: ; PER s + PERMacro + +COp48m8: ; PHA s + PUSHMacro8b [xa] +COp48m16:; PHA s + PUSHMacro16b [xa], [xa+1] +COp8B: ; PHB s + PUSHMacro8b [xdb] +COp0B: ; PHD s + PUSHMacro16b [xd], [xd+1] +COp4B: ; PHK s + PUSHMacro8b [xpb] +COp08: ; PHP s + PUSHMacro8bp +COpDAx8: ; PHX s + PUSHMacro8b [xx] +COpDAx16:; PHX s + PUSHMacro16b [xx], [xx+1] +COp5Ax8: ; PHY s + PUSHMacro8b [xy] +COp5Ax16:; PHY s + PUSHMacro16b [xy], [xy+1] + +COp68m8: ; PLA s + POPMacro8b [xa] +COp68m16:; PLA s + POPMacro16b [xa], [xa+1] +COpAB: ; PLB s + POPMacro8b [xdb] +COp2B: ; PLD s + POPMacro16bd [xd], [xd+1] +COp28: ; PLP s + POPMacroP +COpFAx8: ; PLX s + POPMacro8b [xx] +COpFAx16:; PLX s + POPMacro16b [xx], [xx+1] +COp7Ax8: ; PLY s + POPMacro8b [xy] +COp7Ax16:; PLY s + POPMacro16b [xy], [xy+1] + +COpC2: ; REP # + REPMacro + +COp26m8: ; ROL d + addr_d_8brni + ROLMacro8b + addr_d_8bw + endloop +COp26m16:; ROL d + addr_d_16brni + ROLMacro16b + addr_d_16bw + endloop +COp2Am8: ; ROL A + addr_A_8brni + ROLMacro8b + addr_A_8bw + endloop +COp2Am16:; ROL A + addr_A_16brni + ROLMacro16b + addr_A_16bw + endloop +COp2Em8: ; ROL a + addr_a_8brni + ROLMacro8b + addr_a_8bw + endloop +COp2Em16:; ROL a + addr_a_16brni + ROLMacro16b + addr_a_16bw + endloop +COp36m8: ; ROL d,x + addr_dCx_8brni + ROLMacro8b + addr_dCx_8bw + endloop +COp36m16:; ROL d,x + addr_dCx_16brni + ROLMacro16b + addr_dCx_16bw + endloop +COp3Em8: ; ROL a,x + addr_aCx_8brni + ROLMacro8b + addr_aCx_8bw + endloop +COp3Em16:; ROL a,x + addr_aCx_16brni + ROLMacro16b + addr_aCx_16bw + endloop + +COp66m8: ; ROR d + addr_d_8brni + RORMacro8b + addr_d_8bw + endloop +COp66m16:; ROR d + addr_d_16brni + RORMacro16b + addr_d_16bw + endloop +COp6Am8: ; ROR A + addr_A_8brni + RORMacro8b + addr_A_8bw + endloop +COp6Am16:; ROR A + addr_A_16brni + RORMacro16b + addr_A_16bw + endloop +COp6Em8: ; ROR a + addr_a_8brni + RORMacro8b + addr_a_8bw + endloop +COp6Em16:; ROR a + addr_a_16brni + RORMacro16b + addr_a_16bw + endloop +COp76m8: ; ROR d,x + addr_dCx_8brni + RORMacro8b + addr_dCx_8bw + endloop +COp76m16:; ROR d,x + addr_dCx_16brni + RORMacro16b + addr_dCx_16bw + endloop +COp7Em8: ; ROR a,x + addr_aCx_8brni + RORMacro8b + addr_aCx_8bw + endloop +COp7Em16:; ROR a,x + addr_aCx_16brni + RORMacro16b + addr_aCx_16bw + endloop + +COp40: ; RTI s + RTIMacro +COp6B: ; RTL s + RTLMacro +COp60: ; RTS s + RTSMacro + +COpE1m8nd: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bnd +COpE1m16nd: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bnd +COpE1m8d: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bd +COpE1m16d: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bd +COpE3m8nd: ; SBC d,s + addr_dCs_8br + SBCMacro8bnd +COpE3m16nd: ; SBC d,s + addr_dCs_16br + SBCMacro16bnd +COpE3m8d: ; SBC d,s + addr_dCs_8br + SBCMacro8bd +COpE3m16d: ; SBC d,s + addr_dCs_16br + SBCMacro16bd +COpE5m8nd: ; SBC d + addr_d_8br + SBCMacro8bnd +COpE5m16nd: ; SBC d + addr_d_16br + SBCMacro16bnd +COpE5m8d: ; SBC d + addr_d_8br + SBCMacro8bd +COpE5m16d: ; SBC d + addr_d_16br + SBCMacro16bd +COpE7m8nd: ; SBC [d] + addr_LdL_8br + SBCMacro8bnd +COpE7m16nd: ; SBC [d] + addr_LdL_16br + SBCMacro16bnd +COpE7m8d: ; SBC [d] + addr_LdL_8br + SBCMacro8bd +COpE7m16d: ; SBC [d] + addr_LdL_16br + SBCMacro16bd +COpE9m8nd: ; SBC # + addr_I_8br + SBCMacro8bnd +COpE9m16nd: ; SBC # + addr_I_16br + SBCMacro16bnd +COpE9m8d: ; SBC # + addr_I_8br + SBCMacro8bd +COpE9m16d: ; SBC # + addr_I_16br + SBCMacro16bd +COpEDm8nd: ; SBC a + addr_a_8br + SBCMacro8bnd +COpEDm16nd: ; SBC a + addr_a_16br + SBCMacro16bnd +COpEDm8d: ; SBC a + addr_a_8br + SBCMacro8bd +COpEDm16d: ; SBC a + addr_a_16br + SBCMacro16bd +COpEFm8nd: ; SBC al + addr_al_8br + SBCMacro8bnd +COpEFm16nd: ; SBC al + addr_al_16br + SBCMacro16bnd +COpEFm8d: ; SBC al + addr_al_8br + SBCMacro8bd +COpEFm16d: ; SBC al + addr_al_16br + SBCMacro16bd +COpF1m8nd: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bnd +COpF1m16nd: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bnd +COpF1m8d: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bd +COpF1m16d: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bd +COpF2m8nd: ; SBC (d) + addr_BdB_8br + SBCMacro8bnd +COpF2m16nd: ; SBC (d) + addr_BdB_16br + SBCMacro16bnd +COpF2m8d: ; SBC (d) + addr_BdB_8br + SBCMacro8bd +COpF2m16d: ; SBC (d) + addr_BdB_16br + SBCMacro16bd +COpF3m8nd: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bnd +COpF3m16nd: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bnd +COpF3m8d: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bd +COpF3m16d: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bd +COpF5m8nd: ; SBC d,x + addr_dCx_8br + SBCMacro8bnd +COpF5m16nd: ; SBC d,x + addr_dCx_16br + SBCMacro16bnd +COpF5m8d: ; SBC d,x + addr_dCx_8br + SBCMacro8bd +COpF5m16d: ; SBC d,x + addr_dCx_16br + SBCMacro16bd +COpF7m8nd: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bnd +COpF7m16nd: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bnd +COpF7m8d: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bd +COpF7m16d: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bd +COpF9m8nd: ; SBC a,y + addr_aCy_8br + SBCMacro8bnd +COpF9m16nd: ; SBC a,y + addr_aCy_16br + SBCMacro16bnd +COpF9m8d: ; SBC a,y + addr_aCy_8br + SBCMacro8bd +COpF9m16d: ; SBC a,y + addr_aCy_16br + SBCMacro16bd +COpFDm8nd: ; SBC a,x + addr_aCx_8br + SBCMacro8bnd +COpFDm16nd: ; SBC a,x + addr_aCx_16br + SBCMacro16bnd +COpFDm8d: ; SBC a,x + addr_aCx_8br + SBCMacro8bd +COpFDm16d: ; SBC a,x + addr_aCx_16br + SBCMacro16bd +COpFFm8nd: ; SBC al,x + addr_alCx_8br + SBCMacro8bnd +COpFFm16nd: ; SBC al,x + addr_alCx_16br + SBCMacro16bnd +COpFFm8d: ; SBC al,x + addr_alCx_8br + SBCMacro8bd +COpFFm16d: ; SBC al,x + addr_alCx_16br + SBCMacro16bd + +COp38: ; SEC i + mov dword[flagc],0FFh + endloop +COpF8: ; SED i + or dl,08h + mov bl,dl + mov edi,[tableadc+ebx*4] + endloop +COp78: ; SEI i + or dl,04h + endloop + +COpE2: ; SEP # + SEPMacro + +COp81m8: ; STA(d,x) + STAMacro8b + addr_BdCxB_8bw + endloop +COp81m16:; STA(d,x) + STAMacro16b + addr_BdCxB_16bw + endloop +COp83m8: ; STA d,s + STAMacro8b + addr_dCs_8bw + endloop +COp83m16:; STA d,s + STAMacro16b + addr_dCs_16bw + endloop +COp85m8: ; STA d + STAMacro8b + addr_d_8bw + endloop +COp85m16:; STA d + STAMacro16b + addr_d_16bw + endloop +COp87m8: ; STA [d] + STAMacro8b + addr_LdL_8bw + endloop +COp87m16:; STA [d] + STAMacro16b + addr_LdL_16bw + endloop +COp8Dm8: ; STA a + STAMacro8b + addr_a_8bw + endloop +COp8Dm16:; STA a + STAMacro16b + addr_a_16bw + endloop +COp8Fm8: ; STA al + STAMacro8b + addr_al_8bw + endloop +COp8Fm16:; STA al + STAMacro16b + addr_al_16bw + endloop +COp91m8: ; STA(d),y + STAMacro8b + addr_BdBCy_8bw + endloop +COp91m16:; STA(d),y + STAMacro16b + addr_BdBCy_16bw + endloop +COp92m8: ; STA (d) + STAMacro8b + addr_BdB_8bw + endloop +COp92m16:; STA (d) + STAMacro16b + addr_BdB_16bw + endloop +COp93m8: ; STA(d,s),y + STAMacro8b + addr_BdCsBCy_8bw + endloop +COp93m16:; STA(d,s),y + STAMacro16b + addr_BdCsBCy_16bw + endloop +COp95m8: ; STA d,x + STAMacro8b + addr_dCx_8bw + endloop +COp95m16:; STA d,x + STAMacro16b + addr_dCx_16bw + endloop +COp97m8: ; STA [d],y + STAMacro8b + addr_LdLCy_8bw + endloop +COp97m16:; STA [d],y + STAMacro16b + addr_LdLCy_16bw + endloop +COp99m8: ; STA a,y + STAMacro8b + addr_aCy_8bw + endloop +COp99m16:; STA a,y + STAMacro16b + addr_aCy_16bw + endloop +COp9Dm8: ; STA a,x + STAMacro8b + addr_aCx_8bw + endloop +COp9Dm16:; STA a,x + STAMacro16b + addr_aCx_16bw + endloop +COp9Fm8: ; STA al,x + STAMacro8b + addr_alCx_8bw + endloop +COp9Fm16:; STA al,x + STAMacro16b + addr_alCx_16bw + endloop + +COp86x8: ; STX d + STXMacro8b + addr_d_8bw + endloop +COp86x16:; STX d + STXMacro16b + addr_d_16bw + endloop +COp8Ex8: ; STX a + STXMacro8b + addr_a_8bw + endloop +COp8Ex16:; STX a + STXMacro16b + addr_a_16bw + endloop +COp96x8: ; STX d,y + STXMacro8b + addr_dCy_8bw + endloop +COp96x16:; STX d,y + STXMacro16b + addr_dCy_16bw + endloop + +COp84x8: ; STY d + STYMacro8b + addr_d_8bw + endloop +COp84x16:; STY d + STYMacro16b + addr_d_16bw + endloop +COp8Cx8: ; STY a + STYMacro8b + addr_a_8bw + endloop +COp8Cx16:; STY a + STYMacro16b + addr_a_16bw + endloop +COp94x8: ; STYd,x + STYMacro8b + addr_dCx_8bw + endloop +COp94x16:; STYd,x + STYMacro16b + addr_dCx_16bw + endloop + +COpDB: ; STP i + dec esi + endloop + +COp64m8: ; STZ d + xor al,al + addr_d_8bw + endloop +COp64m16:; STZ d + xor eax,eax + addr_d_16bw + endloop +COp74m8: ; STZ d,x + xor al,al + addr_dCx_8bw + endloop +COp74m16:; STZ d,x + xor eax,eax + addr_dCx_16bw + endloop +COp9Cm8: ; STZ a + xor al,al + addr_a_8bw + endloop +COp9Cm16:; STZ a + xor eax,eax + addr_a_16bw + endloop +COp9Em8: ; STZ a,x + xor al,al + addr_aCx_8bw + endloop +COp9Em16:; STZ a,x + xor eax,eax + addr_aCx_16bw + endloop + +COp14m8: ; TRB d + addr_d_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cl,al + jz .zero + mov word[flagnz],1 + not cl + and al,cl + addr_d_8bw + endloop +.zero + mov word[flagnz],0 + not cl + and al,cl + addr_d_8bw + endloop +COp14m16:; TRB d + addr_d_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[flagnz],1 + not cx + and ax,cx + addr_d_16bw + endloop +.zero + mov word[flagnz],0 + not cx + and ax,cx + addr_d_16bw + endloop +COp1Cm8: ; TRB a + addr_a_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cl,al + jz .zero + mov word[flagnz],1 + not cl + and al,cl + addr_a_8bw + endloop +.zero + mov word[flagnz],0 + not cl + and al,cl + addr_a_8bw + endloop +COp1Cm16:; TRB a + addr_a_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[flagnz],1 + not cx + and ax,cx + addr_a_16bw + endloop +.zero + mov word[flagnz],0 + not cx + and ax,cx + addr_a_16bw + endloop + +COp04m8: ; TSB d + addr_d_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test al,cl + jz .zero + mov word[flagnz],1 + or al,cl + addr_d_8bw + endloop +.zero + mov word[flagnz],0 + or al,cl + addr_d_8bw + endloop +COp04m16:; TSB d + addr_d_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[flagnz],1 + or ax,cx + addr_d_16bw + endloop +.zero + mov word[flagnz],0 + or ax,cx + addr_d_16bw + endloop +COp0Cm8: ; TSB a + addr_a_8brni + mov cl,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test al,cl + jz .zero + mov word[flagnz],1 + or al,cl + addr_a_8bw + endloop +.zero + mov word[flagnz],0 + or al,cl + addr_a_8bw + endloop +COp0Cm16:; TSB a + addr_a_16brni + mov cx,[xa] + test dword[flagnz],18000h + jz .notflags + or dword[flagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[flagnz],1 + or ax,cx + addr_a_16bw + endloop +.zero + mov word[flagnz],0 + or ax,cx + addr_a_16bw + endloop + +COpAAx8: ; TAX i + mov al,[xa] + mov [xx],al + flagsetnz8b + endloop +COpAAx16:; TAX i + mov ax,[xa] + mov [xx],ax + flagsetnz16b + endloop +COpA8x8: ; TAY i + mov al,[xa] + mov [xy],al + flagsetnz8b + endloop +COpA8x16:; TAY i + mov ax,[xa] + mov [xy],ax + flagsetnz16b + endloop +COp5B: ; TCD i + mov ax,[xa] + mov [xd],ax + call UpdateDPage + flagsetnz16b + endloop +COp1B: ; TCS i + mov ax,[xa] + mov [xs],ax + endloop +COp7B: ; TDC i + mov ax,[xd] + mov [xa],ax + flagsetnz16b + endloop +COp3B: ; TSC i + mov ax,[xs] + mov [xa],ax + flagsetnz16b + endloop +COpBAx8: ; TSX i + mov al,[xs] + mov [xx],al + flagsetnz8b + endloop +COpBAx16:; TSX i + mov ax,[xs] + mov [xx],ax + flagsetnz16b + endloop +COp8Am8: ; TXA i + mov al,[xx] + mov [xa],al + flagsetnz8b + endloop +COp8Am16:; TXA i + mov ax,[xx] + mov [xa],ax + flagsetnz16b + endloop +COp9A: ; TXS i + mov ax,[xx] + mov [xs],ax + test byte[xe],1 + jnz .emul + endloop +.emul + mov byte[xs+1],1 + endloop +COp9Bx8: ; TXY i + mov al,[xx] + mov [xy],al + flagsetnz8b + endloop +COp9Bx16:; TXY i + mov ax,[xx] + mov [xy],ax + flagsetnz16b + endloop +COp98m8: ; TYA i + mov al,[xy] + mov [xa],al + flagsetnz8b + endloop +COp98m16:; TYA i + mov ax,[xy] + mov [xa],ax + flagsetnz16b + endloop +COpBBx8: ; TYX i + mov al,[xy] + mov [xx],al + flagsetnz8b + endloop +COpBBx16:; TYX i + mov ax,[xy] + mov [xx],ax + flagsetnz16b + endloop + +COpCB: ; WAI i + WAIMacro + +COpEB: ; XBA i + mov ah,[xa] + mov al,[xa+1] + mov [xa],ax + flagsetnz8b + endloop + +COpFB: ; XCE i + XCEMacro + +COp42: ; WDM + inc esi + endloop + \ No newline at end of file diff --git a/zsnes/src/cpu/execute.asm b/zsnes/src/cpu/execute.asm new file mode 100644 index 00000000..2c5a601c --- /dev/null +++ b/zsnes/src/cpu/execute.asm @@ -0,0 +1,4374 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM StringLength +EXTSYM Get_Time +EXTSYM objhipr +EXTSYM KeyRewind +EXTSYM xa,timer2upd,prevoamptr,ReadHead +EXTSYM prevedi,SA1xpc,SA1RAMArea,sa1dmaptr +EXTSYM DSP1COp,C4WFXVal,C41FXVal,Op00Multiplicand,Op10Coefficient,Op04Angle +EXTSYM Op08X,Op18X,Op28X,Op0CA,Op1CAZ,Op02FX,Op0AVS,Op06X,Op0DX,Op03F,Op14Zr +EXTSYM Op0EH,DSP1Type,Op01m +EXTSYM Voice0Status +EXTSYM UpdateDPage +EXTSYM Interror,MessageOn,MsgCount,Msgptr,StartGUI,cbitmode,debuggeron,romdata +EXTSYM frameskip,initvideo,newgfx16b,oldhandSBo,oldhandSBs,soundon,cvidmode +EXTSYM vidbuffer,vidbufferofsa,vidbufferofsb,disable65816sh,GUISaveVars,virqnodisable +EXTSYM KeySaveState,KeyLoadState,KeyQuickExit,KeyQuickLoad,KeyQuickRst,GUIDoReset +EXTSYM KeyOnStA,KeyOnStB,ProcessKeyOn,printnum,sramsavedis,DSPDisable,C4Enable +EXTSYM IRQHack,HIRQLoc,Offby1line,splitflags,joinflags,KeyQuickSnapShot +EXTSYM csounddisable,videotroub,Open_File,Close_File,Read_File,ResetTripleBuf +EXTSYM Write_File,Output_Text,Create_File,Check_Key,Get_Key,Change_Dir,InitPreGame +EXTSYM OSPort +; EXTSYM tempblah,romdata +EXTSYM Curtableaddr,DeInitSPC,InitSB,PICMaskP,SBHandler,SBInt +EXTSYM SBIrq,curcyc,debugdisble,dmadata,guioff,memtabler8,SetupPreGame +EXTSYM memtablew8,regaccessbankr8,showmenu,snesmap2,snesmmap,DeInitPostGame +EXTSYM spcPCRam,startdebugger,xp,xpb,xpc,tablead,tableadb,tableadc +; EXTSYM oamram +EXTSYM SA1UpdateDPage,Makemode7Table +EXTSYM memtabler16,memaccessbankr848mb,memaccessbankr1648mb +EXTSYM nextmenupopup +EXTSYM MovieProcessing +EXTSYM MovieFileHand, PrintStr +EXTSYM OSExit,DosExit,InitDir,InitDrive,createnewcfg,fnames,gotoroot,previdmode +EXTSYM ramsize,sfxramdata,sram,SRAMDrive,SRAMDir,welcome +; EXTSYM tempstore +EXTSYM printhex +EXTSYM ModemInitStat, DeInitModem +EXTSYM deinitipx +EXTSYM deinitvideo +EXTSYM BRRBuffer,DSPMem,PrepareSaveState,ResetState,SFXEnable,PHdspsave +EXTSYM fnamest,sndrot,spcRam,spcRamDP,tableA,unpackfunct,vram,wramdata +EXTSYM zsmesg,PHnum2writesfxreg,SfxR0,PHnum2writecpureg,PHspcsave,initrevst +EXTSYM C4Ram +EXTSYM SPC7110Enable +EXTSYM SA1Mode,PHnum2writesa1reg,SaveSA1,RestoreSA1,UpdateBanksSDD1 +EXTSYM SDD1Enable +EXTSYM CapturePicture,PrevPicture,NoPictureSave +EXTSYM BRRPlace0,SfxCPB,SfxCROM,SfxLastRamAdr,SfxMemTable,Totalbyteloaded +EXTSYM SfxRAMBR,SfxRAMMem,SfxROMBR,SfxRomBuffer,Voice0Freq +EXTSYM cycpbl,cycpbl2,cycpblt,cycpblt2,irqon,nexthdma +EXTSYM repackfunct,spcnumread,spcon,versn,headerhack,initpitch +EXTSYM SPCMultA,PHnum2writespc7110reg +EXTSYM multchange,procexecloop,vidmemch2 +EXTSYM romispal +EXTSYM dssel +EXTSYM scrndis,sprlefttot,sprleftpr,processsprites,cachesprites +EXTSYM NextLineStart,FlipWait,LastLineStart +EXTSYM opcjmptab +EXTSYM cpuoverptr +EXTSYM CheatOn,INTEnab,JoyAPos,JoyBPos,JoyCRead,NMIEnab,NumCheats,CurrentExecSA1 +EXTSYM ReadInputDevice,StartDrawNewGfx,VIRQLoc,cachevideo,cfield +EXTSYM cheatdata,curblank,curnmi,curypos,cycpl,doirqnext,drawline +EXTSYM execatzerovirq,exechdma,hdmadelay,intrset,newengen,oamaddr +EXTSYM oamaddrs,processmouse,resolutn,showvideo,snesmouse,starthdma +EXTSYM switchtonmi,switchtovirq,totlines,updatetimer,SA1Swap,SA1DoIRQ +EXTSYM JoyAOrig,JoyANow,JoyBOrig,JoyBNow,JoyCOrig,JoyCNow,JoyDOrig,JoyDNow +EXTSYM JoyEOrig,JoyENow,chaton,chatstrL,chatRTL,chatstrR,SA1Message +EXTSYM MultiTapStat,MovieCounter,idledetectspc,SA1Control,SA1Enable,SA1IRQEnable +EXTSYM SPC700read,SPC700write,numspcvblleft,spc700idle,SA1Status,SA1IRQExec +EXTSYM ForceNewGfxOff,LethEnData,C4Pause,GUIQuit +EXTSYM IRAM,SA1Ptr,SA1BWPtr +EXTSYM scrnon,scaddset +EXTSYM outofmemfix,yesoutofmemory +EXTSYM CNetType,Latency,LatencyLeft,NetSwap +; EXTSYM vesa2selec +EXTSYM RemoteSendChar,RemoteGetChar,pl1neten,pl2neten,pl3neten,pl4neten +EXTSYM pl5neten,RemoteSendEAX,prevp1net,prevp2net,prevp3net,prevp4net +EXTSYM RemoteGetEAX,cnetplaybuf,netdelayed,cnetptrtail,cnetptrhead +EXTSYM ChatProgress,RecvProgress,chatTL,WritetochatBuffer,NetAddChar +EXTSYM PreparePacket, SendPacket, NoInputRead, RemoteDisconnect +EXTSYM SendPacketUDP +EXTSYM ChatNick +EXTSYM JoyRead,ChatType2,chatstrR2,chatstrR3,chatstrR4,chatstrR5 +EXTSYM chatRTL2,chatRTL3,chatRTL4,chatRTL5 +EXTSYM NetLoadState +EXTSYM ProcessMovies +EXTSYM C4VBlank +EXTSYM dsp1teststuff +EXTSYM ReturnFromSPCStall,SPCStallSetting,cycpb268,cycpb358,HIRQSkip,scanlines +EXTSYM smallscreenon,ScreenScale +EXTSYM MainLoop,NumberOfOpcodes,SfxCLSR,SfxSCMR,SfxPOR +EXTSYM sfx128lineloc,sfx160lineloc,sfx192lineloc,sfxobjlineloc,sfxclineloc +EXTSYM PLOTJmpa,PLOTJmpb,FxTable,FxTableb,FxTablec,FxTabled +EXTSYM SfxPBR,SCBRrel,SfxSCBR,SfxCOLR,hdmaearlstart,SFXCounter +EXTSYM fxbit01,fxbit01pcal,fxbit23,fxbit23pcal,fxbit45,fxbit45pcal,fxbit67,fxbit67pcal +EXTSYM SfxSFR +EXTSYM cpucycle,debstop,switchtovirqdeb,debstop3,switchtonmideb + + + + + + + +%macro BackupCVMacM 2 + mov edx,%1 + mov ecx,%2 +%%loop + movq mm0,[edx] + movq mm1,[edx+8] + movq [ebx],mm0 + movq [ebx+8],mm1 + add edx,16 + add ebx,16 + loop %%loop +%endmacro + +%macro BackupCVMac 2 + mov edx,%1 + mov ecx,%2 +%%loop + mov eax,[edx] + mov [ebx],eax + add edx,4 + add ebx,4 + loop %%loop +%endmacro + +%macro BackupCVMacB 2 + mov edx,%1 + mov ecx,%2 +%%loop + mov al,[edx] + mov [ebx],al + inc edx + inc ebx + loop %%loop +%endmacro + +%macro BackupCVRMacM 2 + mov edx,%1 + mov ecx,%2 +%%loop + movq mm0,[ebx] + movq mm1,[ebx+8] + movq [edx],mm0 + movq [edx+8],mm1 + add edx,16 + add ebx,16 + loop %%loop +%endmacro + +%macro BackupCVRMac 2 + mov edx,%1 + mov ecx,%2 +%%loop + mov eax,[ebx] + mov [edx],eax + add edx,4 + add ebx,4 + loop %%loop +%endmacro + +%macro BackupCVRMacB 2 + mov edx,%1 + mov ecx,%2 +%%loop + mov al,[ebx] + mov [edx],al + inc edx + inc ebx + loop %%loop +%endmacro + +NEWSYM CBackupPos, dd 0 +NEWSYM StateBackup, dd 0 +NEWSYM PBackupPos, dd 0 +NEWSYM PPValue, dd 0 ; Previous PValue +NEWSYM DPValue, dd 0 ; Destination PValue +NEWSYM CurRecv, dd 0 ; Set to 1 if Recovery mode is on +; if CurRecv=1, then do not send tcp/ip data, always frame skip, do not +; draw to screen, do not key on, restore previous local key presses, +; when disabling key ons, divert dspmem write/read to a different +; array temporarly, then re-copy back in when finished +NEWSYM PPContrl, times 16 dd 0 ; Previous Controller 1 Data +NEWSYM PPContrl2, times 16 dd 0 ; Previous Controller 2 Data +NEWSYM PPContrl3, times 16 dd 0 ; Previous Controller 3 Data +NEWSYM PPContrl4, times 16 dd 0 ; Previous Controller 4 Data +NEWSYM PPContrl5, times 16 dd 0 ; Previous Controller 5 Data +NEWSYM tempedx, dd 0 +NEWSYM NetSent2, dd 0 +NEWSYM NetQuitter, dd 0 +NEWSYM QBackupPos, dd 0 +NEWSYM LatencyV, times 256 db 0 +NEWSYM LatencyRecvPtr, dd 0 +NEWSYM LatencySendPtr, dd 0 +NEWSYM latencytimer, dd 0 +NEWSYM BackState, db 1 +NEWSYM BackStateSize, dd 6 +NEWSYM nojoystickpoll, dd 0 +NEWSYM RemoteLValue, db 0 +NEWSYM LocalLValue, db 0 +NEWSYM chatstrLt, times 15 db 0 +NEWSYM RewindOldPos, dd 0 +NEWSYM RewindPos, dd 0 +NEWSYM RewindTimer, dd 0 +NEWSYM ResendTimer, dd 60 +NEWSYM valuea, dd 0 +NEWSYM valueb, dd 0 +NEWSYM valuet, dd 0 +BackupArray times 2000 dd 0 + +NEWSYM SplitStringChat + push ebx + push eax + push ecx + mov eax,chatstrR + call StringLength + cmp ecx,42 + jbe near .noneed + mov eax,42 +.next2 + cmp byte[chatstrR+eax],' ' + je near .space + cmp eax,33 + jb .dontclipearly + dec eax + jmp .next2 +.space + inc eax + jmp .processclip +.dontclipearly + mov eax,42 +.processclip + push eax + mov ebx,[chatRTL4] + mov [chatRTL5],ebx + mov ebx,[chatRTL3] + mov [chatRTL4],ebx + mov ebx,[chatRTL2] + mov [chatRTL3],ebx + mov ebx,[chatRTL] + mov [chatRTL2],ebx + xor ecx,ecx +.chatcpyloop + mov al,[chatstrR4+ecx] + mov [chatstrR5+ecx],al + mov al,[chatstrR3+ecx] + mov [chatstrR4+ecx],al + mov al,[chatstrR2+ecx] + mov [chatstrR3+ecx],al + mov al,[chatstrR+ecx] + mov [chatstrR2+ecx],al + inc ecx + cmp ecx,100 + jnz .chatcpyloop + pop eax + push eax + xor ecx,ecx + mov byte[chatstrR],' ' + inc ecx +.next + mov bl,[chatstrR2+eax] + mov [chatstrR+ecx],bl + inc eax + inc ecx + or bl,bl + jnz .next + pop eax + mov byte[chatstrR2+eax],0 +.noneed + pop ecx + pop eax + pop ebx + ret + +NEWSYM MoveStringChat + mov ebx,[chatRTL4] + mov [chatRTL5],ebx + mov ebx,[chatRTL3] + mov [chatRTL4],ebx + mov ebx,[chatRTL2] + mov [chatRTL3],ebx + mov ebx,[chatRTL] + mov [chatRTL2],ebx + push eax + push ecx + xor ecx,ecx +.chatcpyloop + mov al,[chatstrR4+ecx] + mov [chatstrR5+ecx],al + mov al,[chatstrR3+ecx] + mov [chatstrR4+ecx],al + mov al,[chatstrR2+ecx] + mov [chatstrR3+ecx],al + mov al,[chatstrR+ecx] + mov [chatstrR2+ecx],al + inc ecx + cmp ecx,100 + jnz .chatcpyloop + pop ecx + pop eax + ret + +NEWSYM GenLatencyDisplay + call Get_Time + mov [.temp],eax + mov ebx,16 + xor eax,eax + xor edx,edx + mov al,[valuea] + mov al,[.temp] + div ebx + add al,48 + add dl,48 + mov byte[chatstrLt+2],32 + cmp al,9 + jbe .bel9 +; sub al,10 +.bel9 + mov [chatstrLt+1],dl + mov [chatstrLt],al + mov ebx,16 + xor eax,eax + xor edx,edx + mov al,[.temp+1] + div ebx + add al,48 + add dl,48 + cmp al,9 + jbe .bel9b +; sub al,10 +.bel9b + mov [chatstrLt+4],dl + mov [chatstrLt+3],al + ret +.temp dd 0 + +NEWSYM ResetExecStuff + mov dword[soundcycleft],0 + mov dword[curexecstate],0 + mov dword[nmiprevaddrl],0 + mov dword[nmiprevaddrh],0 + mov dword[nmirept],0 + mov dword[nmiprevline],224 + mov dword[nmistatus],0 + mov byte[NextLineCache],0 + mov byte[spcnumread],0 + mov dword[timer2upd],0 + mov dword[HIRQCycNext],0 + mov byte[HIRQNextExe],0 + ret + +NEWSYM ProcessRewind + cmp byte[CNetType],20 + jb .okay +.notokayb + ret +.okay + mov eax,dword[KeyRewind] + cmp byte[pressed+eax],1 + jne .notokayb + mov byte[pressed+eax],2 + mov eax,[RewindOldPos] + cmp [RewindPos],eax + je .notokay + dec dword[RewindPos] + and dword[RewindPos],0Fh + mov eax,[RewindOldPos] + cmp [RewindPos],eax + je .notokay2 + dec dword[RewindPos] + and dword[RewindPos],0Fh + mov eax,[RewindPos] + mov [PBackupPos],eax + push ecx + push ebx + call RestoreCVFrame + ; Clear Cache Check + mov ebx,vidmemch2 + mov ecx,4096+4096+4096 +.next + mov byte[ebx],1 + inc ebx + dec ecx + jnz .next + pop ebx + pop ecx + inc dword[RewindPos] + and dword[RewindPos],0Fh + mov edx,[tempedx] + mov dword[RewindTimer],60*3 +.notokay + ret +.notokay2 + inc dword[RewindPos] + and dword[RewindPos],0Fh + ret + +NEWSYM UpdateRewind + cmp byte[OSPort],3 + je .yeswin32 + ret +.yeswin32 + push eax + cmp dword[KeyRewind],0 + je .notftimer + call ProcessRewind + dec dword[RewindTimer] + jnz .notftimer + cmp byte[CNetType],20 + jb .okay +.notftimer + pop eax + ret +.okay + mov eax,[RewindPos] + mov [CBackupPos],eax + mov [tempedx],edx + push ecx + push ebx + call BackupCVFrame + pop ebx + pop ecx + inc dword[RewindPos] + and dword[RewindPos],0Fh + mov eax,[RewindOldPos] + cmp [RewindPos],eax + jne .noteq + inc dword[RewindOldPos] + and dword[RewindOldPos],0Fh +.noteq + mov dword[RewindTimer],60*3 + pop eax + ret + +NEWSYM BackupSystemVars + pushad + mov ebx,BackupArray + BackupCVMacB zsmesg,[PHnum2writecpureg] + BackupCVMac cycpbl,2 + BackupCVMacB sndrot,3019 + BackupCVMacB soundcycleft,33 + BackupCVMac spc700read,10 + BackupCVMac timer2upd,1 + BackupCVMac xa,14 + BackupCVMacB spcnumread,1 + BackupCVMac opcd,6 + BackupCVMacB HIRQCycNext,5 + BackupCVMac oamaddr,14 + BackupCVMacB prevoamptr,1 + BackupCVMac ReadHead,1 + popad + ret + +NEWSYM RestoreSystemVars + pushad + mov dword[RewindPos],0 + mov dword[RewindOldPos],0 + mov dword[RewindTimer],60*4 + mov ebx,BackupArray + BackupCVRMacB zsmesg,[PHnum2writecpureg] + BackupCVRMac cycpbl,2 + BackupCVRMacB sndrot,3019 + BackupCVRMacB soundcycleft,33 + BackupCVRMac spc700read,10 + BackupCVRMac timer2upd,1 + BackupCVRMac xa,14 + BackupCVRMacB spcnumread,1 + BackupCVRMac opcd,6 + BackupCVRMacB HIRQCycNext,5 + BackupCVRMac oamaddr,14 + BackupCVRMacB prevoamptr,1 + BackupCVRMac ReadHead,1 + popad + ret + +NEWSYM BackupCVFrame +;NEWSYM StateBackup, dd 0 +;NEWSYM CBackupPos, dd 0 +;NEWSYM PBackupPos, dd 0 + push edx + push eax + mov ebx,[CBackupPos] + shl ebx,19 + add ebx,[StateBackup] + add ebx,1024 + + BackupCVMacB zsmesg,[PHnum2writecpureg] + BackupCVMac cycpbl,2 + BackupCVMacB sndrot,3019 + BackupCVMacM [wramdata],8192 + BackupCVMacM [vram],4096 + cmp byte[spcon],0 + je .nospcon + BackupCVMacB spcRam,[PHspcsave] + BackupCVMacM DSPMem,16 +.nospcon + cmp byte[C4Enable],1 + jne .noc4 + BackupCVMac [C4Ram],800h +.noc4 + cmp byte[SFXEnable],1 + jne .nosfx + BackupCVMacM [sfxramdata],8192 +.nosfx + cmp byte[SA1Enable],1 + jne near .nossa1 + BackupCVMacB SA1Mode,[PHnum2writesa1reg] + BackupCVMacM [SA1RAMArea],8192 + BackupCVMacB SA1Status,3 + BackupCVMac prevedi,1 + BackupCVMac SA1xpc,1 + BackupCVMac SA1RAMArea,6 + BackupCVMac sa1dmaptr,2 +.nossa1 + cmp byte[DSP1Type],0 + je near .nodsp1type + BackupCVMacB DSP1COp,70+128 + BackupCVMacB C4WFXVal,7*4+7*8+128 + BackupCVMacB C41FXVal,5*4+128 + BackupCVMacB Op00Multiplicand,3*4+128 + BackupCVMacB Op10Coefficient,4*4+128 + BackupCVMacB Op04Angle,4*4+128 + BackupCVMacB Op08X,5*4+128 + BackupCVMacB Op18X,5*4+128 + BackupCVMacB Op28X,4*4+128 + BackupCVMacB Op0CA,5*4+128 + BackupCVMacB Op1CAZ,15*4+128 + BackupCVMacB Op02FX,11*4+3*4+28*8+128 + BackupCVMacB Op0AVS,5*4+14*8+128 + BackupCVMacB Op06X,6*4+10*8+4+128 + BackupCVMacB Op01m,4*4+128 + BackupCVMacB Op0DX,6*4+128 + BackupCVMacB Op03F,6*4+128 + BackupCVMacB Op14Zr,9*4+128 + BackupCVMacB Op0EH,4*4+128 +.nodsp1type + BackupCVMacB soundcycleft,33 + BackupCVMac spc700read,10 + BackupCVMac timer2upd,1 + BackupCVMac xa,14 + BackupCVMacB spcnumread,1 + BackupCVMac opcd,6 + BackupCVMacB HIRQCycNext,5 + BackupCVMac oamaddr,14 + BackupCVMacB prevoamptr,1 + BackupCVMac ReadHead,1 + + mov edx,[sram] + mov ecx,[ramsize] + shr ecx,4 + or ecx,ecx + jz .end +.loop + movq mm0,[edx] + movq mm1,[edx+8] + movq [ebx],mm0 + movq [ebx+8],mm1 + add edx,16 + add ebx,16 + loop .loop +.end + + pop eax + pop edx + mov [ebx],esi + mov [ebx+4],edi + mov ecx,[tempedx] + mov [ebx+8],ecx + mov [ebx+12],ebp + emms + ret + +NEWSYM RestoreCVFrame + push edx + push eax + mov ebx,[PBackupPos] + shl ebx,19 + add ebx,[StateBackup] + add ebx,1024 + + BackupCVRMacB zsmesg,[PHnum2writecpureg] + BackupCVRMac cycpbl,2 + BackupCVRMacB sndrot,3019 + BackupCVRMacM [wramdata],8192 + BackupCVRMacM [vram],4096 + cmp byte[spcon],0 + je .nospcon + BackupCVRMacB spcRam,[PHspcsave] + BackupCVRMacM DSPMem,16 +.nospcon + cmp byte[C4Enable],1 + jne .noc4 + BackupCVRMac [C4Ram],800h +.noc4 + cmp byte[SFXEnable],1 + jne .nosfx + BackupCVRMacM [sfxramdata],8192 +.nosfx + cmp byte[SA1Enable],1 + jne near .nossa1 + BackupCVRMacB SA1Mode,[PHnum2writesa1reg] + BackupCVRMacM [SA1RAMArea],8192 + BackupCVRMacB SA1Status,3 + BackupCVRMac prevedi,1 + BackupCVRMac SA1xpc,1 + BackupCVRMac SA1RAMArea,6 + BackupCVRMac sa1dmaptr,2 +.nossa1 + cmp byte[DSP1Type],0 + je near .nodsp1type + BackupCVRMacB DSP1COp,70+128 + BackupCVRMacB C4WFXVal,7*4+7*8+128 + BackupCVRMacB C41FXVal,5*4+128 + BackupCVRMacB Op00Multiplicand,3*4+128 + BackupCVRMacB Op10Coefficient,4*4+128 + BackupCVRMacB Op04Angle,4*4+128 + BackupCVRMacB Op08X,5*4+128 + BackupCVRMacB Op18X,5*4+128 + BackupCVRMacB Op28X,4*4+128 + BackupCVRMacB Op0CA,5*4+128 + BackupCVRMacB Op1CAZ,15*4+128 + BackupCVRMacB Op02FX,11*4+3*4+28*8+128 + BackupCVRMacB Op0AVS,5*4+14*8+128 + BackupCVRMacB Op06X,6*4+10*8+4+128 + BackupCVRMacB Op01m,4*4+128 + BackupCVRMacB Op0DX,6*4+128 + BackupCVRMacB Op03F,6*4+128 + BackupCVRMacB Op14Zr,9*4+128 + BackupCVRMacB Op0EH,4*4+128 +.nodsp1type + BackupCVRMacB soundcycleft,33 + BackupCVRMac spc700read,10 + BackupCVRMac timer2upd,1 + BackupCVRMac xa,14 + BackupCVRMacB spcnumread,1 + BackupCVRMac opcd,6 + BackupCVRMacB HIRQCycNext,5 + BackupCVRMac oamaddr,14 + BackupCVRMacB prevoamptr,1 + BackupCVRMac ReadHead,1 + + mov edx,[sram] + mov ecx,[ramsize] + shr ecx,4 + or ecx,ecx + jz .end +.loop + movq mm0,[ebx] + movq mm1,[ebx+8] + movq [edx],mm0 + movq [edx+8],mm1 + add edx,16 + add ebx,16 + loop .loop +.end + + pop eax + pop edx + mov esi,[ebx] + mov edi,[ebx+4] + mov ecx,[ebx+8] + mov [tempedx],ecx + mov ebp,[ebx+12] + call UpdateDPage + call SA1UpdateDPage + emms + ret + +NEWSYM MuteVoiceF, db 0 + +VoiceEndMute: + mov byte[MuteVoiceF],0 + ret + + +%macro StartMute 1 + mov al,[Voice0Status+%1] + or al,al + jz %%notmuted + or byte[MuteVoiceF],1 << %1 +%%notmuted +%endmacro + +VoiceStartMute: + mov byte[MuteVoiceF],0 + push eax + StartMute 0 + StartMute 1 + StartMute 2 + StartMute 3 + StartMute 4 + StartMute 5 + StartMute 6 + StartMute 7 + pop eax + ret + +NetSaveState: + call joinflags + ; de-init variables (copy to variables) + mov [spcPCRam],ebp + mov [Curtableaddr],edi + mov [xp],dl + mov [curcyc],dh + mov eax,[initaddrl] + sub esi,eax ; subtract program counter by address + mov [xpc],si + call ResetTripleBuf + mov eax,[KeySaveState] + cmp byte[CNetType],20 + je .skipsoundreinit + test byte[pressed+eax],1 + jnz .soundreinit + mov eax,[KeyLoadState] + test byte[pressed+eax],1 + jz .skipsoundreinit +.soundreinit + mov byte[NoSoundReinit],1 + mov byte[csounddisable],1 +.skipsoundreinit + + call statesaver + + ; initialize variables (Copy from variables) + call UpdateDPage + call SA1UpdateDPage + call Makemode7Table + cmp byte[SFXEnable],0 + je .nosfxud + call UpdateSFX +.nosfxud + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov bl,[xpb] + mov ax,[xpc] + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + jmp .skiplower +.loweraddr + cmp ax,4300h + jb .lower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma +.lower + mov esi,[snesmap2+ebx*4] + jmp .skiplower +.dma + mov esi,dmadata-4300h +.skiplower + mov [initaddrl],esi + add esi,eax ; add program counter to address + mov dl,[xp] ; set flags + mov dh,[curcyc] ; set cycles + + mov bl,dl +; cmp byte[CNetType],20 +; je .skipmovie +; cmp byte[CNetType],21 +; je .skipmovie +; jmp .skipmovie +; cmp byte[MovieProcessing],0 +; jne .movie +;.skipmovie + cmp byte[spcon],0 + je .nosoundta + mov edi,[tableadc+ebx*4] + or byte[curexecstate],2 + jmp .soundta +.nosoundta + mov edi,[tableadb+ebx*4] + and byte[curexecstate],0FDh +.soundta + jmp .nomovie +.movie + mov edi,[tableadc+ebx*4] + test byte[curexecstate],2 + jnz .nomovie + mov edi,[tableadb+ebx*4] +.nomovie + + mov ebp,[spcPCRam] + + mov byte[NoSoundReinit],0 + mov byte[csounddisable],0 + mov byte[NextNGDisplay],0 + + call splitflags + ret + + +%macro stim 0 + cmp byte[OSPort],1 + ja %%nosti + sti +%%nosti +%endmacro + +%macro clim 0 + cmp byte[OSPort],1 + ja %%nocli + cli +%%nocli +%endmacro + +%macro ProcessIRQStuffB 0 + ; check for VIRQ/HIRQ/NMI + test dl,04h + jnz %%noirq + test byte[INTEnab],20h + jz %%novirq + mov ax,[VIRQLoc] + cmp word[curypos],ax + je near .virq + jmp %%noirq +%%novirq + test byte[INTEnab],10h + jnz near .virq +%%noirq + test byte[INTEnab],20h + jz %%novirq2b + mov ax,[VIRQLoc] + cmp word[curypos],ax + jne %%novirq2b + cmp byte[intrset],1 + jne %%nointrset2b + mov byte[intrset],2 +%%nointrset2b +%%novirq2b +%endmacro + +%macro ProcessIRQStuffC 0 + ; check for VIRQ/HIRQ + cmp byte[virqnodisable],1 + je %%virqdo + test dl,04h + jnz %%virqdo + cmp byte[doirqnext],1 + je near .virq +%%virqdo + test byte[INTEnab],20h + jz near %%novirq + mov ax,[VIRQLoc] + add ax,[IRQHack] + cmp ax,[resolutn] + jne %%notres + dec ax +; inc ax +%%notres + cmp ax,0FFFFh + jne %%notzero + xor ax,ax +%%notzero + cmp word[curypos],ax + jne near %%noirq +%%startirq + cmp byte[intrset],1 + jne %%nointrseta + mov byte[intrset],2 +%%nointrseta + mov byte[irqon],80h + test dl,04h + jnz %%irqd + test byte[INTEnab],10h + jnz %%tryhirq + jmp .virq +%%novirq + test byte[INTEnab],10h + jz %%noirq +%%tryhirq + jmp .virq + jmp %%startirq +%%irqd + mov byte[doirqnext],1 +%%noirq +%endmacro + +%macro ProcessIRQStuff 0 + ; check for VIRQ/HIRQ + cmp byte[virqnodisable],1 + je %%virqdo + test dl,04h + jnz %%virqdo + cmp byte[doirqnext],1 + je near .virq +%%virqdo + test byte[INTEnab],20h + jz near %%novirq + mov ax,[VIRQLoc] + add ax,[IRQHack] + cmp ax,[resolutn] + jne %%notres + dec ax +; inc ax +%%notres + cmp ax,0FFFFh + jne %%notzero + xor ax,ax +%%notzero + cmp word[curypos],ax + jne near %%noirq + test byte[INTEnab],10h + jnz %%tryhirq +%%startirq + cmp byte[intrset],1 + jne %%nointrseta + mov byte[intrset],2 +%%nointrseta + mov byte[irqon],80h + test dl,04h + jnz %%irqd + jmp .virq +%%novirq + test byte[INTEnab],10h + jz %%noirq + cmp byte[intrset],2 + jbe %%nointrseta3 + dec byte[intrset] + cmp byte[intrset],2 + ja %%noirq +%%nointrseta3 + cmp byte[intrset],1 + jne %%nointrseta2 + mov byte[intrset],8 + jmp %%noirq +%%nointrseta2 + test dl,04h + jnz %%noirq +%%tryhirq + jmp %%startirq +%%irqd + mov byte[doirqnext],1 +%%noirq +%endmacro + + +; .returnfromsfx + +; pexecs +; *** Copy to PC whenever a non-relative jump is executed + +NEWSYM romloadskip, db 0 +NEWSYM abcdefg, dd 0 +NEWSYM abcdefg1, dd 0 +NEWSYM abcdefg2, dd 0 +NEWSYM abcdefg3, dd 0 +NEWSYM SSKeyPressed, dd 0 +NEWSYM NoSoundReinit, dd 0 +NEWSYM NextNGDisplay, db 0 +NEWSYM TempVidInfo, dd 0 + + +NEWSYM tempdh, db 0 + +NEWSYM start65816 + + call initvideo + + cmp byte[videotroub],1 + jne .notrouble + ret +.notrouble + + +; cmp byte[OSPort],2 +; jae .nonewgfxcheck + jmp .nonewgfxcheck + cmp byte[cbitmode],1 + jne .nonewgfxcheck + cmp byte[newengen],1 + jne .nonewgfxcheck + cmp byte[cvidmode],3 + jne .nocorrectmode + cmp byte[newgfx16b],1 + je .nonewgfxcheck + jmp .correctmode +.nocorrectmode + mov dword[Msgptr],newgfxerror2 + jmp .correctmode + mov dword[Msgptr],newgfxerror +.correctmode + mov eax,[MsgCount] + mov [MessageOn],eax + mov byte[newengen],0 +.nonewgfxcheck + mov edi,[vidbufferofsa] + mov ecx,37518 + xor eax,eax + rep stosd +; mov edi,[vidbufferofsb] +; mov ecx,37518 +; xor eax,eax +; rep stosd + cmp byte[romloadskip],1 + je near StartGUI +NEWSYM continueprog + mov byte[romloadskip],0 + mov byte[debuggeron],0 + mov byte[exiter],0 + + ; clear keyboard presses + mov esi,pressed + mov ecx,256+128+64 + mov al,0 +.loopa + mov [esi],al + inc esi + loop .loopa + + call InitPreGame + +; Incorrect + +NEWSYM reexecute + + ; clear keyboard presses + mov esi,pressed + mov ecx,256+128+64 + mov al,0 +.loopa + cmp byte[esi],2 + jne .notclear + mov [esi],al +.notclear + inc esi + loop .loopa + jmp reexecuteb2 + +NEWSYM reexecuteb + cmp byte[OSPort],1 + ja reexecuteb2 + mov esi,pressed + mov ecx,256+128+64 + mov al,0 +.loopa + cmp byte[esi],2 + jne .notclear + mov [esi],al +.notclear + inc esi + loop .loopa +reexecuteb2: + ; temporary sprite displayer +; mov edx,.sdispname +; call Open_File +; jc .failedsd +; mov bx,ax +; mov ecx,544 +; mov edx,oamram +; call Read_File +; call Close_File +;.failedsd +; jmp .skipsd +;.sdispname db 'MMX3.SPR',0 +;.skipsd + + cmp byte[NoSoundReinit],1 + je .skippregame + call SetupPreGame +.skippregame + + ; initialize variables (Copy from variables) + call UpdateDPage + call SA1UpdateDPage + call Makemode7Table + cmp byte[SFXEnable],0 + je .nosfxud + call UpdateSFX +.nosfxud + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov bl,[xpb] + mov ax,[xpc] + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + jmp .skiplower +.loweraddr + cmp ax,4300h + jb .lower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma +.lower + mov esi,[snesmap2+ebx*4] + jmp .skiplower +.dma + mov esi,dmadata-4300h +.skiplower + mov [initaddrl],esi + add esi,eax ; add program counter to address + mov dl,[xp] ; set flags + mov dh,[curcyc] ; set cycles + + mov bl,dl +; cmp byte[CNetType],20 +; je .skipmovie +; cmp byte[CNetType],21 +; je .skipmovie +; jmp .skipmovie +; cmp byte[MovieProcessing],0 +; jne .movie +;.skipmovie + cmp byte[spcon],0 + je .nosoundta + mov edi,[tableadc+ebx*4] + or byte[curexecstate],2 + jmp .soundta +.nosoundta + mov edi,[tableadb+ebx*4] + and byte[curexecstate],0FDh +.soundta + jmp .nomovie +.movie + mov edi,[tableadc+ebx*4] + test byte[curexecstate],2 + jnz .nomovie + mov edi,[tableadb+ebx*4] +.nomovie + + mov ebp,[spcPCRam] + + mov byte[NoSoundReinit],0 + mov byte[csounddisable],0 + mov byte[NextNGDisplay],0 + + call splitflags + +; cmp byte[MovieProcessing],0 +; jne .movie2 + call execute + jmp .nomovie2 +.movie2 + call cpuover.returntoloop +.nomovie2 + + call joinflags + + ; de-init variables (copy to variables) + + mov [spcPCRam],ebp + mov [Curtableaddr],edi + mov [xp],dl + mov [curcyc],dh + + mov eax,[initaddrl] + sub esi,eax ; subtract program counter by address + mov [xpc],si + call ResetTripleBuf + + mov eax,[KeySaveState] + cmp byte[CNetType],20 + je .skipsoundreinit + test byte[pressed+eax],1 + jnz .soundreinit + mov eax,[KeyLoadState] + test byte[pressed+eax],1 + jz .skipsoundreinit +.soundreinit + mov byte[NoSoundReinit],1 + mov byte[csounddisable],1 +.skipsoundreinit + + cmp byte[NoSoundReinit],1 + je .skippostgame + call DeInitPostGame +.skippostgame + + ; clear all keys + call Check_Key + cmp al,0 + je .nokeys +.yeskeys + call Get_Key + call Check_Key + cmp al,0 + jne .yeskeys +.nokeys + +; mov edi,memtabler8+40h*4 +; mov ecx,30h +; mov eax,memaccessbankr848mb +; rep stosd +; mov edi,memtabler16+40h*4 +; mov ecx,30h +; mov eax,memaccessbankr1648mb +; rep stosd + + cmp byte[nextmenupopup],1 + je near showmenu + cmp byte[ReturnFromSPCStall],1 + je near .activatereset + mov eax,[KeySaveState] + cmp byte[CNetType],20 + je .net + test byte[pressed+eax],1 + jnz near savestate + mov eax,[KeyLoadState] + test byte[pressed+eax],1 + jnz near loadstate + cmp byte[SSKeyPressed],1 + je near showmenu + cmp byte[debugdisble],0 + jne .nodebugger + test byte[pressed+59],1 + jne near startdebugger +.nodebugger + test byte[pressed+59],1 + jne near showmenu + mov eax,[KeyQuickRst] +.net + test byte[pressed+eax],1 + jz .noreset +.activatereset + pushad + call GUIDoReset + popad + mov byte[ReturnFromSPCStall],0 + jmp continueprog +.noreset + cmp byte[guioff],1 + je near endprog + mov eax,[KeyQuickExit] + test byte[pressed+eax],1 + jnz near endprog + jmp StartGUI + +NEWSYM EndMessage +db ' ',13,10,0 + + +NEWSYM endprog + call deinitvideo + + cmp byte[previdmode],3 + jne .noendmessage + mov byte[EndMessage+13],',' + mov eax,[welcome+9] + mov [EndMessage+9],eax + mov ax,[welcome+7] + mov [EndMessage+7],ax + mov edx,EndMessage + call PrintStr +.noendmessage + +; mov eax,[opcd] +; mov eax,[numinst] ;Temporary +; mov eax,[NumBRRconv] +; call printnum + ; save sram + + ; change to sram dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + cmp byte[sramsavedis],1 + je .nosram + cmp dword[ramsize],0 + je .nosram + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + xor esi,esi + xor edi,edi + mov edx,fnames+1 + call Create_File + jc .nosram + mov bx,ax + xor ecx,ecx + mov ecx,[ramsize] + mov edx,[sram] + call Write_File + call Close_File +.nosram + cmp byte[SFXSRAM],0 + je .nosfxsram + mov edx,fnames+1 + call Create_File + jc .nosfxsram + mov bx,ax + mov ecx,65536 + mov edx,[sfxramdata] + call Write_File + call Close_File +.nosfxsram + cmp byte[SA1Enable],1 + jne .nosa1 + mov edx,fnames+1 + call Create_File + jc .nosa1 + mov bx,ax + mov ecx,65536*2 + mov edx,[SA1RAMArea] + call Write_File + call Close_File +.nosa1 + + ; change dir to InitDrive/InitDir + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + + call createnewcfg + call GUISaveVars + + cmp byte[MovieProcessing],0 + je .nomovieclose + mov bx,[MovieFileHand] + mov byte[MovieProcessing],0 + call Close_File +.nomovieclose +;NEWSYM tempstore, times 1024*1024 db 0 +; mov esi,tempstore +; mov ecx,1024*1024 +;.loop +; mov al,[esi] +; cmp al,0 +; jne .faulty +; inc esi +; dec ecx +; jnz .loop +; xor eax,eax +; jmp .notfaulty +;.faulty +; mov eax,1 +;.notfaulty +; mov eax,[vidbufferofsa] +; call printnum +; mov dl,32 +; mov ah,02h +; call Output_Text +; mov eax,[vidbufferofsb] +; call printnum +; mov dl,32 +; mov ah,02h +; call Output_Text +; mov eax,[romdata] +; call printnum + + ; change dir to InitDrive/InitDir + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + + ; Deinit modem if necessary + cmp byte[ModemInitStat],0 + je .nodeinitmodem + call DeInitModem +.nodeinitmodem + cmp byte[OSPort],1 + jae .nodeinitipx + call deinitipx +.nodeinitipx + jmp OSExit + +NEWSYM interror + stim + call deinitvideo + mov edx,.nohand ;use extended + mov ah,9 ;DOS- API + call Output_Text ;to print a string + jmp DosExit + +.nohand db 'Cannot process interrupt handler!',13,10,0 + +; global variables +NEWSYM invalid, db 0 +NEWSYM invopcd, db 0 +NEWSYM pressed, times 256+128+64 db 0 ; keyboard pressed keys in scancode +NEWSYM exiter, db 0 +NEWSYM oldhand9o, dd 0 +NEWSYM oldhand9s, dw 0 +NEWSYM oldhand8o, dd 0 +NEWSYM oldhand8s, dw 0 +NEWSYM opcd, dd 0 +NEWSYM pdh, dd 0 +NEWSYM pcury, dd 0 +NEWSYM timercount, dd 0 +NEWSYM initaddrl, dd 0 ; initial address location +NEWSYM NetSent, dd 0 +NEWSYM nextframe, dd 0 ; tick count for timer +NEWSYM curfps, db 0 ; frame/sec for current screen +NEWSYM SFXSRAM, db 0 +NEWSYM newgfxerror, db 'NEED MEMORY FOR GFX ENGINE',0 +NEWSYM newgfxerror2, db 'NEED 320x240 FOR NEW GFX 16B',0 +;newgfxerror db 'NEW GFX IN 16BIT IS N/A',0 +NEWSYM HIRQCycNext, dd 0 +NEWSYM HIRQNextExe, db 0 + +;******************************************************* +; Save/Load States +;******************************************************* + +NEWSYM sramsave + mov byte[pressed+1],0 + mov byte[pressed+41],0 + ; save sram + cmp byte[sramsavedis],1 + je .nosram + cmp word[ramsize],0 + je .nosram + mov edx,fnames+1 + call Create_File + jc .nosram + mov bx,ax + xor ecx,ecx + mov cx,[ramsize] + mov edx,[sram] + call Write_File + call Close_File + mov dword[Msgptr],.savesrmmsg1 + mov eax,[MsgCount] + mov [MessageOn],eax + jmp reexecute +.nosram + mov dword[Msgptr],.savesrmmsg2 + mov eax,[MsgCount] + mov [MessageOn],eax + jmp reexecute + +.savesrmmsg1 db 'SRAM DATA SAVED.',0 +.savesrmmsg2 db 'NO SRAM DATA.',0 + + + +NEWSYM statesaver + clim + sub dword[Curtableaddr],tableA + sub dword[spcPCRam],spcRam + sub dword[spcRamDP],spcRam + call PrepareSaveState + call unpackfunct + call initrevst +; jmp .skipsaves + ; Save State + mov edx,fnamest+1 + call Create_File + jc near .nosavestuff + ; Save 65816 status, etc. + mov bx,ax + mov ecx,[PHnum2writecpureg] + mov edx,zsmesg + call Write_File + mov ecx,8 + mov edx,cycpbl + call Write_File + ; Save SNES PPU Register status + mov ecx,3019 + mov edx,sndrot + call Write_File + ; Save RAM (WRAM(128k),VRAM(64k),SRAM) +; xor ecx,ecx +; mov cx,[ramsize] + mov ecx,65536+65536 + mov edx,[wramdata] + call Write_File + mov ecx,65536 + mov edx,[vram] + call Write_File + cmp byte[spcon],0 + je .nospcon + ; Save SPC stuff + mov ecx,[PHspcsave] + mov edx,spcRam + call Write_File + ; Save DSP stuff + mov ecx,[PHdspsave] + mov edx,BRRBuffer + call Write_File + ; Save DSP Mem + mov ecx,256 + mov edx,DSPMem + call Write_File +.nospcon + cmp byte[C4Enable],1 + jne .noc4 + mov ecx,2000h + mov edx,[C4Ram] + call Write_File +.noc4 + cmp byte[SFXEnable],1 + jne .nosfx + mov ecx,[SfxCROM] + sub [SfxRomBuffer],ecx + mov ecx,[SfxRAMMem] + sub [SfxLastRamAdr],ecx + mov ecx,65536*2 + mov edx,[sfxramdata] + call Write_File + ; uncomment the following + mov ecx,[PHnum2writesfxreg] + mov edx,SfxR0 + call Write_File + mov ecx,[SfxCROM] + add [SfxRomBuffer],ecx + mov ecx,[SfxRAMMem] + add [SfxLastRamAdr],ecx +.nosfx + cmp byte[SPC7110Enable],1 + jne .nospc7110 + mov edx,[romdata] + add edx,510000h + mov ecx,65536 + call Write_File + mov edx,SPCMultA + mov ecx,[PHnum2writespc7110reg] + call Write_File +.nospc7110 + cmp byte[SA1Enable],1 + jne .nossa1 + ; Convert SA-1 stuff to standard, non displacement format + call SaveSA1 + mov ecx,[PHnum2writesa1reg] + mov edx,SA1Mode + call Write_File + mov ecx,65536*2 + mov edx,[SA1RAMArea] + call Write_File + ; Convert back SA-1 stuff + call RestoreSA1 +.nossa1 + cmp byte[cbitmode],0 + je .nocapturepicture + cmp byte[NoPictureSave],1 + je .nocapturepicture + call CapturePicture + mov ecx,64*56*2 + mov edx,PrevPicture + call Write_File +.nocapturepicture + call Close_File + add dword[Curtableaddr],tableA + add dword[spcPCRam],spcRam + add dword[spcRamDP],spcRam + call ResetState + call initrevst + stim + mov dword[Msgptr],.savemsg + mov eax,[MsgCount] + mov [MessageOn],eax + ret +.nosavestuff + add dword[Curtableaddr],tableA + add dword[spcPCRam],spcRam + add dword[spcRamDP],spcRam + call ResetState + call initrevst + stim + mov dword[Msgptr],.savemsgfail + mov eax,[MsgCount] + mov [MessageOn],eax + ret + +.savemsg db 'STATE SAVED.',0 +.savemsgfail db 'UNABLE TO SAVE.',0 + +NEWSYM savestate + jmp .save + mov byte[pressed+1],0 + mov byte[pressed+60],0 + mov edx,.fname2+1 + call Create_File + mov esi,[vidbuffer] + add esi,16*2+256*2+32*2 + mov edi,[vidbuffer] + mov dl,[resolutn] + mov bx,ax + ; move data to a linear address from esi to edi +.loopa + mov ecx,128 + add esi,64+128*4 + dec dl + jnz .loopa + push edx + push esi + mov ecx,128*4 + mov edx,esi + call Write_File + pop esi + pop edx + add esi,64+128*4 + call Close_File + jmp reexecuteb +.save + mov byte[pressed+1],0 + mov eax,[KeySaveState] + mov byte[pressed+eax],2 + call statesaver + jmp reexecuteb + +.fname2 db 9,'image.dat',0 + + ; Load State +NEWSYM stateloader + mov byte[MovieProcessing],0 + mov byte[prevoamptr],0FFh + ; Load 65816 status, etc. + mov bx,ax + mov ecx,[PHnum2writecpureg] + add dword[Totalbyteloaded],ecx + mov edx,zsmesg + call Read_File + cmp byte[versn],60 + jne near .convert + ; Load SPC timers + mov ecx,8 + add dword[Totalbyteloaded],ecx + mov edx,cycpbl + call Read_File + ; Load SNES PPU Register status + mov ecx,3019 ; 3019 + add dword[Totalbyteloaded],ecx + mov edx,sndrot + call Read_File + ; Load RAM (WRAM(128k),VRAM(64k),SRAM) + mov ecx,65536+65536 + add dword[Totalbyteloaded],ecx + mov edx,[wramdata] + call Read_File + mov ecx,65536 + add dword[Totalbyteloaded],ecx + mov edx,[vram] + call Read_File + cmp byte[spcon],0 + je .nospcon + ; Load SPC stuff + mov ecx,[PHspcsave] + add dword[Totalbyteloaded],ecx + mov edx,spcRam + call Read_File + ; Load DSP stuff + mov ecx,[PHdspsave] + add dword[Totalbyteloaded],ecx + mov edx,BRRBuffer + call Read_File + ; Load DSP Mem + mov ecx,256 + add dword[Totalbyteloaded],ecx + mov edx,DSPMem + call Read_File +.nospcon + cmp byte[SFXEnable],1 + jne near .nosfx + mov ecx,65536*2 + add dword[Totalbyteloaded],ecx + mov edx,[sfxramdata] + call Read_File + + mov ecx,[PHnum2writesfxreg] + add dword[Totalbyteloaded],ecx + mov edx,SfxR0 + call Read_File + + xor ecx,ecx + mov cl,[SfxPBR] + mov ecx,[SfxMemTable+ecx*4] + mov [SfxCPB],ecx + + xor ecx,ecx + mov cl,[SfxROMBR] + mov ecx,[SfxMemTable+ecx*4] + mov [SfxCROM],ecx + + xor ecx,ecx + mov cl,[SfxRAMBR] + shl ecx,16 + add ecx,[sfxramdata] + mov dword [SfxRAMMem],ecx + + mov ecx,[SfxCROM] + add [SfxRomBuffer],ecx + mov ecx,[SfxRAMMem] + add [SfxLastRamAdr],ecx + +.nosfx + + cmp byte[C4Enable],1 + jne .noc4 + mov ecx,2000h + add dword[Totalbyteloaded],ecx + mov edx,[C4Ram] + call Read_File +.noc4 + cmp byte[SPC7110Enable],1 + jne .nospc7110 + mov edx,[romdata] + add edx,510000h + mov ecx,65536 + call Read_File + mov edx,SPCMultA + mov ecx,[PHnum2writespc7110reg] + call Read_File +.nospc7110 + cmp byte[SA1Enable],1 + jne .nossa1 + mov ecx,[PHnum2writesa1reg] + add dword[Totalbyteloaded],ecx + mov edx,SA1Mode + call Read_File + mov ecx,65536*2 + add dword[Totalbyteloaded],ecx + mov edx,[SA1RAMArea] + call Read_File + ; Convert back SA-1 stuff + push ebx + call RestoreSA1 + pop ebx + call SA1UpdateDPage +.nossa1 + cmp byte[SDD1Enable],1 + jne .nosdd1 + call UpdateBanksSDD1 +.nosdd1 + call Close_File + call repackfunct + mov byte[spcnumread],0 + mov byte[nexthdma],0 + +; call headerhack + + call initpitch + call initrevst + ret + +.convert + ; Load SNES PPU Register status + mov ecx,3019 + mov edx,sndrot + call Read_File + ; Load RAM (WRAM(128k),VRAM(64k),SRAM) + mov dword[cycpbl],0 + mov dword[cycpblt],0 + mov ah,[cycpbl2] + mov [cycpbl],ah + mov ah,[cycpblt2] + mov [cycpblt],ah + + mov ecx,[ramsize] + add ecx,65536+65536+65536 + mov edx,[wramdata] + call Read_File + cmp byte[spcon],0 + je .nospconb + ; Load SPC stuff + mov ecx,[PHspcsave] + mov edx,spcRam + call Read_File + ; Load DSP stuff + mov ecx,32 + mov edx,BRRBuffer + call Read_File + ; Convert old to new data + ; read/write 6, jump 2 for 8 times + mov edx,BRRPlace0 + mov ecx,8 +.loopconv + push edx + push ecx + mov ecx,4 + call Read_File + pop ecx + pop edx + add edx,8 + dec ecx + jnz .loopconv +;dspsave equ $-BRRBuffer +;dspconvb equ $-Voice0Freq + ; Load DSP stuff + mov ecx,[PHdspsave] + sub ecx,64+32 + sub ecx,8 + mov edx,Voice0Freq + call Read_File + ; Load DSP Mem + mov ecx,256 + mov edx,DSPMem + call Read_File +.nospconb + call Close_File + call repackfunct + mov dword[cycpbl],0 + mov byte[spcnumread],0 + mov byte[nexthdma],0 + call headerhack + call initpitch + call initrevst + ret +NEWSYM loadstate + mov byte[pressed+1],0 + mov eax,[KeyLoadState] + mov byte[pressed+eax],2 + mov byte[multchange],1 + clim + mov edx,fnamest+1 + call Open_File + jc near .nofile + call stateloader + + ; Clear Cache Check + mov esi,vidmemch2 + mov ecx,4096+4096+4096 +.next + mov byte[esi],1 + inc esi + dec ecx + jnz .next + cmp byte[versn],60 + jne near .convert + mov dword[Msgptr],.loadmsg + jmp .noconvert +.convert + mov dword[Msgptr],.convmsg + mov byte[versn],60 + mov byte[versn-2],'6' +.noconvert + mov eax,[MsgCount] + mov [MessageOn],eax + add dword[Curtableaddr],tableA + add dword[spcPCRam],spcRam + add dword[spcRamDP],spcRam + call ResetState + call procexecloop + stim + jmp reexecuteb +.nofile + mov dword[Msgptr],.nfndmsg + mov eax,[MsgCount] + mov [MessageOn],eax + stim + jmp reexecuteb + +.loadmsg db 'STATE LOADED.',0 +.convmsg db 'STATE LOADED/CONVERTED',0 +.nfndmsg db 'UNABLE TO LOAD.',0 + +NEWSYM loadstate2 + mov edx,fnamest+1 +NEWSYM loadstate3 + call Open_File + jc near .nofile + mov dword[Totalbyteloaded],0 + call stateloader + + ; Clear Cache Check + mov esi,vidmemch2 + mov ecx,4096+4096+4096 +.next + mov byte[esi],1 + inc esi + dec ecx + jnz .next + add dword[Curtableaddr],tableA + add dword[spcPCRam],spcRam + add dword[spcRamDP],spcRam + call ResetState + call procexecloop + ret +.nofile + ret + +;******************************************************* +; Int 08h vector +;******************************************************* + +; sets to either 60Hz or 50Hz depending on PAL/NTSC +NEWSYM init60hz + cmp byte[romispal],0 + jne .dopal + mov al,00110110b + out 43h,al + mov ax,19900 ; 65536/(60/((65536*24+175)/(60*60*24))) + mov dword[timercount],19900 + out 40h,al + mov al,ah + out 40H,al + ret +.dopal + mov al,00110110b + out 43h,al + mov ax,23863 ; 65536/(50/((65536*24+175)/(60*60*24))) + mov dword[timercount],23863 + out 40h,al + mov al,ah + out 40H,al + ret + +NEWSYM init18_2hz + mov al,00110110b + out 43H,al + mov ax,0 + mov dword[timercount],65536 + out 40H,al + mov al,ah + out 40H,al + ret + +NEWSYM Game60hzcall + inc word[t1cc] + inc byte[nextframe] + ret + +NEWSYM handler8h + cli + push ds + push eax +; mov ax,0 + mov ax,[cs:dssel] +NEWSYM handler8hseg + mov ds,ax + call Game60hzcall + mov eax,[timercount] + sub dword[timeradj],eax + jnc .noupd + add dword[timeradj],65536 + pushf + call far [oldhand8o] +.noupd + mov al,20h + out 20h,al + pop eax + pop ds + sti + iretd + +NEWSYM timeradj, dd 65536 +NEWSYM t1cc, dw 0 + +;******************************************************* +; Int 09h vector +;******************************************************* + +NEWSYM skipnextkey42, db 0 + +NEWSYM handler9h + cli + push ds + push eax + push ebx + mov ax,[cs:dssel] + mov ds,ax + xor ebx,ebx + in al,60H ; get keyboard scan code + cmp al,42 + jne .no42 + cmp byte[skipnextkey42],0 + je .no42 + mov byte[skipnextkey42],0 + jmp .skipkeyrel +.no42 + cmp al,0E0h + jne .noE0 + mov byte[skipnextkey42],1 + jmp .skipkeyrel +.noE0 + mov byte[skipnextkey42],0 + mov bl,al + xor bh,bh + test bl,80h ; check if bit 7 is on (key released) + jnz .keyrel + cmp byte[pressed+ebx],0 + jne .skipa + mov byte[pressed+ebx],1 ; if not, set key to pressed +.skipa + jmp .skipkeyrel +.keyrel + and ebx,7Fh + cmp ebx,59 + je .skipkeyrel + cmp ebx,[KeySaveState] + je .skipkeyrel + cmp ebx,[KeyLoadState] + je .skipkeyrel + cmp ebx,[KeyQuickExit] + je .skipkeyrel + cmp ebx,[KeyQuickLoad] + je .skipkeyrel + cmp ebx,[KeyQuickRst] + je .skipkeyrel + cmp bl,1 + je .skipkeyrel + mov byte[pressed+ebx],0 ; if not, set key to pressed +.skipkeyrel + mov byte[pressed],0 + in al,61h + mov ah,al + or al,80h + out 61h,al + mov al,20H ; turn off interrupt mode + out 20H,al + pop ebx ; Pop registers off + pop eax ; stack in correct + pop ds + sti + iretd + +ALIGN32 + +NEWSYM soundcycleft, dd 0 +NEWSYM curexecstate, dd 0 + +NEWSYM nmiprevaddrl, dd 0 ; observed address -5 +NEWSYM nmiprevaddrh, dd 0 ; observed address +5 +NEWSYM nmirept, dd 0 ; NMI repeat check, if 6 then okay +NEWSYM nmiprevline, dd 224 ; previous line +NEWSYM nmistatus, dd 0 ; 0 = none, 1 = waiting for nmi location, + ; 2 = found, disable at next line +NEWSYM joycontren, dd 0 ; joystick read control check +NEWSYM NextLineCache, db 0 +NEWSYM NetQuit, db 0 + +Donextlinecache: + cmp word[curypos],0 + je .nocache + mov ax,[resolutn] + dec ax + cmp word[curypos],ax + jae .nocache + test byte[scrndis],10h + jnz .nocache + cmp byte[curblank],0h + jne .nocache + push ecx + push ebx + push esi + push edi + xor ecx,ecx + mov cl,[curypos] + push edx +.next + mov byte[sprlefttot+ecx],0 + mov dword[sprleftpr+ecx*4],0 + inc cl + jnz .next + call processsprites + call cachesprites + pop edx + pop edi + pop esi + pop ebx + pop ecx +.nocache + mov byte[NextLineCache],0 + ret + +%macro NetHelpExecSend 1 + cmp byte[pl1neten+%1],1 + jne %%nopl + mov eax,[ecx] + mov [cnetplaybuf+ebx],al + inc ebx + and ebx,1FFh + mov [cnetplaybuf+ebx],ah + inc ebx + and ebx,1FFh + ror eax,16 + mov [cnetplaybuf+ebx],al + inc ebx + and ebx,1FFh + mov [cnetplaybuf+ebx],ah + inc ebx + and ebx,1FFh + ror eax,16 + call RemoteSendEAX + add ecx,4 +%%nopl +%endmacro + +%macro NetHelpExecRecv 1 + cmp byte[pl1neten+%1],2 + jne %%nopl + call RemoteGetEAX + mov [ecx],eax +%%nopl + add ecx,4 +%endmacro + +%macro NetHelpExecRecv2 1 + cmp byte[pl1neten+%1],1 + jne %%nopl + mov al,[cnetplaybuf+ebx] + inc ebx + and ebx,1FFh + mov ah,[cnetplaybuf+ebx] + inc ebx + and ebx,1FFh + ror eax,16 + mov al,[cnetplaybuf+ebx] + inc ebx + and ebx,1FFh + mov ah,[cnetplaybuf+ebx] + inc ebx + and ebx,1FFh + ror eax,16 + mov [ecx],eax +%%nopl + add ecx,4 +%endmacro + +;******************************************************* +; 65816 execution +;******************************************************* + +SpeedHackSafeTable + db 1,0,1,0,0,0,1,0,1,0,1,1,0,0,0,0 + db 0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0 + db 0,0,0,0,0,0,1,0,1,0,1,1,0,0,1,0 + db 0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0 + db 0,0,0,0,0,1,1,1,1,1,1,1,0,1,1,1 + db 0,1,1,1,0,1,1,1,0,1,1,0,0,0,1,0 + db 0,1,0,1,0,1,1,1,0,1,1,0,0,1,1,1 + db 0,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1 + db 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0 + db 0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0 + db 0,1,0,1,0,1,1,1,1,1,0,0,0,1,1,1 + db 0,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1 + +NEWSYM exitloop2 + mov byte[ExecExitOkay],0 +NEWSYM exitloop + ret + cmp byte[nextmenupopup],1 + je .okay + cmp byte[ExecExitOkay],0 + je .okay + mov byte[pressed+1],0 + mov byte[pressed+59],0 + mov eax,[KeySaveState] + mov byte[pressed+eax],0 + mov eax,[KeyLoadState] + mov byte[pressed+eax],0 + mov eax,[KeyQuickExit] + mov byte[pressed+eax],0 + mov eax,[KeyQuickLoad] + mov byte[pressed+eax],0 + mov eax,[KeyQuickRst] + mov byte[pressed+eax],0 + mov byte[ExecExitOkay],5 + mov eax,[KeyQuickSnapShot] + mov byte[pressed+eax],0 + mov byte[SSKeyPressed],0 + jmp cpuover.returntoloop +.okay + mov byte[ExecExitOkay],5 + ret + +ALIGN16 + +%macro FlipCheck 0 + cmp byte[FlipWait],0 + je %%noflip + push edx + push eax + mov dx,3DAh ;VGA status port + in al,dx + test al,8 + jz %%skipflip + push ebx + push ecx + mov ax,4F07h + mov bh,00h + mov bl,00h + xor cx,cx + mov dx,[NextLineStart] + mov [LastLineStart],dx + int 10h + mov byte[FlipWait],0 + pop ecx + pop ebx +%%skipflip + pop eax + pop edx +%%noflip +%endmacro + + +NEWSYM execute +NEWSYM execloop + mov bl,dl + test byte[curexecstate],2 + jnz .sound + mov edi,[tableadb+ebx*4] + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc .cpuover +.startagain + call dword near [edi+ebx*4] +.cpuover + jmp cpuover +.sound + mov edi,[tableadc+ebx*4] + sub dword[cycpbl],55 + jnc .skipallspc + mov eax,[cycpblt] + mov bl,[ebp] + add dword[cycpbl],eax + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx +.skipallspc + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc .cpuovers + call dword near [edi+ebx*4] +.cpuovers + jmp cpuover + + + +SECTION .data +ALIGN32 +NEWSYM ExecExitOkay, db 1 +NEWSYM JoyABack, dd 0 +NEWSYM JoyBBack, dd 0 +NEWSYM JoyCBack, dd 0 +NEWSYM JoyDBack, dd 0 +NEWSYM JoyEBack, dd 0 +NEWSYM NetCommand, dd 0 +NEWSYM spc700read, dd 0 +NEWSYM lowestspc, dd 0 +NEWSYM highestspc, dd 0 +NEWSYM SA1UBound, dd 0 +NEWSYM SA1LBound, dd 0 +NEWSYM SA1SH, dd 0 +NEWSYM SA1SHb, dd 0 +NEWSYM NumberOfOpcodes2, dd 0 +NEWSYM ChangeOps, dd 0 +NEWSYM SFXProc, dd 0 +SECTION .text + + +%macro C4Paused 0 +; cmp byte[C4Pause],0 +; je %%notpaused +; inc esi +; xor dh,dh +; jmp cpuover +;%%notpaused +%endmacro + +NEWSYM cpuover + dec esi + cmp byte[HIRQNextExe],0 + je .nohirq + mov dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + jmp .hirq +.nohirq + cmp byte[SA1Enable],0 + je near .nosa1b + test byte[exiter],01h + jnz near .nosa1 + mov byte[cycpl],150 + test byte[SA1Control],60h + jnz near .nosa1 + call SA1Swap + cmp byte[CurrentExecSA1],15 + ja .nocontinueexec + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain +.nocontinueexec + + ; check for sa-1 speed hacks + mov byte[SA1SHb],0 + cmp word[IRAM+0A0h],80BFh + jne .noshb2 + cmp word[IRAM+020h],0 + jne .noshb2 + mov ecx,[SA1Ptr] ; small speed hack + sub ecx,[romdata] + cmp ecx,83h + jb .skipsh + cmp ecx,97h + ja .skipsh + mov byte[SA1SHb],1 +.skipsh +.noshb2 + + mov ecx,[SA1Ptr] ; small speed hack + cmp dword[ecx],0FCF04BA5h + je .shm + cmp dword[ecx-2],0FCF04BA5h + jne .skipshm +.shm + cmp byte[IRAM+4Bh],0 + jne .skipshm + mov byte[SA1SHb],1 +.skipshm + + cmp dword[ecx],80602EEEh + jne .skipshc + sub ecx,[romdata] + cmp ecx,4E5h + jb .skipshc + cmp ecx,4E8h + ja .skipshc + mov byte[SA1SHb],1 + mov ecx,[SA1BWPtr] + add word[ecx+602Eh],4 +.skipshc + + test word[IRAM+0Ah],8000h + jnz .noshb2b + test word[IRAM+0Eh],8000h + jz .noshb2b + mov ecx,[SA1Ptr] ; small speed hack + sub ecx,[romdata] + cmp ecx,0C93h + jb .skipshb + cmp ecx,0C9Bh + ja .skipshb + mov byte[SA1SHb],1 +.skipshb + cmp ecx,0CB8h + jb .skipshb3 + cmp ecx,0CC0h + ja .skipshb3 + mov byte[SA1SHb],1 +.skipshb3 +.noshb2b + + sub esi,[wramdata] + cmp esi,224h + jb .nosh + cmp esi,22Eh + ja .nosh + mov ecx,[wramdata] + mov dword[SA1LBound],224h + mov dword[SA1UBound],22Eh + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.nosh + cmp esi,1F7C6h + jb .noshb + cmp esi,1F7CCh + ja .noshb + mov ecx,[wramdata] + mov dword[SA1LBound],1F7C6h + mov dword[SA1UBound],1F7CCh + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.noshb + cmp esi,14h + jb .noshc + cmp esi,1Ch + ja .noshc + mov ecx,[wramdata] + cmp dword[ecx+14h],0F023002Ch + jne .noshc + mov dword[SA1LBound],14h + mov dword[SA1UBound],1Ch + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.noshc + add esi,[wramdata] + sub esi,[romdata] + cmp esi,0A56h + jb .noshbc + cmp esi,0A59h + ja .noshbc + mov ecx,[romdata] + mov dword[SA1LBound],0A56h + mov dword[SA1UBound],0A59h + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.noshbc + xor ecx,ecx + add esi,[romdata] + xor dh,dh + mov byte[cycpl],10 + cmp byte[CurrentExecSA1],255 + jne .notsa1255 + mov byte[cycpl],160 +.notsa1255 + mov byte[CurrentExecSA1],0 + test dl,04h + jnz .nosa1 + test byte[SA1IRQEnable],80h + jz .nosa1 + test byte[SA1DoIRQ],4 + jz .nosa1 + and byte[SA1DoIRQ],0FBh + mov al,byte[SA1Message+1] + mov byte[SA1Message+3],al + or byte[SA1IRQExec],1 + ; Start IRQ + add dh,10 + jmp .virq +.nosa1 + test byte[SA1IRQEnable],20h + jz .nosa1chirq + test byte[SA1DoIRQ],8 + jz .nosa1chirq +; jmp .nosa1chirq + and byte[SA1DoIRQ],0F7h + mov al,byte[SA1Message+1] + mov byte[SA1Message+3],al + or byte[SA1IRQExec],2 + ; Start IRQ + add dh,10 + jmp .virq +.nosa1chirq +.nosa1b + FlipCheck + cmp byte[NextLineCache],0 + je .nosprcache + call Donextlinecache +.nosprcache + cmp byte[KeyOnStB],0 + je .nokeyon + mov al,[KeyOnStB] + call ProcessKeyOn +.nokeyon + mov al,[KeyOnStA] + mov [KeyOnStB],al + mov byte[KeyOnStA],0 + test byte[exiter],01h + jnz near exitloop2 + + test byte[SfxSFR],20h + jnz near StartSFX +.returnfromsfx +; inc dword[numinst] ;Temporary + inc word[curypos] + add dh,[cycpl] + mov ax,[totlines] + cmp word[curypos],ax + ja near .overy + cmp byte[spcon],0 + je .nosound + call updatetimer +.nosound + mov ax,[resolutn] + inc ax + cmp [curypos],ax + je near .nmi + + mov ax,[resolutn] + cmp [curypos],ax + je near .hdma +; add ax,2 +; cmp [curypos],ax +; je near .hdma +.hdmacont + + cmp byte[curypos],100 + jne .noline100 + mov ax,[scrnon] + mov [TempVidInfo],ax + mov ax,[scaddset] + mov [TempVidInfo+2],ax +.noline100 + + ; check for VIRQ/HIRQ/NMI + ProcessIRQStuff + mov ax,[resolutn] + dec ax + cmp [curypos],ax + jb .drawline + + +; mov ax,[resolutn] +; cmp [curypos],ax +; jb .drawline + C4Paused + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.hdma + call exechdma + jmp .hdmacont + +.drawline + mov al,[nmiprevline] + cmp [curypos],al + jb near .noskip + cmp byte[nmirept],10 + jb near .noskip + ; if between correct address, decrease by 2, set nmistatus as 2 + ; if not, set nmistatus as 1, increase by 2 + cmp byte[curexecstate],0 + jne .nn + xor dh,dh +.nn + cmp byte[nmistatus],2 + jae near .noskip + cmp esi,[nmiprevaddrl] + jb .failcheck2 + cmp esi,[nmiprevaddrh] + ja .failcheck2 + cmp byte[nmiprevline],20 + jb .nodec + sub byte[nmiprevline],10 +.nodec + xor eax,eax + mov al,[esi] + cmp byte[disable65816sh],1 + je .ohno + cmp byte[SpeedHackSafeTable+eax],1 + jne .okay +.ohno + mov byte[nmirept],0 + mov dword[nmiprevaddrl],0FFFFFFFFh + mov dword[nmiprevaddrh],0 + jmp .noskip +.okay + mov byte[nmistatus],2 + and byte[curexecstate],0FEh +.nodis65816 + jmp .noskip +.failcheck2 + add byte[nmiprevline],1 + mov byte[nmistatus],1 +.noskip + cmp byte[hdmadelay],0 + je .dohdma + dec byte[hdmadelay] + jmp .nodohdma +.dohdma + cmp word[curypos],1 + jne .nooffby1line + test byte[INTEnab],20h + jz .nooffby1line + cmp word[VIRQLoc],0 + je .nodohdma +.nooffby1line + call exechdma +.nodohdma + cmp word[curypos],1 + jne .nocache + call cachevideo +.nocache + cmp byte[curblank],0 + jne .nodrawlineb2 + call drawline +.nodrawlineb2 + cmp byte[curexecstate],2 + je near pexecs + cmp byte[curexecstate],0 + jne .yesexec + xor dh,dh +.yesexec + C4Paused + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.nmi + mov byte[doirqnext],0 + inc dword[NetSent] + cmp byte[yesoutofmemory],1 + jne .noout + call outofmemfix +.noout + +; pushad +; call GenLatencyDisplay +; popad + + + ; NetCommand : bit 0 = Okay (should be 1), bit 1 = control update, + ; bit 2 = print update, bit 3 = quit, bit 4 = reset + + dec word[curypos] + mov [tempdh],dh + xor dh,dh + mov byte[doirqnext],0 + + call exechdma + call exechdma + +; push es +; cmp byte[cbitmode],1 +; jne .nodisptest +; mov es,[vesa2selec] +; mov word[es:10+640],1111111111111111b +;.nodisptest +; pop es + + mov byte[NetCommand],0 + + mov byte[NextNGDisplay],1 + + cmp byte[newengen],0 + je .nonewgfx + cmp byte[curblank],0h + jne .nonewgfx + cmp byte[ForceNewGfxOff],0 + jne .nonewgfx +; cmp byte[NextNGDisplay],0 +; je .nonewgfx + call StartDrawNewGfx +.nonewgfx + + cmp byte[chaton],1 + je near .nonet + cmp byte[CNetType],20 + je near .net + cmp byte[GUIQuit],1 + je near endprog + mov eax,dword[KeyQuickSnapShot] + or eax,eax + jz .nosskey + test byte[pressed+eax],1 + jz .nosskey + mov byte[SSKeyPressed],1 + mov byte[pressed+eax],2 + jmp exitloop +.nosskey + test byte[pressed+1],01h + jnz near exitloop + test byte[pressed+59],01h + jnz near exitloop + cmp byte[nextmenupopup],1 + je near exitloop + cmp byte[nextmenupopup],2 + jb .skipmenupop + dec byte[nextmenupopup] +.skipmenupop + mov eax,[KeySaveState] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyLoadState] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyQuickRst] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyQuickExit] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyQuickLoad] + test byte[pressed+eax],01h + jnz near exitloop + cmp byte[ExecExitOkay],0 + je .returntoloop + dec byte[ExecExitOkay] +.returntoloop + jmp .nonet +.net + test byte[pressed+1],01h + jz .nonetexit + or byte[NetCommand],08h +.nonetexit + mov eax,[KeySaveState] + test byte[pressed+eax],01h + jz .notnetsave + mov byte[pressed+eax],2 + call NetSaveState +.notnetsave + mov eax,[KeyLoadState] + test byte[pressed+eax],01h + jz .notnetload + or byte[NetCommand],88h +.notnetload +.nonet + mov dh,[tempdh] + inc word[curypos] + + cmp byte[CurRecv],1 + je .noinputread + cmp byte[NoInputRead],1 + je .noinputread + call ReadInputDevice +.noinputread + + call UpdateRewind + + + mov byte[NetQuit],0 + cmp byte[CNetType],20 + jne near .nozerons + test byte[NetSwap],1 + jnz near .noonens + + cmp byte[CurRecv],1 + je near .noreceiveb2 + + mov eax,[JoyAOrig] + cmp eax,[prevp1net] + je .nochange1 + or byte[NetCommand],02h + mov [prevp1net],eax +.nochange1 + mov eax,[JoyBOrig] + cmp eax,[prevp2net] + je .nochange2 + or byte[NetCommand],02h + mov [prevp2net],eax +.nochange2 + mov eax,[JoyCOrig] + cmp eax,[prevp3net] + je .nochange3 + or byte[NetCommand],02h + mov [prevp3net],eax +.nochange3 + mov eax,[JoyDOrig] + cmp eax,[prevp4net] + je .nochange4 + or byte[NetCommand],02h + mov [prevp4net],eax +.nochange4 + test byte[NetCommand],02h + jz .nochangeatall + mov dword[ResendTimer],60 + jmp .yeschanged +.nochangeatall + dec dword[ResendTimer] + jnz .yeschanged + or byte[NetCommand],02h + mov dword[ResendTimer],60 +.yeschanged + ; Send command & store command + call PreparePacket + push ebx + push ecx + mov al,[NetCommand] + mov ebx,[cnetptrhead] + mov [cnetplaybuf+ebx],al + call RemoteSendChar + ; ################## + ; Send latency value + cmp byte[OSPort],3 + jne .nolatencysend + cmp byte[BackState],1 + jne .nolatencysend + mov ebx,[LatencySendPtr] + and ebx,0FFh + inc dword[LatencySendPtr] + mov byte[LatencyV+ebx],0 + mov ebx,[PBackupPos] + mov al,[LocalLValue] +; inc al + call RemoteSendChar +.nolatencysend + mov ebx,[cnetptrhead] + mov ecx,JoyAOrig + inc ebx + and ebx,1FFh + test byte[NetCommand],02h + jz near .nosendextra + NetHelpExecSend 0 + NetHelpExecSend 1 + NetHelpExecSend 2 + NetHelpExecSend 3 + NetHelpExecSend 4 +.nosendextra + mov [cnetptrhead],ebx + + call SendPacketUDP + + cmp byte[chaton],0 + jne .nosendchats + cmp byte[chatstrL],0 + je .nosendchats + cmp dword[chatTL],0 + jne .nosendchats + mov byte[NetCommand],04h +.nosendchats + + ; send chat string + test byte[NetCommand],04h + jz near .nosendchatsend + call PreparePacket + mov al,04h + call RemoteSendChar + + call MoveStringChat + + push esi + mov esi,chatstrR + + cmp byte[OSPort],2 + jae .notwin32b + mov byte[esi],'L' + mov byte[esi+1],'>' + add esi,2 + jmp .skipsendnick +.notwin32b + cmp dword[chatstrL+1],'/ME ' + jne .noaction + mov al,'*' + push ebx + push eax + mov [esi],al + inc esi + call RemoteSendChar + pop eax + pop ebx +.noaction + mov ebx,ChatNick +.nextchatc2 + mov al,[ebx] + cmp al,0 + je .nonextchat + push ebx + push eax + mov [esi],al + inc esi + call RemoteSendChar + pop eax + pop ebx + inc ebx + cmp byte[ebx-1],0 + jne .nextchatc2 +.nonextchat + mov al,'>' + cmp dword[chatstrL+1],'/ME ' + jne .noaction2 + mov al,' ' +.noaction2 + push ebx + push eax + mov [esi],al + inc esi + call RemoteSendChar + pop eax + pop ebx +.skipsendnick + mov ebx,chatstrL+1 + cmp byte[OSPort],2 + jb .noaction3 + cmp dword[chatstrL+1],'/ME ' + jne .noaction3 + mov ebx,chatstrL+5 +.noaction3 +.nextchatc + mov al,[ebx] + push ebx + push eax + mov [esi],al + inc esi + call RemoteSendChar + pop eax + pop ebx + inc ebx + cmp byte[ebx-1],0 + jne .nextchatc + mov byte[esi],0 + pop esi + mov ecx,45 + mov ebx,chatstrL +.chatsendloop + mov al,[ebx+1] + mov [ebx],al + inc ebx + loop .chatsendloop + mov byte[chatstrL],0 + mov dword[chatTL],10 + mov dword[chatRTL],8*60 + call SplitStringChat + call SendPacket +.nosendchatsend + pop ecx + pop ebx + jmp .noreceiveb3 +.noreceiveb2 +.noreceiveb3 + + mov dword[JoyAOrig],0 + mov dword[JoyBOrig],0 + mov dword[JoyCOrig],0 + mov dword[JoyDOrig],0 + mov dword[JoyEOrig],0 + + cmp byte[LatencyLeft],0 + jne near .latencyleft + + mov [tempedx],edx + + push ecx + push ebx + cmp byte[OSPort],3 + jne .nobackstate + cmp byte[BackState],1 + jne .nobackstate + call BackupCVFrame +.nobackupcvframe + mov ebx,[CBackupPos] + inc ebx + and ebx,0Fh + mov [CBackupPos],ebx +.nobackstate + pop ebx + pop ecx + + push ebx + push ecx + + cmp dword[CurRecv],1 + je .yesreceive2 + xor ebx,ebx +.latencyloop + add dword[LatencyV+ebx*4],01010101h + inc ebx + cmp ebx,64 + jne .latencyloop +.yesreceive2 + + cmp dword[CurRecv],1 + jne near .notreceive + mov ebx,[PPValue] + inc ebx + and ebx,0Fh + mov [PPValue],ebx + cmp ebx,[DPValue] + jne near .notreceive + mov dword[CurRecv],0 + call VoiceEndMute + cmp byte[t1cc],4 + jbe .noframesskippedb + mov byte[t1cc],4 +.noframesskippedb + jmp .received +.notreceive +.received + pop ecx + pop ebx + + ; Receive command from net and process + push ebx + push ecx + + cmp byte[CurRecv],1 + je near .nocrupdate3b + + xor bl,bl + mov cx,[t1cc] + add cx,60*15 +.notfoundchar +.onlychatchar + call RemoteGetChar +; cmp [t1cc],cx +; jne .notor + jmp .notor +.netquit2 + or byte[NetQuit],80h + mov byte[RemoteDisconnect],1 + jmp .skipallnet +.notor + cmp dh,0 + jne .foundchar + cmp byte[OSPort],3 + jne .notwin32 + push ebx + cmp byte[BackState],1 + jne .nobackstate2 + mov ebx,[CBackupPos] + dec ebx + sub ebx,[PBackupPos] + sub ebx,[BackStateSize] + and ebx,0Fh +; inc ebx +; and ebx,0Fh +; cmp ebx,[PBackupPos] + jne near .nocrupdate3 ; ************************* +.nobackstate2 + pop ebx +;NEWSYM StateBackup, dd 0 +;NEWSYM CBackupPos, dd 0 +;NEWSYM PBackupPos, dd 0 +;NEWSYM PPValue, dd 0 ; Previous PValue +;NEWSYM DPValue, dd 0 ; Destination PValue +;NEWSYM CurRecv, dd 0 ; Set to 1 if Recovery mode is on +; if CurRecv=1, then do not send tcp/ip data, always frame skip, do not +; draw to screen, do not key on, restore previous local key presses, +; when disabling key ons, divert dspmem write/read to a different +; array temporarly, then re-copy back in when finished +;NEWSYM PPContrl, times 16 dd 0 ; Previous Controller 1 Data +;NEWSYM PPContrl2, times 16 dd 0 ; Previous Controller 2 Data +;NEWSYM PPContrl3, times 16 dd 0 ; Previous Controller 3 Data +;NEWSYM PPContrl4, times 16 dd 0 ; Previous Controller 4 Data +;NEWSYM PPContrl5, times 16 dd 0 ; Previous Controller 5 Data + + pushad + mov byte[nojoystickpoll],1 + call JoyRead + mov byte[nojoystickpoll],0 +; call ChatType2 + popad + cmp word[t1cc],4*60 + jb .notwin32 + cmp byte[pressed+1],1 + je .netquit2 +.notwin32 + mov bl,1 + jmp .notfoundchar +.foundchar + cmp dl,04h + jne .notchatchar + jmp .recvchats +.notchatchar + cmp byte[t1cc],4 + jbe .noframesskipped + mov byte[t1cc],4 +.noframesskipped + + inc byte[netdelayed] + cmp bl,0 + jne .yesdelay + mov byte[netdelayed],0 +.yesdelay + cmp byte[netdelayed],10 + jne .nodelayfix + mov byte[netdelayed],0 + cmp byte[t1cc],0 + je .nodelayfix + dec byte[t1cc] +.nodelayfix + mov [NetCommand],dl + + pushad + ; Receive latency value + ; ##################### + cmp byte[OSPort],3 + jne near .nolatencyrecv2 + cmp byte[BackState],1 + jne near .nolatencyrecv2 +.tryagainlatency + call RemoteGetChar ; ********** + cmp byte[RemoteDisconnect],1 + je near .netquit + cmp dh,0 + je .tryagainlatency + mov ebx,[LatencyRecvPtr] + and ebx,0FFh + inc dword[LatencyRecvPtr] + mov al,[LatencyV+ebx] + mov [RemoteLValue],dl + mov [LocalLValue],al + cmp al,dl + jbe .nolatencyrecv3 + ; incr t1cc -> make local speed faster if local latency > remote + inc dword[latencytimer] + cmp dword[latencytimer],5 + jb .nolatencyrecv2 + mov dword[latencytimer],0 + cmp byte[t1cc],0 + je .nolatencyrecv2 + dec byte[t1cc] + jmp .nolatencyrecv2 +.nolatencyrecv3 + cmp al,dl + je .nolatencyrecv2 + inc dword[latencytimer] + cmp dword[latencytimer],5 + jb .nolatencyrecv2 + mov dword[latencytimer],0 + inc byte[t1cc] +.nolatencyrecv2 + popad + inc dword[NetSent2] + + test dl,01h + jnz near .netfailed + test dl,070h + jnz near .netfailed + + cmp dword[NetQuitter],0 + je .noforcequit + mov ebx,[PBackupPos] + inc ebx + and ebx,0Fh + cmp ebx,[QBackupPos] + je .forcequit +.noforcequit + test dl,08h + jz .noquit +.forcequit + test dl,80h + jz .noloadstate + mov byte[NetLoadState],1 +.noloadstate + or byte[NetQuit],1 + cmp byte[BackState],1 + jne .noquit + push edx + mov ebx,[PBackupPos] + inc ebx + and ebx,0Fh + cmp ebx,[CBackupPos] + je .noquit2 + call RestoreCVFrame + add dword[NetSent],1000 +.noquit2 + pop edx +.noquit + test dl,02h + jz near .nocrupdate2 + + cmp byte[OSPort],3 + jne .notwin32d + cmp byte[BackState],1 + jne .notwin32d + push edx + mov ebx,[PBackupPos] + inc ebx + and ebx,0Fh + cmp ebx,[CBackupPos] + je .noupdate + call RestoreCVFrame + mov ebx,[PBackupPos] ; ***************** + inc ebx + and ebx,0Fh + mov [PPValue],ebx + mov ebx,[CBackupPos] + mov [DPValue],ebx + mov ebx,[PPValue] + mov [CBackupPos],ebx + mov dword[CurRecv],1 ; ***************** + call VoiceStartMute +.noupdate + mov ebx,[PBackupPos] + inc ebx + and ebx,0Fh + mov [PBackupPos],ebx + pop edx +.notwin32d + mov ecx,JoyAOrig + NetHelpExecRecv 0 + NetHelpExecRecv 1 + NetHelpExecRecv 2 + NetHelpExecRecv 3 + NetHelpExecRecv 4 + jmp .donecrupdate +.nocrupdate3 + pop ebx +.nocrupdate3b + mov byte[NetCommand],0 + jmp .nocrupdate +.nocrupdate2 + mov ebx,[PBackupPos] + inc ebx + and ebx,0Fh + mov [PBackupPos],ebx +.nocrupdate + cmp byte[pl1neten],2 + jne .nopl1recv + mov eax,[JoyABack] + mov [JoyAOrig],eax +.nopl1recv + cmp byte[pl2neten],2 + jne .nopl2recv + mov eax,[JoyBBack] + mov [JoyBOrig],eax +.nopl2recv + cmp byte[pl3neten],2 + jne .nopl3recv + mov eax,[JoyCBack] + mov [JoyCOrig],eax +.nopl3recv + cmp byte[pl4neten],2 + jne .nopl4recv + mov eax,[JoyDBack] + mov [JoyDOrig],eax +.nopl4recv + cmp byte[pl5neten],2 + jne .nopl5recv + mov eax,[JoyEBack] + mov [JoyEOrig],eax +.nopl5recv +.donecrupdate + + jmp .norecvchats +.recvchats + push ebx + call MoveStringChat + + mov ebx,chatstrR + push edx +.nextchatcr + push ebx + push ecx + mov cx,[t1cc] + add cx,60*10 +.tryagainchatc + call RemoteGetChar ; ********** + cmp byte[RemoteDisconnect],1 + je .netquit + cmp [t1cc],cx + jne .noto +.netquit + or byte[NetQuit],80h + mov dh,1 +.noto + cmp dh,0 + je .tryagainchatc ; ********* + pop ecx + pop ebx + mov [ebx],dl + inc ebx + cmp dl,0 + jne .nextchatcr ; ********* + pop edx + pushad + cmp byte[OSPort],2 + jae .notwin32e + mov dl,'R' + call NetAddChar + mov dl,'>' + call NetAddChar +.notwin32e + mov esi,chatstrR + call WritetochatBuffer + mov dl,13 + call NetAddChar + mov dl,10 + call NetAddChar + popad + mov dword[chatRTL],60*8 + call SplitStringChat + pop ebx + jmp .onlychatchar +.norecvchats + + jmp .skipfailed +.netfailed + or byte[NetQuit],80h +.skipfailed + + cmp byte[CurRecv],1 + je near .noreceiveb + ; Process previous command from buffer + mov ebx,[cnetptrtail] + mov ecx,JoyAOrig + mov dl,[cnetplaybuf+ebx] + inc ebx + and ebx,1FFh + test dl,08h + jz .noquit2b + push ebx + mov ebx,[PBackupPos] + cmp ebx,[CBackupPos] + je .yesquit + cmp dword[NetQuitter],1 + je .quitlater + test dl,80h + jz .noloadstateb + mov byte[NetLoadState],2 +.noloadstateb + mov dword[NetQuitter],1 + mov ebx,[CBackupPos] + mov [QBackupPos],ebx + jmp .quitlater +.yesquit + test dl,80h + jz .noloadstateb2 + mov byte[NetLoadState],2 +.noloadstateb2 + or byte[NetQuit],1 +.quitlater + pop ebx +;NEWSYM NetQuitter, dd 0 +;NEWSYM QBackupPos, dd 0 +.noquit2b + test dl,02h + jz near .nocrupdate2b + NetHelpExecRecv2 0 + NetHelpExecRecv2 1 + NetHelpExecRecv2 2 + NetHelpExecRecv2 3 + NetHelpExecRecv2 4 + jmp .donecrupdate2 +.nocrupdate2b + cmp byte[pl1neten],1 + jne .nopl1recv2 + mov eax,[JoyABack] + mov [JoyAOrig],eax +.nopl1recv2 + cmp byte[pl2neten],1 + jne .nopl2recv2 + mov eax,[JoyBBack] + mov [JoyBOrig],eax +.nopl2recv2 + cmp byte[pl3neten],1 + jne .nopl3recv2 + mov eax,[JoyCBack] + mov [JoyCOrig],eax +.nopl3recv2 + cmp byte[pl4neten],1 + jne .nopl4recv2 + mov eax,[JoyDBack] + mov [JoyDOrig],eax +.nopl4recv2 + cmp byte[pl5neten],1 + jne .nopl5recv2 + mov eax,[JoyEBack] + mov [JoyEOrig],eax +.nopl5recv2 +.donecrupdate2 + mov [cnetptrtail],ebx +.noreceiveb + + ; backup keyboard presses if recv=1 (delayed by 1 frame) + ; else restore + ; Restore previous keys if CurRecv = 1 + ; ************************************ + cmp byte[CurRecv],1 + je near .noreceive + ; backup keypresses + mov ebx,[CBackupPos] + dec ebx + and ebx,0Fh + mov ecx,[JoyAOrig] + mov [PPContrl+ebx*4],ecx + mov ecx,[JoyBOrig] + mov [PPContrl2+ebx*4],ecx + mov ecx,[JoyCOrig] + mov [PPContrl3+ebx*4],ecx + mov ecx,[JoyDOrig] + mov [PPContrl4+ebx*4],ecx + mov ecx,[JoyEBack] + mov [PPContrl4+ebx*4],ecx + jmp .yesreceive +.noreceive + mov ebx,[PPValue] + dec ebx + and ebx,0Fh + cmp byte[pl1neten],1 + jne .nopl1recv3 + mov ecx,[PPContrl+ebx*4] + mov [JoyAOrig],ecx +.nopl1recv3 + cmp byte[pl2neten],1 + jne .nopl2recv3 + mov ecx,[PPContrl2+ebx*4] + mov [JoyBOrig],ecx +.nopl2recv3 + cmp byte[pl3neten],1 + jne .nopl3recv3 + mov ecx,[PPContrl3+ebx*4] + mov [JoyCOrig],ecx +.nopl3recv3 + cmp byte[pl4neten],1 + jne .nopl4recv3 + mov ecx,[PPContrl4+ebx*4] + mov [JoyDOrig],ecx +.nopl4recv3 + cmp byte[pl5neten],1 + jne .nopl5recv3 + mov ecx,[PPContrl5+ebx*4] + mov [JoyEOrig],ecx +.nopl5recv3 +.yesreceive + +.skipallnet + pop ecx + pop ebx + mov edx,[tempedx] + xor ebx,ebx + jmp .donelatency +.latencyleft + dec byte[LatencyLeft] +.donelatency + mov eax,[JoyAOrig] + mov [JoyABack],eax + mov eax,[JoyBOrig] + mov [JoyBBack],eax + mov eax,[JoyCOrig] + mov [JoyCBack],eax + mov eax,[JoyDOrig] + mov [JoyDBack],eax + mov eax,[JoyEOrig] + mov [JoyEBack],eax + jmp .reprocjoy +.noonens + test byte[NetSwap],1 + jz .nozerons + ; copy previous frame values into JoyxOrig and JoyxNow + mov eax,[JoyABack] + mov [JoyAOrig],eax + mov eax,[JoyBBack] + mov [JoyBOrig],eax + mov eax,[JoyCBack] + mov [JoyCOrig],eax + mov eax,[JoyDBack] + mov [JoyDOrig],eax + mov eax,[JoyEBack] + mov [JoyEOrig],eax +.reprocjoy + mov eax,[JoyAOrig] + rol eax,16 + mov [JoyANow],eax + mov eax,[JoyBOrig] + rol eax,16 + mov [JoyBNow],eax + mov eax,[JoyCOrig] + rol eax,16 + mov [JoyCNow],eax + mov eax,[JoyDOrig] + mov [JoyDNow],eax + mov eax,[JoyEOrig] + mov [JoyENow],eax +.nozerons + + cmp byte[snesmouse],4 + jne .nolethalen + mov eax,[LethEnData] + mov [JoyBNow],eax +.nolethalen + + xor byte[NetSwap],1 + + cmp byte[NetQuit],0 + je .noquitb + pushad + mov esi,[wramdata] + mov ecx,65536*2 + xor eax,eax + xor ebx,ebx +.quitloop + mov al,[esi] + add bx,ax + inc esi + loop .quitloop + mov [valuea],bx + popad + add [valuea],dh + + mov byte[ExecExitOkay],0 + mov byte[pressed+1],01h + jmp exitloop +.noquitb + + cmp byte[MovieProcessing],0 + je .noprocmovie + call ProcessMovies +.noprocmovie + + test byte[INTEnab],1 + jz .noresetjoy + mov eax,[JoyAOrig] + rol eax,16 + mov [JoyANow],eax + mov eax,[JoyBOrig] + rol eax,16 + mov [JoyBNow],eax + mov eax,[JoyCOrig] + rol eax,16 + mov [JoyCNow],eax + mov eax,[JoyDOrig] + mov [JoyDNow],eax + mov eax,[JoyEOrig] + mov [JoyENow],eax + mov byte[JoyCRead],0 +.noresetjoy + mov byte[MultiTapStat],80h + + cmp byte[C4Enable],0 + je .noC4 + call C4VBlank +.noC4 +; mov byte[hdmastartsc],0 + mov byte[joycontren],0 + test byte[curexecstate],01h + jnz .dis65816 + or byte[curexecstate],01h +; call changeexecloop +.dis65816 + cmp byte[CheatOn],1 + je near .cheater +.returncheat + mov ax,[VIRQLoc] + cmp word[curypos],ax + jne .novirqz + inc word[VIRQLoc] +.novirqz + mov ax,[oamaddrs] + mov [oamaddr],ax + call showvideo +; call dsp1teststuff + xor ebx,ebx + mov byte[NMIEnab],81h + test byte[INTEnab],80h + jz near .nonmi +; cmp byte[intrset],1 +; je near .nonmi + +.nmiokay + mov byte[curnmi],1 + cmp byte[intrset],1 + jne .nointrset + mov byte[intrset],2 +.nointrset + cmp byte[nmistatus],1 + jne .notnonmifound + mov byte[nmirept],0 +.notnonmifound + mov byte[nmistatus],0 + cmp byte[nmirept],0 + jne .nocheck + mov al,[resolutn] + sub al,2 + mov [nmiprevline],al + mov dword[nmiprevaddrl],0FFFFFFFFh + mov dword[nmiprevaddrh],0 + mov byte[nmirept],1 + mov byte[doirqnext],0 + C4Paused + jmp switchtonmi +.nocheck + cmp byte[nmirept],10 + je .nextcheck + cmp esi,[nmiprevaddrl] + jae .notlower + mov [nmiprevaddrl],esi +.notlower + cmp esi,[nmiprevaddrh] + jbe .notgreater + mov [nmiprevaddrh],esi +.notgreater + inc byte[nmirept] + C4Paused + jmp switchtonmi +.nextcheck + mov eax,[nmiprevaddrh] + sub eax,[nmiprevaddrl] + cmp eax,10 + ja .failcheck + cmp esi,[nmiprevaddrl] + jb .failcheck + cmp esi,[nmiprevaddrh] + ja .failcheck + mov byte[doirqnext],0 + C4Paused + jmp switchtonmi +.failcheck + mov byte[nmirept],0 + mov dword[nmiprevaddrl],0FFFFFFFFh + mov dword[nmiprevaddrh],0 + mov byte[doirqnext],0 + C4Paused + jmp switchtonmi +.nonmi + cmp byte[intrset],1 + jne .nointrset2w + mov byte[intrset],2 +.nointrset2w + cmp byte[esi],0CBh + jne .nowai + jmp .nowai + test dl,04h + jz .nowai + or byte[INTEnab],80h +.nowai + C4Paused + xor ebx,ebx + xor ecx,ecx + mov bl,[esi] + inc esi + jmp execloop.startagain + + +.overy + shr dh,1 + cmp byte[smallscreenon],1 + je .nocfield + cmp byte[ScreenScale],1 + je .nocfield + cmp byte[scanlines],0 + jne .nocfield + xor byte[cfield],1 +.nocfield + mov word[curypos],0 + + cmp dword[numspcvblleft],0 + je near .novblch + cmp [lowestspc],ebp + ja .failspc + cmp [highestspc],ebp + jb .failspc + jmp .okayspc +.failspc + mov eax,ebp + sub eax,10 + mov [lowestspc],eax + add eax,20 + mov [highestspc],eax + mov dword[spc700idle],0 +.okayspc + cmp dword[SPC700write],0 + jne .notwritespc + cmp dword[spc700read],0 + je .notwritespc + cmp dword[SPC700read],1500 + jb .notwritespc + inc dword[spc700idle] + cmp dword[spc700idle],30 + jne .noidleend + call idledetectspc + cmp byte[ReturnFromSPCStall],1 + jne .noidleend + mov byte[ExecExitOkay],0 + jmp exitloop +.noidleend + jmp .notidle +.notwritespc + mov dword[spc700idle],0 +.notidle + dec dword[numspcvblleft] + mov dword[SPC700write],0 + mov dword[SPC700read],0 + mov dword[spc700read],0 +.novblch + + mov byte[NMIEnab],01h + +; call cachevideo + call starthdma +; cmp byte[Offby1line],1 +; je .noirqhack +; cmp byte[IRQHack],0 +; je .noirqhack +; call exechdma +.noirqhack + + + ; check for VIRQ/HIRQ/NMI + cmp byte[execatzerovirq],1 + je near .noexecatzero + ProcessIRQStuff +.noexecatzero + + C4Paused + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.virq + C4Paused + test byte[INTEnab],10h + jz .skiphirq + cmp word[HIRQLoc],0 + je .skiphirq + jmp .skiphirq + cmp word[HIRQLoc],339 + jbe .hirqnotover + mov word[HIRQLoc],339 +.hirqnotover + ; first dh = HIRQLoc*DHAdd/340, second dh = DHAdd-first dh + push edx + mov ax,[HIRQLoc] + xor ecx,ecx + mov cl,[cycpl] + mul cx + mov cx,340 + div cx + pop edx + mov dh,al + mov cl,[cycpl] + sub cl,al + xor cl,cl + mov [HIRQCycNext],cl + mov byte[HIRQNextExe],1 +; jmp .hirq + jmp .returnfromhirq +.skiphirq + test byte[curexecstate],01h + jnz .dis658162 + or byte[curexecstate],01h +; call changeexecloop +.dis658162 + mov byte[doirqnext],0 + xor ebx,ebx + mov ax,[resolutn] + cmp word[curypos],ax + jnb .nodrawline + cmp byte[hdmadelay],0 + je .dohdma2 + dec byte[hdmadelay] + jmp .nodohdma2 +.dohdma2 + call exechdma +.nodohdma2 + cmp word[curypos],1 + jne .nocache2 + call cachevideo +.nocache2 + cmp byte[curblank],0 + jne .nodrawline + call drawline +.nodrawline + cmp byte[intrset],1 + jne .nointrset2 + mov byte[intrset],2 +.nointrset2 +; sub dh,8 + jmp switchtovirq + +.hirq + C4Paused + mov byte[HIRQNextExe],0 + test byte[INTEnab],10h + jz .hirqnotokay + test byte[curexecstate],01h + jnz .dis658162h + or byte[curexecstate],01h +.dis658162h + mov byte[doirqnext],0 + cmp byte[intrset],1 + jne .nointrset2h + mov byte[intrset],2 +.nointrset2h + test dl,04h + jnz .irqd + jmp switchtovirq +.irqd + mov byte[doirqnext],1 +.hirqnotokay + jmp .nodrawlineh + +.returnfromhirq + mov ax,[resolutn] + cmp word[curypos],ax + jnb .nodrawlineh + cmp byte[hdmadelay],0 + je .dohdma2h + dec byte[hdmadelay] + jmp .nodohdma2h +.dohdma2h + call exechdma +.nodohdma2h + cmp word[curypos],1 + jne .nocache2h + call cachevideo +.nocache2h + cmp byte[curblank],0 + jne .nodrawlineh + call drawline +.nodrawlineh + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.cheater + push eax + push ebx + push ecx + push edx + mov al,[NumCheats] + mov byte[.numcheat],al + xor edx,edx +.anothercheat + xor ebx,ebx + xor ecx,ecx + test byte[cheatdata+edx],5 + jnz .nonormcheat + test byte[cheatdata+edx-28],80h + jnz .nonormcheat + test byte[cheatdata+edx],80h + jnz .cheatcodereflect + mov al,[cheatdata+edx+1] + mov cx,[cheatdata+edx+2] + mov bl,[cheatdata+edx+4] + push edx + call dword near [memtablew8+ebx*4] + pop edx + jmp .nonormcheat +.cheatcodereflect + cmp byte[.numcheat],1 + je .nonormcheat + mov cx,[cheatdata+edx+2+28] + mov bl,[cheatdata+edx+4+28] + push edx + call dword near [memtabler8+ebx*4] + pop edx + mov cx,[cheatdata+edx+2] + mov bl,[cheatdata+edx+4] + push edx + call dword near [memtablew8+ebx*4] + pop edx + add edx,28 + dec byte[.numcheat] +.nonormcheat + add edx,28 + dec byte[.numcheat] + jnz near .anothercheat + pop edx + pop ecx + pop ebx + pop eax + jmp .returncheat + +.numcheat db 0 + +ALIGN16 + +NEWSYM pexecs + mov byte[soundcycleft],30 +.sloop + mov bl,[ebp] + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx + dec byte[soundcycleft] + jnz .sloop + xor dh,dh + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +NEWSYM pexecs2 +.sloop + mov bl,[ebp] + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx + dec dword[soundcycleft] + jnz .sloop + ret + +NEWSYM UpdatePORSCMR + push ebx + push eax + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + + mov al,[SfxSCMR] + and eax,00000011b + mov bl,[SfxPOR] + and bl,0Fh + shl bl,2 + or al,bl + mov ebx,[PLOTJmpb+eax*4] + mov eax,[PLOTJmpa+eax*4] + mov dword [FxTable+4Ch*4],eax + mov dword [FxTableb+4Ch*4],eax + mov dword [FxTablec+4Ch*4],eax + mov dword [FxTabled+4Ch*4],ebx + pop eax + pop ebx + ret + +NEWSYM UpdateSCBRCOLR + push eax + push ebx + mov ebx,[SfxSCBR] + shl ebx,10 + add ebx,[sfxramdata] + mov [SCBRrel],ebx + mov eax,[SfxCOLR] + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + pop ebx + pop eax + ret + +NEWSYM UpdateCLSR + mov dword [NumberOfOpcodes2],350 ; 0FFFFFFFh;350 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword [NumberOfOpcodes2],700 ;700 +.nohighsfx + cmp byte[SFXCounter],1 + je .noyi + mov dword [NumberOfOpcodes2],0FFFFFFFh +.noyi + ret + +NEWSYM UpdateSFX + call UpdatePORSCMR + call UpdatePORSCMR + call UpdateCLSR + ret + +NEWSYM StartSFX + push edx + push esi + push edi + push ebp + xor ebx,ebx + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov eax,[NumberOfOpcodes2] + mov [NumberOfOpcodes],eax + call MainLoop +.noaccess + pop ebp + pop edi + pop esi + pop edx + xor ebx,ebx + xor ecx,ecx + jmp cpuover.returnfromsfx + +NEWSYM StartSFXdebug + push edx + push esi + push edi + push ebx + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov dword [NumberOfOpcodes],350 ; 0FFFFFFFh;350 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword [NumberOfOpcodes],700 ;700 +.nohighsfx + cmp byte[SFXCounter],1 + jne .noyi + mov dword [NumberOfOpcodes],0FFFFFFFFh +.noyi +; call SFXDebugLoop +.noaccess + pop ebx + pop edi + pop esi + pop edx + xor ecx,ecx + jmp execsingle.returnfromsfx + +NEWSYM StartSFXdebugb + push edx + push esi + push edi + push ebp + push ebx + + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + + mov al,[SfxSCMR] + and eax,00000011b + mov bl,[SfxPOR] + and bl,0Fh + shl bl,2 + or al,bl + mov ebx,[PLOTJmpb+eax*4] + mov eax,[PLOTJmpa+eax*4] + mov dword [FxTable+4Ch*4],eax + mov dword [FxTableb+4Ch*4],eax + mov dword [FxTablec+4Ch*4],eax + mov dword [FxTabled+4Ch*4],ebx + + mov ebx,[SfxSCBR] + shl ebx,10 + add ebx,[sfxramdata] + mov [SCBRrel],ebx + + mov eax,[SfxCOLR] + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + xor ebx,ebx + + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov dword [NumberOfOpcodes],400 ;678 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword [NumberOfOpcodes],800 ;678*2 +.nohighsfx + cmp byte[SFXCounter],1 + jne .noyi + mov dword [NumberOfOpcodes],0FFFFFFFh +.noyi + call MainLoop +.noaccess + pop ebx + pop ebp + pop edi + pop esi + pop edx + xor ecx,ecx + jmp execsingle.returnfromsfx + +NEWSYM StartSFXret + test byte[SfxSFR],20h + jz .endfx + pushad + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov dword [NumberOfOpcodes],400 ;678 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword [NumberOfOpcodes],800 ;678*2 +.nohighsfx + mov dword [NumberOfOpcodes],0FFFFFFFFh + call MainLoop +.noaccess + popad +.endfx + ret + +;******************************************************* +; Execute a Single 65816 instruction (debugging purpose) +;******************************************************* +NEWSYM execloopdeb + jmp exitloop2 + +NEWSYM execsingle + + xor ebx,ebx + test byte[curexecstate],2 + jz .nosoundb + sub dword[cycpbl],55 + jnc .skipallspc + mov eax,[cycpblt] + mov bl,[ebp] + add dword[cycpbl],eax + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx +.skipallspc +.nosoundb + + mov bl,dl + mov byte[exiter],01h + mov edi,[tablead+ebx*4] + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc .cpuover + mov [pdh],dh + xor dh,dh + jmp dword near [edi+ebx*4] +.cpuover + +; cmp byte[SA1Enable],0 +; je .nosa1 +; test byte[SA1Control],60h +; jnz .nosa1 +; dec esi +; call SA1Swap +; mov bl,[esi] +; inc esi +; cmp byte[SA1Status],0 +; je near .nosa1 +; mov [pdh],dh +; xor dh,dh +; jmp cpuover +;.nosa1 + + cmp byte[SA1Enable],0 + je near .nosa1 + mov byte[cycpl],150 + test byte[SA1Control],60h + jnz near .nosa1 + dec esi + call SA1Swap + + mov bl,[esi] + inc esi + mov [pdh],dh + xor dh,dh + cmp byte[CurrentExecSA1],17 + jb near cpuover + mov byte[CurrentExecSA1],0 + mov byte[cycpl],5 + jmp .nosa1 +.nosa1 + + cmp byte[KeyOnStB],0 + je .nokeyon + mov al,[KeyOnStB] + call ProcessKeyOn +.nokeyon + mov al,[KeyOnStA] + mov [KeyOnStB],al + mov byte[KeyOnStA],0 + test byte[SfxSFR],20h + jnz near StartSFXdebugb +.returnfromsfx + add dh,[cycpl] + mov [pdh],dh + + cmp byte[spcon],0 + je .nosound + call updatetimer + push ebx + xor ebx,ebx + mov bl,dl + mov edi,[tablead+ebx*4] + pop ebx +.nosound + xor dh,dh + inc word[curypos] + mov ax,[resolutn] + inc ax + cmp word[curypos],ax + je near .nmi + cmp word[curypos],261 + ja near .overy + ; check for VIRQ/HIRQ/NMI + ProcessIRQStuff + +; test dl,04h +; jnz .noirq +; test byte[INTEnab],20h +; jz .novirq +; mov ax,[VIRQLoc] +; cmp word[curypos],ax +; je near .virq +; jmp .noirq +;.novirq +; test byte[INTEnab],10h +; jnz near .virq +;.noirq +; test byte[INTEnab],20h +; jz .novirq2b +; mov ax,[VIRQLoc] +; cmp word[curypos],ax +; jne .novirq2b +; cmp byte[intrset],1 +; jne .nointrset2b +; mov byte[intrset],2 +;.nointrset2b +;.novirq2b + mov ax,[resolutn] + cmp word[curypos],ax + jb .drawline + jmp dword near [edi+ebx*4] + +.drawline + cmp byte[hdmadelay],0 + je .dohdma + dec byte[hdmadelay] + jmp .nodohdma +.dohdma + call exechdma +.nodohdma + cmp byte[curblank],0 + jne .nodrawlineb + call drawline +.nodrawlineb + jmp dword near [edi+ebx*4] + +.nmi + cmp byte[C4Enable],0 + je .noC4 + call C4VBlank +.noC4 +; mov byte[hdmastartsc],0 + mov byte[joycontren],0 + mov ax,[VIRQLoc] + cmp word[curypos],ax + jne .novirqz + inc word[VIRQLoc] +.novirqz + + call ReadInputDevice + + test byte[INTEnab],1 + jz .noresetjoy + mov eax,[JoyAOrig] + rol eax,16 + mov [JoyANow],eax + mov eax,[JoyBOrig] + rol eax,16 + mov [JoyBNow],eax + mov eax,[JoyCOrig] + rol eax,16 + mov [JoyCNow],eax + mov eax,[JoyDOrig] + mov [JoyDNow],eax + mov byte[JoyCRead],0 +.noresetjoy + + cmp byte[snesmouse],4 + jne .nolethalen + mov eax,[LethEnData] + mov [JoyBNow],eax +.nolethalen + + mov byte[MultiTapStat],80h + mov byte[NMIEnab],81h + test byte[INTEnab],80h + jz .nonmi + mov byte[curnmi],1 + dec esi + cmp byte[intrset],1 + jne .nointrset + mov byte[intrset],2 +.nointrset +; mov byte[debstop3],1 + jmp switchtonmideb +.nonmi + cmp byte[intrset],1 + jne .nointrset2w + mov byte[intrset],2 +.nointrset2w + cmp byte[esi],0CBh + jne .nowai + and dl,0FBh +.nowai + jmp dword near [edi+ebx*4] + +.overy + shr dh,1 + mov word[curypos],0 + mov byte[NMIEnab],01h + add dword[opcd],170*262 + call cachevideo + call starthdma + + ProcessIRQStuff + +; test dl,04h +; jnz .novirq2 +; test byte[INTEnab],20h +; jz .novirq2 +; mov ax,[VIRQLoc] +; cmp word[curypos],ax +; je near .virq +; mov ax,[VIRQLoc] +; cmp ax,[totlines] +; jae .virq +;.novirq2 + jmp dword near [edi+ebx*4] + +.virq + mov ax,[resolutn] + cmp word[curypos],ax + jnb .nodrawline + cmp byte[hdmadelay],0 + je .dohdma2 + dec byte[hdmadelay] + jmp .nodohdma2 +.dohdma2 + call exechdma +.nodohdma2 + cmp byte[curblank],0 + jne .nodrawline + call drawline +.nodrawline + dec esi + cmp byte[intrset],1 + jne .nointrset2 + mov byte[intrset],2 +.nointrset2 +; mov byte[debstop3],1 + jmp switchtovirqdeb + + + + + + \ No newline at end of file diff --git a/zsnes/src/cpu/irq.asm b/zsnes/src/cpu/irq.asm new file mode 100644 index 00000000..edcf1781 --- /dev/null +++ b/zsnes/src/cpu/irq.asm @@ -0,0 +1,524 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM flagnz,flago,flagc +EXTSYM SfxSCMR,curnmi,execloop,initaddrl,nmiv,snesmap2 +EXTSYM snesmmap,stackand,stackor,wramdata +EXTSYM xe,xirqb,xpb,xpc,xs +EXTSYM irqon,irqv +EXTSYM irqv8 +EXTSYM execloopdeb +EXTSYM nmiv8 + + + + + + +; NMI Hardware 00FFFA,B 00FFEA,B 3 -> 000108 +; RES Hardware 00FFFC.D 00FFFC,D 1 +; BRK Software 00FFFE,F 00FFE6,7 N/A +; IRQ Hardware 00FFFE,F 00FFEE,F 4 -> 00010C + + +%macro makedl 0 + and dl,00111100b + test dword[flagnz],18000h + jz %%noneg + or dl,80h +%%noneg + test dword[flagnz],0FFFFh + jnz %%nozero + or dl,02h +%%nozero + test dword[flagc],0FFh + jz %%nocarry + or dl,01h +%%nocarry + test dword[flago],0FFh + jz %%nov + or dl,40h +%%nov +%endmacro + +;******************************************************* +; SwitchToNMI/VIRQ Calls NMI/VIRQ +;******************************************************* +NEWSYM switchtonmi + mov byte[curnmi],1 + test byte[xe],1 + jne near NMIemulmode + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + xor ebx,ebx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[nmiv] + test byte[SfxSCMR],10h + jz .nosfxnmi +; mov ax,0108h +.nosfxnmi + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop + +NEWSYM NMIemulmode + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,[xpb] + xor eax,eax + mov ax,[nmiv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop + +NEWSYM switchtovirq + mov byte[irqon],80h + test byte[xe],1 + jne near IRQemulmode + + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + xor ebx,ebx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[irqv] +; test byte[SfxSCMR],10h +; jz .nosfxnmi +; mov ax,010Ch +;.nosfxnmi + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop + +NEWSYM switchtovirqret + mov byte[irqon],80h + test byte[xe],1 + jne near IRQemulmode + + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + xor ebx,ebx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[irqv] +; test byte[SfxSCMR],10h +; jz .nosfxnmi +; mov ax,010Ch +;.nosfxnmi + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + ret +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + ret + +NEWSYM IRQemulmode + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,[xpb] + xor eax,eax + mov ax,[irqv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloop + + +NEWSYM switchtovirqdeb + mov byte[irqon],80h + test byte[xe],1 + jne near IRQemulmodedeb + + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + xor ebx,ebx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[irqv] +; test byte[SfxSCMR],10h +; jz .nosfxnmi +; mov ax,010Ch +;.nosfxnmi + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb + +NEWSYM IRQemulmodedeb + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,[xpb] + xor eax,eax + mov ax,[irqv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb + +NEWSYM switchtonmideb + mov byte[curnmi],1 + test byte[xe],1 + jne near NMIemulmodedeb + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + xor ebx,ebx + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,byte[xirqb] + mov [xpb],bl + xor eax,eax + mov ax,[nmiv] + test byte[SfxSCMR],10h + jz .nosfxnmi +; mov ax,0108h +.nosfxnmi + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb + +NEWSYM NMIemulmodedeb + mov ebx,esi + sub ebx,[initaddrl] + mov [xpc],bx + + mov eax,[wramdata] + mov bx,[xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [xs],bx + xor bh,bh + + mov bl,[xpb] + xor eax,eax + mov ax,[nmiv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + jmp execloopdeb + + \ No newline at end of file diff --git a/zsnes/src/cpu/memory.asm b/zsnes/src/cpu/memory.asm new file mode 100644 index 00000000..05fbfb10 --- /dev/null +++ b/zsnes/src/cpu/memory.asm @@ -0,0 +1,4406 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM romdata,sramb4save,pressed,vidbuffer,oamram +EXTSYM C4TransfWireFrame2 +EXTSYM C4WFXVal,C4WFYVal,C4WFX2Val,C4WFY2Val,C4CalcWireFrame +EXTSYM C4WFDist,C4WFScale,C4TransfWireFrame,C4WFZVal +EXTSYM debstop3 +EXTSYM C41FXVal,C41FYVal,C41FAngleRes,C41FDist,C4Op1F,C4Op15 +EXTSYM C41FDistVal,C4Op0D +EXTSYM SFXEnable,regptra,sfxramdata,snesmmap,wramdataa,debstop,C4Ram,C4Enable +EXTSYM C4RamR,C4RamW,snesmap2,SPC7110Enable +EXTSYM DSP1Read16b +EXTSYM DSP1Write8b,regptwa,writeon +EXTSYM Bank0datr8,Bank0datw8,Bank0datr16,Bank0datw16,xd,SA1xd +EXTSYM DSP1Read8b,DSP1Type,SA1Enable +EXTSYM DSP1Write16b +EXTSYM CurDecompPtr,PrevDecompPtr,CurDecompSize +EXTSYM SPCDecmPtr,SPCCompPtr,SPCCompCounter +EXTSYM ramsize,ramsizeand,sram +EXTSYM ram7fa +EXTSYM DosExit,invalid,invopcd,previdmode,printhex8 +EXTSYM SA1Status,IRAM,CurBWPtr,SA1RAMArea +EXTSYM SA1Overflow +EXTSYM Sdd1Mode,Sdd1Bank,Sdd1Addr,Sdd1NewAddr,memtabler8,AddrNoIncr,SDD1BankA +EXTSYM SPC7110Entries,spc7110romptr + + + + + + +; C4SprScale + +;******************************************************* +; Register & Memory Access Banks (0 - 3F) / (80 - BF) +;******************************************************* +; enter : BL = bank number, CX = address location +; leave : AL = value read + + +; ****************************************************** +; C4 Emulation, reverse engineered & written by zsKnight +; ****************************************************** + +C4ProcessVectors: + mov esi,[C4Ram] + mov edi,esi + add edi,1F8Ch + xor edx,edx + mov dx,[esi+1F8Ah] + cmp dx,128 + ja .ret + cmp dx,0 + jne .nozero +.ret + ret +.nozero + cmp dx,10h + jb .less + mov dx,10h +.less + mov esi,[C4Ram] + add esi,800h +.loop + mov ecx,100h + xor ebx,ebx + xor eax,eax + movsx bx,byte[edi] +.spotloop + add ah,80h + mov byte[esi],ah + sub ah,80h + add ax,bx + inc esi + loop .spotloop + add edi,3 + dec dx + jnz .loop + ret + +C4ObjDisp dd 0 +C4ColRot db 1 +NEWSYM C4ObjSelec, db 0 +NEWSYM C4SObjSelec, db 0 +NEWSYM C4Pause, db 0 +C4DataCopy times 64 db 0 +;NEWSYM C4Data times 64*4096 db 0 ; 15 sprites, 4 bytes each + ; x,y,oamptr,stat (b0=oamb8,b1=16x16) + ; 4 byte header (#sobj,?,?,?) +CObjNum dw 0 +C4Temp dd 0 + +C4Edit: + ; C4 editing routines + ; Register keyboard presses + ; [ = prev object, ] = next object + ; p = pause/unpause + cmp byte[pressed+1Ah],0 + je .notpressed + mov byte[pressed+1Ah],0 + inc byte[C4ObjSelec] + inc byte[C4Temp] +.notpressed + cmp byte[pressed+1Bh],0 + je .notpressed2 + mov byte[pressed+1Bh],0 + dec byte[C4ObjSelec] + dec byte[C4Temp] +.notpressed2 + cmp byte[pressed+19h],0 + je .notpressed3 + mov byte[pressed+19h],0 + xor byte[C4Pause],1 +.notpressed3 + + ; Setup variables + mov esi,[C4Ram] + add byte[C4ColRot],16 + mov al,[esi+620h] + cmp byte[C4ObjSelec],0FFh + jne .notneg + dec al + mov byte[C4ObjSelec],al + jmp .notof +.notneg + cmp byte[C4ObjSelec],al + jb .notof + xor al,al + mov [C4ObjSelec],al +.notof + + ; Draw the dots on-screen + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + add eax,[C4Ram] + add eax,220h + mov byte[.flipped],0 + test byte[eax+6],40h + jz .notflip + mov byte[.flipped],1 +.notflip + +; 00/01 - x position relative to BG scroll value +; 02/03 - y position relative to BG scroll value +; 04 - palette/priority settings +; 05 - OAM pointer value +; 06 - flip settings : b6 = flipx, b7 = flipy +; 07 - looks like some sprite displacement values +; 08/09 - ??? +; 0A-0F - unused + xor ebx,ebx + mov bx,[eax+8] + mov [CObjNum],bx + cmp bx,4096 + jae near .skipall + shl ebx,6 + add ebx,[C4Data] + + ; t,f,g,h = move current object + ; q = copy current object structure, w = paste current object structure + cmp byte[pressed+14h],0 + je .notmove + mov byte[pressed+14h],0 + pushad + mov ecx,15 +.next + add ebx,4 + dec byte[ebx+1] + loop .next + popad +.notmove + cmp byte[pressed+21h],0 + je .notmove2 + mov byte[pressed+21h],0 + pushad + mov ecx,15 +.next2 + add ebx,4 + cmp byte[.flipped],0 + je .noflipx + add byte[ebx],2 +.noflipx + dec byte[ebx] + loop .next2 + popad +.notmove2 + cmp byte[pressed+22h],0 + je .notmove3 + mov byte[pressed+22h],0 + pushad + mov ecx,15 +.next3 + add ebx,4 + inc byte[ebx+1] + loop .next3 + popad +.notmove3 + cmp byte[pressed+23h],0 + je .notmove4 + mov byte[pressed+23h],0 + pushad + mov ecx,15 +.next4 + add ebx,4 + cmp byte[.flipped],0 + je .noflipx2 + sub byte[ebx],2 +.noflipx2 + inc byte[ebx] + loop .next4 + popad +.notmove4 + cmp byte[pressed+10h],0 + je .notcopy + mov byte[pressed+10h],0 + pushad + mov edx,C4DataCopy + mov ecx,64 +.copylp + mov al,[ebx] + mov [edx],al + inc ebx + inc edx + loop .copylp + popad +.notcopy + cmp byte[pressed+11h],0 + je .notpaste + mov byte[pressed+11h],0 + pushad + mov edx,C4DataCopy + mov ecx,64 +.pastelp + mov al,[edx] + mov [ebx],al + inc ebx + inc edx + loop .pastelp + popad +.notpaste + + ; - = remove sub-object, + = add sub-object + ; ; = previous sub-object, ' = next sub-object + cmp byte[pressed+0Ch],0 + je .notpressed4 + mov byte[pressed+0Ch],0 + cmp byte[ebx],0 + je .notpressed4 + dec byte[ebx] +.notpressed4 + cmp byte[pressed+0Dh],0 + je .notpressed5 + mov byte[pressed+0Dh],0 + cmp byte[ebx],15 + je .notpressed5 + inc byte[ebx] +.notpressed5 + cmp byte[pressed+27h],0 + je .notpressed6 + mov byte[pressed+27h],0 + dec byte[C4SObjSelec] +.notpressed6 + cmp byte[pressed+28h],0 + je .notpressed7 + mov byte[pressed+28h],0 + inc byte[C4SObjSelec] +.notpressed7 + + ; get current sub-object displacement (0 if no sub-objects) + xor ecx,ecx + cmp byte[ebx],0 + je near .nosubobjs + + mov cl,[ebx] + cmp byte[C4ObjSelec],0FFh + jne .sobjokay2 + dec cl + mov byte[C4SObjSelec],cl + jmp .sobjokay +.sobjokay2 + cmp byte[C4SObjSelec],cl + jb .sobjokay + mov byte[C4SObjSelec],0 +.sobjokay + + xor ecx,ecx + mov cl,byte[C4SObjSelec] + shl ecx,2 + add ebx,ecx + add ebx,4 + + ; i,j,k,l = move current sub-object (17,24,25,26) + ; u = toggle between 8x8 and 16x16 tiles + ; o = toggle between high/low oam value + ; . = decrease oam value, / = increase oam value of sub-object + cmp byte[pressed+17h],0 + je .notpressed8 + mov byte[pressed+17h],0 + dec byte[ebx+1] +.notpressed8 + cmp byte[pressed+24h],0 + je .notpressed9 + mov byte[pressed+24h],0 + dec byte[ebx] + cmp byte[.flipped],0 + je .notpressed9 + add byte[ebx],2 +.notpressed9 + cmp byte[pressed+26h],0 + je .notpressed11 + mov byte[pressed+26h],0 + inc byte[ebx] + cmp byte[.flipped],0 + je .notpressed11 + sub byte[ebx],2 +.notpressed11 + cmp byte[pressed+25h],0 + je .notpressed10 + mov byte[pressed+25h],0 + inc byte[ebx+1] +.notpressed10 + cmp byte[pressed+16h],0 + je .notpressed12 + mov byte[pressed+16h],0 + xor byte[ebx+3],2 +.notpressed12 + cmp byte[pressed+18h],0 + je .notpressed13 + mov byte[pressed+18h],0 + xor byte[ebx+3],1 +.notpressed13 + cmp byte[pressed+34h],0 + je .notpressed14 + mov byte[pressed+34h],0 + dec byte[ebx+2] +.notpressed14 + cmp byte[pressed+35h],0 + je .notpressed15 + mov byte[pressed+35h],0 + inc byte[ebx+2] +.notpressed15 + + mov cl,[ebx] + mov ch,[ebx+1] +.nosubobjs + mov edx,ecx + xor ebx,ebx + xor ecx,ecx + mov bl,[eax] + sub bl,[esi+621h] + add bl,dl + mov cl,[eax+2] + sub cl,[esi+623h] + add cl,dh + mov esi,[vidbuffer] + add esi,16*2+256*2+32*2 + add esi,ebx + add esi,ebx + mov ebx,ecx + shl ebx,9 + shl ecx,6 + add esi,ebx + add esi,ecx + mov al,[C4ColRot] + mov ah,al + xor ah,0FFh + mov [esi],ax + mov [esi+16],ax + mov [esi+288*8*2],ax + mov [esi+16+288*8*2],ax +.skipall + ret +.flipped db 0 + +C4AddSprite: + cmp dword[C4count],0 + je near .nosprite + mov [edi],ax + mov [edi+2],bx + mov ebx,[C4usprptr] + and [ebx],dl + mov al,dl + xor al,0FFh + and dh,al + or [ebx],dh + add edi,4 + rol dl,2 + rol dh,2 + dec dword[C4count] + cmp dl,0FCh + jne .nosprite + inc dword[C4usprptr] +.nosprite + ret + +C4ConvOAM: + inc byte[C4Timer] + and byte[C4Timer],15 + inc byte[C4Timer2] + and byte[C4Timer2],7 + mov esi,[C4Ram] + xor ecx,ecx + mov edi,esi + mov cl,[esi+620h] + mov bx,[esi+621h] + mov [.addx],bx + mov bx,[esi+623h] + mov [.addy],bx + mov [C4usprptr],esi + add dword[C4usprptr],200h + mov eax,[C4ObjDisp] + add edi,eax + shr eax,4 + add dword[C4usprptr],eax + add esi,220h + ; Convert from esi to edi + mov dl,0FCh + push ecx + mov cl,byte[C4sprites] + and cl,3 + add cl,cl + rol dl,cl + pop ecx + cmp cl,0 + je near .none + mov dword[C4count],128 + mov eax,[C4sprites] + sub dword[C4count],eax + +.loop + push ecx + push esi +; 00/01 - x position relative to BG scroll value +; 02/03 - y position relative to BG scroll value +; 04 - palette/priority settings +; 05 - OAM pointer value +; 06 - flip settings : b6 = flipx, b7 = flipy +; 07 - ??? +; 08/09 - Pointer to Sprite Structure +; 0A-0F - unused +;bit 1-3 = palette number bit 4,5 = playfield priority +;bit 6 = horizontal flip bit 7 = horizonal flip + mov ax,[esi] + sub ax,[.addx] + mov [C4SprX],ax + mov ax,[esi+2] + sub ax,[.addy] + mov [C4SprY],ax + mov al,[esi+5] + mov [C4SprOAM],al + mov al,[esi+4] + mov ah,al + and ah,0Eh + cmp ah,0 + jmp .notstage2 + jne .notstage1 + cmp byte[C4Timer],0 + je .flash + jmp .noflash +.notstage1 + jmp .notstage2 + cmp ah,4 + jne .notstage2 + cmp byte[C4Timer2],0 + je .flash +.noflash + and al,0F1h + or al,2 + jmp .notstage2 +.flash + and al,0F1h +.notstage2 + mov [C4SprAttr],al + mov al,[esi+6] + or [C4SprAttr],al +; mov [C4SprFlip],al + + xor ecx,ecx + mov cl,[esi+9] + shl ecx,16 + mov cx,[esi+7] + add cx,cx + shr ecx,1 + add ecx,[romdata] + + mov al,[ecx] + or al,al + jz near .singlespr + mov [C4SprCnt],al + inc ecx +.nextspr + xor ebx,ebx + movsx bx,byte[ecx+1] + test byte[C4SprAttr],40h + jz .notflipx + neg bx + sub bx,8 +.notflipx + add bx,[C4SprX] + xor dh,dh + test byte[ecx],20h + jz .no16x16 + or dh,10101010b + test byte[C4SprAttr],40h + jz .no16x16 + sub bx,8 +.no16x16 + cmp bx,-16 + jl near .nosprite + cmp bx,272 + jg near .nosprite + mov al,bl + test bx,100h + jz .not512b + or dh,01010101b +.not512b + xor ebx,ebx + movsx bx,byte[ecx+2] + test byte[C4SprAttr],80h + jz .notflipy + neg bx + sub bx,8 +.notflipy + add bx,[C4SprY] + test byte[ecx],20h + jz .no16x16b + test byte[C4SprAttr],80h + jz .no16x16b + sub bx,8 +.no16x16b + cmp bx,-16 + jl near .nosprite + cmp bx,224 + jg near .nosprite + mov ah,bl + mov bh,[C4SprAttr] + mov bl,[ecx] + and bl,0C0h + xor bh,bl + mov bl,[C4SprOAM] + add bl,[ecx+3] + call C4AddSprite +.nosprite + add ecx,4 + dec byte[C4SprCnt] + jnz near .nextspr + jmp .donemultispr +.singlespr + mov dh,10101010b + test byte[C4SprX+1],1 + jz .not512 + or dh,01010101b +.not512 + mov al,[C4SprX] + mov ah,[C4SprY] + mov bl,[C4SprOAM] + mov bh,[C4SprAttr] + call C4AddSprite +.donemultispr + pop esi + pop ecx + +;NEWSYM C4Data times 64*4096 db 0 ; 15 sprites, 4 bytes each + ; x,y,oamptr,stat (b0=oamb8,b1=16x16) + ; 4 byte header (#sobj,?,?,?) + + add esi,16 + dec cl + jnz near .loop +.none + mov esi,oamram + mov edi,[C4Ram] + mov ecx,544 +.next + mov al,[edi] + mov [esi],al + inc edi + inc esi + loop .next + ret +.addx dw 0 +.addy dw 0 + +C4count dd 0 +C4usprptr dd 0 +C4SprX dw 0 +C4SprY dw 0 +C4SprCnt db 0 +C4SprAttr db 0 +C4SprOAM db 0 +C4SprFlip db 0 +C4Timer db 0 +C4Timer2 db 0 + +NEWSYM C4VBlank + ret +NEWSYM C4ProcessSprites + push ecx + push esi + push edi + push ebx + push edx +; call C4ProcessVectors + +; call C4Edit + + mov esi,[C4Ram] + mov dword[C4count],8 + mov cl,[esi+626h] + mov byte[C4sprites],cl + mov ecx,[C4sprites] + shl ecx,2 + mov dword[C4ObjDisp],ecx + mov ecx,128 +; cmp byte[esi+65],50h +; jne .noincdisp + mov dword[C4count],32 + sub ecx,[C4sprites] +.noincdisp + add esi,[C4ObjDisp] + ; Clear OAM to-be ram +.next + mov byte[esi+1],0E0h + add esi,4 + dec ecx + jnz .next + + call C4ConvOAM + + pop edx + pop ebx + pop edi + pop esi + pop ecx + ret + +NEWSYM SprValAdd, db 0 +C4Data dd 0 +C4sprites dd 0 + +NEWSYM InitC4 + pushad + mov esi,[romdata] + add esi,4096*1024 + mov [C4Data],esi + add dword[C4Data],128*1024 + mov [C4RamR],esi + mov [C4RamW],esi + mov [C4Ram],esi + add dword[C4RamW],8192*4 + add dword[C4Ram],8192*8 + mov ecx,8192 +.c4loop + mov dword[esi],C4ReadReg + mov dword[esi+8192*4],C4WriteReg + mov dword[esi+8192*8],0 + add esi,4 + dec ecx + jnz .c4loop + mov esi,[C4RamW] + mov dword[esi+1F4Fh*4],C4RegFunction + mov esi,[C4Data] + mov ecx,16*4096 +.c4loopb + mov dword[esi],0 + add esi,4 + loop .c4loopb + popad + ret + +C4ClearSpr: + mov esi,ebx + mov edi,eax +; xor ecx,ecx +; mov cx,[eax+1F44h] +; sub cx,6000h +; add eax,ecx + shl ch,3 +.scloop2 + mov cl,byte[C4SprPos] + shl cl,2 +.scloop + mov byte[edi],0 + mov byte[edi+2000h],0 + inc edi + dec cl + jnz .scloop + dec ch + jnz .scloop2 + ret + +C4SprBitPlane: + mov edi,eax + shl ebx,2 +.scloop3 + mov ch,[C4SprPos] + push esi +.scloop4 + push esi + mov cl,8 +.loop + mov dh,8 + mov dl,80h + mov eax,[esi] +.nextd + test al,1 + jz .not0 + or byte[edi],dl +.not0 + test al,2 + jz .not1 + or byte[edi+1],dl +.not1 + test al,4 + jz .not2 + or byte[edi+16],dl +.not2 + test al,8 + jz .not3 + or byte[edi+17],dl +.not3 + shr eax,4 + shr dl,1 + dec dh + jnz .nextd + add esi,ebx + add edi,2 + dec cl + jnz .loop + add edi,16 + pop esi + add esi,4 + dec ch + jnz .scloop4 + pop esi + shl ebx,3 + add esi,ebx + add edi,dword[C4SprPtrInc] + shr ebx,3 + dec byte[C4SprPos+1] + jnz .scloop3 +.end + ret + +C4XXScale dw 0 +C4XYScale dw 0 +C4YXScale dw 0 +C4YYScale dw 0 +C4CXPos dw 0 +C4CYPos dw 0 +C4CXMPos dd 0 +C4CYMPos dd 0 +C4PCXMPos dd 0 +C4PCYMPos dd 0 + +DoScaleRotate: + pushad + mov esi,eax + ; Calculate X scaler + mov ax,[esi+1F80h] + and eax,01FFh + mov ax,[CosTable+eax*2] + mov bx,[esi+1F8Fh] + test bx,8000h + jz .notover + mov bx,7FFFh +.notover + imul bx + add ax,ax + adc dx,dx + mov [C4XXScale],dx + mov ax,[esi+1F80h] + and eax,01FFh + mov ax,[SinTable+eax*2] + imul bx + add ax,ax + adc dx,dx + mov [C4XYScale],dx + ; Calculate Y scaler + mov ax,[esi+1F80h] + and eax,01FFh + mov ax,[CosTable+eax*2] + mov bx,[esi+1F92h] + test bx,8000h + jz .notoverb + mov bx,7FFFh +.notoverb + imul bx + add ax,ax + add dx,dx + mov [C4YYScale],dx + mov ax,[esi+1F80h] + and eax,01FFh + mov ax,[SinTable+eax*2] + imul bx + add ax,ax + adc dx,dx + neg dx + mov [C4YXScale],dx + cmp word[esi+1F80h],0 + jne .effect + cmp word[esi+1F92h],1000h + jne .effect + mov word[C4YYScale],1000h + mov word[C4YXScale],0 +.effect + ; Calculate Pixel Resolution + mov cl,byte[C4SprPos] + shl cl,3 + mov byte[C4SprPos+2],cl + mov cl,byte[C4SprPos+1] + shl cl,3 + mov byte[C4SprPos+3],cl + ; Calculate Positions + ; (1-scale)*(pos/2) + xor eax,eax + mov al,[C4SprPos+2] + shl eax,11 + mov [C4PCXMPos],eax + xor eax,eax + mov al,[C4SprPos+3] + shl eax,11 + mov [C4PCYMPos],eax + + mov bx,[C4XXScale] + xor eax,eax + mov al,[C4SprPos+2] + shr ax,1 + imul bx + shl edx,16 + mov dx,ax + sub [C4PCXMPos],edx + mov bx,[C4YXScale] + xor eax,eax + mov al,[C4SprPos+3] + shr ax,1 + imul bx + shl edx,16 + mov dx,ax + sub [C4PCXMPos],edx + + mov bx,[C4XYScale] + xor eax,eax + mov al,[C4SprPos+2] + shr ax,1 + imul bx + shl edx,16 + mov dx,ax + sub [C4PCYMPos],edx + mov bx,[C4YYScale] + xor eax,eax + mov al,[C4SprPos+3] + shr ax,1 + imul bx + shl edx,16 + mov dx,ax + sub [C4PCYMPos],edx + + ; Start loop + mov word[C4CYPos],0 + xor edi,edi +.loop + mov ecx,[C4PCXMPos] + mov [C4CXMPos],ecx + mov ecx,[C4PCYMPos] + mov [C4CYMPos],ecx + mov al,[C4SprPos+2] + mov byte[C4CXPos],al +.loop2 + xor eax,eax + mov al,[C4SprPos+2] + mov ebx,[C4CXMPos] + sar ebx,12 + cmp ebx,eax + jae near .blank + xor eax,eax + mov al,[C4SprPos+3] + mov ebx,[C4CYMPos] + sar ebx,12 + cmp ebx,eax + jae near .blank + ; Get pixel value + mov ebx,[C4CYMPos] + xor eax,eax + shr ebx,12 + mov al,[C4SprPos+2] + mul ebx + mov ebx,[C4CXMPos] + shr ebx,12 + add eax,ebx + mov ebx,[C4SprPtr] + test al,1 + jnz .upperb + shr eax,1 + add ebx,eax + mov al,[ebx] + jmp .lowerb +.upperb + shr eax,1 + add ebx,eax + mov al,[ebx] + shr al,4 +.lowerb + mov ebx,edi + shr ebx,1 + add ebx,esi + test edi,1 + jnz .upperb2 + and al,0Fh + and byte[ebx+2000h],0F0h + or byte[ebx+2000h],al + jmp .done +.upperb2 + shl al,4 + and byte[ebx+2000h],0Fh + or byte[ebx+2000h],al + jmp .done +.blank + mov eax,edi + shr eax,1 + add eax,esi + test edi,1 + jnz .upper + and byte[eax+2000h],0F0h + jmp .done +.upper + and byte[eax+2000h],0Fh +.done + movsx eax,word[C4XXScale] + add [C4CXMPos],eax + movsx eax,word[C4XYScale] + add [C4CYMPos],eax + inc edi + dec byte[C4CXPos] + jne near .loop2 + movsx eax,word[C4YXScale] + add [C4PCXMPos],eax + movsx eax,word[C4YYScale] + add [C4PCYMPos],eax + inc word[C4CYPos] + mov al,[C4SprPos+3] + cmp byte[C4CYPos],al + jne near .loop +.noimage + popad + ret + +DoScaleRotate2: + pushad + xor ebx,ebx + mov bx,[eax+1F8Fh] + cmp bx,1000h + ja .scaled + mov bx,1000h +.scaled + mov [C4SprScale],ebx + xor ebx,ebx + mov bx,[eax+1F92h] + cmp bx,1000h + ja .scaledb + mov bx,1000h +.scaledb + mov [C4SprScaleY],ebx + mov cl,[C4SprPos] + shl cl,3 + mov ch,cl + xor ebx,ebx +.leftovercheck + dec ch + add ebx,[C4SprScale] +.leftovercheckb + cmp ebx,1000h + jb .leftovercheck + sub ebx,1000h + dec cl + jz .donecheck + jmp .leftovercheckb +.donecheck + shr ch,1 + mov cl,ch + and ecx,0FFh + mov esi,ecx + + mov cl,[C4SprPos+1] + shl cl,3 + mov ch,cl + xor ebx,ebx +.leftovercheckc + dec ch + add ebx,[C4SprScaleY] +.leftovercheckd + cmp ebx,1000h + jb .leftovercheckc + sub ebx,1000h + dec cl + jz .donecheckc + jmp .leftovercheckd +.donecheckc + shr ch,1 + mov cl,ch + and ecx,0FFh + push eax + xor eax,eax + mov al,[C4SprPos] + shl al,3 + mul ecx + add esi,eax + pop eax + + mov dword[C4SprScalerY],0 + xor edi,edi + mov cl,[C4SprPos+1] + shl cl,3 + mov [C4SprPos+3],cl +.next + push esi + push edi + xor ecx,ecx + mov cl,[C4SprPos] + shl cl,3 + mov ch,cl + mov dword[C4SprScaler],0 + xor edx,edx +.loop + mov edx,edi + shr edx,1 + add edx,[C4SprPtr] + mov bl,[edx] + test esi,1 + jz .notupper + shr bl,4 +.notupper + and bl,0Fh + mov edx,esi + shr edx,1 + test esi,1 + jz .notupperb + shl bl,4 + or byte[eax+edx+2000h],bl + jmp .notlowerb +.notupperb + or byte[eax+edx+2000h],bl +.notlowerb + inc esi + mov ebx,[C4SprScale] + add dword[C4SprScaler],ebx + dec ch +.nextcheck + cmp dword[C4SprScaler],1000h + jb near .loop + sub dword[C4SprScaler],1000h + inc edi + dec cl + jz .done + jmp .nextcheck +.done + pop edi + pop esi + xor edx,edx + mov dl,[C4SprPos] + shl dl,3 + add esi,edx + + mov ebx,[C4SprScaleY] + add dword[C4SprScalerY],ebx +.nextcheckb + cmp dword[C4SprScalerY],1000h + jb near .next + sub dword[C4SprScalerY],1000h + add edi,edx + dec byte[C4SprPos+3] + jz .doneb + jmp .nextcheckb +.doneb + + popad + ret + +C4SprScaleR: + push ecx + push ebx + push edx + push esi + push edi + mov dword[C4SprPtrInc],0 + xor ebx,ebx + mov bl,[eax+1F42h] + shl ebx,16 + mov bx,[eax+1F40h] + add bx,bx + shr ebx,1 + add ebx,[romdata] + mov ch,[eax+1F8Ch] + shr ch,3 + mov cl,[eax+1F89h] + shr cl,3 + mov [C4SprPos],cx + mov [C4SprPtr],ebx + + call C4ClearSpr + + call DoScaleRotate + + mov esi,eax + add esi,2000h + xor ebx,ebx + mov bl,[C4SprPos] + call C4SprBitPlane + pop edi + pop esi + pop edx + pop ebx + pop ecx + ret + +C4SprRotateR: + push ecx + push ebx + push edx + push esi + push edi + xor ebx,ebx + mov ebx,600h + add ebx,[C4Ram] + mov [C4SprPtr],esi + mov ch,[eax+1F8Ch] + shr ch,3 + mov cl,[eax+1F89h] + shr cl,3 + add ch,2 + mov [C4SprPos],cx + mov dword[C4SprPtrInc],64 + mov [C4SprPtr],ebx + sub byte[C4SprPos+1],2 + call C4ClearSpr + + call DoScaleRotate + mov esi,eax + add esi,2000h + xor ebx,ebx + mov bl,[C4SprPos] + add byte[C4SprPos+1],2 + call C4SprBitPlane + pop edi + pop esi + pop edx + pop ebx + pop ecx + ret + +C4SprDisintegrate: + pushad + mov dword[C4SprPtrInc],0 + xor ebx,ebx + mov bl,[eax+1F42h] + shl ebx,16 + mov bx,[eax+1F40h] + add bx,bx + shr ebx,1 + add ebx,[romdata] + mov ch,[eax+1F8Ch] + shr ch,3 + mov cl,[eax+1F89h] + shr cl,3 + mov [C4SprPos],cx + mov [C4SprPtr],ebx + + call C4ClearSpr + + mov esi,[C4Ram] + xor ebx,ebx + mov bx,[esi+1F86h] + xor eax,eax + mov al,[esi+1F89h] + shr al,1 + mul ebx + neg eax + xor ebx,ebx + mov bl,[esi+1F89h] + shr bl,1 + shl ebx,8 + add eax,ebx + push eax + xor ebx,ebx + mov bx,[esi+1F8Fh] + xor eax,eax + mov al,[esi+1F8Ch] + shr al,1 + mul ebx + neg eax + xor ebx,ebx + mov bl,[esi+1F8Ch] + shr bl,1 + shl ebx,8 + add ebx,eax + mov edx,ebx + pop ebx + mov esi,[C4Ram] + mov cl,[esi+1F89h] + mov ch,[esi+1F8Ch] + mov [C4SprPos+2],cx + movsx eax,word[esi+1F86h] + mov [.scalex],eax + movsx eax,word[esi+1F8Fh] + mov [.scaley],eax + mov esi,[C4SprPtr] + mov edi,[C4Ram] + add edi,2000h + + ; convert to 8-bit bitmap + mov cx,[C4SprPos+2] + shr cl,1 +.loop2 + mov al,[esi] + mov [edi],al + mov al,[esi] + shr al,4 + mov [edi+1],al + inc esi + add edi,2 + dec cl + jnz .loop2 + dec ch + jnz .loop2 + + mov edi,[C4Ram] + add edi,4000h + mov ecx,2000h +.lp + mov byte[edi],0 + inc edi + loop .lp + + mov esi,[C4Ram] + add esi,2000h + mov edi,[C4Ram] + add edi,4000h + + mov cx,[C4SprPos+2] +.next2 + push ebx +.next + xor eax,eax + mov ah,[C4SprPos+2] + cmp ebx,eax + jae .fail + xor eax,eax + mov ah,[C4SprPos+3] + cmp edx,eax + jae .fail + push ecx + push edx + xor eax,eax + mov al,[C4SprPos+2] + xor ecx,ecx + mov cl,dh + mul ecx + mov ecx,ebx + shr ecx,8 + add eax,ecx + mov dl,[esi] + cmp eax,2000h + jae .skipdisi + mov [edi+eax],dl +.skipdisi + pop edx + pop ecx +.fail + inc esi + add ebx,[.scalex] + dec cl + jnz near .next + pop ebx + add edx,[.scaley] + mov cl,[C4SprPos+2] + dec ch + jnz near .next2 + +.skipall + ; convert to 4-bit bitmap + mov esi,[C4Ram] + add esi,4000h + mov edi,[C4Ram] + add edi,6000h + mov cx,[C4SprPos+2] + shr cl,1 +.loop + mov al,[esi] + mov [edi],al + mov al,[esi+1] + shl al,4 + or [edi],al + inc edi + add esi,2 + dec cl + jnz .loop + dec ch + jnz .loop + + mov esi,[C4Ram] + add esi,6000h +; mov esi,[C4SprPtr] + mov eax,[C4Ram] + xor ebx,ebx + mov bl,[C4SprPos] + call C4SprBitPlane + + popad + ret +.scalex dd 0 +.scaley dd 0 + +C4BitPlaneWave: + pushad + mov esi,[C4Ram] + mov dword[.temp],10h + xor eax,eax + mov al,[esi+1F83h] + mov dword[.waveptr],eax + mov word[.temp+4],0C0C0h + mov word[.temp+6],03F3Fh +.bmloopb + mov edi,[C4Ram] + add edi,[.waveptr] + xor eax,eax + movsx ax,byte[edi+$0B00] + neg ax + sub ax,16 + mov edi,[C4Ram] + add edi,0A00h + xor ecx,ecx +.bmloopa + mov ebx,[.bmptr+ecx*4] + mov dx,[.temp+6] + and [esi+ebx],dx + xor dx,dx + cmp ax,0 + jl .less + mov dx,0FF00h + cmp ax,8 + jae .less + mov dx,[edi+eax*2] +.less + and dx,[.temp+4] + or [esi+ebx],dx + inc ax + inc ecx + cmp ecx,28h + jne .bmloopa + add dword[.waveptr],1 + and dword[.waveptr],07Fh + ror word[.temp+4],2 + ror word[.temp+6],2 + cmp word[.temp+4],0C0C0h + jne near .bmloopb + add esi,16 +.bmloopa2b + mov edi,[C4Ram] + add edi,[.waveptr] + xor eax,eax + movsx ax,byte[edi+$0B00] + neg ax + sub ax,16 + mov edi,[C4Ram] + add edi,0A00h + xor ecx,ecx +.bmloopa2 + mov ebx,[.bmptr+ecx*4] + mov dx,[.temp+6] + and [esi+ebx],dx + xor dx,dx + cmp ax,0 + jl .less2 + mov dx,0FF00h + cmp ax,8 + jae .less2 + mov dx,[edi+eax*2+16] +.less2 + and dx,[.temp+4] + or [esi+ebx],dx + inc ax + inc ecx + cmp ecx,28h + jne .bmloopa2 + add dword[.waveptr],1 + and dword[.waveptr],07Fh + ror word[.temp+4],2 + ror word[.temp+6],2 + cmp word[.temp+4],0C0C0h + jne near .bmloopa2b + add esi,16 + dec dword[.temp] + jnz near .bmloopb + mov esi,[C4Ram] +; mov cx,[esi+1F80h] +; mov [C4values],cx +; mov cx,[esi+1F83h] +; mov [C4values+2],cx + popad + ret +.bmptr dd 0000h,0002h,0004h,0006h,0008h,000Ah,000Ch,000Eh + dd 0200h,0202h,0204h,0206h,0208h,020Ah,020Ch,020Eh + dd 0400h,0402h,0404h,0406h,0408h,040Ah,040Ch,040Eh + dd 0600h,0602h,0604h,0606h,0608h,060Ah,060Ch,060Eh + dd 0800h,0802h,0804h,0806h,0808h,080Ah,080Ch,080Eh +.temp dd 0,0 +.waveptr dd 0 + +C4DrawLine: +;C4X1 dw 0 +;C4Y1 dw 0 +;C4Z1 dw 0 +;C4X2 dw 0 +;C4Y2 dw 0 +;C4Z2 dw 0 +;C4Col dw 0 + pushad + + ; transform both coordinates + push esi + mov ax,word[C4X1] + mov [C4WFXVal],ax + mov ax,word[C4Y1] + mov [C4WFYVal],ax + mov ax,word[C4Z1] + mov [C4WFZVal],ax + mov al,[esi+1F90h] + mov [C4WFScale],al + mov al,[esi+1F86h] + mov [C4WFX2Val],al + mov al,[esi+1F87h] + mov [C4WFY2Val],al + mov al,[esi+1F88h] + mov [C4WFDist],al + call C4TransfWireFrame2 + mov ax,[C4WFXVal] + mov word[C4X1],ax + mov ax,[C4WFYVal] + mov word[C4Y1],ax + + mov ax,word[C4X2] + mov [C4WFXVal],ax + mov ax,word[C4Y2] + mov [C4WFYVal],ax + mov ax,word[C4Z2] + mov [C4WFZVal],ax + call C4TransfWireFrame2 + mov ax,[C4WFXVal] + mov word[C4X2],ax + mov ax,[C4WFYVal] + mov word[C4Y2],ax + + add word[C4X1],48 + add word[C4Y1],48 + add word[C4X2],48 + add word[C4Y2],48 + shl dword[C4X1],8 + shl dword[C4X2],8 + shl dword[C4Y1],8 + shl dword[C4Y2],8 + ; get line info + mov ax,[C4X1+1] + mov [C4WFXVal],ax + mov ax,[C4Y1+1] + mov [C4WFYVal],ax + mov ax,[C4X2+1] + mov [C4WFX2Val],ax + mov ax,[C4Y2+1] + mov [C4WFY2Val],ax + call C4CalcWireFrame + xor ecx,ecx + mov cx,[C4WFDist] + or ecx,ecx + jnz .not0 + mov ecx,1 +.not0 + movsx eax,word[C4WFXVal] + mov [C4X2],eax + movsx eax,word[C4WFYVal] + mov [C4Y2],eax + pop esi + ; render line +.loop + ; plot pixel + cmp word[C4X1+1],0 + jl near .noplot + cmp word[C4Y1+1],0 + jl near .noplot + cmp word[C4X1+1],95 + jg near .noplot + cmp word[C4Y1+1],95 + jg near .noplot + xor eax,eax + mov dx,[C4Y1+1] + shr dx,3 + mov ax,dx + shl ax,6 + shl dx,8 + sub dx,ax + mov ax,[C4X1+1] + shr ax,3 + shl ax,4 + add ax,dx + mov dx,[C4Y1+1] + and dx,07h + add dx,dx + add ax,dx + mov dl,07Fh + push ecx + mov cl,[C4X1+1] + and cl,07h + ror dl,cl + pop ecx + and byte[esi+eax+300h],dl + and byte[esi+eax+301h],dl + xor dl,0FFh + test byte[C4Col],1 + jz .nocolor0 + or byte[esi+eax+300h],dl +.nocolor0 + test byte[C4Col],2 + jz .nocolor1 + or byte[esi+eax+301h],dl +.nocolor1 +.noplot + mov eax,[C4X2] + add [C4X1],eax + mov eax,[C4Y2] + add [C4Y1],eax + dec ecx + jnz near .loop + popad + ret + +DrawWireFrame: + mov esi,[C4Ram] + mov edi,esi + xor ebx,ebx + mov bl,[esi+1F82h] + shl ebx,16 + mov bx,[esi+1F80h] + add bx,bx + shr ebx,1 + add ebx,[romdata] + mov edi,ebx + xor ecx,ecx + mov cl,[esi+295h] +.loop + xor eax,eax + mov al,[esi+1F82h] + shl eax,16 + mov al,[edi+1] + mov ah,[edi+0] + mov edx,edi +.nextprev + cmp ax,0FFFFh + jne .notprev + sub edx,5 + mov al,[edx+3] + mov ah,[edx+2] + jmp .nextprev +.notprev + add ax,ax + shr eax,1 + add eax,[romdata] + xor edx,edx + mov dl,[esi+1F82h] + shl edx,16 + mov dl,[edi+3] + mov dh,[edi+2] +; mov [C4values+6],dx + add dx,dx + shr edx,1 + add edx,[romdata] + xor ebx,ebx + mov bh,[eax] + mov bl,[eax+1] + mov [C4X1],ebx + mov bh,[eax+2] + mov bl,[eax+3] + mov [C4Y1],ebx + mov bh,[eax+4] + mov bl,[eax+5] + mov [C4Z1],ebx + mov bh,[edx] + mov bl,[edx+1] + mov [C4X2],ebx + mov bh,[edx+2] + mov bl,[edx+3] + mov [C4Y2],ebx + mov bh,[edx+4] + mov bl,[edx+5] + mov [C4Z2],ebx + mov al,[edi+4] + mov [C4Col],al + add edi,5 + call C4DrawLine + dec ecx + jnz near .loop + ret + +C4X1 dd 0 +C4Y1 dd 0 +C4Z1 dd 0 +C4X2 dd 0 +C4Y2 dd 0 +C4Z2 dd 0 +C4Col dd 0 + +WireFrameB: + pushad + ; 28EECA + ; 7F80 (3bytes) = pointer to data + ; 7F86-7F88 = rotation, 7F90 = scale (/7A?) + ; 6295 = # of lines, 7FA5 = ??? + mov esi,[C4Ram] + add esi,300h + mov ecx,16*12*3 +.loop + mov dword[esi],0 + add esi,4 + loop .loop + call DrawWireFrame + + mov esi,[C4Ram] + mov cx,[esi+1FA5h] +; mov [C4values],cx +; mov cx,[esi+1F86h] +; mov [C4values],cx +; mov cx,[esi+1F88h] +; mov [C4values+2],cx +; mov cx,[esi+1F90h] +; mov [C4values+4],cx + popad + ret + +WireFrameB2: + pushad + call DrawWireFrame + popad + ret + +C4WireFrame: + pushad + mov esi,[C4Ram] + mov ax,[esi+1F83h] + and ax,0FFh + mov [C4WFX2Val],ax +; mov [C4values],ax + mov ax,[esi+1F86h] + and ax,0FFh + mov [C4WFY2Val],ax +; mov [C4values+2],ax + mov ax,[esi+1F89h] + and ax,0FFh + mov [C4WFDist],ax +; mov [C4values+4],ax + mov ax,[esi+1F8Ch] + and ax,0FFh + mov [C4WFScale],ax +; mov [C4values+6],ax + + ; transform vertices (MMX2 - 36 vertices, 54 lines) + xor ecx,ecx + mov cx,[esi+1F80h] + xor al,al +.loop + mov ax,[esi+1] + mov [C4WFXVal],ax + mov ax,[esi+5] + mov [C4WFYVal],ax + mov ax,[esi+9] + mov [C4WFZVal],ax + push esi + push ecx + call C4TransfWireFrame + pop ecx + pop esi + ; Displace + mov ax,[C4WFXVal] + add ax,80h + mov [esi+1],ax + mov ax,[C4WFYVal] + add ax,50h + mov [esi+5],ax + add esi,10h + loop .loop + ; Uses 6001,6005,6600,6602,6605 + + mov esi,[C4Ram] + mov word[esi+$600],23 + mov word[esi+$602],60h + mov word[esi+$605],40h + mov word[esi+$600+8],23 + mov word[esi+$602+8],60h + mov word[esi+$605+8],40h + + xor ecx,ecx + mov cx,[esi+0B00h] + mov edi,esi + add edi,0B02h +.lineloop + xor eax,eax + mov al,[edi] + shl eax,4 + add eax,[C4Ram] + mov bx,[eax+1] + mov [C4WFXVal],bx + mov bx,[eax+5] + mov [C4WFYVal],bx + xor eax,eax + mov al,[edi+1] + shl eax,4 + add eax,[C4Ram] + mov bx,[eax+1] + mov [C4WFX2Val],bx + mov bx,[eax+5] + mov [C4WFY2Val],bx + push esi + push edi + push ecx + call C4CalcWireFrame + pop ecx + pop edi + pop esi + mov ax,[C4WFDist] + or ax,ax + jnz .yeswire + mov ax,1 +.yeswire + mov word[esi+$600],ax + mov ax,[C4WFXVal] + mov word[esi+$602],ax + mov ax,[C4WFYVal] + mov word[esi+$605],ax + add edi,2 + add esi,8 + dec ecx + jnz near .lineloop +.done + popad + ret + +C4Transform: + ; 7F81,4,7,9,A,B,0,1,D + pushad + mov esi,[C4Ram] + mov ax,word[esi+1F81h] + mov [C4WFXVal],ax + mov ax,word[esi+1F84h] + mov [C4WFYVal],ax + mov ax,word[esi+1F87h] + mov [C4WFZVal],ax + mov al,[esi+1F90h] + mov [C4WFScale],al + mov al,[esi+1F89h] + mov [C4WFX2Val],al + mov al,[esi+1F8Ah] + mov [C4WFY2Val],al + mov al,[esi+1F8Bh] + mov [C4WFDist],al + call C4TransfWireFrame2 + mov ax,[C4WFXVal] + mov word[esi+1F80h],ax + mov ax,[C4WFYVal] + mov word[esi+1F83h],ax + popad + ret + +C4SprPos dd 0 +C4SprScale dd 0 +C4SprScaleY dd 0 +C4SprScaler dd 0 +C4SprScalerY dd 0 +C4SprPtr dd 0 +C4SprPtrInc dd 0 +NEWSYM C4values, dd 0,0,0 + +C4activate: + add ecx,[C4Ram] + mov [ecx],al + sub ecx,[C4Ram] + cmp al,00h + je near .dosprites + cmp al,01h + je near .dowireframe + cmp al,05h ; ? + je near .propulsion + cmp al,0Dh ; ? + je near .equatevelocity + cmp al,10h ; supply angle+distance, return x/y displacement + je near .direction + cmp al,13h ; ? + je near .something2 + cmp al,15h ; ? + je near .calcdistance + cmp al,1Fh ; supply x/y displacement, return angle (+distance?) + je near .calcangle + cmp al,22h ; supply x/y displacement, return angle (+distance?) + je near .linearray + cmp al,2Dh ; ??? + je near .transform + cmp al,89h + je near .immediaterom + cmp al,5Ch + je near .immediatereg + ret +.dowireframe + call WireFrameB + ret +.linearray + pushad + ; C,F,0,3,6,9 -> 6800 (E1h bytes) + ; 0,3 = screen scroll coordinates + ; 6,9 = light source coordinates + ; C,F = angle of both arrays + mov esi,[C4Ram] + xor ecx,ecx +.loopline + ; process position + xor eax,eax + mov al,[esi+1F8Ch] + or ecx,ecx + jz .secondlineb + mov al,[esi+1F8Fh] +.secondlineb + test al,80h + jz .notua + or ah,1 +.notua + movsx ebx,word[CosTable+eax*2] + mov ax,word[SinTable+eax*2] + shl eax,16 + cmp ebx,0 + je near .finish + xor edx,edx + test eax,80000000h + jz .notnegline + mov edx,0FFFFFFFFh +.notnegline + idiv ebx + mov [C4Temp],eax + xor edx,edx + mov bx,[esi+1F83h] + sub bx,[esi+1F89h] + dec bx + movsx ebx,bx +.nextline + test ebx,80000000h + jnz .none + mov eax,[C4Temp] + imul eax,ebx + sar eax,16 + sub ax,[esi+1F80h] + add ax,[esi+1F86h] + inc ax + add ax,cx + cmp ax,0 + jge .not0line + xor ax,ax + or ecx,ecx + jz .not0line + mov byte[esi+edx+$800],1 +.not0line + cmp ax,255 + jl .not255line + mov ax,255 +.not255line + jmp .doneline +.none + mov al,1 + sub al,cl +.doneline + or ecx,ecx + jnz .secondline + mov [esi+edx+$800],al + jmp .firstline +.secondline + mov [esi+edx+$900],al +.firstline + inc ebx + inc edx + cmp edx,0E1h + jne .nextline + or ecx,ecx + jnz .finish + mov ecx,1 + jmp .loopline +.finish + mov cx,[C4Temp] +; mov [C4values],cx + mov cx,[C4Temp+2] +; mov [C4values+2],cx + mov cx,[esi+1F8Ch] +; mov [C4values+4],cx + mov cx,[esi+1F8Fh] +; mov [C4values+6],cx + popad + ret +.propulsion + pushad + ; 81 = 5B, 83 = 0x300 + ; 0x300 = /1, 0x280 = /4 + mov esi,[C4Ram] + + mov cx,[esi+1F83h] + mov [C4values+2],cx + mov cx,[esi+1F81h] + mov [C4values],cx + xor bx,bx + +; mov ax,256*256 + xor ax,ax + mov dx,1 + mov bx,[esi+1F83h] + or dx,dx + jz .done + idiv bx + mov [C4values+6],ax + mov bx,[esi+1F81h] + imul bx + shl edx,16 + mov dx,ax + sar edx,8 +.done + mov word[esi+1F80h],dx + mov [C4values+4],dx + +; and eax,1FFh +; mov bx,[SinTable+eax*2] +; mov ax,[esi+1F81h] ; distance? +; imul bx +; mov ax,dx +; shl ax,1 +; shl dx,3 +; add dx,ax + + popad + ret +.something2 + pushad + mov esi,[C4Ram] + xor ecx,ecx + mov ax,[esi+1F80h] + and eax,1FFh + mov bx,[CosTable+eax*2] + mov ax,[esi+1F83h] + imul bx + add ax,ax + adc dx,dx + mov ax,dx + movsx edx,dx + mov [esi+1F87h],edx + mov ax,[esi+1F80h] + and eax,1FFh + mov bx,[SinTable+eax*2] + mov ax,[esi+1F83h] + imul bx + add ax,ax + adc dx,dx + mov ax,dx + movsx edx,dx + mov al,[esi+198Dh] + mov [esi+1F8Ah],edx + mov [esi+198Dh],al +; mov cx,[esi+1F83h] +; mov [C4values+4],cx +; mov cx,[esi+1F86h] +; mov [C4values],cx +; mov cx,[esi+1F89h] +; mov [C4values+2],cx + popad + ret + ret +.dosprites +; mov byte[debstop3],0 + push eax + mov eax,[C4Ram] + cmp byte[eax+1F4Dh],0 + je near .sprites + cmp byte[eax+1F4Dh],3 + je near .scaler + cmp byte[eax+1F4Dh],5 + je near .lines + cmp byte[eax+1F4Dh],7 + je near .rotater + cmp byte[eax+1F4Dh],8 + je near .wireframeb + cmp byte[eax+1F4Dh],0Bh + je near .disintegrate + cmp byte[eax+1F4Dh],0Ch + je near .bitmap + pop eax + ret +.wireframeb + pop eax + call WireFrameB2 + ret +.sprites + pop eax + call C4ProcessSprites + ret +.disintegrate + call C4SprDisintegrate + pop eax + ret +.dolines +; mov byte[debstop3],0 + ret +.bitmap + call C4BitPlaneWave + pop eax + ret +.calcdistance + pushad + mov esi,[C4Ram] + mov bx,[esi+1F80h] + mov [C41FXVal],bx + mov bx,[esi+1F83h] + mov [C41FYVal],bx +; mov eax,[C4Ram] +; mov cx,[eax+1F80h] +; mov [C4values+0],cx +; mov cx,[eax+1F83h] +; mov [C4values+2],cx + call C4Op15 + mov eax,[C4Ram] + mov bx,[C41FDist] + mov [eax+1F80h],bx +; mov word[eax+1F80h],50 +; mov cx,[eax+1F80h] +; mov [C4values+4],cx + popad + ret +.calcangle + pushad + mov esi,[C4Ram] + mov bx,[esi+1F80h] + mov [C41FXVal],bx + mov bx,[esi+1F83h] + mov [C41FYVal],bx + call C4Op1F + mov eax,[C4Ram] + mov bx,[C41FAngleRes] + mov [eax+1F86h],bx +; mov esi,[C4Ram] +; mov cx,[esi+1F86h] +; mov [C4values],cx +; mov cx,[esi+1F80h] +; mov [C4values+2],cx +; mov cx,[esi+1F83h] +; mov [C4values+4],cx + popad + ret +.transform + ; 7F81,4,7,9,A,B,0,1,D +; mov byte[debstop3],0 + pushad +; mov eax,[C4Ram] + call C4Transform +; mov word[eax+1F80h],0 +; mov word[eax+1F83h],0 + popad + ret +.equatevelocity + pushad + mov esi,[C4Ram] + mov bx,[esi+1F80h] + mov [C41FXVal],bx + mov bx,[esi+1F83h] + mov [C41FYVal],bx + mov bx,[esi+1F86h] + mov [C41FDistVal],bx + call C4Op0D + mov bx,[C41FXVal] + mov [esi+1F89h],bx + mov bx,[C41FYVal] + mov [esi+1F8Ch],bx + popad + ret + + + pushad + mov esi,[C4Ram] + mov cx,[esi+$1F86] + cmp cx,40h + jb .nomult + shr cx,7 +.nomult + mov ax,[esi+$1F80] +; imul cx + shl ax,4 + mov word[esi+$1F89],ax + mov ax,[esi+$1F83] +; imul cx + shl ax,4 + mov word[esi+$1F8C],ax +; mov cx,[esi+$1F80] +; mov [C4values],cx +; mov cx,[esi+$1F83] +; mov [C4values+2],cx +; mov cx,[esi+$1F86] +; mov [C4values+4],cx + popad + ret +.lines + call C4WireFrame + pop eax + ret +.scaler + push esi + push ecx + mov esi,[C4Ram] +; mov cx,[esi+1F8Fh] +; mov [C4values],cx +; mov cx,[esi+1F92h] +; mov [C4values+2],cx +; mov cx,[esi+1F80h] +; mov [C4values+4],cx + pop ecx + pop esi + call C4SprScaleR + pop eax + ret +.rotater + push esi + push ecx + mov esi,[C4Ram] +; mov cx,[esi+1F8Fh] +; mov [C4values],cx +; mov cx,[esi+1F92h] +; mov [C4values+2],cx +; mov cx,[esi+1F80h] +; mov [C4values+4],cx + pop ecx + pop esi + call C4SprRotateR + pop eax + ret +.direction + push eax + push ebx + push esi + push edx + push ecx + mov esi,[C4Ram] + xor ecx,ecx + mov ax,[esi+1F80h] + and eax,1FFh + mov bx,[CosTable+eax*2] + mov ax,[esi+1F83h] + imul bx + add ax,ax + adc dx,dx + mov ax,dx + movsx edx,dx + mov [esi+1F86h],edx + mov ax,[esi+1F80h] + and eax,1FFh + mov bx,[SinTable+eax*2] + mov ax,[esi+1F83h] + imul bx + add ax,ax + adc dx,dx + mov ax,dx + movsx edx,dx + mov eax,edx + sar eax,6 + sub edx,eax + mov al,[esi+198Ch] + mov [esi+1F89h],edx + mov [esi+198Ch],al +; mov cx,[esi+1F80h] +; mov [C4values],cx +; mov cx,[esi+1F83h] +; mov [C4values+2],cx +; mov cx,[esi+1F86h] +; mov [C4values+4],cx + pop ecx + pop edx + pop esi + pop ebx + pop eax + ret +.immediaterom + push eax + mov eax,[C4Ram] + mov byte[eax+1F80h],36h + mov byte[eax+1F81h],43h + mov byte[eax+1F82h],05h + pop eax + ret +.immediatereg + push eax + mov eax,[C4Ram] + mov dword[eax+0*4],0FF000000h + mov dword[eax+1*4],0FF00FFFFh + mov dword[eax+2*4],0FF000000h + mov dword[eax+3*4],00000FFFFh + mov dword[eax+4*4],00000FFFFh + mov dword[eax+5*4],07FFFFF80h + mov dword[eax+6*4],0FF008000h + mov dword[eax+7*4],07FFF007Fh + mov dword[eax+8*4],0FFFF7FFFh + mov dword[eax+9*4],0FF010000h + mov dword[eax+10*4],00100FEFFh + mov dword[eax+11*4],000FEFF00h + pop eax + ret + +C4RegFunction: + cmp ecx,1F4Fh + je near C4activate + add ecx,[C4Ram] + mov [ecx],al + sub ecx,[C4Ram] + ret + +NEWSYM C4ReadReg + add ecx,[C4Ram] + mov al,[ecx] + sub ecx,[C4Ram] + ret + +NEWSYM C4WriteReg + add ecx,[C4Ram] + mov [ecx],al + sub ecx,[C4Ram] + ret + +SinTable: +dw $00000,$00192,$00324,$004B6,$00647,$007D9,$0096A,$00AFB,$00C8B,$00E1B,$00FAB +dw $01139,$012C8,$01455,$015E2,$0176D,$018F8,$01A82,$01C0B,$01D93,$01F19,$0209F +dw $02223,$023A6,$02528,$026A8,$02826,$029A3,$02B1F,$02C98,$02E11,$02F87,$030FB +dw $0326E,$033DE,$0354D,$036BA,$03824,$0398C,$03AF2,$03C56,$03DB8,$03F17,$04073 +dw $041CE,$04325,$0447A,$045CD,$0471C,$04869,$049B4,$04AFB,$04C3F,$04D81,$04EBF +dw $04FFB,$05133,$05269,$0539B,$054CA,$055F5,$0571D,$05842,$05964,$05A82,$05B9D +dw $05CB4,$05DC7,$05ED7,$05FE3,$060EC,$061F1,$062F2,$063EF,$064E8,$065DD,$066CF +dw $067BD,$068A6,$0698C,$06A6D,$06B4A,$06C24,$06CF9,$06DCA,$06E96,$06F5F,$07023 +dw $070E2,$0719E,$07255,$07307,$073B5,$0745F,$07504,$075A5,$07641,$076D9,$0776C +dw $077FA,$07884,$07909,$0798A,$07A05,$07A7D,$07AEF,$07B5D,$07BC5,$07C29,$07C89 +dw $07CE3,$07D39,$07D8A,$07DD6,$07E1D,$07E5F,$07E9D,$07ED5,$07F09,$07F38,$07F62 +dw $07F87,$07FA7,$07FC2,$07FD8,$07FE9,$07FF6,$07FFD,$07FFF,$07FFD,$07FF6,$07FE9 +dw $07FD8,$07FC2,$07FA7,$07F87,$07F62,$07F38,$07F09,$07ED5,$07E9D,$07E5F,$07E1D +dw $07DD6,$07D8A,$07D39,$07CE3,$07C89,$07C29,$07BC5,$07B5D,$07AEF,$07A7D,$07A05 +dw $0798A,$07909,$07884,$077FA,$0776C,$076D9,$07641,$075A5,$07504,$0745F,$073B5 +dw $07307,$07255,$0719E,$070E2,$07023,$06F5F,$06E96,$06DCA,$06CF9,$06C24,$06B4A +dw $06A6D,$0698C,$068A6,$067BD,$066CF,$065DD,$064E8,$063EF,$062F2,$061F1,$060EC +dw $05FE3,$05ED7,$05DC7,$05CB4,$05B9D,$05A82,$05964,$05842,$0571D,$055F5,$054CA +dw $0539B,$05269,$05133,$04FFB,$04EBF,$04D81,$04C3F,$04AFB,$049B4,$04869,$0471C +dw $045CD,$0447A,$04325,$041CE,$04073,$03F17,$03DB8,$03C56,$03AF2,$0398C,$03824 +dw $036BA,$0354D,$033DE,$0326E,$030FB,$02F87,$02E11,$02C98,$02B1F,$029A3,$02826 +dw $026A8,$02528,$023A6,$02223,$0209F,$01F19,$01D93,$01C0B,$01A82,$018F8,$0176D +dw $015E2,$01455,$012C8,$01139,$00FAB,$00E1B,$00C8B,$00AFB,$0096A,$007D9,$00647 +dw $004B6,$00324,$00192 +dw $00000,$0FE6E,$0FCDC,$0FB4A,$0F9B9,$0F827,$0F696,$0F505,$0F375,$0F1E5,$0F055 +dw $0EEC7,$0ED38,$0EBAB,$0EA1E,$0E893,$0E708,$0E57E,$0E3F5,$0E26D,$0E0E7,$0DF61 +dw $0DDDD,$0DC5A,$0DAD8,$0D958,$0D7DA,$0D65D,$0D4E1,$0D368,$0D1EF,$0D079,$0CF05 +dw $0CD92,$0CC22,$0CAB3,$0C946,$0C7DC,$0C674,$0C50E,$0C3AA,$0C248,$0C0E9,$0BF8D +dw $0BE32,$0BCDB,$0BB86,$0BA33,$0B8E4,$0B797,$0B64C,$0B505,$0B3C1,$0B27F,$0B141 +dw $0B005,$0AECD,$0AD97,$0AC65,$0AB36,$0AA0B,$0A8E3,$0A7BE,$0A69C,$0A57E,$0A463 +dw $0A34C,$0A239,$0A129,$0A01D,$09F14,$09E0F,$09D0E,$09C11,$09B18,$09A23,$09931 +dw $09843,$0975A,$09674,$09593,$094B6,$093DC,$09307,$09236,$0916A,$090A1,$08FDD +dw $08F1E,$08E62,$08DAB,$08CF9,$08C4B,$08BA1,$08AFC,$08A5B,$089BF,$08927,$08894 +dw $08806,$0877C,$086F7,$08676,$085FB,$08583,$08511,$084A3,$0843B,$083D7,$08377 +dw $0831D,$082C7,$08276,$0822A,$081E3,$081A1,$08163,$0812B,$080F7,$080C8,$0809E +dw $08079,$08059,$0803E,$08028,$08017,$0800A,$08003,$08001,$08003,$0800A,$08017 +dw $08028,$0803E,$08059,$08079,$0809E,$080C8,$080F7,$0812B,$08163,$081A1,$081E3 +dw $0822A,$08276,$082C7,$0831D,$08377,$083D7,$0843B,$084A3,$08511,$08583,$085FB +dw $08676,$086F7,$0877C,$08806,$08894,$08927,$089BF,$08A5B,$08AFC,$08BA1,$08C4B +dw $08CF9,$08DAB,$08E62,$08F1E,$08FDD,$090A1,$0916A,$09236,$09307,$093DC,$094B6 +dw $09593,$09674,$0975A,$09843,$09931,$09A23,$09B18,$09C11,$09D0E,$09E0F,$09F14 +dw $0A01D,$0A129,$0A239,$0A34C,$0A463,$0A57E,$0A69C,$0A7BE,$0A8E3,$0AA0B,$0AB36 +dw $0AC65,$0AD97,$0AECD,$0B005,$0B141,$0B27F,$0B3C1,$0B505,$0B64C,$0B797,$0B8E4 +dw $0BA33,$0BB86,$0BCDB,$0BE32,$0BF8D,$0C0E9,$0C248,$0C3AA,$0C50E,$0C674,$0C7DC +dw $0C946,$0CAB3,$0CC22,$0CD92,$0CF05,$0D079,$0D1EF,$0D368,$0D4E1,$0D65D,$0D7DA +dw $0D958,$0DAD8,$0DC5A,$0DDDD,$0DF61,$0E0E7,$0E26D,$0E3F5,$0E57E,$0E708,$0E893 +dw $0EA1E,$0EBAB,$0ED38,$0EEC7,$0F055,$0F1E5,$0F375,$0F505,$0F696,$0F827,$0F9B9 +dw $0FB4A,$0FCDC,$0FE6E + + +CosTable: +dw $07FFF,$07FFD,$07FF6,$07FE9,$07FD8,$07FC2,$07FA7,$07F87,$07F62,$07F38,$07F09 +dw $07ED5,$07E9D,$07E5F,$07E1D,$07DD6,$07D8A,$07D39,$07CE3,$07C89,$07C29,$07BC5 +dw $07B5D,$07AEF,$07A7D,$07A05,$0798A,$07909,$07884,$077FA,$0776C,$076D9,$07641 +dw $075A5,$07504,$0745F,$073B5,$07307,$07255,$0719E,$070E2,$07023,$06F5F,$06E96 +dw $06DCA,$06CF9,$06C24,$06B4A,$06A6D,$0698C,$068A6,$067BD,$066CF,$065DD,$064E8 +dw $063EF,$062F2,$061F1,$060EC,$05FE3,$05ED7,$05DC7,$05CB4,$05B9D,$05A82,$05964 +dw $05842,$0571D,$055F5,$054CA,$0539B,$05269,$05133,$04FFB,$04EBF,$04D81,$04C3F +dw $04AFB,$049B4,$04869,$0471C,$045CD,$0447A,$04325,$041CE,$04073,$03F17,$03DB8 +dw $03C56,$03AF2,$0398C,$03824,$036BA,$0354D,$033DE,$0326E,$030FB,$02F87,$02E11 +dw $02C98,$02B1F,$029A3,$02826,$026A8,$02528,$023A6,$02223,$0209F,$01F19,$01D93 +dw $01C0B,$01A82,$018F8,$0176D,$015E2,$01455,$012C8,$01139,$00FAB,$00E1B,$00C8B +dw $00AFB,$0096A,$007D9,$00647,$004B6,$00324,$00192,$00000,$0FE6E,$0FCDC,$0FB4A +dw $0F9B9,$0F827,$0F696,$0F505,$0F375,$0F1E5,$0F055,$0EEC7,$0ED38,$0EBAB,$0EA1E +dw $0E893,$0E708,$0E57E,$0E3F5,$0E26D,$0E0E7,$0DF61,$0DDDD,$0DC5A,$0DAD8,$0D958 +dw $0D7DA,$0D65D,$0D4E1,$0D368,$0D1EF,$0D079,$0CF05,$0CD92,$0CC22,$0CAB3,$0C946 +dw $0C7DC,$0C674,$0C50E,$0C3AA,$0C248,$0C0E9,$0BF8D,$0BE32,$0BCDB,$0BB86,$0BA33 +dw $0B8E4,$0B797,$0B64C,$0B505,$0B3C1,$0B27F,$0B141,$0B005,$0AECD,$0AD97,$0AC65 +dw $0AB36,$0AA0B,$0A8E3,$0A7BE,$0A69C,$0A57E,$0A463,$0A34C,$0A239,$0A129,$0A01D +dw $09F14,$09E0F,$09D0E,$09C11,$09B18,$09A23,$09931,$09843,$0975A,$09674,$09593 +dw $094B6,$093DC,$09307,$09236,$0916A,$090A1,$08FDD,$08F1E,$08E62,$08DAB,$08CF9 +dw $08C4B,$08BA1,$08AFC,$08A5B,$089BF,$08927,$08894,$08806,$0877C,$086F7,$08676 +dw $085FB,$08583,$08511,$084A3,$0843B,$083D7,$08377,$0831D,$082C7,$08276,$0822A +dw $081E3,$081A1,$08163,$0812B,$080F7,$080C8,$0809E,$08079,$08059,$0803E,$08028 +dw $08017,$0800A,$08003 +dw $08001,$08003,$0800A,$08017,$08028,$0803E,$08059,$08079,$0809E,$080C8,$080F7, +dw $0812B,$08163,$081A1,$081E3,$0822A,$08276,$082C7,$0831D,$08377,$083D7,$0843B, +dw $084A3,$08511,$08583,$085FB,$08676,$086F7,$0877C,$08806,$08894,$08927,$089BF, +dw $08A5B,$08AFC,$08BA1,$08C4B,$08CF9,$08DAB,$08E62,$08F1E,$08FDD,$090A1,$0916A, +dw $09236,$09307,$093DC,$094B6,$09593,$09674,$0975A,$09843,$09931,$09A23,$09B18, +dw $09C11,$09D0E,$09E0F,$09F14,$0A01D,$0A129,$0A239,$0A34C,$0A463,$0A57E,$0A69C, +dw $0A7BE,$0A8E3,$0AA0B,$0AB36,$0AC65,$0AD97,$0AECD,$0B005,$0B141,$0B27F,$0B3C1, +dw $0B505,$0B64C,$0B797,$0B8E4,$0BA33,$0BB86,$0BCDB,$0BE32,$0BF8D,$0C0E9,$0C248, +dw $0C3AA,$0C50E,$0C674,$0C7DC,$0C946,$0CAB3,$0CC22,$0CD92,$0CF05,$0D079,$0D1EF, +dw $0D368,$0D4E1,$0D65D,$0D7DA,$0D958,$0DAD8,$0DC5A,$0DDDD,$0DF61,$0E0E7,$0E26D, +dw $0E3F5,$0E57E,$0E708,$0E893,$0EA1E,$0EBAB,$0ED38,$0EEC7,$0F055,$0F1E5,$0F375, +dw $0F505,$0F696,$0F827,$0F9B9,$0FB4A,$0FCDC,$0FE6E,$00000,$00192,$00324,$004B6, +dw $00647,$007D9,$0096A,$00AFB,$00C8B,$00E1B,$00FAB,$01139,$012C8,$01455,$015E2, +dw $0176D,$018F8,$01A82,$01C0B,$01D93,$01F19,$0209F,$02223,$023A6,$02528,$026A8, +dw $02826,$029A3,$02B1F,$02C98,$02E11,$02F87,$030FB,$0326E,$033DE,$0354D,$036BA, +dw $03824,$0398C,$03AF2,$03C56,$03DB8,$03F17,$04073,$041CE,$04325,$0447A,$045CD, +dw $0471C,$04869,$049B4,$04AFB,$04C3F,$04D81,$04EBF,$04FFB,$05133,$05269,$0539B, +dw $054CA,$055F5,$0571D,$05842,$05964,$05A82,$05B9D,$05CB4,$05DC7,$05ED7,$05FE3, +dw $060EC,$061F1,$062F2,$063EF,$064E8,$065DD,$066CF,$067BD,$068A6,$0698C,$06A6D, +dw $06B4A,$06C24,$06CF9,$06DCA,$06E96,$06F5F,$07023,$070E2,$0719E,$07255,$07307, +dw $073B5,$0745F,$07504,$075A5,$07641,$076D9,$0776C,$077FA,$07884,$07909,$0798A, +dw $07A05,$07A7D,$07AEF,$07B5D,$07BC5,$07C29,$07C89,$07CE3,$07D39,$07D8A,$07DD6, +dw $07E1D,$07E5F,$07E9D,$07ED5,$07F09,$07F38,$07F62,$07F87,$07FA7,$07FC2,$07FD8, +dw $07FE9,$07FF6,$07FFD + + +NEWSYM regaccessbankr8 + test ecx,8000h + jz .regacc + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,2000h + jae .regs + mov al,[wramdataa+ecx] + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptra+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .hiromsram + xor al,al + ret +.hiromsram + cmp byte[SPC7110Enable],1 + je near .spc7110ram + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[C4Enable],1 + je near .c4ram + and ebx,7Fh + cmp bl,10h + jb .dsp1 + cmp bl,30h + jae .hiromsramok + mov al,080h + xor ebx,ebx + ret +.dsp1 + mov al,80h + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Read8b +.nodsp1 + xor ebx,ebx + ret +.hiromsramok + push ecx + sub ecx,6000h + and ecx,1fffh + sub bl,30h + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankr8b + pop ecx + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov al,[ebx+ecx] + xor ebx,ebx + pop ecx + ret +.c4ram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[C4RamR] + call dword near [ebx+ecx*4] + xor ebx,ebx + pop ecx + ret +.spc7110ram + push ecx + sub ecx,6000h + and ecx,1fffh + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankr8b + pop ecx + ret + +NEWSYM regaccessbankr16 + test ecx,8000h + jz .regacc + mov ebx,[snesmmap+ebx*4] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,2000h + jae .regs + mov ax,[wramdataa+ecx] + ret +.regs + cmp ecx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptr] +; call dword near [ebx] + call dword near [regptra+ecx*4-8000h] + inc ecx + mov ah,al +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptr] +; call dword near [ebx] + call dword near [regptra+ecx*4-8000h] + mov bl,al + dec ecx + mov al,ah + mov ah,bl + xor ebx,ebx + ret +.invaccess +; jmp regexiter + cmp ecx,6000h + jae .hiromsram + xor ax,ax + ret +.hiromsram + cmp byte[SPC7110Enable],1 + je near .spc7110ram + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[C4Enable],1 + je near .c4ram + and ebx,7Fh + cmp bl,10h + jb .dsp1 + cmp bl,30h + jae .hiromsramok + mov ax,08080h + xor ebx,ebx + ret +.dsp1 + mov ax,8080h + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Read16b +.nodsp1 + xor ebx,ebx + ret +.hiromsramok + push ecx + sub ecx,6000h + and ecx,1fffh + sub bl,30h + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankr16b + pop ecx + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov ax,[ebx+ecx] + xor ebx,ebx + pop ecx + ret +.c4ram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[C4RamR] + inc ecx + call dword near [ebx+ecx*4] + dec ecx + mov ah,al + call dword near [ebx+ecx*4] + xor ebx,ebx + pop ecx + ret +.spc7110ram + push ecx + sub ecx,6000h + and ecx,1fffh + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankr16b + pop ecx + ret + +NEWSYM regaccessbankw8 + test ecx,8000h + jnz .romacc + cmp ecx,2000h + jae .regs + mov [wramdataa+ecx],al + ret +.romacc + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap+ebx*4] + mov [ebx+ecx],al + xor ebx,ebx + ret +.regs + cmp ecx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptw] +; call dword near [ebx] + call dword near [regptwa+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess +; jmp regexiter + cmp ecx,6000h + jae .hiromsram + ret +.hiromsram + cmp byte[SPC7110Enable],1 + je near .spc7110ram + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[C4Enable],1 + je near .c4ram + and ebx,7Fh + cmp bl,10h + jb .dsp1 + cmp bl,30h + jae .hiromsramok + xor ebx,ebx + ret +.dsp1 + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Write8b +.nodsp1 + xor ebx,ebx + ret +.hiromsramok + push ecx + sub ecx,6000h + and ecx,1fffh + sub bl,30h + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankw8b + pop ecx + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov [ebx+ecx],al + xor ebx,ebx + pop ecx + ret +.c4ram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[C4RamW] + call dword near [ebx+ecx*4] + xor ebx,ebx + pop ecx + ret +.spc7110ram + push ecx + sub ecx,6000h + and ecx,1fffh + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankw8b + pop ecx + ret + +NEWSYM regaccessbankw16 + test ecx,8000h + jnz .romacc + cmp ecx,2000h + jae .regs + mov [wramdataa+ecx],ax + ret +.romacc + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap+ebx*4] + mov [ebx+ecx],ax + xor ebx,ebx + ret +.regs + cmp cx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptw] +; call dword near [ebx] + call dword near [regptwa+ecx*4-8000h] + inc ecx + mov al,ah +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptw] +; call dword near [ebx] + call dword near [regptwa+ecx*4-8000h] + dec ecx + xor ebx,ebx + ret +.invaccess +; jmp regexiter + cmp ecx,6000h + jae .hiromsram + ret +.hiromsram + cmp byte[SPC7110Enable],1 + je near .spc7110ram + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[C4Enable],1 + je near .c4ram + and ebx,7Fh + cmp bl,10h + jb .dsp1 + cmp bl,30h + jae .hiromsramok + xor al,al + xor ebx,ebx + ret +.dsp1 + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Write16b +.nodsp1 + ret +.hiromsramok + push ecx + sub ecx,6000h + and ecx,1fffh + sub bl,30h + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankw16b + pop ecx + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov [ebx+ecx],ax + xor ebx,ebx + pop ecx + ret +.c4ram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[C4Ram] + mov [ebx+ecx],ax + mov ebx,[C4RamW] + push eax + call dword near [ebx+ecx*4] + inc ecx + mov al,ah + call dword near [ebx+ecx*4] + pop eax + dec ecx + xor ebx,ebx + pop ecx + ret +.spc7110ram + push ecx + sub ecx,6000h + and ecx,1fffh + shl ebx,13 + add ecx,ebx + and ecx,0FFFFh + call sramaccessbankw16b + pop ecx + ret + +NEWSYM regaccessbankr8mp + ret + +;******************************************************* +; Register & Memory Bank (Bank 0) +;******************************************************* +; enter : BL = bank number, CX = address location +; leave : AL = value read + +%macro writetobank0table 2 + mov ebx,%1 + mov ecx,%2 +%%loop + mov [eax],ebx + add eax,4 + loop %%loop +%endmacro + +NEWSYM DPageR8, dd 0 +NEWSYM DPageR16, dd 0 +NEWSYM DPageW8, dd 0 +NEWSYM DPageW16, dd 0 +NEWSYM SA1DPageR8, dd 0 +NEWSYM SA1DPageR16, dd 0 +NEWSYM SA1DPageW8, dd 0 +NEWSYM SA1DPageW16, dd 0 + +NEWSYM UpdateDPage + push eax + xor eax,eax + mov al,[xd+1] + push ecx + mov ecx,[Bank0datr8+eax*4] + mov [DPageR8],ecx + mov ecx,[Bank0datr16+eax*4] + mov [DPageR16],ecx + mov ecx,[Bank0datw8+eax*4] + mov [DPageW8],ecx + mov ecx,[Bank0datw16+eax*4] + mov [DPageW16],ecx + pop ecx + pop eax + ret + +NEWSYM SA1UpdateDPage + push eax + xor eax,eax + mov al,[SA1xd+1] + push ecx + mov ecx,[Bank0datr8+eax*4] + mov [SA1DPageR8],ecx + mov ecx,[Bank0datr16+eax*4] + mov [SA1DPageR16],ecx + mov ecx,[Bank0datw8+eax*4] + mov [SA1DPageW8],ecx + mov ecx,[Bank0datw16+eax*4] + mov [SA1DPageW16],ecx + pop ecx + pop eax + ret + +NEWSYM GenerateBank0Table + mov eax,Bank0datr8 + writetobank0table membank0r8ram,20h + writetobank0table membank0r8reg,28h + writetobank0table membank0r8inv,17h + writetobank0table membank0r8chip,1Fh + writetobank0table membank0r8rom,81h + writetobank0table membank0r8romram,1h + mov eax,Bank0datw8 + writetobank0table membank0w8ram,20h + writetobank0table membank0w8reg,28h + writetobank0table membank0w8inv,17h + writetobank0table membank0w8chip,1Fh + writetobank0table membank0w8rom,81h + writetobank0table membank0w8romram,1h + mov eax,Bank0datr16 + writetobank0table membank0r16ram,20h + writetobank0table membank0r16reg,28h + writetobank0table membank0r16inv,17h + writetobank0table membank0r16chip,1Fh + writetobank0table membank0r16rom,81h + writetobank0table membank0r16romram,1h + mov eax,Bank0datw16 + writetobank0table membank0w16ram,20h + writetobank0table membank0w16reg,28h + writetobank0table membank0w16inv,17h + writetobank0table membank0w16chip,1Fh + writetobank0table membank0w16rom,81h + writetobank0table membank0w16romram,1h + ret + +NEWSYM GenerateBank0TableSA1 + mov eax,Bank0datr8 + writetobank0table membank0r8ramSA1,20h + mov eax,Bank0datw8 + writetobank0table membank0w8ramSA1,20h + mov eax,Bank0datr16 + writetobank0table membank0r16ramSA1,20h + mov eax,Bank0datw16 + writetobank0table membank0w16ramSA1,20h + ret + +; SA1 Stuff +NEWSYM membank0r8ramSA1 ; 0000-1FFF + cmp byte[SA1Status],0 + jne .nowram + mov al,[wramdataa+ecx+ebx] + ret +.nowram + cmp ecx,800h + jae .invaccess + mov al,[IRAM+ecx+ebx] + ret +.invaccess + xor al,al + ret +NEWSYM membank0r16ramSA1 ; 0000-1FFF + cmp byte[SA1Status],0 + jne .nowram + mov ax,[wramdataa+ecx+ebx] + ret +.nowram + cmp ecx,800h + jae .invaccess + mov ax,[IRAM+ecx+ebx] + ret +.invaccess + xor ax,ax + ret +NEWSYM membank0w8ramSA1 ; 0000-1FFF + cmp byte[SA1Status],0 + jne .nowram + mov [wramdataa+ecx+ebx],al + ret +.nowram + cmp ecx,800h + jae .invaccess + mov [IRAM+ecx+ebx],al +.invaccess + ret +NEWSYM membank0w16ramSA1 ; 0000-1FFF + cmp byte[SA1Status],0 + jne .nowram + mov [wramdataa+ecx+ebx],ax + ret +.nowram + cmp ecx,800h + jae .invaccess + mov [IRAM+ecx+ebx],ax +.invaccess + ret + +; --- 8 BIT READ STUFF --- +NEWSYM membank0r8ram ; 0000-1FFF + mov al,[wramdataa+ebx+ecx] + ret +NEWSYM membank0r8reg ; 2000-48FF + add ecx,ebx + call dword near [regptra+ecx*4-8000h] + xor ebx,ebx + ret +NEWSYM membank0r8inv ; 4800-5FFF + mov al,80h + ret +NEWSYM membank0r8chip ; 6000-7FFF + add ecx,ebx + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[SA1Enable],1 + je .sa1ram + mov al,80h + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Read8b +.nodsp1 + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov al,[ebx+ecx] + xor ebx,ebx + pop ecx + ret +.sa1ram + mov ebx,[CurBWPtr] + mov al,[ebx+ecx] + xor ebx,ebx + ret +NEWSYM membank0r8rom ; 8000-FFFF + add ebx,[snesmmap] + mov al,[ebx+ecx] + xor ebx,ebx + ret +NEWSYM membank0r8romram ; 0000-1FFF + add cx,bx + test cx,8000h + jnz .rom + mov al,[wramdataa+ecx] + ret +.rom + mov ebx,[snesmmap] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +; --- 16 BIT READ STUFF --- +NEWSYM membank0r16ram ; 0000-1FFF + mov ax,[wramdataa+ebx+ecx] + ret +NEWSYM membank0r16reg ; 2000-48FF + add ecx,ebx + call dword near [regptra+ecx*4-8000h] + inc ecx + mov ah,al + call dword near [regptra+ecx*4-8000h] + mov bl,al + dec ecx + mov al,ah + mov ah,bl + xor ebx,ebx + ret +NEWSYM membank0r16inv ; 4800-5FFF + mov ax,8080h + ret +NEWSYM membank0r16chip ; 6000-FFFF + add ecx,ebx + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[SA1Enable],1 + je .sa1ram + mov ax,8080h + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Read16b +.nodsp1 + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov ax,[ebx+ecx] + xor ebx,ebx + pop ecx + ret +.sa1ram + mov ebx,[CurBWPtr] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +NEWSYM membank0r16rom ; 8000-FFFF + add ebx,[snesmmap] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +NEWSYM membank0r16romram ; 0000-1FFF + add cx,bx + test cx,8000h + jnz .rom + mov ax,[wramdataa+ecx] + ret +.rom + mov ebx,[snesmmap] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +; --- 8 BIT WRITE STUFF --- +NEWSYM membank0w8ram ; 0000-1FFF + mov [wramdataa+ebx+ecx],al + ret +NEWSYM membank0w8reg ; 2000-48FF + add ecx,ebx + call dword near [regptwa+ecx*4-8000h] + xor ebx,ebx + ret +NEWSYM membank0w8inv ; 4800-5FFF + ret +NEWSYM membank0w8chip ; 6000-FFFF + add ecx,ebx + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[SA1Enable],1 + je .sa1ram + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Write8b +.nodsp1 + ret +.sfxram + push ecx + sub cx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov [ebx+ecx],al + xor ebx,ebx + pop ecx + ret +.sa1ram + mov ebx,[CurBWPtr] + mov [ebx+ecx],al + xor ebx,ebx + ret +NEWSYM membank0w8rom ; 8000-FFFF + ret +NEWSYM membank0w8romram ; 0000-1FFF + add cx,bx + test cx,8000h + jnz .rom + mov [wramdataa+ecx],al + ret +.rom + ret + +; --- 16 BIT WRITE STUFF --- +NEWSYM membank0w16ram ; 0000-1FFF + mov [wramdataa+ebx+ecx],ax + ret +NEWSYM membank0w16reg ; 2000-48FF + add ecx,ebx + call dword near [regptwa+ecx*4-8000h] + inc ecx + mov al,ah + call dword near [regptwa+ecx*4-8000h] + dec ecx + xor ebx,ebx + ret +NEWSYM membank0w16inv ; 4800-5FFF + ret +NEWSYM membank0w16chip ; 6000-FFFF + add ecx,ebx +NEWSYM membank0w16rom ; 8000-FFFF + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[SA1Enable],1 + je .sa1ram + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Write16b +.nodsp1 + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov [ebx+ecx],ax + xor ebx,ebx + pop ecx + ret +.sa1ram + mov ebx,[CurBWPtr] + mov [ebx+ecx],ax + xor ebx,ebx + ret +NEWSYM membank0w16romram ; 0000-1FFF + add cx,bx + test cx,8000h + jnz .rom + mov [wramdataa+ecx],ax + ret +.rom + ret + +NEWSYM membank0r8 + cmp byte[SA1Enable],1 + je near membank0r8SA1 + cmp ecx,2000h + jae .regs + mov al,[wramdataa+ecx] + ret +.regs + test ecx,8000h + jz .regacc + mov ebx,[snesmmap] + mov al,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptr] +; call dword near [ebx] + call dword near [regptra+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .dsp1 + mov al,80h + ret +.dsp1 + cmp byte[SFXEnable],1 + je .sfxram + mov al,80h + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Read8b +.nodsp1 + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov al,[ebx+ecx] + xor ebx,ebx + pop ecx + ret + +NEWSYM membank0r16 + cmp byte[SA1Enable],1 + je near membank0r16SA1 + cmp ecx,2000h + jae .regs + mov ax,[wramdataa+ecx] + ret +.regs + test ecx,8000h + jz .regacc + mov ebx,[snesmmap] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptr] +; call dword near [ebx] + call dword near [regptra+ecx*4-8000h] + inc ecx + mov ah,al +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptr] +; call dword near [ebx] + call dword near [regptra+ecx*4-8000h] + mov bl,al + dec ecx + mov al,ah + mov ah,bl + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .dsp1 + mov ax,8080h + ret +.dsp1 + cmp byte[SFXEnable],1 + je .sfxram + mov ax,8080h + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Read16b +.nodsp1 + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov ax,[ebx+ecx] + xor ebx,ebx + pop ecx + ret + +NEWSYM membank0w8 + cmp byte[SA1Enable],1 + je near membank0w8SA1 + cmp ecx,2000h + jae .regs + mov [wramdataa+ecx],al + ret +.romacc + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap] + mov [ebx+ecx],al + xor ebx,ebx + ret +.regs + test ecx,8000h + jnz .romacc + cmp ecx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptw] +; call dword near [ebx] + call dword near [regptwa+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .dsp1 + ret +.dsp1 + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Write8b +.nodsp1 + ret +.sfxram + push ecx + sub cx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov [ebx+ecx],al + xor ebx,ebx + pop ecx + ret +NEWSYM membank0w16 + cmp byte[SA1Enable],1 + je near membank0w16SA1 + cmp ecx,2000h + jae .regs + mov [wramdataa+ecx],ax + ret +.romacc + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap] + mov [ebx+ecx],ax + xor ebx,ebx + ret +.regs + test ecx,8000h + jnz .romacc + cmp ecx,48FFh + ja .invaccess +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptw] +; call dword near [ebx] + call dword near [regptwa+ecx*4-8000h] + inc ecx + mov al,ah +; mov ebx,ecx +; shl ebx,2 +; add ebx,[regptw] +; call dword near [ebx] + call dword near [regptwa+ecx*4-8000h] + dec ecx + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .dsp1 + ret +.dsp1 + cmp byte[SFXEnable],1 + je .sfxram + cmp byte[DSP1Type],2 + jne .nodsp1 + call DSP1Write16b +.nodsp1 + ret +.sfxram + push ecx + sub ecx,6000h + and ecx,1fffh + mov ebx,[sfxramdata] + mov [ebx+ecx],ax + xor ebx,ebx + pop ecx + ret + +NEWSYM membank0r8SA1 + test ecx,8000h + jz .regacc + mov ebx,[snesmmap] + mov al,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov al,[wramdataa+ecx] + ret +.nowram + cmp ecx,800h + jae .invaccess + mov al,[IRAM+ecx] + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptra+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + xor al,al + ret +.bwram + mov ebx,[CurBWPtr] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM membank0r16SA1 + test ecx,8000h + jz .regacc + mov ebx,[snesmmap] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov ax,[wramdataa+ecx] + ret +.nowram + cmp ecx,800h + jae .invaccess + mov ax,[IRAM+ecx] + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptra+ecx*4-8000h] + inc ecx + mov ah,al + call dword near [regptra+ecx*4-8000h] + mov bl,al + dec ecx + mov al,ah + mov ah,bl + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + xor ax,ax + ret +.bwram + mov ebx,[CurBWPtr] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM membank0w8SA1 + test ecx,8000h + jnz .romacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov [wramdataa+ecx],al + ret +.nowram + cmp ecx,800h + jae .invaccess + mov [IRAM+ecx],al + ret +.romacc + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptwa+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + ret +.bwram + mov ebx,[CurBWPtr] + mov [ebx+ecx],al + xor ebx,ebx + ret + +NEWSYM membank0w16SA1 + test ecx,8000h + jnz .romacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov [wramdataa+ecx],ax + ret +.nowram + cmp ecx,800h + jae .invaccess + mov [IRAM+ecx],ax + ret +.romacc + ret +.regs + cmp cx,48FFh + ja .invaccess + call dword near [regptwa+ecx*4-8000h] + inc ecx + mov al,ah + call dword near [regptwa+ecx*4-8000h] + dec ecx + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + ret +.bwram + mov ebx,[CurBWPtr] + mov [ebx+ecx],ax + xor ebx,ebx + ret + +;******************************************************* +; ROM Only Access Banks (40 - 6F) / (C0 - FF) +;******************************************************* +%macro TestSDD1 0 + cmp ebx,0DAh + jne %%nobank + cmp ecx,1C01h + jbe %%nobank + cmp ecx,[LatestBank] + ja %%nobank + mov [LatestBank],ecx +%%nobank +%endmacro + +NEWSYM memaccessspc7110r8 + + + xor al,al + push ebx + xor ebx,ebx + mov bx,[SPCDecmPtr] + add ebx,[romdata] + add ebx,510000h + mov al,[ebx] + pop ebx + + dec word[SPCCompCounter] + inc dword[SPCCompPtr] + inc word[SPCDecmPtr] + inc word[CurDecompSize] + ret + + mov byte[debstop3],1 + mov ebx,[romdata] + add ebx,510000h + mov al,[ebx+ecx] + cmp cx,[CurDecompPtr] + jb .noptr + mov [CurDecompPtr],cx + mov bx,cx + sub bx,[PrevDecompPtr] + inc bx + mov [CurDecompSize],bx +.noptr + xor ebx,ebx + ret +NEWSYM memaccessspc7110r16 + mov byte[debstop3],1 + mov ebx,[romdata] + add ebx,510000h + mov ax,[ebx+ecx] + cmp cx,[CurDecompPtr] + jb .noptr + mov [CurDecompPtr],cx + mov bx,cx + sub bx,[PrevDecompPtr] + add bx,2 + mov [CurDecompSize],bx +.noptr + xor ebx,ebx + ret +NEWSYM memaccessspc7110w8 + mov ebx,[romdata] + add ebx,510000h + mov [ebx+ecx],al + xor ebx,ebx + ret +NEWSYM memaccessspc7110w16 + mov ebx,[romdata] + add ebx,510000h + mov [ebx+ecx],ax + xor ebx,ebx + ret + +NEWSYM memaccessbankr8 +; TestSDD1 + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM memaccessbankr16 +; TestSDD1 + mov ebx,[snesmmap+ebx*4] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM memaccessbankw8 + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap+ebx*4] + mov [ebx+ecx],al + xor ebx,ebx + ret + +NEWSYM memaccessbankw16 + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap+ebx*4] + mov [ebx+ecx],ax + xor ebx,ebx + ret + +NEWSYM memaccessbankr848mb + test ecx,8000h + jz .map2 + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + xor ebx,ebx + ret +.map2 + mov ebx,[snesmap2+ebx*4] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM memaccessbankr1648mb + test ecx,8000h + jz .map2 + mov ebx,[snesmmap+ebx*4] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +.map2 + mov ebx,[snesmap2+ebx*4] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +;******************************************************* +; SRAM Access Bank (70h) +;******************************************************* + +NEWSYM sramaccessbankr8 + push ecx + sub bl,70h + shl ebx,15 + add ecx,ebx + call sramaccessbankr8b + pop ecx + ret +NEWSYM sramaccessbankr16 + push ecx + sub bl,70h + shl ebx,15 + add ecx,ebx + call sramaccessbankr16b + pop ecx + ret +NEWSYM sramaccessbankw8 + push ecx + sub bl,70h + shl ebx,15 + add ecx,ebx + call sramaccessbankw8b + pop ecx + ret +NEWSYM sramaccessbankw16 + push ecx + sub bl,70h + shl ebx,15 + add ecx,ebx + call sramaccessbankw16b + pop ecx + ret + +NEWSYM sramaccessbankr8s + push ecx + sub bl,78h + shl ebx,15 + add ecx,ebx + call sramaccessbankr8b + pop ecx + ret +NEWSYM sramaccessbankr16s + push ecx + sub bl,78h + shl ebx,15 + add ecx,ebx + call sramaccessbankr16b + pop ecx + ret +NEWSYM sramaccessbankw8s + push ecx + sub bl,78h + shl ebx,15 + add ecx,ebx + call sramaccessbankw8b + pop ecx + ret +NEWSYM sramaccessbankw16s + push ecx + sub bl,78h + shl ebx,15 + add ecx,ebx + call sramaccessbankw16b + pop ecx + ret + +NEWSYM sramaccessbankr8b + cmp dword[ramsize],0 + je .noaccess + push ecx + and ecx,[ramsizeand] + mov ebx,[sram] + mov al,[ebx+ecx] + pop ecx + xor ebx,ebx + ret +.noaccess + xor al,al + xor ebx,ebx + ret + +NEWSYM sramaccessbankr16b + cmp dword[ramsize],0 + je .noaccess + mov ebx,[sram] + push ecx + and ecx,[ramsizeand] + mov al,[ebx+ecx] + inc ecx + and ecx,[ramsizeand] + mov ah,[ebx+ecx] + pop ecx + xor ebx,ebx + ret +.noaccess + xor ax,ax + xor ebx,ebx + ret + +NEWSYM sramaccessbankw8b + cmp dword[ramsize],0 + je .noaccess + mov ebx,[sram] + push ecx + and ecx,[ramsizeand] + mov [ebx+ecx],al + pop ecx + mov dword[sramb4save],5*60 +.noaccess + xor ebx,ebx + ret + +NEWSYM sramaccessbankw16b + cmp dword[ramsize],0 + je .noaccess + mov ebx,[sram] + push ecx + and ecx,[ramsizeand] + mov [ebx+ecx],al + inc ecx + and ecx,[ramsizeand] + mov [ebx+ecx],ah + pop ecx + mov dword[sramb4save],5*60 +.noaccess + xor ebx,ebx + ret + +;******************************************************* +; WorkRAM/ExpandRAM Access Bank (7Eh) +;******************************************************* + +NEWSYM wramaccessbankr8 +; mov ebx,[wramdata] +; mov al,[ebx+ecx] +; xor ebx,ebx + mov al,[wramdataa+ecx] + ret + +NEWSYM wramaccessbankr16 +; mov ebx,[wramdata] +; mov ax,[ebx+ecx] +; xor ebx,ebx + mov ax,[wramdataa+ecx] + ret + +NEWSYM wramaccessbankw8 +; mov ebx,[wramdata] +; mov [ebx+ecx],al +; xor ebx,ebx + mov [wramdataa+ecx],al + ret + +NEWSYM wramaccessbankw16 +; mov ebx,[wramdata] +; mov [ebx+ecx],ax +; xor ebx,ebx + mov [wramdataa+ecx],ax + ret + +;******************************************************* +; ExpandRAM Access Bank (7Fh) +;******************************************************* +NEWSYM eramaccessbankr8 +; mov ebx,[ram7f] +; mov al,[ebx+ecx] +; xor ebx,ebx + mov al,[ram7fa+ecx] + ret + +NEWSYM eramaccessbankr16 +; mov ebx,[ram7f] +; mov ax,[ebx+ecx] +; xor ebx,ebx + mov ax,[ram7fa+ecx] + ret + +NEWSYM eramaccessbankw8 +; mov ebx,[ram7f] +; mov [ebx+ecx],al +; xor ebx,ebx + mov [ram7fa+ecx],al + ret + +NEWSYM eramaccessbankw16 +; mov ebx,[ram7f] +; mov [ebx+ecx],ax +; xor ebx,ebx + mov [ram7fa+ecx],ax + ret + +;******************************************************* +; Invalid Access Bank (710000h-7DFFFFh) +;******************************************************* +NEWSYM invaccessbank + xor eax,eax + mov byte[invalid],1 + mov [invopcd],bl + mov al,[previdmode] + mov ah,0 + int 10h + mov ah,9 + mov edx,.invalidbank + int 21h + xor eax,eax + mov al,[invopcd] + call printhex8 + mov ah,2 + mov dl,13 + int 21h + mov ah,2 + mov dl,10 + int 21h + jmp DosExit + +.invalidbank db 'Invalid Bank Access : $' + ret + + +;******************************************************* +; SA-1 Bank Accesses +;******************************************************* + +NEWSYM regaccessbankr8SA1 + test ecx,8000h + jz .regacc + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov al,[wramdataa+ecx] + ret +.nowram + cmp ecx,800h + jae .invaccess + mov al,[IRAM+ecx] + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptra+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + xor al,al + ret +.bwram + mov ebx,[CurBWPtr] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM regaccessbankr16SA1 + test ecx,8000h + jz .regacc + mov ebx,[snesmmap+ebx*4] + mov ax,[ebx+ecx] + xor ebx,ebx + ret +.regacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov ax,[wramdataa+ecx] + ret +.nowram + cmp ecx,800h + jae .invaccess + mov ax,[IRAM+ecx] + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptra+ecx*4-8000h] + inc ecx + mov ah,al + call dword near [regptra+ecx*4-8000h] + mov bl,al + dec ecx + mov al,ah + mov ah,bl + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + xor ax,ax + ret +.bwram + mov ebx,[CurBWPtr] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM regaccessbankw8SA1 + test ecx,8000h + jnz .romacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov [wramdataa+ecx],al + ret +.nowram + cmp ecx,800h + jae .invaccess + mov [IRAM+ecx],al + ret +.romacc + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap+ebx*4] + mov [ebx+ecx],al + xor ebx,ebx + ret +.regs + cmp ecx,48FFh + ja .invaccess + call dword near [regptwa+ecx*4-8000h] + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + ret +.bwram + mov ebx,[CurBWPtr] + mov [ebx+ecx],al + xor ebx,ebx + ret + +NEWSYM regaccessbankw16SA1 + test ecx,8000h + jnz .romacc + cmp ecx,2000h + jae .regs + cmp byte[SA1Status],0 + jne .nowram + mov [wramdataa+ecx],ax + ret +.nowram + cmp ecx,800h + jae .invaccess + mov [IRAM+ecx],ax + ret +.romacc + cmp byte[writeon],0 + jne .modrom + ret +.modrom + mov ebx,[snesmmap+ebx*4] + mov [ebx+ecx],ax + xor ebx,ebx + ret +.regs + cmp cx,48FFh + ja .invaccess + call dword near [regptwa+ecx*4-8000h] + inc ecx + mov al,ah + call dword near [regptwa+ecx*4-8000h] + dec ecx + xor ebx,ebx + ret +.invaccess + cmp ecx,6000h + jae .bwram + ret +.bwram + mov ebx,[CurBWPtr] + mov [ebx+ecx],ax + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankr8 + and ebx,03h + shl ebx,16 + add ebx,[SA1RAMArea] + mov al,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankr16 + and ebx,03h + shl ebx,16 + add ebx,[SA1RAMArea] + mov ax,[ebx+ecx] + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankw8 + and ebx,03h + shl ebx,16 + add ebx,[SA1RAMArea] + mov [ebx+ecx],al + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankw16 + and ebx,03h + shl ebx,16 + add ebx,[SA1RAMArea] + mov [ebx+ecx],ax + xor ebx,ebx + ret + + +NEWSYM SA1RAMaccessbankr8b + test byte[SA1Overflow],80h + jnz .2bit + and ebx,07h + shl ebx,15 + test ecx,1 + jnz .4bitb + shr ecx,1 + add ebx,[SA1RAMArea] + mov al,[ebx+ecx] + xor ebx,ebx + and al,0Fh + ret +.4bitb + shr ecx,1 + add ebx,[SA1RAMArea] + mov al,[ebx+ecx] + xor ebx,ebx + shr al,4 + ret +.2bit + and ebx,0Fh + shl ebx,14 + add ebx,[SA1RAMArea] + test ecx,2 + jnz .bit1 + test ecx,1 + jnz .bit0 + shr ecx,2 + mov al,[ebx+ecx] + and al,3 + xor ebx,ebx + ret +.bit0 + shr ecx,2 + mov al,[ebx+ecx] + shr al,2 + and al,3 + xor ebx,ebx + ret +.bit1 + test ecx,1 + jnz .bit0b + shr ecx,2 + mov al,[ebx+ecx] + shr al,4 + and al,3 + xor ebx,ebx + ret +.bit0b + shr ecx,2 + mov al,[ebx+ecx] + shr al,6 + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankr16b + test byte[SA1Overflow],80h + jnz .2bit + and ebx,07h + shl ebx,15 + test ecx,1 + jnz .4bitb + shr ecx,1 + add ebx,[SA1RAMArea] + mov al,[ebx+ecx] + and al,0Fh + mov ah,[ebx+ecx] + shr ah,4 + xor ebx,ebx + ret +.4bitb + shr ecx,1 + add ebx,[SA1RAMArea] + mov ah,[ebx+ecx+1] + and ah,0Fh + mov al,[ebx+ecx] + shr al,4 + xor ebx,ebx + ret +.2bit + and ebx,0Fh + shl ebx,14 + add ebx,[SA1RAMArea] + test ecx,2 + jnz .bit1 + test ecx,1 + jnz .bit0 + shr ecx,2 + mov al,[ebx+ecx] + and al,3 + mov ah,[ebx+ecx] + shr ah,2 + and ah,3 + xor ebx,ebx + ret +.bit0 + shr ecx,2 + mov al,[ebx+ecx] + shr al,2 + and al,2 + mov ah,[ebx+ecx] + shr ah,4 + and ah,3 + xor ebx,ebx + ret +.bit1 + test ecx,1 + jnz .bit0b + shr ecx,2 + mov al,[ebx+ecx] + shr al,4 + and al,3 + mov ah,[ebx+ecx] + shr ah,6 + xor ebx,ebx + ret +.bit0b + shr ecx,2 + mov al,[ebx+ecx] + shr al,6 + mov ah,[ebx+ecx+1] + and ah,3 + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankw8b + xor ebx,ebx + ret + +NEWSYM SA1RAMaccessbankw16b + xor ebx,ebx + ret + +NEWSYM SDD1Array, times 1 db 0 +NEWSYM SDD1Entry, dd 0 +NEWSYM SDD1EntryPtr, dd 0 + + +%macro GetBankLog 1 + cmp bl,0C0h + jb %%illegal + cmp bl,0D0h + jb %%firstbank + cmp bl,0E0h + jb %%secondbank + cmp bl,0F0h + jb %%thirdbank + mov %1,[SDD1BankA+3] + jmp %%done +%%firstbank + mov %1,[SDD1BankA] + jmp %%done +%%secondbank + mov %1,[SDD1BankA+1] + jmp %%done +%%thirdbank + mov %1,[SDD1BankA+2] + jmp %%done +%%illegal + mov %1,0Fh +%%done +%endmacro + +NEWSYM LatestBank, dd 0FFFFh +NEWSYM memaccessbankr8sdd1 +; TestSDD1 +; jmp debugdecompress + cmp byte[AddrNoIncr],0 + je near .failed + cmp dword[Sdd1Mode],2 + je near .decompress + + mov [Sdd1Bank],ebx + mov [Sdd1Addr],ecx + mov [Sdd1NewAddr],ecx + ; Start Actual Decompressor + mov dword[Sdd1Mode],2 + push edx + push eax + push ecx + mov dword[SDD1EntryPtr],0 + mov eax,ebx + shl eax,16 + mov ax,cx + shl eax,4 + GetBankLog cl + or al,cl + mov ecx,[SPC7110Entries] + mov edx,[spc7110romptr] + or ecx,ecx + jz .notfound +.loop + cmp dword[edx],eax + je .found2 + add edx,12 + loop .loop + jmp .notfound +.found2 + mov eax,[edx+4] + mov [SDD1EntryPtr],eax +.notfound + pop ecx + pop eax + pop edx + + push eax + mov eax,[SDD1Entry] + cmp eax,65536 + je near .nomore + push edx + xor edx,edx + or eax,eax + jz .noentries +.trynext + cmp byte[SDD1Array+edx],bl + jne .nomatch + cmp byte[SDD1Array+edx+1],ch + jne .nomatch + cmp byte[SDD1Array+edx+2],cl + jne .nomatch + jmp .found +.nomatch + add edx,8 + cmp edx,eax + jne .trynext +.noentries + pop edx + mov [SDD1Array+eax],bl + mov [SDD1Array+eax+1],ch + mov [SDD1Array+eax+2],cl + mov [SDD1Array+eax+3],dh + mov [SDD1Array+eax+4],dl + push ebx + GetBankLog bl + cmp dword[SDD1EntryPtr],0 + je .notthere + or bl,0F0h +.notthere + mov [SDD1Array+eax+7],bl + pop ebx + add dword[SDD1Entry],8 +.nomore + pop eax + jmp .decompress +.found + mov eax,edx + pop edx + push ebx + mov ebx,eax + mov al,[SDD1Array+ebx+4] + mov ah,[SDD1Array+ebx+3] + cmp ax,dx + jae .notgreater + mov [SDD1Array+ebx+4],dl + mov [SDD1Array+ebx+3],dh +.notgreater + pop ebx + pop eax + +.decompress + cmp [Sdd1Bank],ebx + jne .nomoredec + cmp [Sdd1Addr],ecx + je .yesdec +.nomoredec + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + push eax + mov eax,memtabler8+0C0h*4 + mov ebx,40h +.loopb + mov dword[eax],memaccessbankr8 + add eax,4 + dec ebx + jnz .loopb + pop eax + xor ebx,ebx + ret +.yesdec + cmp dword[SDD1EntryPtr],0 + je .nodecompress + push ebx + mov ebx,[SDD1EntryPtr] + inc dword[SDD1EntryPtr] + mov al,[ebx] + pop ebx + ret +.nodecompress + mov al,0FFh + ret +.failed + push ebx + call .nomoredec + pop ebx + jmp memaccessbankr8 + ; Start Debug Decompressor + +debugdecompress: + cmp byte[AddrNoIncr],0 + je near .failed + cmp dword[Sdd1Mode],2 + je near .decompress + TestSDD1 + mov [Sdd1Bank],ebx + mov [Sdd1Addr],ecx + mov [Sdd1NewAddr],ecx + mov dword[Sdd1Mode],2 + jmp .decompress ; comment this out to activate array + push eax + mov eax,[SDD1Entry] + cmp eax,65536 + je near .nomore + push edx + xor edx,edx + or eax,eax + jz .noentries +.trynext + cmp byte[SDD1Array+edx],bl + jne .nomatch + cmp byte[SDD1Array+edx+1],ch + jne .nomatch + cmp byte[SDD1Array+edx+2],cl + jne .nomatch + jmp .found +.nomatch + add edx,8 + cmp edx,eax + jne .trynext +.noentries + pop edx + mov [SDD1Array+eax],bl + mov [SDD1Array+eax+1],ch + mov [SDD1Array+eax+2],cl + mov [SDD1Array+eax+3],dh + mov [SDD1Array+eax+4],dl + push ebx + GetBankLog bl + mov [SDD1Array+eax+7],bl + pop ebx + add dword[SDD1Entry],8 +.nomore + pop eax + jmp .decompress +.found + pop edx + pop eax +.decompress + cmp [Sdd1Bank],ebx + jne .nomoredec + cmp [Sdd1Addr],ecx + je .yesdec +.nomoredec + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + push eax + mov eax,memtabler8+0C0h*4 + mov ebx,40h +.loop + mov dword[eax],memaccessbankr8 + add eax,4 + dec ebx + jnz .loop + pop eax + xor ebx,ebx + ret +.yesdec + push ecx + mov ecx,[Sdd1NewAddr] + mov ebx,[snesmmap+ebx*4] + mov al,[ebx+ecx] + xor ebx,ebx + inc word[Sdd1NewAddr] + pop ecx + ret +.failed + push ebx + call .nomoredec + pop ebx + jmp memaccessbankr8 + \ No newline at end of file diff --git a/zsnes/src/cpu/regs.inc b/zsnes/src/cpu/regs.inc new file mode 100644 index 00000000..edf654d5 --- /dev/null +++ b/zsnes/src/cpu/regs.inc @@ -0,0 +1,1099 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM SFXEnable,regptr,initsfxregsr,initSA1regs,SA1Enable,initSDD1regs +EXTSYM SPC7110Enable,initSPC7110regs,RTCEnable,RTCReset +EXTSYM curypos,cycpl,debuggeron,pdh,Reg4212hack +EXTSYM vram +EXTSYM romispal +EXTSYM reg1read,spcnumread,spcon +EXTSYM reg2read +EXTSYM reg3read +EXTSYM reg4read +EXTSYM JoyEOrig,JoyENow +EXTSYM snesmouse +EXTSYM cycphb,joycontren +EXTSYM DosExit,invalid,numinst,previdmode,printhex,printnum + + + + + + +NEWSYM initregr + ; Fill register pointer with invalid register accesses + mov edi,[regptr] + add edi,8000h + mov ecx,3000h + mov eax,regINVALID +.loopa + mov [edi],eax + add edi,4 + loop .loopa + ; Set all valid register accesses + setreg 2134h*4,reg2134r + setreg 2135h*4,reg2135r + setreg 2136h*4,reg2136r + setreg 2137h*4,reg2137r + setreg 2138h*4,reg2138r + setreg 2139h*4,reg2139r + setreg 213Ah*4,reg213Ar + setreg 213Bh*4,reg213Br + setreg 213Ch*4,reg213Cr + setreg 213Dh*4,reg213Dr + setreg 213Eh*4,reg213Er + setreg 213Fh*4,reg213Fr + setreg 2140h*4,reg2140r + setreg 2141h*4,reg2141r + setreg 2142h*4,reg2142r + setreg 2143h*4,reg2143r + setreg 2180h*4,reg2180r + setreg 4016h*4,reg4016r + setreg 4017h*4,reg4017r + setreg 4210h*4,reg4210r + setreg 4211h*4,reg4211r + setreg 4212h*4,reg4212r + setreg 4213h*4,reg4213r + setreg 4214h*4,reg4214r + setreg 4215h*4,reg4215r + setreg 4216h*4,reg4216r + setreg 4217h*4,reg4217r + setreg 4218h*4,reg4218r + setreg 4219h*4,reg4219r + setreg 421Ah*4,reg421Ar + setreg 421Bh*4,reg421Br + setreg 421Ch*4,reg421Cr + setreg 421Dh*4,reg421Dr + setreg 421Eh*4,reg421Er + setreg 421Fh*4,reg421Fr + + setreg 4300h*4,reg43XXr + setreg 4301h*4,reg43XXr + setreg 4302h*4,reg43XXr + setreg 4303h*4,reg43XXr + setreg 4304h*4,reg43XXr + setreg 4305h*4,reg43XXr + setreg 4306h*4,reg43XXr + setreg 4307h*4,reg43XXr + setreg 4308h*4,reg43XXr + setreg 4309h*4,reg43XXr + setreg 430Ah*4,reg43XXr + setreg 430Bh*4,reg43XXr + setreg 430Ch*4,reg43XXr + setreg 430Dh*4,reg43XXr + setreg 430Eh*4,reg43XXr + setreg 430Fh*4,reg43XXr + setreg 4310h*4,reg43XXr + setreg 4311h*4,reg43XXr + setreg 4312h*4,reg43XXr + setreg 4313h*4,reg43XXr + setreg 4314h*4,reg43XXr + setreg 4315h*4,reg43XXr + setreg 4316h*4,reg43XXr + setreg 4317h*4,reg43XXr + setreg 4318h*4,reg43XXr + setreg 4319h*4,reg43XXr + setreg 431Ah*4,reg43XXr + setreg 431Bh*4,reg43XXr + setreg 431Ch*4,reg43XXr + setreg 431Dh*4,reg43XXr + setreg 431Eh*4,reg43XXr + setreg 431Fh*4,reg43XXr + setreg 4320h*4,reg43XXr + setreg 4321h*4,reg43XXr + setreg 4322h*4,reg43XXr + setreg 4323h*4,reg43XXr + setreg 4324h*4,reg43XXr + setreg 4325h*4,reg43XXr + setreg 4326h*4,reg43XXr + setreg 4327h*4,reg43XXr + setreg 4328h*4,reg43XXr + setreg 4329h*4,reg43XXr + setreg 432Ah*4,reg43XXr + setreg 432Bh*4,reg43XXr + setreg 432Ch*4,reg43XXr + setreg 432Dh*4,reg43XXr + setreg 432Eh*4,reg43XXr + setreg 432Fh*4,reg43XXr + setreg 4330h*4,reg43XXr + setreg 4331h*4,reg43XXr + setreg 4332h*4,reg43XXr + setreg 4333h*4,reg43XXr + setreg 4334h*4,reg43XXr + setreg 4335h*4,reg43XXr + setreg 4336h*4,reg43XXr + setreg 4337h*4,reg43XXr + setreg 4338h*4,reg43XXr + setreg 4339h*4,reg43XXr + setreg 433Ah*4,reg43XXr + setreg 433Bh*4,reg43XXr + setreg 433Ch*4,reg43XXr + setreg 433Dh*4,reg43XXr + setreg 433Eh*4,reg43XXr + setreg 433Fh*4,reg43XXr + setreg 4340h*4,reg43XXr + setreg 4341h*4,reg43XXr + setreg 4342h*4,reg43XXr + setreg 4343h*4,reg43XXr + setreg 4344h*4,reg43XXr + setreg 4345h*4,reg43XXr + setreg 4346h*4,reg43XXr + setreg 4347h*4,reg43XXr + setreg 4348h*4,reg43XXr + setreg 4349h*4,reg43XXr + setreg 434Ah*4,reg43XXr + setreg 434Bh*4,reg43XXr + setreg 434Ch*4,reg43XXr + setreg 434Dh*4,reg43XXr + setreg 434Eh*4,reg43XXr + setreg 434Fh*4,reg43XXr + setreg 4350h*4,reg43XXr + setreg 4351h*4,reg43XXr + setreg 4352h*4,reg43XXr + setreg 4353h*4,reg43XXr + setreg 4354h*4,reg43XXr + setreg 4355h*4,reg43XXr + setreg 4356h*4,reg43XXr + setreg 4357h*4,reg43XXr + setreg 4358h*4,reg43XXr + setreg 4359h*4,reg43XXr + setreg 435Ah*4,reg43XXr + setreg 435Bh*4,reg43XXr + setreg 435Ch*4,reg43XXr + setreg 435Dh*4,reg43XXr + setreg 435Eh*4,reg43XXr + setreg 435Fh*4,reg43XXr + setreg 4360h*4,reg43XXr + setreg 4361h*4,reg43XXr + setreg 4362h*4,reg43XXr + setreg 4363h*4,reg43XXr + setreg 4364h*4,reg43XXr + setreg 4365h*4,reg43XXr + setreg 4366h*4,reg43XXr + setreg 4367h*4,reg43XXr + setreg 4368h*4,reg43XXr + setreg 4369h*4,reg43XXr + setreg 436Ah*4,reg43XXr + setreg 436Bh*4,reg43XXr + setreg 436Ch*4,reg43XXr + setreg 436Dh*4,reg43XXr + setreg 436Eh*4,reg43XXr + setreg 436Fh*4,reg43XXr + setreg 4370h*4,reg43XXr + setreg 4371h*4,reg43XXr + setreg 4372h*4,reg43XXr + setreg 4373h*4,reg43XXr + setreg 4374h*4,reg43XXr + setreg 4375h*4,reg43XXr + setreg 4376h*4,reg43XXr + setreg 4377h*4,reg43XXr + setreg 4378h*4,reg43XXr + setreg 4379h*4,reg43XXr + setreg 437Ah*4,reg43XXr + setreg 437Bh*4,reg43XXr + setreg 437Ch*4,reg43XXr + setreg 437Dh*4,reg43XXr + setreg 437Eh*4,reg43XXr + setreg 437Fh*4,reg43XXr + cmp byte[SFXEnable],0 + je .nosfx + call initsfxregsr +.nosfx + cmp byte[SA1Enable],0 + je .nosa1 + call initSA1regs +.nosa1 + cmp byte[SDD1Enable],0 + je .nosdd1 + call initSDD1regs +.nosdd1 + cmp byte[SPC7110Enable],0 + je .nospc7110 + call initSPC7110regs +.nospc7110 + cmp byte[RTCEnable],0 + je .noRTC + call RTCReset +.noRTC + ret + +; global variables +NEWSYM invreg, dw 0 +NEWSYM sndrot, db 0 ; rotates to use A,X or Y for sound skip +NEWSYM sndrot2, db 0 ; rotates a random value for sound skip +NEWSYM INTEnab, db 0 ; enables NMI(7)/VIRQ(5)/HIRQ(4)/JOY(0) +NEWSYM NMIEnab, db 1 ; controlled in e65816 loop. Sets to 81h +NEWSYM VIRQLoc, dw 0 ; VIRQ Y location +NEWSYM vidbright, db 0 ; screen brightness (0 .. 15) +NEWSYM previdbr, db 0 ; previous screen brightness +NEWSYM forceblnk, db 80h ; force blanking on/off ($80=on) +NEWSYM objptr, dd 0 ; pointer to object data in VRAM +NEWSYM objptrn, dd 0 ; pointer2 to object data in VRAM +NEWSYM objsize1, db 1 ; 1 = 8dot, 4=16 dot, 16=32 dot, 64=64dot +NEWSYM objsize2, db 4 ; large object size +NEWSYM objmovs1, db 2 ; number of bytes to move/paragraph +NEWSYM objadds1, dw 14 ; number of bytes to add/paragraph +NEWSYM objmovs2, db 2 ; number of bytes to move/paragraph +NEWSYM objadds2, dw 14 ; number of bytes to add/paragraph +NEWSYM oamaddrt, dw 0 ; oam address +NEWSYM oamaddrs, dw 0 ; oam address at beginning of vblank +NEWSYM objhipr, db 0 ; highest priority object # +NEWSYM bgmode, db 0 ; graphics mode ( 0 .. 7 ) +NEWSYM bg3highst, db 0 ; is 1 if background 3 has the highest priority +NEWSYM bgtilesz, db 0 ; 0 = 8x8, 1 = 16x16, bit 0=bg1,bit1=bg2,etc +NEWSYM mosaicon, db 0 ; mosaic on, bit 0=bg1,bit1=bg2, etc +NEWSYM mosaicsz, db 0 ; mosaic size in pixels +NEWSYM bg1ptr, dw 0 ; pointer to background1 +NEWSYM bg2ptr, dw 0 ; pointer to background2 +NEWSYM bg3ptr, dw 0 ; pointer to background3 +NEWSYM bg4ptr, dw 0 ; pointer to background4 +NEWSYM bg1ptrb, dw 0 ; pointer to background1 +NEWSYM bg2ptrb, dw 0 ; pointer to background2 +NEWSYM bg3ptrb, dw 0 ; pointer to background3 +NEWSYM bg4ptrb, dw 0 ; pointer to background4 +NEWSYM bg1ptrc, dw 0 ; pointer to background1 +NEWSYM bg2ptrc, dw 0 ; pointer to background2 +NEWSYM bg3ptrc, dw 0 ; pointer to background3 +NEWSYM bg4ptrc, dw 0 ; pointer to background4 +NEWSYM bg1ptrd, dw 0 ; pointer to background1 +NEWSYM bg2ptrd, dw 0 ; pointer to background2 +NEWSYM bg3ptrd, dw 0 ; pointer to background3 +NEWSYM bg4ptrd, dw 0 ; pointer to background4 +NEWSYM bg1scsize, db 0 ; bg #1 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg2scsize, db 0 ; bg #2 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg3scsize, db 0 ; bg #3 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg4scsize, db 0 ; bg #4 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg1objptr, dw 0 ; pointer to tiles in background1 +NEWSYM bg2objptr, dw 0 ; pointer to tiles in background2 +NEWSYM bg3objptr, dw 0 ; pointer to tiles in background3 +NEWSYM bg4objptr, dw 0 ; pointer to tiles in background4 +NEWSYM bg1scrolx, dw 0 ; background 1 x position +NEWSYM bg2scrolx, dw 0 ; background 2 x position +NEWSYM bg3scrolx, dw 0 ; background 3 x position +NEWSYM bg4scrolx, dw 0 ; background 4 x position +NEWSYM bg1sx, dw 0 ; Temporary Variable for Debugging purposes +NEWSYM bg1scroly, dw 0 ; background 1 y position +NEWSYM bg2scroly, dw 0 ; background 2 y position +NEWSYM bg3scroly, dw 0 ; background 3 y position +NEWSYM bg4scroly, dw 0 ; background 4 y position +NEWSYM addrincr, dw 2 ; vram increment (2,64,128,256) +NEWSYM vramincr, db 0 ; 0 = inrement at 2118/2139, 1 = 2119,213A +NEWSYM vramread, db 0 ; 0 = address set, 1 = already read once +NEWSYM vramaddr, dd 0 ; vram address +NEWSYM cgaddr, dw 0 ; cg (palette) address +NEWSYM cgmod, db 0 ; if cgram is modified or not +NEWSYM scrnon, dw 0 ; main & sub screen on +NEWSYM scrndist, db 0 ; which background is disabled +NEWSYM resolutn, dw 224 ; screen resolution +NEWSYM multa, db 0 ; multiplier A +NEWSYM diva, dw 0 ; divisor C +NEWSYM divres, dw 0 ; quotent of divc/divb +NEWSYM multres, dw 0 ; result of multa * multb/remainder of divc/divb +NEWSYM latchx, dw 0 ; latched x value +NEWSYM latchy, dw 0 ; latched y value +NEWSYM latchxr, db 0 ; low or high byte read for x value +NEWSYM latchyr, db 0 ; low or high byte read for y value +NEWSYM frskipper, db 0 ; used to control frame skipping +NEWSYM winl1, db 0 ; window 1 left position +NEWSYM winr1, db 0 ; window 1 right position +NEWSYM winl2, db 0 ; window 2 left position +NEWSYM winr2, db 0 ; window 2 right position +NEWSYM winbg1en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG1 +NEWSYM winbg2en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG2 +NEWSYM winbg3en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG3 +NEWSYM winbg4en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG4 +NEWSYM winobjen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on sprites +NEWSYM wincolen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on backarea +NEWSYM winlogica, db 0 ; Window logic type for BG1 to 4 +NEWSYM winlogicb, db 0 ; Window logic type for Sprites and Backarea +NEWSYM winenabm, db 0 ; Window logic enable for main screen +NEWSYM winenabs, db 0 ; Window logic enable for sub screen +NEWSYM mode7set, db 0 ; mode 7 settings +NEWSYM mode7A, dw 0 ; A value for Mode 7 +NEWSYM mode7B, dw 0 ; B value for Mode 7 +NEWSYM mode7C, dw 0 ; C value for Mode 7 +NEWSYM mode7D, dw 0 ; D value for Mode 7 +NEWSYM mode7X0, dw 0 ; Center X for Mode 7 +NEWSYM mode7Y0, dw 0 ; Center Y for Mode 7 +NEWSYM JoyAPos, db 0 ; Old-Style Joystick Read Position for Joy 1 & 3 +NEWSYM JoyBPos, db 0 ; Old-Style Joystick Read Position for Joy 2 & 4 +NEWSYM compmult, dd 0 ; Complement Multiplication for Mode 7 +NEWSYM joyalt, db 0 ; temporary joystick alternation + +NEWSYM wramrwadr, dd 0 ; continuous read/write to wram address +NEWSYM dmadata, times 129 db 0h ; dma data (written from ports 43xx) +NEWSYM irqon, db 0 ; if IRQ has been called (80h) or not (0) +NEWSYM nexthdma, db 0 ; HDMA data to execute once vblank ends +NEWSYM curhdma, db 0 ; Currently executed hdma +NEWSYM hdmadata, times 8*19 db 0 ; 4 dword register addresses, # of bytes to + ; transfer/line, address increment (word) +NEWSYM hdmatype, db 0 ; if first time executing hdma or not +NEWSYM coladdr, db 0 ; red value of color to add +NEWSYM coladdg, db 0 ; green value of color to add +NEWSYM coladdb, db 0 ; blue value of color to add +NEWSYM colnull, db 0 ; keep this 0 (when accessing colors by dword) +NEWSYM scaddset, db 0 ; screen/fixed color addition settings +NEWSYM scaddtype, db 0 ; which screen to add/sub +NEWSYM Voice0Disabl2, db 1 ; Disable Voice 0 +NEWSYM Voice1Disabl2, db 1 ; Disable Voice 1 +NEWSYM Voice2Disabl2, db 1 ; Disable Voice 2 +NEWSYM Voice3Disabl2, db 1 ; Disable Voice 3 +NEWSYM Voice4Disabl2, db 1 ; Disable Voice 4 +NEWSYM Voice5Disabl2, db 1 ; Disable Voice 5 +NEWSYM Voice6Disabl2, db 1 ; Disable Voice 6 +NEWSYM Voice7Disabl2, db 1 ; Disable Voice 7 + +NEWSYM oamram, times 1024 db 0 ; OAMRAM (544 bytes) +NEWSYM cgram, times 512 db 0 ; CGRAM +NEWSYM pcgram, times 512 db 0 ; Previous CGRAM + +NEWSYM vraminctype, db 0 + +; New variables +NEWSYM vramincby8on, db 0 ; if increment by 8 is on +NEWSYM vramincby8left, db 0 ; how many left +NEWSYM vramincby8totl, db 0 ; how many in total (32,64,128) +NEWSYM vramincby8rowl, db 0 ; how many left in that row (start at 8) +NEWSYM vramincby8ptri, dw 0 ; increment by how many when rowl = 0 + +NEWSYM nexthprior, db 0 +NEWSYM doirqnext, db 0 + +NEWSYM vramincby8var, dw 0 +NEWSYM screstype, db 0 +NEWSYM extlatch, db 0 +NEWSYM cfield, db 0 +NEWSYM interlval, db 0 + +NEWSYM HIRQLoc, dw 0 ; HIRQ X location + +NEWSYM KeyOnStA, db 0 +NEWSYM KeyOnStB, db 0 + +NEWSYM SDD1BankA, db 0 +NEWSYM SDD1BankB, db 1 +NEWSYM SDD1BankC, db 2 +NEWSYM SDD1BankD, db 3 + +NEWSYM tempdat, times 484 db 0 ; expandable area + +num2writeppureg equ $-sndrot +; pharos equ hack *sigh* +NEWSYM PHnum2writeppureg, dd num2writeppureg + +NEWSYM scrndis, db 0 ; which background is disabled + +ALIGN32 +NEWSYM oamaddr, dd 0 ; oam address + +NEWSYM bg1ptrx, dd 0 ; pointer to background1 +NEWSYM bg2ptrx, dd 0 ; pointer to background2 +NEWSYM bg3ptrx, dd 0 ; pointer to background3 +NEWSYM bg4ptrx, dd 0 ; pointer to background4 + +NEWSYM bg1ptry, dd 0 ; pointer to background1 +NEWSYM bg2ptry, dd 0 ; pointer to background2 +NEWSYM bg3ptry, dd 0 ; pointer to background3 +NEWSYM bg4ptry, dd 0 ; pointer to background4 + +NEWSYM Voice0Disable, db 1 ; Disable Voice 0 +NEWSYM Voice1Disable, db 1 ; Disable Voice 1 +NEWSYM Voice2Disable, db 1 ; Disable Voice 2 +NEWSYM Voice3Disable, db 1 ; Disable Voice 3 +NEWSYM Voice4Disable, db 1 ; Disable Voice 4 +NEWSYM Voice5Disable, db 1 ; Disable Voice 5 +NEWSYM Voice6Disable, db 1 ; Disable Voice 6 +NEWSYM Voice7Disable, db 1 ; Disable Voice 7 + +NEWSYM BG116x16t, db 0 +NEWSYM BG216x16t, db 0 +NEWSYM BG316x16t, db 0 +NEWSYM BG416x16t, db 0 +NEWSYM SPC700read, dd 0 +NEWSYM SPC700write, dd 0 + +NEWSYM JoyCRead, db 0 + +NEWSYM ClearRegs + mov word[VIRQLoc],0 + mov word[bg1ptr],0 + mov word[bg2ptr],0 + mov word[bg3ptr],0 + mov word[bg4ptr],0 + mov word[bg1ptrb],0 + mov word[bg2ptrb],0 + mov word[bg3ptrb],0 + mov word[bg4ptrb],0 + mov word[bg1ptrc],0 + mov word[bg2ptrc],0 + mov word[bg3ptrc],0 + mov word[bg4ptrc],0 + mov word[bg1ptrd],0 + mov word[bg2ptrd],0 + mov word[bg3ptrd],0 + mov word[bg4ptrd],0 + mov word[bg1objptr],0 + mov word[bg2objptr],0 + mov word[bg3objptr],0 + mov word[bg4objptr],0 + ret + +; Multiply Result Low +reg2134r: + checkmultchange + mov al,[compmult] + ret + +; Multiply Result Middle +reg2135r: + checkmultchange + mov al,[compmult+1] + ret + +; Multiply Result High +reg2136r: + checkmultchange + mov al,[compmult+2] + ret + +; Software latch for horizontal/vertical counter +reg2137r: + cmp byte[debuggeron],1 + je .debugger + xor ebx,ebx + mov bl,[cycpl] + sub bl,dh + add bx,bx + mov [latchx],bx + mov bx,[curypos] + mov [latchy],bx + mov bl,[INTEnab] + and bl,30h + cmp bl,30h + jne .novhirq + cmp word[HIRQLoc],0F0h + ja .incry + cmp dh,20 + jae .noincly +.incry + inc word[latchy] +.novhirq +.noincly + xor al,al + mov byte[extlatch],0 + ret +.debugger +debblah: + xor ebx,ebx + mov bl,[cycpl] + sub bl,[pdh] + add bx,bx + mov [latchx],bx + mov bx,[curypos] + mov [latchy],bx + mov bl,[INTEnab] + and bl,30h + cmp bl,30h + jne .novhirq + cmp word[HIRQLoc],0F0h +; ja .incry + cmp word[latchx],80 +; jb .noincly +.incry + inc word[latchy] +.novhirq +.noincly + xor al,al + mov byte[extlatch],0 + ret + + push eax + push edx + xor eax,eax + xor ebx,ebx + mov al,[cycpl] + sub al,[pdh] + mov bx,339 + mul bx + xor ebx,ebx + mov bl,[cycpl] + div bx + mov [latchx],ax + pop edx + pop eax + mov bx,[curypos] + mov [latchy],bx + mov bl,[INTEnab] + and bl,30h + cmp bl,30h + jne .novhirq2 + cmp word[HIRQLoc],0F0h + ja .incry2 + cmp word[latchx],80 + jb .noincly2 +.incry2 + inc word[latchy] +.novhirq2 +.noincly2 + xor al,al + mov byte[extlatch],0 + ret + +; Read OAM Data (Low, High) +reg2138r: + xor ebx,ebx + mov bx,word[oamaddr] + add ebx,oamram + mov al,[ebx] + inc word[oamaddr] + cmp word[oamaddr],543 + ja .wrapoam + ret +.wrapoam + mov word[oamaddr],0 + ret + +; Read VRAM Data (Low) +reg2139r: + xor ebx,ebx + mov bx,[vramaddr] + add ebx,[vram] + mov al,[ebx] + cmp byte[vramincr],0 + je .noincr + cmp byte[vramread],0 + je .noincr2 + mov bx,[addrincr] + add [vramaddr],bx + cmp byte[vramincby8on],1 + jne .noincr + dec byte[vramincby8left] + jnz .noincr + add word[vramaddr],2 + mov bl,byte[vramincby8totl] + mov byte[vramincby8left],bl + dec byte[vramincby8rowl] + jz .nextrow + mov bx,[vramincby8ptri] + sub [vramaddr],bx + jmp .noincr +.nextrow + mov byte[vramincby8rowl],8 + sub word[vramaddr],16 +.noincr + ret +.noincr2 + mov byte[vramread],1 + ret + +; Read VRAM Data (High) +reg213Ar: + xor ebx,ebx + mov bx,[vramaddr] + add ebx,[vram] + mov al,[ebx+1] + cmp byte[vramincr],1 + je .noincr + cmp byte[vramread],0 + je .noincr2 + mov bx,[addrincr] + add [vramaddr],bx + cmp byte[vramincby8on],1 + jne .noincr + dec byte[vramincby8left] + jnz .noincr + add word[vramaddr],2 + mov bl,byte[vramincby8totl] + mov byte[vramincby8left],bl + dec byte[vramincby8rowl] + jz .nextrow + mov bx,[vramincby8ptri] + sub [vramaddr],bx + jmp .noincr +.nextrow + mov byte[vramincby8rowl],8 + sub word[vramaddr],16 +.noincr + ret +.noincr2 + mov byte[vramread],1 + ret + +; Read CGRAM Data +reg213Br: + xor ebx,ebx + mov bx,[cgaddr] + mov al,[cgram+ebx] + inc word[cgaddr] + and word[cgaddr],01FFh + ret + +; H counter data by external or software latch +reg213Cr: + cmp byte[latchxr],1 + je .highv + mov al,byte[latchx] + mov byte[latchxr],1 + ret +.highv + mov al,byte[latchx+1] + mov byte[latchxr],0 + ret + +; V counter data by external or software latch +reg213Dr: + cmp byte[latchyr],1 + je .highv + mov al,byte[latchy] + mov byte[latchyr],1 + ret +.highv + mov al,byte[latchy+1] + mov byte[latchyr],0 + ret + +; PPU Status Flag & Version number (OBJ over flags) +reg213Er: + mov al,01h + ret + +; PPU Status Flag & Version number (NTSC/PAL/EXTRN Latch flag) +reg213Fr: + mov al,[romispal] + shl al,4 + or al,[cfield] + mov byte[latchxr],0 + mov byte[latchyr],0 + or al,[extlatch] + ret + +; Sound Reg #1 +reg2140r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg1read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + cmp word[ebx],0FB10h + jne .noret + mov word[ebx],0EAEAh +.noret + mov al,5 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + inc byte[sndrot2] + cmp byte[sndrot2],3 + jne .a + mov byte[sndrot2],0 +.a + xor al,al + test byte[sndrot2],01h + jz .n + mov al,[xa] +.n + ret + +; Sound Reg #2 +reg2141r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg2read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + mov al,3 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + xor byte[sndrot],01h + mov al,[xa+1] + test byte[sndrot],01h + jz .n + mov al,[xa] +.n + ret + +; Sound Reg #3 +reg2142r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg3read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + mov al,3 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + mov al,[xa] + test byte[sndrot],01h + jz .n + mov al,[xa+1] +.n + ret + +; Sound Reg #4 +reg2143r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg4read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + mov al,3 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + mov al,[xa+1] + ret + +; WRAM Read +reg2180r: + mov ebx,[wramrwadr] + add ebx,[wramdata] + mov al,[ebx] + inc dword[wramrwadr] + and dword[wramrwadr],01FFFFh + ret + +; Joystick Data for controller 1 and 2 + +reg4016r: + xor al,al + test dword[JoyANow],80000000h + jz .noal + mov al,1 +.noal + rol dword[JoyANow],1 + ret + +NEWSYM MultiTap, db 0 +; Joystick Data for controller 2 and 4 +reg4017r: + cmp byte[snesmouse],0 + jne .nomultitap + cmp byte[MultiTap],1 + je .multitap +.nomultitap + xor al,al + test dword[JoyBNow],80000000h + jz .noal + mov al,1 +.noal + rol dword[JoyBNow],1 + ret +.multitap + test byte[MultiTapStat],1 + jz .no1 + mov al,0FFh + ret +.no1 + test byte[MultiTapStat],80h + jz .contr45 + xor al,al + test dword[JoyBNow],80000000h + jz .nojb + or al,01h +.nojb + test dword[JoyCNow],80000000h + jz .nojc + or al,02h +.nojc + rol dword[JoyBNow],1 + rol dword[JoyCNow],1 + ret +.contr45 + xor al,al + test dword[JoyDNow],80000000h + jz .nojd + or al,1 +.nojd + test dword[JoyENow],80000000h + jz .noje + or al,02h +.noje + rol dword[JoyDNow],1 + rol dword[JoyENow],1 + ret + +; NMI Check Register +reg4210r: + mov al,[NMIEnab] + cmp byte[curnmi],0 + jne .nmi + mov byte[NMIEnab],01h +.nmi + mov byte[curnmi],0 + ret + +; Video IRQ Register +reg4211r: + mov al,[irqon] + mov byte[irqon],0 + ret + +; H/V Blank Flag & Joystick Controller Enable Flag +; bit 7 = vblank, 0=out,1=in, bit 6 = hblank, 0=out,1=in, bit 0 = joystick on +reg4212r: + xor al,al + cmp byte[joycontren],25 + jb .nojoyc +.yesjoy + mov al,1 +.nojoyc + inc byte[joycontren] + cmp byte[joycontren],50 + jne .n + mov byte[joycontren],0 +.n + cmp byte[debuggeron],1 + je .debugger + mov bx,[resolutn] + sub bx,[Reg4212hack] + inc bx + cmp word[curypos],bx + jb .novbl + cmp word[curypos],261 + jae .novbl + or al,80h +; jmp .nohblank +.novbl + cmp dh,[cycphb] + jae .nohblank + or al,40h +.nohblank + test byte[INTEnab],01h + jz .nojoy + mov bx,[resolutn] + add bx,2 + cmp word[curypos],bx + jne .nojoy + cmp dh,5 + ja .nojoy + ret +.nojoy + ret +.debugger +debblah2: + push edx + mov dh,[pdh] + mov bx,[resolutn] + sub bx,[Reg4212hack] + inc bx + cmp word[curypos],bx + jb .novbl + cmp word[curypos],261 + jae .novbl + or al,80h +; jmp .nohblank +.novbl + cmp dh,[cycphb] + jae .nohblank + or al,40h +.nohblank + test byte[INTEnab],01h + jz .nojoy + mov bx,[resolutn] + add bx,2 + cmp word[curypos],bx + jne .nojoy + cmp dh,5 + ja .nojoy + pop edx + ret +.nojoy + pop edx + ret + + + mov bx,[resolutn] + inc bx + cmp word[curypos],bx + jb .novbl2 + or al,80h + jmp .nohblank2 +.novbl2 + mov bl,[pdh] + cmp bl,[cycphb] + jae .nohblank2 + or al,40h +.nohblank2 + test byte[INTEnab],01h + jz .nojoy2 + mov bx,[resolutn] + add bx,2 + cmp word[curypos],bx + jne .nojoy2 + cmp byte[pdh],5 + ja .nojoy +; or al,01h + ret +.nojoy2 + ret + +; Programmable I/O port +reg4213r: +; mov al,[mode7A] +; xor al,al +; mov al,0FFh + ret + +; Quotent of Divide Result (Low) +reg4214r: + mov al,[divres] + ret + +; Quotent of Divide Result (High) +reg4215r: + mov al,[divres+1] + ret + +; Product of Multiplication Result or Remainder of Divide Result (Low) +reg4216r: + mov al,[multres] + ret + +; Product of Multiplication Result or Remainder of Divide Result (High) +reg4217r: + mov al,[multres+1] + ret + +; Joystick 1 Low +; bit7=X,bit6=Y,bit5=L,bit4=R +reg4218r: + mov al,[JoyAOrig+2] + ret + +; Joystick 1 High +; bit7=A,bit6=B,bit5=Sel,bit4=Start,bit3=up,bit2=down,bit1=left,bit0=right +reg4219r: + mov al,[JoyAOrig+3] + ret + +; Joystick 2 Low +reg421Ar: + mov al,[JoyBOrig+2] + ret + +; Joystick 2 High +reg421Br: + mov al,[JoyBOrig+3] + ret + +; Joystick 3 Low +reg421Cr: + mov al,[JoyDOrig+2] + ret + +; Joystick 3 High +reg421Dr: + mov al,[JoyDOrig+3] + ret + +; Joystick 4 Low +reg421Er: + mov al,[JoyCOrig+2] + ret + +; Joystick 4 High +reg421Fr: + mov al,[JoyCOrig+3] + ret + +; DMA Reader +reg43XXr: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov al,[dmadata+ebx] + ret + +regINVALID: ; Invalid Register + xor al,al +; mov al,30h + ret + mov al,[previdmode] + mov ah,0 + int 10h + mov byte[invalid],1 + mov [invreg],cx + mov ah,9 + mov edx,.invalidreg + int 21h + xor eax,eax + mov ax,[invreg] + call printhex + mov ah,2 + mov dl,13 + int 21h + mov ah,2 + mov dl,10 + int 21h + mov eax,[numinst] ;Temporary + call printnum + jmp DosExit + +.invalidreg db 'Invalid Read Register : $' + + \ No newline at end of file diff --git a/zsnes/src/cpu/regs.mac b/zsnes/src/cpu/regs.mac new file mode 100644 index 00000000..461739c0 --- /dev/null +++ b/zsnes/src/cpu/regs.mac @@ -0,0 +1,101 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +;******************************************************* +; InitReg Initializes Registers +;******************************************************* + +%macro setreg 2 + mov edi,%1 + add edi,[regptr] + mov eax,%2 + mov [edi],eax +%endmacro + +;******************************************************* +; Registers Note : Remember to restore AH, ECX, & DX +;******************************************************* + +%macro checkmultchange 0 + ; execute multiplication + cmp byte[multchange],0 + je .nomult + push edx + push eax + xor bh,bh + mov bl,[mode7B+1] + mov ax,[mode7A] + test bl,80h + jz .noneg + mov bh,0FFh +.noneg + imul bx + mov [compmult],ax + mov [compmult+2],dl + pop eax + pop edx + mov byte[multchange],0 +.nomult +%endmacro + +%macro mouse4016doxA 2 + cmp byte[JoyAPos],%1 + jne .nx7 + mov bx,[mousexpos] + shr bx,%2 + and bx,1 + mov al,bl +.nx7 +%endmacro + +%macro mouse4016doyA 2 + cmp byte[JoyAPos],%1 + jne .ny7 + mov bx,[mouseypos] + shr bx,%2 + and bx,1 + mov al,bl +.ny7 +%endmacro + +%macro mouse4017dox 2 + cmp byte[JoyBPos],%1 + jne .nx7 + mov bx,[mousexpos] + shr bx,%2 + and bx,1 + mov al,bl +.nx7 +%endmacro + +%macro mouse4017doy 2 + cmp byte[JoyBPos],%1 + jne .ny7 + mov bx,[mouseypos] + shr bx,%2 + and bx,1 + mov al,bl +.ny7 +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/regsw.inc b/zsnes/src/cpu/regsw.inc new file mode 100644 index 00000000..383f6dc7 --- /dev/null +++ b/zsnes/src/cpu/regsw.inc @@ -0,0 +1,1772 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM initsfxregsw,reg420Bw,reg420Cw,regptw,initSA1regsw,SDD1Reset +EXTSYM SPC7110Reset,RTCReset2 +EXTSYM xat,xdbt,xdt,xpbt,xst,xxt,xyt +EXTSYM DSPMem,WDSPReg0C,WDSPReg0D,WDSPReg0F,WDSPReg1C,WDSPReg1F +EXTSYM WDSPReg2C,WDSPReg2F,WDSPReg3C,WDSPReg3D,WDSPReg3F,WDSPReg4F +EXTSYM WDSPReg5F,WDSPReg6C,WDSPReg6F,WDSPReg7D,WDSPReg7F +EXTSYM debstop +EXTSYM cachesprites,curblank,processsprites,sprleftpr,sprlefttot,NextLineCache +EXTSYM vidmemch2,vidmemch4,vidmemch8,vrama +EXTSYM nmirept,sndwrit,spcRam +EXTSYM HIRQCycNext,HIRQNextExe,HIRQSkip +EXTSYM cycpb268,cycpb358,cycpbl,cycpblt,opexec268,opexec268cph +EXTSYM opexec358,opexec358cph +EXTSYM hdmarestart +EXTSYM printhex8 + + + + + + +NEWSYM testgfxv1, db 0 +NEWSYM testgfxv2, db 0 + + +NEWSYM initregw + ; Fill register pointer with invalid register accesses + mov edi,[regptw] + add edi,8000h + mov ecx,3000h + mov eax,regINVALIDw +.loopa + mov [edi],eax + add edi,4 + loop .loopa + ; Set all valid register accesses + setregw 2100h*4,reg2100w + setregw 2101h*4,reg2101w + setregw 2102h*4,reg2102w + setregw 2103h*4,reg2103w + setregw 2104h*4,reg2104w + setregw 2105h*4,reg2105w + setregw 2106h*4,reg2106w + setregw 2107h*4,reg2107w + setregw 2108h*4,reg2108w + setregw 2109h*4,reg2109w + setregw 210Ah*4,reg210Aw + setregw 210Bh*4,reg210Bw + setregw 210Ch*4,reg210Cw + setregw 210Dh*4,reg210Dw + setregw 210Eh*4,reg210Ew + setregw 210Fh*4,reg210Fw + setregw 2110h*4,reg2110w + setregw 2111h*4,reg2111w + setregw 2112h*4,reg2112w + setregw 2113h*4,reg2113w + setregw 2114h*4,reg2114w + setregw 2115h*4,reg2115w + setregw 2116h*4,reg2116w + setregw 2117h*4,reg2117w + setregw 2118h*4,reg2118 + setregw 2119h*4,reg2119inc + setregw 211Ah*4,reg211Aw + setregw 211Bh*4,reg211Bw + setregw 211Ch*4,reg211Cw + setregw 211Dh*4,reg211Dw + setregw 211Eh*4,reg211Ew + setregw 211Fh*4,reg211Fw + setregw 2120h*4,reg2120w + setregw 2121h*4,reg2121w + setregw 2122h*4,reg2122w + setregw 2123h*4,reg2123w + setregw 2124h*4,reg2124w + setregw 2125h*4,reg2125w + setregw 2126h*4,reg2126w + setregw 2127h*4,reg2127w + setregw 2128h*4,reg2128w + setregw 2129h*4,reg2129w + setregw 212Ah*4,reg212Aw + setregw 212Bh*4,reg212Bw + setregw 212Ch*4,reg212Cw + setregw 212Dh*4,reg212Dw + setregw 212Eh*4,reg212Ew + setregw 212Fh*4,reg212Fw + setregw 2130h*4,reg2130w + setregw 2131h*4,reg2131w + setregw 2132h*4,reg2132w + setregw 2133h*4,reg2133w + setregw 2140h*4,reg2140w + setregw 2141h*4,reg2141w + setregw 2142h*4,reg2142w + setregw 2143h*4,reg2143w + setregw 2180h*4,reg2180w + setregw 2181h*4,reg2181w + setregw 2182h*4,reg2182w + setregw 2183h*4,reg2183w + setregw 4016h*4,reg4016w + setregw 4017h*4,reg4017w + setregw 4200h*4,reg4200w + setregw 4201h*4,reg4201w + setregw 4202h*4,reg4202w + setregw 4203h*4,reg4203w + setregw 4204h*4,reg4204w + setregw 4205h*4,reg4205w + setregw 4206h*4,reg4206w + setregw 4207h*4,reg4207w + setregw 4208h*4,reg4208w + setregw 4209h*4,reg4209w + setregw 420Ah*4,reg420Aw + setregw 420Bh*4,reg420Bw + setregw 420Ch*4,reg420Cw + setregw 420Dh*4,reg420Dw + setregw 420Eh*4,reg420Ew + setregw 4210h*4,reg4210w + setregw 4211h*4,reg4211w + setregw 4212h*4,reg4212w + setregw 4216h*4,reg4216w + setregw 4300h*4,reg43X0w + setregw 4301h*4,reg43X1w + setregw 4302h*4,reg43x2w + setregw 4303h*4,reg43x3w + setregw 4304h*4,reg43x4w + setregw 4305h*4,reg43x5w + setregw 4306h*4,reg43x6w + setregw 4307h*4,reg43x7w + setregw 4308h*4,reg43x8w + setregw 4309h*4,reg43x9w + setregw 430Ah*4,reg43XAw + setregw 430Bh*4,reg43XAw + setregw 430Ch*4,reg43XAw + setregw 430Dh*4,reg43XAw + setregw 430Eh*4,reg43XAw + setregw 430Fh*4,reg43XAw + setregw 4310h*4,reg43X0w + setregw 4311h*4,reg43X1w + setregw 4312h*4,reg43x2w + setregw 4313h*4,reg43x3w + setregw 4314h*4,reg43x4w + setregw 4315h*4,reg43x5w + setregw 4316h*4,reg43x6w + setregw 4317h*4,reg43x7w + setregw 4318h*4,reg43x8w + setregw 4319h*4,reg43x9w + setregw 431Ah*4,reg43XAw + setregw 431Bh*4,reg43XAw + setregw 431Ch*4,reg43XAw + setregw 431Dh*4,reg43XAw + setregw 431Eh*4,reg43XAw + setregw 431Fh*4,reg43XAw + setregw 4320h*4,reg43X0w + setregw 4321h*4,reg43X1w + setregw 4322h*4,reg43x2w + setregw 4323h*4,reg43x3w + setregw 4324h*4,reg43x4w + setregw 4325h*4,reg43x5w + setregw 4326h*4,reg43x6w + setregw 4327h*4,reg43x7w + setregw 4328h*4,reg43x8w + setregw 4329h*4,reg43x9w + setregw 432Ah*4,reg43XAw + setregw 432Bh*4,reg43XAw + setregw 432Ch*4,reg43XAw + setregw 432Dh*4,reg43XAw + setregw 432Eh*4,reg43XAw + setregw 432Fh*4,reg43XAw + setregw 4330h*4,reg43X0w + setregw 4331h*4,reg43X1w + setregw 4332h*4,reg43x2w + setregw 4333h*4,reg43x3w + setregw 4334h*4,reg43x4w + setregw 4335h*4,reg43x5w + setregw 4336h*4,reg43x6w + setregw 4337h*4,reg43x7w + setregw 4338h*4,reg43x8w + setregw 4339h*4,reg43x9w + setregw 433Ah*4,reg43XAw + setregw 433Bh*4,reg43XAw + setregw 433Ch*4,reg43XAw + setregw 433Dh*4,reg43XAw + setregw 433Eh*4,reg43XAw + setregw 433Fh*4,reg43XAw + setregw 4340h*4,reg43X0w + setregw 4341h*4,reg43X1w + setregw 4342h*4,reg43x2w + setregw 4343h*4,reg43x3w + setregw 4344h*4,reg43x4w + setregw 4345h*4,reg43x5w + setregw 4346h*4,reg43x6w + setregw 4347h*4,reg43x7w + setregw 4348h*4,reg43x8w + setregw 4349h*4,reg43x9w + setregw 434Ah*4,reg43XAw + setregw 434Bh*4,reg43XAw + setregw 434Ch*4,reg43XAw + setregw 434Dh*4,reg43XAw + setregw 434Eh*4,reg43XAw + setregw 434Fh*4,reg43XAw + setregw 4350h*4,reg43X0w + setregw 4351h*4,reg43X1w + setregw 4352h*4,reg43x2w + setregw 4353h*4,reg43x3w + setregw 4354h*4,reg43x4w + setregw 4355h*4,reg43x5w + setregw 4356h*4,reg43x6w + setregw 4357h*4,reg43x7w + setregw 4358h*4,reg43x8w + setregw 4359h*4,reg43x9w + setregw 435Ah*4,reg43XAw + setregw 435Bh*4,reg43XAw + setregw 435Ch*4,reg43XAw + setregw 435Dh*4,reg43XAw + setregw 435Eh*4,reg43XAw + setregw 435Fh*4,reg43XAw + setregw 4360h*4,reg43X0w + setregw 4361h*4,reg43X1w + setregw 4362h*4,reg43x2w + setregw 4363h*4,reg43x3w + setregw 4364h*4,reg43x4w + setregw 4365h*4,reg43x5w + setregw 4366h*4,reg43x6w + setregw 4367h*4,reg43x7w + setregw 4368h*4,reg43x8w + setregw 4369h*4,reg43x9w + setregw 436Ah*4,reg43XAw + setregw 436Bh*4,reg43XAw + setregw 436Ch*4,reg43XAw + setregw 436Dh*4,reg43XAw + setregw 436Eh*4,reg43XAw + setregw 436Fh*4,reg43XAw + setregw 4370h*4,reg43X0w + setregw 4371h*4,reg43X1w + setregw 4372h*4,reg43x2w + setregw 4373h*4,reg43x3w + setregw 4374h*4,reg43x4w + setregw 4375h*4,reg43x5w + setregw 4376h*4,reg43x6w + setregw 4377h*4,reg43x7w + setregw 4378h*4,reg43x8w + setregw 4379h*4,reg43x9w + setregw 437Ah*4,reg43XAw + setregw 437Bh*4,reg43XAw + setregw 437Ch*4,reg43XAw + setregw 437Dh*4,reg43XAw + setregw 437Eh*4,reg43XAw + setregw 437Fh*4,reg43XAw + cmp byte[SFXEnable],0 + je .nosfx + call initsfxregsw +.nosfx + cmp byte[SA1Enable],0 + je .nosa1 + call initSA1regsw +.nosa1 + cmp byte[SDD1Enable],0 + je .nosdd1 + call SDD1Reset +.nosdd1 + cmp byte[SPC7110Enable],0 + je .nospc7110 + call SPC7110Reset +.nospc7110 + cmp byte[RTCEnable],0 + je .nortc + call RTCReset2 +.nortc + ret + +; video memory change buffer for caching (65536/16=4096) +;vidmemch2 times 4096 db 0 +;vidmemch4 times 4096 db 0 +;vidmemch8 times 4096 db 0 + + +NEWSYM unpackfunct + mov ebx,[oamaddr] + mov [oamaddrt],bx + + mov ax,[xa] + mov [xat],ax + mov al,[xdb] + mov [xdbt],al + mov al,[xpb] + mov [xpbt],al + mov ax,[xs] + mov [xst],ax + mov ax,[xd] + mov [xdt],ax + mov ax,[xx] + mov [xxt],ax + mov ax,[xy] + mov [xyt],ax + ret + + +NEWSYM repackfunct + ; Global/Echo Volumes + mov al,[DSPMem+0Ch] + call WDSPReg0C + mov al,[DSPMem+1Ch] + call WDSPReg1C + mov al,[DSPMem+2Ch] + call WDSPReg2C + mov al,[DSPMem+3Ch] + call WDSPReg3C + ; Echo Values + mov al,[DSPMem+7Dh] + call WDSPReg7D + mov al,[DSPMem+0Dh] + call WDSPReg0D + ; FIR Filter Values + mov al,[DSPMem+00Fh] + call WDSPReg0F + mov al,[DSPMem+01Fh] + call WDSPReg1F + mov al,[DSPMem+02Fh] + call WDSPReg2F + mov al,[DSPMem+03Fh] + call WDSPReg3F + mov al,[DSPMem+04Fh] + call WDSPReg4F + mov al,[DSPMem+05Fh] + call WDSPReg5F + mov al,[DSPMem+06Fh] + call WDSPReg6F + mov al,[DSPMem+07Fh] + call WDSPReg7F + ; Noise + mov al,[DSPMem+6Ch] + call WDSPReg6C + mov al,[DSPMem+3Dh] + call WDSPReg3D + + mov bx,[bg1ptrb] + sub bx,[bg1ptr] + mov [bg1ptrx],bx + mov bx,[bg1ptrc] + sub bx,[bg1ptr] + mov [bg1ptry],bx + mov bx,[bg2ptrb] + sub bx,[bg2ptr] + mov [bg2ptrx],bx + mov bx,[bg2ptrc] + sub bx,[bg2ptr] + mov [bg2ptry],bx + mov bx,[bg3ptrb] + sub bx,[bg3ptr] + mov [bg3ptrx],bx + mov bx,[bg3ptrc] + sub bx,[bg3ptr] + mov [bg3ptry],bx + mov bx,[bg4ptrb] + sub bx,[bg4ptr] + mov [bg4ptrx],bx + mov bx,[bg4ptrc] + sub bx,[bg4ptr] + mov [bg4ptry],bx + + ; 16x16 tiles + mov bl,[bgtilesz] + shl bl,4 + mov dword[BG116x16t],0 + add bl,bl + adc byte[BG416x16t],0 + add bl,bl + adc byte[BG316x16t],0 + add bl,bl + adc byte[BG216x16t],0 + add bl,bl + adc byte[BG116x16t],0 + + mov ebx,[oamaddrt] + and ebx,0FFFFh + mov [oamaddr],ebx + + mov ax,[xat] + mov [xa],ax + mov al,[xdbt] + mov [xdb],al + mov al,[xpbt] + mov [xpb],al + mov ax,[xst] + mov [xs],ax + mov ax,[xdt] + mov [xd],ax + mov ax,[xxt] + mov [xx],ax + mov ax,[xyt] + mov [xy],ax + + cmp byte[vramincby8on],1 + je near .incby8 + mov ebx,[regptw] + cmp byte[vramincr],1 + je .from2118 + mov dword[ebx+2118h*4],reg2118 + mov dword[ebx+2119h*4],reg2119inc + ret +.from2118 + mov dword[ebx+2118h*4],reg2118inc + mov dword[ebx+2119h*4],reg2119 + ret +.incby8 + mov ebx,[regptw] + cmp byte[vramincr],1 + je .from2118b + mov dword[ebx+2118h*4],reg2118inc8 + mov dword[ebx+2119h*4],reg2119inc8inc + ret +.from2118b + mov dword[ebx+2118h*4],reg2118inc8inc + mov dword[ebx+2119h*4],reg2119inc8 + ret + +;******************************************************* +; Registers Note : restore AH, ECX, ESI, EDI, *S & DX +;******************************************************* + + +; Screen display register +reg2100w: + mov [vidbright],al + and byte[vidbright],0Fh + mov [forceblnk],al + and byte[forceblnk],80h + ret + +NEWSYM prevoamptr, db 0 + +; OAM size register +reg2101w: + cmp byte[prevoamptr],0FFh + je .noskip + cmp byte[prevoamptr],al + je near .noproc +.noskip + mov byte[prevoamptr],al + xor ebx,ebx + mov bl,al + and bl,03h + shl bx,14 + mov [objptr],bx + mov [objptrn],bx + xor ebx,ebx + mov bl,al + and bl,18h + shr bl,3 + shl bx,13 + add [objptrn],bx + xor ebx,ebx + mov bl,al + shr bl,5 + push eax + mov byte[NextLineCache],1 + mov al,[.objsize1+ebx] + mov [objsize1],al + mov al,[.objsize2+ebx] + mov [objsize2],al + mov al,[.objmovs1+ebx] + mov [objmovs1],al + mov al,[.objmovs2+ebx] + mov [objmovs2],al + mov ax,[.objadds1+ebx*2] + mov [objadds1],ax + mov ax,[.objadds2+ebx*2] + mov [objadds2],ax + pop eax +.noproc + ret + +.objsize1 db 1,1,1,4,4,16,1,1 +.objsize2 db 4,16,64,16,64,64,4,4 +.objmovs1 db 2,2,2,2,2,4,2,2 +.objmovs2 db 2,4,8,4,8,8,2,2 +.objadds1 dw 14,14,14,14,14,12,14,14 +.objadds2 dw 14,12,8,12,8,8,14,14 + +; OAM address register +reg2102w: + shr word[oamaddr],1 + mov [oamaddr],al + shl word[oamaddr],1 + mov bx,[oamaddr] + mov [oamaddrs],bx + cmp byte[nexthprior],1 + je .priorset + mov byte[objhipr],0 + jmp .cachespr +.priorset + mov bl,al + cmp bl,80h + jae .noreset +; xor bl,bl +.noreset + mov [objhipr],bl + mov byte[nexthprior],0 +.cachespr + ret + +; OAM address register +reg2103w: + mov bl,al + and bl,01h + shr word[oamaddr],1 + mov [oamaddr+1],bl + shl word[oamaddr],1 + mov bx,[oamaddr] + mov [oamaddrs],bx + test al,80h + jnz .hipri + mov byte[NextLineCache],1 + ret +.hipri + mov byte[nexthprior],1 + mov byte[NextLineCache],1 + ret + +; OAM data register +reg2104w: + mov ebx,[oamaddr] + inc dword[oamaddr] + cmp ebx,544 + je .overflow + mov [oamram+ebx],al + ret +.overflow + xor ebx,ebx + mov dword[oamaddr],1 + mov [oamram+ebx],al + ret + +; Screen mode register +reg2105w: + mov bl,al + and bl,00000111b + mov [bgmode],bl + mov bl,al + shr bl,3 + and bl,01h + mov [bg3highst],bl + mov bl,al + shr bl,4 + mov [bgtilesz],bl + mov bl,al + mov dword[BG116x16t],0 + add bl,bl + adc byte[BG416x16t],0 + add bl,bl + adc byte[BG316x16t],0 + add bl,bl + adc byte[BG216x16t],0 + add bl,bl + adc byte[BG116x16t],0 + ret + +; Screen pixelation register +reg2106w: + mov bl,al + and bl,0Fh + mov [mosaicon],bl + mov bl,al + shr bl,4 + mov [mosaicsz],bl + ret + +; BG1 VRAM location register +reg2107w: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg1ptr],bx + mov [bg1ptrb],bx + mov [bg1ptrc],bx + mov [bg1ptrd],bx + mov dword[bg1ptrx],0 + mov dword[bg1ptry],0 + mov bl,al + and bl,00000011b + mov [bg1scsize],bl + cmp bl,1 + jne .skipa + add word[bg1ptrb],800h + add word[bg1ptrd],800h + mov dword[bg1ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg1ptrc],800h + add word[bg1ptrd],800h + mov dword[bg1ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg1ptrb],800h + add word[bg1ptrc],1000h + add word[bg1ptrd],1800h + mov dword[bg1ptrx],800h + mov dword[bg1ptry],1000h +.skipc + ret + +; BG2 VRAM location register +reg2108w: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg2ptr],bx + mov [bg2ptrb],bx + mov [bg2ptrc],bx + mov [bg2ptrd],bx + mov dword[bg2ptrx],0 + mov dword[bg2ptry],0 + mov bl,al + and bl,00000011b + mov [bg2scsize],bl + cmp bl,1 + jne .skipa + add word[bg2ptrb],800h + add word[bg2ptrd],800h + mov dword[bg2ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg2ptrc],800h + add word[bg2ptrd],800h + mov dword[bg2ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg2ptrb],800h + add word[bg2ptrc],1000h + add word[bg2ptrd],1800h + mov dword[bg2ptrx],800h + mov dword[bg2ptry],1000h +.skipc + ret + +; BG3 VRAM location register +reg2109w: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg3ptr],bx + mov [bg3ptrb],bx + mov [bg3ptrc],bx + mov [bg3ptrd],bx + mov dword[bg3ptrx],0 + mov dword[bg3ptry],0 + mov bl,al + and bl,00000011b + mov [bg3scsize],bl + cmp bl,1 + jne .skipa + add word[bg3ptrb],800h + add word[bg3ptrd],800h + mov dword[bg3ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg3ptrc],800h + add word[bg3ptrd],800h + mov dword[bg3ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg3ptrb],800h + add word[bg3ptrc],1000h + add word[bg3ptrd],1800h + mov dword[bg3ptrx],800h + mov dword[bg3ptry],1000h +.skipc + ret + +; BG4 VRAM location register +reg210Aw: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg4ptr],bx + mov [bg4ptrb],bx + mov [bg4ptrc],bx + mov [bg4ptrd],bx + mov dword[bg4ptrx],0 + mov dword[bg4ptry],0 + mov bl,al + and bl,00000011b + mov [bg4scsize],bl + cmp bl,1 + jne .skipa + add word[bg4ptrb],800h + add word[bg4ptrd],800h + mov dword[bg4ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg4ptrc],800h + add word[bg4ptrd],800h + mov dword[bg4ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg4ptrb],800h + add word[bg4ptrc],1000h + add word[bg4ptrd],1800h + mov dword[bg4ptrx],800h + mov dword[bg4ptry],1000h +.skipc + ret + +; BG1 & BG2 VRAM location register +reg210Bw: + xor ebx,ebx + mov bl,al + and bl,0Fh + shl bx,13 + mov [bg1objptr],bx + mov bl,al + shr bl,4 + shl bx,13 + mov [bg2objptr],bx + ret + +; BG3 & BG4 VRAM location register +reg210Cw: + xor ebx,ebx + mov bl,al + and bl,0Fh + shl bx,13 + mov [bg3objptr],bx + mov bl,al + shr bl,4 + shl bx,13 + mov [bg4objptr],bx + ret + +; BG1 horizontal scroll register +reg210Dw: + mov bl,byte[bg1scrolx+1] + mov byte[bg1scrolx],bl + mov byte[bg1scrolx+1],al + ret + +; BG1 vertical scroll register +reg210Ew: + mov bl,byte[bg1scroly+1] + add bl,[bgscroltemp] + mov byte[bg1scroly],bl + mov byte[bg1scroly+1],al + ret + +bgscroltemp db 0 + +; BG2 horizontal scroll register +reg210Fw: + mov bl,byte[bg2scrolx+1] + mov byte[bg2scrolx],bl + mov byte[bg2scrolx+1],al + ret + +; BG2 vertical scroll register +reg2110w: + mov bl,byte[bg2scroly+1] + add bl,[bgscroltemp] + mov byte[bg2scroly],bl + mov byte[bg2scroly+1],al + ret + +; BG3 horizontal scroll register +reg2111w: + mov bl,byte[bg3scrolx+1] + mov byte[bg3scrolx],bl + mov byte[bg3scrolx+1],al + ret + +; BG3 vertical scroll register +reg2112w: + mov bl,byte[bg3scroly+1] + add bl,[bgscroltemp] + mov byte[bg3scroly],bl + mov byte[bg3scroly+1],al + ret + +; BG4 horizontal scroll register +reg2113w: + mov bl,byte[bg4scrolx+1] + mov byte[bg4scrolx],bl + mov byte[bg4scrolx+1],al + ret + +; BG4 vertical scroll register +reg2114w: + mov bl,byte[bg4scroly+1] + add bl,[bgscroltemp] + mov byte[bg4scroly],bl + mov byte[bg4scroly+1],al + ret + +; Video port control +reg2115w: + and al,11111111b + mov [vraminctype],al + mov bl,al + and bl,00000011b + cmp bl,0 + jne .skip1 + mov word[addrincr],2 +.skip1 + cmp bl,1 + jne .skip2 + mov word[addrincr],64 +.skip2 + cmp bl,2 + jne .skip3 + mov word[addrincr],256 +.skip3 + cmp bl,3 + jne .skip4 + mov word[addrincr],256 +.skip4 + mov bl,al + mov byte[vramincby8on],0 + and bl,00001100b + jz near .noincby8 + mov byte[vramincby8on],1 + cmp bl,4 + jne .nextinc8 + mov byte[vramincby8left],64-1 + mov byte[vramincby8totl],5 + mov word[vramincby8ptri],65535-511 + mov word[vramincby8var],256+128+64 +.nextinc8 + cmp bl,8 + jne .nextinc8b + mov byte[vramincby8left],128-1 + mov byte[vramincby8totl],6 + mov word[vramincby8ptri],65535-1023 + mov word[vramincby8var],512+256+128 +.nextinc8b + cmp bl,12 + jne .nextinc8c + mov byte[vramincby8left],256-1 + mov byte[vramincby8totl],7 + mov word[vramincby8ptri],65535-2047 + mov word[vramincby8var],1024+512+256 +.nextinc8c + mov ebx,[regptw] + test al,80h + jz .from2118 + mov dword[ebx+2118h*4],reg2118inc8 + mov dword[ebx+2119h*4],reg2119inc8inc + mov byte[vramincr],0 + jmp .from2119 +.from2118 + mov dword[ebx+2118h*4],reg2118inc8inc + mov dword[ebx+2119h*4],reg2119inc8 + mov byte[vramincr],1 +.from2119 + ret +.noincby8 + mov ebx,[regptw] + test al,80h + jz .from2118b + mov dword[ebx+2118h*4],reg2118 + mov dword[ebx+2119h*4],reg2119inc + mov byte[vramincr],0 + jmp .from2119b +.from2118b + mov dword[ebx+2118h*4],reg2118inc + mov dword[ebx+2119h*4],reg2119 + mov byte[vramincr],1 +.from2119b + ret + +; Video port address (Low) +reg2116w: + shr word[vramaddr],1 + mov byte[vramaddr],al + shl word[vramaddr],1 + mov byte[vramread],0 + ret + +; Video port address (High) +reg2117w: + shr word[vramaddr],1 + mov byte[vramaddr+1],al + shl word[vramaddr],1 + mov byte[vramread],0 + ret + +; Video port data (Low) +reg2118: + cmp dword[vramaddr],0E000h + jb .skip + mov byte[debstop],1 +.skip + mov ebx,[vramaddr] +; cmp [vrama+ebx],al +; je .nochange + mov [vrama+ebx],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange + ret + +reg2118inc: + mov ebx,[vramaddr] +; cmp [vrama+ebx],al +; je .nochange + mov [vrama+ebx],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange + mov ebx,[addrincr] + add [vramaddr],bx + ret + +reg2118inc8: + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx + add ebx,[vram] +; cmp [ebx],al +; je .nochange2 + mov [ebx],al + sub ebx,[vram] + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + ret + +reg2118inc8inc: + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx + add ebx,[vram] +; cmp [ebx],al +; je .nochange2 + mov [ebx],al + sub ebx,[vram] + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + mov ebx,[addrincr] + add [vramaddr],bx + ret + +reg2119: + cmp dword[vramaddr],0E000h + jb .skip + mov byte[debstop],1 +.skip + mov ebx,[vramaddr] +; cmp [vrama+ebx+1],al +; je .nochange + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange + ret + +reg2119inc: + mov ebx,[vramaddr] +; cmp [vrama+ebx+1],al +; je .nochange + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange + mov ebx,[addrincr] + add [vramaddr],bx + ret + +reg2119inc8: + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx +; cmp [vrama+ebx+1],al +; je .nochange2 + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + ret + +reg2119inc8inc: + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx +; cmp [vrama+ebx+1],al +; je .nochange2 + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + mov ebx,[addrincr] + add [vramaddr],bx + ret + +; MODE7 settings register +reg211Aw: + mov [mode7set],al + ret + +NEWSYM multchange, db 1 + +; COS (COSINE) rotate angle / X Expansion +reg211Bw: + mov bl,[mode7A+1] + mov [mode7A],bl + mov [mode7A+1],al + mov byte[multchange],1 + ret + +; SIN (SIN) rotate angle / X Expansion & Complement Multiplication Start +reg211Cw: + mov bl,[mode7B+1] + mov [mode7B],bl + mov [mode7B+1],al + mov byte[multchange],1 + ret + +; SIN (SIN) rotate angle / Y Expansion +reg211Dw: + mov bl,[mode7C+1] + mov [mode7C],bl + mov [mode7C+1],al + ret + +; COS (COSINE) rotate angle / Y Expansion +reg211Ew: + mov bl,[mode7D+1] + mov [mode7D],bl + mov [mode7D+1],al + ret + +; Center position X (13-bit data only) +reg211Fw: + mov bl,[mode7X0+1] + mov [mode7X0],bl + mov [mode7X0+1],al + ret + +; Center position Y (13-bit data only) +reg2120w: + mov bl,[mode7Y0+1] + mov [mode7Y0],bl + mov [mode7Y0+1],al + ret + +; Colour # (or palette) selection register +reg2121w: + xor bh,bh + mov bl,al + shl bx,1 + mov [cgaddr],bx + and word[cgaddr],01FFh + ret + +; Colour data register +reg2122w: + xor ebx,ebx + mov bx,[cgaddr] + cmp [cgram+ebx],al + je .nomod + mov [cgram+ebx],al + mov byte[cgmod],1 +.nomod + inc word[cgaddr] + and word[cgaddr],01FFh + ret + +; Window mask settings register [W12SEL] +reg2123w: + mov bl,al + and bl,0Fh + mov [winbg1en],bl + mov bl,al + shr bl,4 + mov [winbg2en],bl + ret + +; Window mask settings register [W34SEL] +reg2124w: + mov bl,al + and bl,0Fh + mov [winbg3en],bl + mov bl,al + shr bl,4 + mov [winbg4en],bl + ret + +; Window mask settings register [WOBJSEL] +reg2125w: + mov bl,al + and bl,0Fh + mov [winobjen],bl + mov bl,al + shr bl,4 + mov [wincolen],bl + ret + +; Window 1 left position register +reg2126w: + mov [winl1],al + ret + +; Window 1 right position register +reg2127w: + mov [winr1],al + ret + +; Window 2 left position register +reg2128w: + mov [winl2],al + ret + +; Window 2 right position register +reg2129w: + mov [winr2],al + ret + +; Mask logic settings for Window 1 & 2 per screen +reg212Aw: + mov [winlogica],al + ret + +; Mask logic settings for Colour Windows & OBJ Windows +reg212Bw: + mov [winlogicb],al + ret + +; Main screen designation +reg212Cw: + mov [scrnon],al + ret + +; Sub-screen designation +reg212Dw: + mov [scrnon+1],al + ret + +; Window mask main screen designation register +reg212Ew: + mov [winenabm],al + ret + +; Window mask sub screen designation register +reg212Fw: + mov [winenabs],al + ret + +; Fixed color addition or screen addition register +reg2130w: + mov [scaddset],al + ret + +; Addition/subtraction for screens, BGs, & OBJs +reg2131w: + mov [scaddtype],al + ret + +; Fixed colour data for fixed colour +/- +reg2132w: + mov bl,al + and bl,1Fh + test al,20h + jz .nored + mov [coladdr],bl +.nored + test al,40h + jz .nogreen + mov [coladdg],bl +.nogreen + test al,80h + jz .noblue + mov [coladdb],bl +.noblue + ret + +; Screen mode/video select register +reg2133w: + mov [interlval],al + and byte[interlval],41h + test al,04h + jnz .line239 + mov word[resolutn],224 + ret +.line239 + mov word[resolutn],239 + ret + +NEWSYM CleartheScreen, db 0 + +; Sound Register #1 +reg2140w: + mov byte[sndwrit],1 + cmp byte[nmistatus],2 + jne .n + mov byte[nmirept],0 +.n + mov byte[spcRam+0F4h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Sound Register #2 +reg2141w: + mov byte[sndwrit],1 + mov byte[spcRam+0F5h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Sound Register #3 +reg2142w: + mov byte[sndwrit],1 + mov byte[spcRam+0F6h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Sound Register #4 +reg2143w: + mov byte[sndwrit],1 + mov byte[spcRam+0F7h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Read/write WRAM register +reg2180w: + mov ebx,[wramrwadr] + add ebx,[wramdata] + mov [ebx],al + inc dword[wramrwadr] + and dword[wramrwadr],01FFFFh + ret + +; WRAM data register (low byte) +reg2181w: + mov byte[wramrwadr],al + ret + +; WRAM data register (middle byte) +reg2182w: + mov byte[wramrwadr+1],al + ret + +; WRAM data register (high byte) +reg2183w: + mov bl,al + and bl,01h + mov byte[wramrwadr+2],bl + ret + +; Joystick 1 & 2 status bytes +NEWSYM MultiTapStat, db 0 + +reg4016w: + test byte[INTEnab],1 + jnz .nointenab + mov ebx,[JoyAOrig] + mov [JoyANow],ebx + mov ebx,[JoyBOrig] + mov [JoyBNow],ebx + mov ebx,[JoyCOrig] + mov [JoyCNow],ebx + mov ebx,[JoyDOrig] + mov [JoyDNow],ebx + mov ebx,[JoyEOrig] + mov [JoyENow],ebx + cmp al,01h + jne .noreset + or byte[MultiTapStat],1 + ret +.noreset + and byte[MultiTapStat],0FEh + ret +.nointenab + cmp al,01h + jne .noone + or byte[MultiTapStat],1 + or byte[JoyCRead],2 + ret +.noone + and byte[MultiTapStat],0FEh + cmp al,0 + jne .nozero + or byte[JoyCRead],1 + cmp byte[JoyCRead],3 + jne .nozero +.resetports + mov ebx,[JoyAOrig] + mov [JoyANow],ebx + mov ebx,[JoyBOrig] + mov [JoyBNow],ebx + mov ebx,[JoyCOrig] + mov [JoyCNow],ebx + mov ebx,[JoyDOrig] + mov [JoyDNow],ebx + mov ebx,[JoyEOrig] + mov [JoyENow],ebx +.nozero + ret + +; Joystick 1 & 2 status bytes +reg4017w: + ret + +; Counter enable +reg4200w: + mov byte[INTEnab],al + ret + +; Programmable I/O port (out-port) +reg4201w: + mov bl,al + and bl,80h + and byte[MultiTapStat],07Fh + or byte[MultiTapStat],bl + ret + +; Multiplicand 'A' +reg4202w: + mov [multa],al + ret + +; Multiplier 'B' +reg4203w: + push edx + push eax + xor ah,ah + xor bh,bh + mov bl,[multa] + mul bx + mov [multres],ax + pop eax + pop edx + ret + +; Dividend C (Low) +reg4204w: + mov [diva],al + ret + +; Dividend C (High) +reg4205w: + mov [diva+1],al + ret + +; Divisor B +reg4206w: + cmp al,0 + je .divby0 + push eax + push edx + xor ebx,ebx + xor edx,edx + mov bl,al + mov ax,[diva] + div bx + mov [divres],ax + mov [multres],dx + pop edx + pop eax + ret +.divby0 + push eax + mov word[divres],0FFFFh + mov ax,[diva] + mov [multres],ax + pop eax + ret + + +DetermineHIRQExec + cmp byte[HIRQSkip],1 + je near .ret + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + mov byte[HIRQNextExe],0 + push eax + push ecx + push edx + mov ax,[HIRQLoc] + xor ecx,ecx + mov cl,[cycpl] + mul cx + mov cx,340 + div cx + mov cl,[cycpl] + sub cl,al + pop edx + cmp dh,cl + ja .hirqokay +.notokay + pop ecx + pop eax +.ret + ret +.hirqokay + sub dh,cl + add dh,30 + mov [HIRQCycNext],cl + mov byte[HIRQNextExe],1 + pop ecx + pop eax + ret + +; Video horizontal IRQ beam position/pointer (Low) +reg4207w: + cmp [HIRQLoc],al + je .nohirqc + mov [HIRQLoc],al + mov bx,[curypos] + cmp bx,[VIRQLoc] + je near DetermineHIRQExec +.nohirqc + ret + +; Video horizontal IRQ beam position/pointer (High) +reg4208w: + cmp [HIRQLoc+1],al + je .nohirqc + mov [HIRQLoc+1],al + mov bx,[curypos] + cmp bx,[VIRQLoc] + je near DetermineHIRQExec +.nohirqc + ret + +; Video vertical IRQ beam position/pointer (Low) +reg4209w: + mov [VIRQLoc],al +; mov bx,[curypos] + cmp byte[HIRQNextExe],1 + je .nohirq + ret +.nohirq + mov bx,[curypos] + cmp bx,[VIRQLoc] + je .nocancelhirq + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + mov byte[HIRQNextExe],0 +.nocancelhirq + ret + +; Video vertical IRQ beam position/pointer (High) +reg420Aw: + and al,01h + mov [VIRQLoc+1],al + cmp byte[HIRQNextExe],1 + je .nohirq + ret +.nohirq + mov bx,[curypos] + cmp bx,[VIRQLoc] + je .nocancelhirq + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + mov byte[HIRQNextExe],0 +.nocancelhirq + ret + +; Cycle speed register +reg420Dw: + test al,01h + jnz .speed358 + ; 2.68 Mhz + mov al,[opexec268] + mov byte[cycpl],al ; 2.68 Mhz + mov al,[opexec268cph] + mov byte[cycphb],al ; 2.68 Mhz + and byte[xirqb],00h + mov bl,[cycpb268] + mov byte[cycpblt],bl ; percentage of CPU/SPC to run + ret +.speed358 + ; 3.58 Mhz + mov al,[opexec358] + mov byte[cycpl],al ; 3.58 Mhz + mov al,[opexec358cph] + mov byte[cycphb],al ; 3.58 Mhz + or byte[xirqb],80h + mov bl,[cycpb358] + mov byte[cycpblt],bl ; percentage of CPU/SPC to run + ret + +; ??? +reg420Ew: + ret + +; NMI Check register +reg4210w: + ret + +; Video IRQ register +reg4211w: + ret + +; Status register +reg4212w: + ret + +; Product of Multiplication Result or Remainder of Divide Result (Low) +reg4216w: + ret + +; DMA Control register +reg43X0w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + mov byte[hdmarestart],1 + ret + +; DMA Destination register +reg43X1w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + mov byte[hdmarestart],1 + ret + +; Source address (Low) +reg43x2w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al +; mov [dmadata+ebx+6],al + ret + +; Source address (High) +reg43x3w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al +; mov [dmadata+ebx+6],al + ret + +; Source bank address +reg43x4w + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; DMA transfer size & HDMA address register (Low) +reg43x5w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; DMA transfer size & HDMA address register (High) +reg43x6w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; DMA transfer size & HDMA address register (Bank) +reg43x7w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; Table Address of A-BUS by DMA < A2 Table Address (Low) +reg43x8w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; Table Address of A-BUS by DMA < A2 Table Address (High) +reg43x9w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; Number of lines for HDMA transfer +reg43XAw: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +regINVALIDw: ; Invalid Register + ret + + +regexiter: + mov bl,[xpb] + mov ax,[xpc] + test ax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax ; subtract program counter by address + mov [.invaddr],bx + mov bl,[xpb] + mov [.invbank],bl + + mov al,[previdmode] + mov ah,0 + int 10h + mov byte[invalid],1 + mov [invreg],cx + mov ah,9 + mov edx,.invalidreg + int 21h + xor eax,eax + mov ax,[invreg] + call printhex + mov ah,9 + mov edx,.invalidreg + int 21h + xor eax,eax + mov al,[.invbank] + call printhex8 + mov ax,[.invaddr] + call printhex + mov ah,2 + mov dl,13 + int 21h + mov ah,2 + mov dl,10 + int 21h + mov eax,[numinst] + call printnum + jmp DosExit + +.invalidreg db 'Invalid Write Register : $' +.invalidaddr db ' at address $' +.invbank db 0 +.invaddr db 0 + \ No newline at end of file diff --git a/zsnes/src/cpu/regsw.mac b/zsnes/src/cpu/regsw.mac new file mode 100644 index 00000000..f4cf02ef --- /dev/null +++ b/zsnes/src/cpu/regsw.mac @@ -0,0 +1,52 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM tableadc + + + + + + + +;******************************************************* +; InitRegW Initializes Write Registers +;******************************************************* + +%macro reenablespc 0 + cmp dword[cycpbl],1000000h + jb %%enspc + mov dword[cycpbl],0 + test byte[curexecstate],02h + jnz %%enspc + or byte[curexecstate],02h + push ebx + xor ebx,ebx + mov bl,dl + mov edi,[tableadc+ebx*4] + pop ebx +%%enspc +%endmacro + +%macro setregw 2 + mov edi,%1 + add edi,[regptw] + mov eax,%2 + mov [edi],eax +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/s65816d.inc b/zsnes/src/cpu/s65816d.inc new file mode 100644 index 00000000..bb333814 --- /dev/null +++ b/zsnes/src/cpu/s65816d.inc @@ -0,0 +1,1574 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM Sflagnz, Sflago, Sflagc,dmadata +;EXTSYM spcRamDP,spcRamDPb,spcRam + EXTSYM IRAM + + + + + + +;******************************************************* +; Flag Setting Macros +;******************************************************* + + +%macro endloop 0 + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc %%cpuover + jmp dword near [edi+ebx*4] +%%cpuover + ret +%endmacro + +%macro restoredl 0 + mov dword[Sflagnz],0 + test dl,80h + jz %%noneg + or dword[Sflagnz],10000h +%%noneg + test dl,2h + jnz %%zero + or dword[Sflagnz],1 +%%zero + mov dword[Sflagc],0 + test dl,01h + jz %%nocarry + mov dword[Sflagc],0FFh +%%nocarry + mov dword[Sflago],0 + test dl,40h + jz %%nov + mov dword[Sflago],0FFh +%%nov +%endmacro + +%macro makedl 0 + and dl,00111100b + test dword[Sflagnz],18000h + jz %%noneg + or dl,80h +%%noneg + test dword[Sflagnz],0FFFFh + jnz %%nozero + or dl,02h +%%nozero + test dword[Sflagc],0FFh + jz %%nocarry + or dl,01h +%%nocarry + test dword[Sflago],0FFh + jz %%nov + or dl,40h +%%nov +%endmacro + +NEWSYM Ssplitflags + restoredl + ret + +NEWSYM Sjoinflags + makedl + ret + +; Sets flags n and z according to al +%macro flagsetnz8b 0 + mov dword[Sflagnz],0 + mov [Sflagnz+1],al + endloop +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16b 0 + mov cx,ax + mov [Sflagnz],ecx + endloop +%endmacro + +; Sets flags n and z according to al +%macro flagsetnz8bnel 0 + mov dword[Sflagnz],0 + mov [Sflagnz+1],al +%endmacro + +; Sets flags n and z according to ax +%macro flagsetnz16bnel 0 + mov cx,ax + mov [Sflagnz],ecx +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzc8b 0 + mov dword[Sflagnz],0 + mov al,[SA1xa] + seto byte[Sflago] + mov [Sflagnz+1],al + jc .carry + mov dword[Sflagc],0h + endloop +.carry + mov dword[Sflagc],0FFh + endloop +%endmacro + +%macro flagsetnvzc16b 0 + mov cx,[SA1xa] + seto byte[Sflago] + mov [Sflagnz],ecx + jc .carry + mov dword[Sflagc],0h + endloop +.carry + mov dword[Sflagc],0FFh + endloop +%endmacro + +; Sets flags N V . . . . Z C according to flags +%macro flagsetnvzcs8b 0 + mov dword[Sflagnz],0 + mov al,[SA1xa] + seto byte[Sflago] + mov [Sflagnz+1],al + jc .carry + mov dword[Sflagc],0FFh + endloop +.carry + mov dword[Sflagc],0h + endloop +%endmacro + +%macro flagsetnvzcs16b 0 + mov cx,[SA1xa] + seto byte[Sflago] + mov [Sflagnz],ecx + jc .carry + mov dword[Sflagc],0FFh + endloop +.carry + mov dword[Sflagc],0h + endloop +%endmacro + +; Sets flags N V . . . . Z C for 16-bit decimal mode only +%macro flagsetnvzcd 0 + mov cx,[SA1xa] + seto byte[Sflago] + mov [Sflagnz],ecx + jc .carry + mov dword[Sflagc],0h + endloop +.carry + mov dword[Sflagc],0FFh + endloop +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc8b 0 + mov dword[Sflagnz],0 + mov dword[Sflagc],0h + mov [Sflagnz+1],al + jnc .carry + mov dword[Sflagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and don't jump to execloop +%macro flagsetnzc 0 + mov cx,ax + mov dword[Sflagc],0h + mov [Sflagnz],ecx + jnc .carry + mov dword[Sflagc],0FFh +.carry +%endmacro + +; Sets flags N . . . . . Z C according to flags and jump to execloop +%macro flagsetnzcel8b 0 + mov dword[Sflagnz],0h + jc .carry + mov [Sflagnz+1],cl + mov dword[Sflagc],0FFh + endloop +.carry + mov [Sflagnz+1],cl + mov dword[Sflagc],0h + endloop +%endmacro + +%macro flagsetnzcel16b 0 + jc .carry + mov [Sflagnz],ecx + mov dword[Sflagc],0FFh + endloop +.carry + mov [Sflagnz],ecx + mov dword[Sflagc],0h + endloop +%endmacro + +;******************************************************* +; Opcode Instructions +;******************************************************* + +%macro ADCMacro8bnd 0 + mov cl,[Sflagc] + add cl,cl + adc [SA1xa],al + flagsetnvzc8b +%endmacro + +%macro ADCMacro16bnd 0 + mov cl,[Sflagc] + add cl,cl + adc [SA1xa],ax + flagsetnvzc16b +%endmacro + +%macro ADCMacro8bd 0 + mov cl,[Sflagc] + add cl,cl + mov cl,al + mov al,[SA1xa] + adc al,cl + daa + mov [SA1xa],al + flagsetnvzc8b + endloop +%endmacro + +%macro ADCMacro16bd 0 + mov cl,[Sflagc] + add cl,cl + mov cx,ax + mov al,[SA1xa] + adc al,cl + daa + mov [SA1xa],al + mov al,[SA1xa+1] + adc al,ch + daa + mov [SA1xa+1],al + flagsetnvzcd +%endmacro + +%macro ANDMacro8b 0 + and al,[SA1xa] + mov dword[Sflagnz],0 + mov [SA1xa],al + mov [Sflagnz+1],al + endloop +%endmacro + +%macro ANDMacro16b 0 + and eax,[SA1xa] + mov [SA1xa],ax + flagsetnz16b +%endmacro + +%macro ASLMacro8b 0 + add al,al + flagsetnzc8b +%endmacro + +%macro ASLMacro16b 0 + add ax,ax + flagsetnzc +%endmacro + +%macro JumpMacro 0 + movsx eax,byte[esi] + add esi,eax +.skip + inc esi + endloop +%endmacro + +%macro BITMacroim8b 0 + mov al,[esi] + test dword[Sflagnz],18000h + jz .notSflagnz + or dword[Sflagnz],10000h +.notSflagnz + inc esi + test [SA1xa],al + jz .zero + mov word[Sflagnz],1 + endloop +.zero + mov word[Sflagnz],0 + endloop +%endmacro + +%macro BITMacroim16b 0 + mov ax,[esi] + test dword[Sflagnz],18000h + jz .notSflagnz + or dword[Sflagnz],10000h +.notSflagnz + add esi,2 + test [SA1xa],ax + jz .zero + mov word[Sflagnz],1 + endloop +.zero + mov word[Sflagnz],0 + endloop +%endmacro + +%macro BITMacro8b 0 + mov dword[Sflagnz],10000h + test al,80h + jnz .flagn + mov dword[Sflagnz],0 +.flagn + mov dword[Sflago],1 + test al,40h + jnz .Sflago + mov dword[Sflago],0 +.Sflago + test [SA1xa],al + jz .zero + mov word[Sflagnz],1 + endloop +.zero + mov word[Sflagnz],0 + endloop +%endmacro + +%macro BITMacro16b 0 + mov dword[Sflagnz],10000h + test ax,8000h + jnz .flagn + mov dword[Sflagnz],0 +.flagn + mov dword[Sflago],1 + test ax,4000h + jnz .Sflago + mov dword[Sflago],0 +.Sflago + test [SA1xa],ax + jz .zero + mov word[Sflagnz],1 + endloop +.zero + mov word[Sflagnz],0 + endloop +%endmacro + +%macro BRKMacro 0 + inc esi + test byte[xe],1 + jne near BRKemulmode + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[SA1xs] + mov cl,[SA1xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [SA1xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [SA1xpb],bl + xor eax,eax + mov ax,[brkv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +BRKemulmode + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[SA1xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [SA1xs],bx + xor bh,bh + mov bl,[SA1xpb] + xor eax,eax + mov ax,[brkv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro BRLMacro 0 + mov ebx,esi + sub ebx,[initaddrl] + add bx,2 + xor eax,eax + add bx,[esi] + mov ax,bx + xor ebx,ebx + mov [xpc],ax + mov bl,[SA1xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CMPMacro8b 0 + mov cl,[SA1xa] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CMPMacro16b 0 + mov cx,[SA1xa] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro COPMacro 0 + inc esi + test byte[xe],1 + jne near COPemulmode + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[SA1xs] + mov cl,[SA1xpb] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [SA1xs],bx + xor bh,bh + mov bl,byte[xirqb] + mov [SA1xpb],bl + xor eax,eax + mov ax,[copv] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +COPemulmode + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax + mov [xpc],bx + mov eax,[wramdata] + mov bx,[SA1xs] + mov cl,[xpc+1] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov cl,[xpc] + mov [eax+ebx],cl + dec bx + and bx,word[stackand] + or bx,word[stackor] + makedl + mov [eax+ebx],dl + dec bx + and bx,word[stackand] + or bx,word[stackor] + mov [SA1xs],bx + xor bh,bh + mov bl,[SA1xpb] + xor eax,eax + mov ax,[copv8] + mov [xpc],ax + and dl,11110011b + or dl,00000100b + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro CPXMacro8b 0 + mov cl,[SA1xx] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPXMacro16b 0 + mov cx,[SA1xx] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro CPYMacro8b 0 + mov cl,[SA1xy] + sub cl,al + flagsetnzcel8b +%endmacro + +%macro CPYMacro16b 0 + mov cx,[SA1xy] + sub cx,ax + flagsetnzcel16b +%endmacro + +%macro EORMacro8b 0 + xor al,[SA1xa] + mov dword[Sflagnz],0 + mov [SA1xa],al + mov [Sflagnz+1],al + endloop +%endmacro + +%macro EORMacro16b 0 + xor eax,[SA1xa] + mov [SA1xa],ax + flagsetnz16b +%endmacro + +%macro JMLMacro 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + add cx,2 + push eax + call membank0r8 + mov bl,al + pop eax + mov [xpc],ax + mov [SA1xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro4C 0 + xor eax,eax + mov ax,[esi] + mov bl,[SA1xpb] + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr +; mov esi,[snesmap2+ebx*4] +; mov [initaddrl],esi +; add esi,eax + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro6C 0 + mov cx,[esi] + xor eax,eax + call membank0r16 + mov [xpc],ax + mov bl,[SA1xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro7C 0 + mov cx,[esi] + xor eax,eax + add cx,[SA1xx] + mov bl,[SA1xpb] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[SA1xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JMPMacro5C 0 + xor eax,eax + mov bl,[esi+2] + mov ax,[esi] + mov [SA1xpb],bl + mov [xpc],ax + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSLMacro 0 + mov ebx,esi + sub ebx,[initaddrl] + add bx,2 + mov [xpc],bx + + mov cx,[SA1xs] + mov al,[SA1xpb] + call membank0w8 + dec cx + mov al,[xpc+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[xpc] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + + xor eax,eax + xor bh,bh + mov ax,[esi] + mov bl,[esi+2] + mov [xpc],ax + mov [SA1xpb],bl + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + cmp ebx,0 + jne .notupper + cmp eax,2000h + ja .upperbank +.notupper + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.upperbank + mov esi,IRAM + sub esi,3000h + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacro20 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + + mov cx,[SA1xs] + mov al,[xpc+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[xpc] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + + xor eax,eax + mov ax,[esi] + xor bh,bh + mov [xpc],ax + mov bl,[SA1xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + endloop +.upperlower + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro JSRMacroFC 0 + mov ebx,esi + sub ebx,[initaddrl] + inc bx + mov [xpc],bx + + mov cx,[SA1xs] + mov al,[xpc+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[xpc] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + + xor eax,eax + xor bh,bh + mov cx,[esi] + mov bl,[SA1xpb] + add cx,[SA1xx] + call dword near [memtabler16+ebx*4] + mov [xpc],ax + mov bl,[SA1xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro LDAMacro8b 0 + mov dword[Sflagnz],0 + mov [SA1xa],al + mov [Sflagnz+1],al + endloop +%endmacro + +%macro LDAMacro16b 0 + mov [SA1xa],ax + flagsetnz16b + endloop +%endmacro + +%macro LDXMacro8b 0 + mov dword[Sflagnz],0 + mov [SA1xx],al + mov [Sflagnz+1],al + endloop +%endmacro + +%macro LDXMacro16b 0 + mov [SA1xx],ax + flagsetnz16b + endloop +%endmacro + +%macro LDYMacro8b 0 + mov dword[Sflagnz],0 + mov [SA1xy],al + mov [Sflagnz+1],al + endloop +%endmacro + +%macro LDYMacro16b 0 + mov [SA1xy],ax + flagsetnz16b + endloop +%endmacro + +%macro LSRMacro8b 0 + shr al,1 + flagsetnzc8b +%endmacro + +%macro LSRMacro16b 0 + shr ax,1 + flagsetnzc +%endmacro + +%macro MVNMacro 0 + mov ax,[esi] + mov [SA1xdb],al + mov bl,ah + mov cx,[SA1xx] + call dword near [memtabler8+ebx*4] + mov bl,[SA1xdb] + mov cx,[SA1xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz .pagezero + inc word[SA1xx] + inc word[SA1xy] + dec word[SA1xa] + cmp word[SA1xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + inc byte[SA1xx] + inc byte[SA1xy] + dec word[SA1xa] + cmp word[SA1xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro MVPMacro 0 + mov ax,[esi] + mov [SA1xdb],al + mov bl,ah + mov cx,[SA1xx] + call dword near [memtabler8+ebx*4] + mov bl,[SA1xdb] + mov cx,[SA1xy] + call dword near [memtablew8+ebx*4] + test dl,10h + jnz .pagezero + dec word[SA1xx] + dec word[SA1xy] + dec word[SA1xa] + cmp word[SA1xa],0FFFFh + je .endmove + dec esi + endloop +.endmove + add esi,2 + endloop +.pagezero + dec byte[SA1xx] + dec byte[SA1xy] + dec word[SA1xa] + cmp word[SA1xa],0FFFFh + je .endmove + dec esi + endloop +%endmacro + +%macro ORAMacro8b 0 + or al,[SA1xa] + mov dword[Sflagnz],0 + mov [SA1xa],al + mov [Sflagnz+1],al + endloop +%endmacro + +%macro ORAMacro16b 0 + or ax,[SA1xa] + mov [SA1xa],ax + flagsetnz16b +%endmacro + +%macro PUSHMacro8b 1 + mov eax,[wramdata] + mov cx,[SA1xs] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + endloop +%endmacro + +%macro PUSHMacro8bp 0 + mov eax,[wramdata] + makedl + mov cx,[SA1xs] + mov al,dl + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + endloop +%endmacro + +%macro PUSHMacro16b 2 + mov cx,[SA1xs] + mov al,%2 + call membank0w8 + dec cx + or cx,word[stackor] + mov al,%1 + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + endloop +%endmacro + +%macro PEAMacro 0 + mov cx,[SA1xs] + mov al,[esi+1] + call membank0w8 + dec cx + or cx,word[stackor] + mov al,[esi] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + add esi,2 + endloop +%endmacro + +%macro PEIMacro 0 + xor ah,ah + mov al,[esi] + mov cx,[SA1xd] + inc esi + add cx,ax + call membank0r16 + mov cx,[SA1xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + endloop +%endmacro + +%macro PERMacro 0 + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr + mov eax,[snesmmap+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[SA1xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + xor ebx,ebx + endloop +.loweraddr + mov eax,[snesmap2+ebx*4] + mov ebx,esi + sub ebx,eax + add bx,[esi] + mov ax,bx + add esi,2 + add ax,2 + mov cx,[SA1xs] + push eax + mov al,ah + call membank0w8 + pop eax + dec cx + or cx,word[stackor] + call membank0w8 + dec cx + or cx,word[stackor] + mov [SA1xs],cx + xor ebx,ebx + endloop +%endmacro + +%macro POPMacro8b 1 + mov eax,[wramdata] + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [SA1xs],cx + mov %1,al + flagsetnz8b + endloop +%endmacro + +%macro POPMacro16b 2 + mov eax,[wramdata] + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [SA1xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + mov [SA1xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacro16bd 2 + mov eax,[wramdata] + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov %1,al + mov [SA1xs],cx + inc cx + and cx,word[stackand] + call membank0r8 + mov %2,al + call SA1UpdateDPage + mov [SA1xs],cx + mov ah,al + mov al,%1 + flagsetnz16b +%endmacro + +%macro POPMacroP 0 + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [SA1xs],cx + mov dl,al + restoredl + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[SA1tablead+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[SA1xx+1],0 + mov byte[SA1xy+1],0 + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop +%endmacro + +%macro REPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz .extraflags + not al + and dl,al + test byte[xe],01h + jnz .emul + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop + +.extraflags + not al + makedl + and dl,al + restoredl + test byte[xe],01h + jnz .emul2 + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop +.emul2 + or dl,00110000b + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop +%endmacro + +%macro ROLMacro8b 0 + mov cl,[Sflagc] + add cl,cl + rcl al,1 + flagsetnzc8b +%endmacro + +%macro ROLMacro16b 0 + mov cl,[Sflagc] + add cl,cl + rcl ax,1 + flagsetnzc +%endmacro + +%macro RORMacro8b 0 + mov cl,[Sflagc] + add cl,cl + rcr al,1 + flagsetnzc8b +%endmacro + +%macro RORMacro16b 0 + mov cl,[Sflagc] + add cl,cl + rcr ax,1 + flagsetnzc +%endmacro + +%macro RTIMacro 0 + cmp byte[curexecstate],0 + jne .nn + xor dh,dh +.nn +.nodis658162 + mov byte[curnmi],0 + + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov dl,al + restoredl + + inc cx + and cx,word[stackand] + call membank0r8 + mov [xpc],al + inc cx + and cx,word[stackand] + call membank0r8 + mov [xpc+1],al + inc cx + and cx,word[stackand] + call membank0r8 + mov [SA1xpb],al + mov [SA1xs],cx + + xor bh,bh + xor eax,eax + mov bl,dl + mov edi,[SA1tablead+ebx*4] + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + cmp eax,4300h + jae .upperlower + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[SA1xx+1],0 + mov byte[SA1xy+1],0 + endloop +.upperlower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +.dma + mov esi,dmadata-4300h + mov [initaddrl],esi + add esi,eax + test dl,00010000b + jnz .setx + endloop +%endmacro + +%macro RTLMacro 0 + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [xpc],al + inc cx + and cx,word[stackand] + call membank0r8 + mov [xpc+1],al + inc cx + and cx,word[stackand] + call membank0r8 + mov [SA1xpb],al + mov [SA1xs],cx + + xor bh,bh + xor eax,eax + inc word[xpc] + mov bl,[SA1xpb] + mov ax,[xpc] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro RTSMacro 0 + mov cx,[SA1xs] + inc cx + and cx,word[stackand] + call membank0r8 + mov [xpc],al + inc cx + and cx,word[stackand] + call membank0r8 + mov [xpc+1],al + mov [SA1xs],cx + + xor bh,bh + inc word[xpc] + xor eax,eax + mov ax,[xpc] + mov bl,[SA1xpb] + test eax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +.loweraddr + mov esi,[snesmap2+ebx*4] + mov [initaddrl],esi + add esi,eax + endloop +%endmacro + +%macro SBCMacro8bnd 0 + mov cl,[Sflagc] + sub cl,1 + sbb [SA1xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bnd 0 + mov cl,[Sflagc] + sub cl,1 + sbb [SA1xa],ax + flagsetnvzcs16b + endloop +%endmacro + +%macro SBCMacro8bd 0 + mov cl,[Sflagc] + sub cl,1 + mov cl,al + mov al,[SA1xa] + sbb al,cl + das + mov [SA1xa],al + flagsetnvzcs8b + endloop +%endmacro + +%macro SBCMacro16bd 0 + mov cl,[Sflagc] + sub cl,1 + mov cx,ax + mov al,[SA1xa] + sbb al,cl + das + mov [SA1xa],al + mov al,[SA1xa+1] + sbb al,ch + das + mov [SA1xa+1],al + cmc + flagsetnvzcd + endloop +%endmacro + +%macro SEPMacro 0 + mov al,[esi] + inc esi + test al,11000011b + jnz .extraflags + or dl,al + mov bl,dl + mov edi,[SA1tablead+ebx*4] + test dl,00010000b + jnz .setx + endloop +.setx + mov byte[SA1xx+1],0 + mov byte[SA1xy+1],0 + endloop +.extraflags + makedl + or dl,al + restoredl + mov bl,dl + mov edi,[SA1tablead+ebx*4] + test dl,00010000b + jnz .setx2 + endloop +.setx2 + mov byte[SA1xx+1],0 + mov byte[SA1xy+1],0 + endloop +%endmacro + +%macro STAMacro8b 0 + mov al,[SA1xa] +%endmacro + +%macro STAMacro16b 0 + mov eax,[SA1xa] +%endmacro + +%macro STXMacro8b 0 + mov al,[SA1xx] +%endmacro + +%macro STXMacro16b 0 + mov eax,[SA1xx] +%endmacro + +%macro STYMacro8b 0 + mov al,[SA1xy] +%endmacro + +%macro STYMacro16b 0 + mov eax,[SA1xy] +%endmacro + +%macro WAIMacro 0 + cmp byte[intrset],1 + jne .notws + dec esi + endloop +.notws + test byte[intrset],0FFh + jz .waitstate + cmp byte[intrset],2 + je .stopint + dec esi + endloop +.waitstate + mov byte[intrset],1 + dec esi + endloop +.stopint + mov byte[intrset],0 + endloop +%endmacro + +%macro XCEMacro 0 + mov al,[Sflagc] + mov dword[Sflagc],0 + and al,00000001b + test byte[xe],0FFh + jz .noemul + mov dword[Sflagc],0FFh +.noemul + mov [xe],al + test byte[xe],01h + jnz .emul + or dl,00100000b + mov word[stackand],0FFFFh + mov word[stackor],0000h + endloop +.emul + or dl,00110000b + mov bl,dl + mov edi,[SA1tablead+ebx*4] + mov byte[SA1xx+1],0 + mov byte[SA1xy+1],0 + mov byte[SA1xs+1],1 + mov word[stackand],01FFh + mov word[stackor],0100h + endloop +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/saddress.inc b/zsnes/src/cpu/saddress.inc new file mode 100644 index 00000000..265e3bc9 --- /dev/null +++ b/zsnes/src/cpu/saddress.inc @@ -0,0 +1,812 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM SA1DPageR8,SA1DPageR16,SA1DPageW8,SA1DPageW16 + + + + + + +;******************************************************* +; Address Modes +;******************************************************* + +; 1. Immediate Addressing -- # - DONE IN PROGRAM + +%macro addr_I_8br 0 + mov al,[esi] + inc esi +%endmacro + +%macro addr_I_16br 0 + mov eax,[esi] + add esi,2 +%endmacro + +; 2. Absolute -- a (TESTED) + +%macro addr_a_8br 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_a_16br 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_a_8bw 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_a_16bw 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + call dword near [memtablew16+ebx*4] +%endmacro + +; 3. Absolute Long -- al + +%macro addr_al_8br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_al_16br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_al_8bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_al_16bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + call dword near [memtablew16+ebx*4] +%endmacro + +; 4. Direct -- d (TESTED) + +%macro addr_d_8br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR8] +%endmacro + +%macro addr_d_16br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] +%endmacro + +%macro addr_d_8bw 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageW8] +%endmacro + +%macro addr_d_16bw 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageW16] +%endmacro + +; 5. Accumulator -- A + +%macro addr_A_8br 0 + mov al,[SA1xa] +%endmacro + +%macro addr_A_16br 0 + mov eax,[SA1xa] +%endmacro + +%macro addr_A_8bw 0 + mov [SA1xa],al +%endmacro + +%macro addr_A_16bw 0 + mov [SA1xa],ax +%endmacro + +; 7. Direct Indirect Indexed -- (d),y + +%macro addr_BdBCy_8br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdBCy_16br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdBCy_8bw 0 + push ax + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .np + inc bl +.np + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdBCy_16bw 0 + push ax + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .np + inc bl +.np + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 8. Direct Indirect Indexed Long -- [d],y + +%macro addr_LdLCy_8br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdLCy_16br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_LdLCy_8bw 0 + push ax + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[SA1xy] + pop ax + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_LdLCy_16bw 0 + push ax + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + push cx + call membank0r16 + pop cx + add cx,2 + xor bl,bl + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[SA1xy] + pop ax + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 9. Direct Indexed Indirect -- (d,x) + +%macro addr_BdCxB_8br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCxB_16br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdCxB_8bw 0 + push ax + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdCxB_16bw 0 + push ax + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 10. Direct Indexed With X -- d,x + +%macro addr_dCx_8br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0r8 +%endmacro + +%macro addr_dCx_16br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0r16 +%endmacro + +%macro addr_dCx_8bw 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0w8 +%endmacro + +%macro addr_dCx_16bw 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xx] + call membank0w16 +%endmacro + +; 11. Direct Indexed With Y -- d,y + +%macro addr_dCy_8br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xy] + call membank0r8 +%endmacro + +%macro addr_dCy_16br 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xy] + call membank0r16 +%endmacro + +%macro addr_dCy_8bw 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xy] + call membank0w8 +%endmacro + +%macro addr_dCy_16bw 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + inc esi + add cx,[SA1xy] + call membank0w16 +%endmacro + +; 12. Absolute Indexed With X -- a,x + +%macro addr_aCx_8br 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCx_16br 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_aCx_8bw 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_aCx_16bw 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 13. Absolute Indexed With Y -- a,y + +%macro addr_aCy_8br 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCy_16br 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_aCy_8bw 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_aCy_16bw 0 + mov cx,[esi] + mov bl,[SA1xdb] + add esi,2 + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 14. Absolute Long Indexed With X -- al,x + +%macro addr_alCx_8br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_alCx_16br 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_alCx_8bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_alCx_16bw 0 + mov cx,[esi] + mov bl,[esi+2] + add esi,3 + add cx,[SA1xx] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + +; 18. Direct Indirect -- (d) +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; | 00 | (direct address) | +; + | DB | +; ------------------------------- +; Address: | effective address | + +%macro addr_BdB_8br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdB_16br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdB_8bw 0 + push ax + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdB_16bw 0 + push ax + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 19. Direct Indirect Long -- [d] +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; ------------------------------- +; Address: | (direct address) | + +%macro addr_LdL_8br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdL_16br 0 + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_LdL_8bw 0 + push ax + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + pop ax + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_LdL_16bw 0 + push ax + mov bl,[esi] + mov ecx,[SA1xd] + inc esi + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + pop ax + call dword near [memtablew16+ebx*4] +%endmacro + +; 22. Stack Relative -- d,s + +%macro addr_dCs_8br 0 + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0r8 +%endmacro + +%macro addr_dCs_16br 0 + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0r16 +%endmacro + +%macro addr_dCs_8bw 0 + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0w8 +%endmacro + +%macro addr_dCs_16bw 0 + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0w16 +%endmacro + +; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED) + +%macro addr_BdCsBCy_8br 0 + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16br 0 + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtabler16+ebx*4] +%endmacro + +%macro addr_BdCsBCy_8bw 0 + push ax + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + pop ax + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtablew8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16bw 0 + push ax + mov bl,[esi] + mov cx,[SA1xs] + inc esi + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + pop ax + add cx,[SA1xy] + jnc .np + inc bl +.np + call dword near [memtablew16+ebx*4] +%endmacro + \ No newline at end of file diff --git a/zsnes/src/cpu/saddrni.inc b/zsnes/src/cpu/saddrni.inc new file mode 100644 index 00000000..bc1184c1 --- /dev/null +++ b/zsnes/src/cpu/saddrni.inc @@ -0,0 +1,404 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + +;******************************************************* +; Address Modes +;******************************************************* + +; 1. Immediate Addressing -- # - DONE IN PROGRAM + +%macro addr_I_8brni 0 + mov al,[esi] +%endmacro + +%macro addr_I_16brni 0 + mov ax,[esi] +%endmacro + +; 2. Absolute -- a (TESTED) + +%macro addr_a_8brni 0 + mov cx,[esi] + mov bl,[SA1xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_a_16brni 0 + mov cx,[esi] + mov bl,[SA1xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 3. Absolute Long -- al + +%macro addr_al_8brni 0 + mov cx,[esi] + mov bl,[esi+2] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_al_16brni 0 + mov cx,[esi] + mov bl,[esi+2] + call dword near [memtabler16+ebx*4] +%endmacro + +; 4. Direct -- d (TESTED) + +%macro addr_d_8brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + call dword near [SA1DPageR8] +%endmacro + +%macro addr_d_16brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + call dword near [SA1DPageR16] +%endmacro + +; 5. Accumulator -- A + +%macro addr_A_8brni 0 + mov al,[SA1xa] +%endmacro + +%macro addr_A_16brni 0 + mov ax,[SA1xa] +%endmacro + +; 7. Direct Indirect Indexed -- (d),y + +%macro addr_BdBCy_8brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdBCy_16brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 8. Direct Indirect Indexed Long -- [d],y + +%macro addr_LdLCy_8brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdLCy_16brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 9. Direct Indexed Indirect -- (d,x) + +%macro addr_BdCxB_8brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + add cx,[SA1xx] + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCxB_16brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + add cx,[SA1xx] + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 10. Direct Indexed With X -- d,x + +%macro addr_dCx_8brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + add cx,[SA1xx] + call membank0r8 +%endmacro + +%macro addr_dCx_16brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + add cx,[SA1xx] + call membank0r16 +%endmacro + +; 11. Direct Indexed With Y -- d,y + +%macro addr_dCy_8brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + add cx,[SA1xy] + call membank0r8 +%endmacro + +%macro addr_dCy_16brni 0 + mov ecx,[SA1xd] + mov bl,[esi] + add cx,bx + add cx,[SA1xy] + call membank0r16 +%endmacro + +; 12. Absolute Indexed With X -- a,x + +%macro addr_aCx_8brni 0 + mov cx,[esi] + mov bl,[SA1xdb] + add cx,[SA1xx] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCx_16brni 0 + mov cx,[esi] + mov bl,[SA1xdb] + add cx,[SA1xx] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 13. Absolute Indexed With Y -- a,y + +%macro addr_aCy_8brni 0 + mov cx,[esi] + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_aCy_16brni 0 + mov cx,[esi] + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 14. Absolute Long Indexed With X -- al,x + +%macro addr_alCx_8brni 0 + mov cx,[esi] + mov bl,[esi+2] + add cx,[SA1xx] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_alCx_16brni 0 + mov cx,[esi] + mov bl,[esi+2] + add cx,[SA1xx] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + +; 18. Direct Indirect -- (d) +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; | 00 | (direct address) | +; + | DB | +; ------------------------------- +; Address: | effective address | + +%macro addr_BdB_8brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdB_16brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + call dword near [SA1DPageR16] + mov cx,ax + mov bl,[SA1xdb] + call dword near [memtabler16+ebx*4] +%endmacro + +; 19. Direct Indirect Long -- [d] +; ___________________ +; Instruction: | opcode | offset | +; ~~~~~~~~~~~~~~~~~~~ +; | Direct Register | +; + | offset | +; --------------------- +; | 00 | direct address | +; then: +; ------------------------------- +; Address: | (direct address) | + +%macro addr_LdL_8brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_LdL_16brni 0 + mov bl,[esi] + mov ecx,[SA1xd] + add cx,bx + push cx + call membank0r16 + pop cx + add cx,2 + push ax + call membank0r8 + mov bl,al + pop ax + mov cx,ax + call dword near [memtabler16+ebx*4] +%endmacro + +; 22. Stack Relative -- d,s + +%macro addr_dCs_8brni 0 + mov bl,[esi] + mov cx,[SA1xs] + add cx,bx + call membank0r8 +%endmacro + +%macro addr_dCs_16brni 0 + mov bl,[esi] + mov cx,[SA1xs] + add cx,bx + call membank0r16 +%endmacro + +; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED) + +%macro addr_BdCsBCy_8brni 0 + mov bl,[esi] + mov cx,[SA1xs] + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler8+ebx*4] +%endmacro + +%macro addr_BdCsBCy_16brni 0 + mov bl,[esi] + mov cx,[SA1xs] + add cx,bx + call membank0r16 + mov cx,ax + mov bl,[SA1xdb] + add cx,[SA1xy] + jnc .npb + inc bl +.npb + call dword near [memtabler16+ebx*4] +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/cpu/se65816.inc b/zsnes/src/cpu/se65816.inc new file mode 100644 index 00000000..06c8b939 --- /dev/null +++ b/zsnes/src/cpu/se65816.inc @@ -0,0 +1,1990 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM brkv,brkv8,copv,copv8,curexecstate,curnmi +EXTSYM initaddrl,membank0r16,membank0r8 +EXTSYM membank0w16,membank0w8,memtabler16,memtabler8,memtablew16,memtablew8 +EXTSYM nmistatus,regaccessbankr8,snesmap2,snesmmap,stackand,stackor +EXTSYM wramdata,SA1xa,SA1xd,SA1xdb,xe,xirqb,SA1xpb,xpc,SA1xs,SA1xx,SA1xy +EXTSYM switchtovirq,cpuoverptr,debstop4 + + + + + + +; B = ( or ) +; C = , +; L = [ or ] +; I = # + + +SA1COp61m8nd: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bnd +SA1COp61m16nd: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bnd +SA1COp61m8d: ; ADC(d,x) + addr_BdCxB_8br + ADCMacro8bd +SA1COp61m16d: ; ADC(d,x) + addr_BdCxB_16br + ADCMacro16bd +SA1COp63m8nd: ; ADC d,s + addr_dCs_8br + ADCMacro8bnd +SA1COp63m16nd: ; ADC d,s + addr_dCs_16br + ADCMacro16bnd +SA1COp63m8d: ; ADC d,s + addr_dCs_8br + ADCMacro8bd +SA1COp63m16d: ; ADC d,s + addr_dCs_16br + ADCMacro16bd +SA1COp65m8nd: ; ADC d + addr_d_8br + ADCMacro8bnd +SA1COp65m16nd: ; ADC d + addr_d_16br + ADCMacro16bnd +SA1COp65m8d: ; ADC d + addr_d_8br + ADCMacro8bd +SA1COp65m16d: ; ADC d + addr_d_16br + ADCMacro16bd +SA1COp67m8nd: ; ADC [d] + addr_LdL_8br + ADCMacro8bnd +SA1COp67m16nd: ; ADC [d] + addr_LdL_16br + ADCMacro16bnd +SA1COp67m8d: ; ADC [d] + addr_LdL_8br + ADCMacro8bd +SA1COp67m16d: ; ADC [d] + addr_LdL_16br + ADCMacro16bd +SA1COp69m8nd: ; ADC # + addr_I_8br + ADCMacro8bnd +SA1COp69m16nd: ; ADC # + addr_I_16br + ADCMacro16bnd +SA1COp69m8d: ; ADC # + addr_I_8br + ADCMacro8bd +SA1COp69m16d: ; ADC # + addr_I_16br + ADCMacro16bd +SA1COp6Dm8nd: ; ADC a + addr_a_8br + ADCMacro8bnd +SA1COp6Dm16nd: ; ADC a + addr_a_16br + ADCMacro16bnd +SA1COp6Dm8d: ; ADC a + addr_a_8br + ADCMacro8bd +SA1COp6Dm16d: ; ADC a + addr_a_16br + ADCMacro16bd +SA1COp6Fm8nd: ; ADC al + addr_al_8br + ADCMacro8bnd +SA1COp6Fm16nd: ; ADC al + addr_al_16br + ADCMacro16bnd +SA1COp6Fm8d: ; ADC al + addr_al_8br + ADCMacro8bd +SA1COp6Fm16d: ; ADC al + addr_al_16br + ADCMacro16bd +SA1COp71m8nd: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bnd +SA1COp71m16nd: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bnd +SA1COp71m8d: ; ADC(d),y + addr_BdBCy_8br + ADCMacro8bd +SA1COp71m16d: ; ADC(d),y + addr_BdBCy_16br + ADCMacro16bd +SA1COp72m8nd: ; ADC (d) + addr_BdB_8br + ADCMacro8bnd +SA1COp72m16nd: ; ADC (d) + addr_BdB_16br + ADCMacro16bnd +SA1COp72m8d: ; ADC (d) + addr_BdB_8br + ADCMacro8bd +SA1COp72m16d: ; ADC (d) + addr_BdB_16br + ADCMacro16bd +SA1COp73m8nd: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bnd +SA1COp73m16nd: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bnd +SA1COp73m8d: ; ADC(d,s),y + addr_BdCsBCy_8br + ADCMacro8bd +SA1COp73m16d: ; ADC(d,s),y + addr_BdCsBCy_16br + ADCMacro16bd +SA1COp75m8nd: ; ADC d,x + addr_dCx_8br + ADCMacro8bnd +SA1COp75m16nd: ; ADC d,x + addr_dCx_16br + ADCMacro16bnd +SA1COp75m8d: ; ADC d,x + addr_dCx_8br + ADCMacro8bd +SA1COp75m16d: ; ADC d,x + addr_dCx_16br + ADCMacro16bd +SA1COp77m8nd: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bnd +SA1COp77m16nd: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bnd +SA1COp77m8d: ; ADC [d],y + addr_LdLCy_8br + ADCMacro8bd +SA1COp77m16d: ; ADC [d],y + addr_LdLCy_16br + ADCMacro16bd +SA1COp79m8nd: ; ADC a,y + addr_aCy_8br + ADCMacro8bnd +SA1COp79m16nd: ; ADC a,y + addr_aCy_16br + ADCMacro16bnd +SA1COp79m8d: ; ADC a,y + addr_aCy_8br + ADCMacro8bd +SA1COp79m16d: ; ADC a,y + addr_aCy_16br + ADCMacro16bd +SA1COp7Dm8nd: ; ADC a,x + addr_aCx_8br + ADCMacro8bnd +SA1COp7Dm16nd: ; ADC a,x + addr_aCx_16br + ADCMacro16bnd +SA1COp7Dm8d: ; ADC a,x + addr_aCx_8br + ADCMacro8bd +SA1COp7Dm16d: ; ADC a,x + addr_aCx_16br + ADCMacro16bd +SA1COp7Fm8nd: ; ADC al,x + addr_alCx_8br + ADCMacro8bnd +SA1COp7Fm16nd: ; ADC al,x + addr_alCx_16br + ADCMacro16bnd +SA1COp7Fm8d: ; ADC al,x + addr_alCx_8br + ADCMacro8bd +SA1COp7Fm16d: ; ADC al,x + addr_alCx_16br + ADCMacro16bd + +SA1COp21m8: ; AND(d,x) + addr_BdCxB_8br + ANDMacro8b +SA1COp21m16:; AND(d,x) + addr_BdCxB_16br + ANDMacro16b +SA1COp23m8: ; AND d,s + addr_dCs_8br + ANDMacro8b +SA1COp23m16:; AND d,s + addr_dCs_16br + ANDMacro16b +SA1COp25m8: ; AND d + addr_d_8br + ANDMacro8b +SA1COp25m16:; AND d + addr_d_16br + ANDMacro16b +SA1COp27m8: ; AND [d] + addr_LdL_8br + ANDMacro8b +SA1COp27m16:; AND [d] + addr_LdL_16br + ANDMacro16b +SA1COp29m8: ; AND # + addr_I_8br + ANDMacro8b +SA1COp29m16:; AND # + addr_I_16br + ANDMacro16b +SA1COp2Dm8: ; AND a + addr_a_8br + ANDMacro8b +SA1COp2Dm16:; AND a + addr_a_16br + ANDMacro16b +SA1COp2Fm8: ; AND al + addr_al_8br + ANDMacro8b +SA1COp2Fm16:; AND al + addr_al_16br + ANDMacro16b +SA1COp31m8: ; AND(d),y + addr_BdBCy_8br + ANDMacro8b +SA1COp31m16:; AND(d),y + addr_BdBCy_16br + ANDMacro16b +SA1COp32m8: ; AND (d) + addr_BdB_8br + ANDMacro8b +SA1COp32m16:; AND (d) + addr_BdB_16br + ANDMacro16b +SA1COp33m8: ; AND(d,s),y + addr_BdCsBCy_8br + ANDMacro8b +SA1COp33m16:; AND(d,s),y + addr_BdCsBCy_16br + ANDMacro16b +SA1COp35m8: ; AND d,x + addr_dCx_8br + ANDMacro8b +SA1COp35m16:; AND d,x + addr_dCx_16br + ANDMacro16b +SA1COp37m8: ; AND [d],y + addr_LdLCy_8br + ANDMacro8b +SA1COp37m16:; AND [d],y + addr_LdLCy_16br + ANDMacro16b +SA1COp39m8: ; AND a,y + addr_aCy_8br + ANDMacro8b +SA1COp39m16:; AND a,y + addr_aCy_16br + ANDMacro16b +SA1COp3Dm8: ; AND a,x + addr_aCx_8br + ANDMacro8b +SA1COp3Dm16:; AND a,x + addr_aCx_16br + ANDMacro16b +SA1COp3Fm8: ; AND al,x + addr_alCx_8br + ANDMacro8b +SA1COp3Fm16:; AND al,x + addr_alCx_16br + ANDMacro16b + +SA1COp06m8: ; ASL d + addr_d_8brni + ASLMacro8b + addr_d_8bw + endloop +SA1COp06m16:; ASL d + addr_d_16brni + ASLMacro16b + addr_d_16bw + endloop +SA1COp0Am8: ; ASL A + addr_A_8brni + ASLMacro8b + addr_A_8bw + endloop +SA1COp0Am16:; ASL A + addr_A_16brni + ASLMacro16b + addr_A_16bw + endloop +SA1COp0Em8: ; ASL a + addr_a_8brni + ASLMacro8b + addr_a_8bw + endloop +SA1COp0Em16:; ASL a + addr_a_16brni + ASLMacro16b + addr_a_16bw + endloop +SA1COp16m8: ; ASL d,x + addr_dCx_8brni + ASLMacro8b + addr_dCx_8bw + endloop +SA1COp16m16:; ASL d,x + addr_dCx_16brni + ASLMacro16b + addr_dCx_16bw + endloop +SA1COp1Em8: ; ASL a,x + addr_aCx_8brni + ASLMacro8b + addr_aCx_8bw + endloop +SA1COp1Em16:; ASL a,x + addr_aCx_16brni + ASLMacro16b + addr_aCx_16bw + endloop + +SA1COp90: ; BCC r + test byte[Sflagc],01h + jnz .skip + JumpMacro +SA1COpB0: ; BCS r + test byte[Sflagc],01h + jz .skip + JumpMacro +SA1COpF0: ; BEQ r + test dword[Sflagnz],0FFFFh + jnz .skip + JumpMacro +SA1COp30: ; BMI r + test dword[Sflagnz],018000h + jz .skip + JumpMacro +SA1COpD0: ; BNE r + test dword[Sflagnz],0FFFFh + jz .skip + JumpMacro +SA1COp10: ; BPL r + test dword[Sflagnz],018000h + jnz .skip + JumpMacro +SA1COp80: ; BRA r + movsx eax,byte[esi] + inc esi + add esi,eax + endloop +SA1COp50: ; BVC r + test dword[Sflago],0FFh + jnz .skip + JumpMacro +SA1COp70: ; BVS r + test dword[Sflago],0FFh + jz .skip + JumpMacro + +; BIT instruction does not affect N and V flags when using immediate +; addressing mode. When using other addressing modes, the N and V flags + +SA1COp89m8: ; BIT # + BITMacroim8b +SA1COp89m16:; BIT # + BITMacroim16b + +SA1COp24m8: ; BIT d + addr_d_8br + BITMacro8b +SA1COp24m16:; BIT d + addr_d_16br + BITMacro16b +SA1COp2Cm8: ; BIT a + addr_a_8br + BITMacro8b +SA1COp2Cm16:; BIT a + addr_a_16br + BITMacro16b +SA1COp34m8: ; BIT d,x + addr_dCx_8br + BITMacro8b +SA1COp34m16:; BIT d,x + addr_dCx_16br + BITMacro16b +SA1COp3Cm8: ; BIT a,x + addr_aCx_8br + BITMacro8b +SA1COp3Cm16:; BIT a,x + addr_aCx_16br + BITMacro16b + +SA1COp00: ; BRK s + mov byte[debstop4],1 + dec esi + endloop + BRKMacro + +SA1COp82: ; BRL rl + BRLMacro + +SA1COp18: ; CLC i + mov dword[Sflagc],0 + endloop +SA1COpD8: ; CLD i + and dl,0F7h + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop +SA1COp58: ; CLI i + and dl,0FBh + endloop +SA1COpB8: ; CLV i + mov dword[Sflago],0 + endloop + +SA1COpC1m8: ; CMP(d,x) + addr_BdCxB_8br + CMPMacro8b +SA1COpC1m16:; CMP(d,x) + addr_BdCxB_16br + CMPMacro16b +SA1COpC3m8: ; CMP d,s + addr_dCs_8br + CMPMacro8b +SA1COpC3m16:; CMP d,s + addr_dCs_16br + CMPMacro16b +SA1COpC5m8: ; CMP d + addr_d_8br + CMPMacro8b +SA1COpC5m16:; CMP d + addr_d_16br + CMPMacro16b +SA1COpC7m8: ; CMP [d] + addr_LdL_8br + CMPMacro8b +SA1COpC7m16:; CMP [d] + addr_LdL_16br + CMPMacro16b +SA1COpC9m8: ; CMP # + addr_I_8br + CMPMacro8b +SA1COpC9m16:; CMP # + addr_I_16br + CMPMacro16b +SA1COpCDm8: ; CMP a + addr_a_8br + CMPMacro8b +SA1COpCDm16:; CMP a + addr_a_16br + CMPMacro16b +SA1COpCFm8: ; CMP al + addr_al_8br + CMPMacro8b +SA1COpCFm16:; CMP al + addr_al_16br + CMPMacro16b +SA1COpD1m8: ; CMP(d),y + addr_BdBCy_8br + CMPMacro8b +SA1COpD1m16:; CMP(d),y + addr_BdBCy_16br + CMPMacro16b +SA1COpD2m8: ; CMP (d) + addr_BdB_8br + CMPMacro8b +SA1COpD2m16:; CMP (d) + addr_BdB_16br + CMPMacro16b +SA1COpD3m8: ; CMP(d,s),y + addr_BdCsBCy_8br + CMPMacro8b +SA1COpD3m16:; CMP(d,s),y + addr_BdCsBCy_16br + CMPMacro16b +SA1COpD5m8: ; CMP d,x + addr_dCx_8br + CMPMacro8b +SA1COpD5m16:; CMP d,x + addr_dCx_16br + CMPMacro16b +SA1COpD7m8: ; CMP [d],y + addr_LdLCy_8br + CMPMacro8b +SA1COpD7m16:; CMP [d],y + addr_LdLCy_16br + CMPMacro16b +SA1COpD9m8: ; CMP a,y + addr_aCy_8br + CMPMacro8b +SA1COpD9m16:; CMP a,y + addr_aCy_16br + CMPMacro16b +SA1COpDDm8: ; CMP a,x + addr_aCx_8br + CMPMacro8b +SA1COpDDm16:; CMP a,x + addr_aCx_16br + CMPMacro16b +SA1COpDFm8: ; CMP al,x + addr_alCx_8br + CMPMacro8b +SA1COpDFm16:; CMP al,x + addr_alCx_16br + CMPMacro16b + +SA1COp02: ; SA1COp s + COPMacro + +SA1COpE0x8: ; CPX # + addr_I_8br + CPXMacro8b +SA1COpE0x16:; CPX # + addr_I_16br + CPXMacro16b +SA1COpE4x8: ; CPX d + addr_d_8br + CPXMacro8b +SA1COpE4x16:; CPX d + addr_d_16br + CPXMacro16b +SA1COpECx8: ; CPX a + addr_a_8br + CPXMacro8b +SA1COpECx16:; CPX a + addr_a_16br + CPXMacro16b + +SA1COpC0x8: ; CPY # + addr_I_8br + CPYMacro8b +SA1COpC0x16:; CPY # + addr_I_16br + CPYMacro16b +SA1COpC4x8: ; CPY d + addr_d_8br + CPYMacro8b +SA1COpC4x16:; CPY d + addr_d_16br + CPYMacro16b +SA1COpCCx8: ; CPY a + addr_a_8br + CPYMacro8b +SA1COpCCx16:; CPY a + addr_a_16br + CPYMacro16b + +SA1COp3Am8: ; DEC A + addr_A_8brni + dec al + flagsetnz8bnel + addr_A_8bw + endloop +SA1COp3Am16:; DEC A + addr_A_16brni + dec ax + flagsetnz16bnel + addr_A_16bw + endloop +SA1COpCEm8: ; DEC a + addr_a_8brni + dec al + flagsetnz8bnel + addr_a_8bw + endloop +SA1COpCEm16:; DEC a + addr_a_16brni + dec ax + flagsetnz16bnel + addr_a_16bw + endloop +SA1COpC6m8: ; DEC d + addr_d_8brni + dec al + flagsetnz8bnel + addr_d_8bw + endloop +SA1COpC6m16:; DEC d + addr_d_16brni + dec ax + flagsetnz16bnel + addr_d_16bw + endloop +SA1COpD6m8: ; DEC d,x + addr_dCx_16brni + dec al + flagsetnz8bnel + addr_dCx_16bw + endloop +SA1COpD6m16:; DEC d,x + addr_dCx_16brni + dec ax + flagsetnz16bnel + addr_dCx_16bw + endloop +SA1COpDEm8: ; DEC a,x + addr_aCx_8brni + dec al + flagsetnz8bnel + addr_aCx_8bw + endloop +SA1COpDEm16:; DEC a,x + addr_aCx_16brni + dec ax + flagsetnz16bnel + addr_aCx_16bw + endloop + +SA1COpCAx8: ; DEX i + dec byte[SA1xx] + mov al,[SA1xx] + flagsetnz8b + endloop +SA1COpCAx16:; DEX i + dec word[SA1xx] + mov ax,[SA1xx] + flagsetnz16b + endloop +SA1COp88x8: ; DEY i + dec byte[SA1xy] + mov al,[SA1xy] + flagsetnz8b + endloop +SA1COp88x16:; DEY i + dec word[SA1xy] + mov ax,[SA1xy] + flagsetnz16b + endloop + +SA1COp41m8: ; EOR(d,x) + addr_BdCxB_8br + EORMacro8b +SA1COp41m16:; EOR(d,x) + addr_BdCxB_16br + EORMacro16b +SA1COp43m8: ; EOR d,s + addr_dCs_8br + EORMacro8b +SA1COp43m16:; EOR d,s + addr_dCs_16br + EORMacro16b +SA1COp45m8: ; EOR d + addr_d_8br + EORMacro8b +SA1COp45m16:; EOR d + addr_d_16br + EORMacro16b +SA1COp47m8: ; EOR [d] + addr_LdL_8br + EORMacro8b +SA1COp47m16:; EOR [d] + addr_LdL_16br + EORMacro16b +SA1COp49m8: ; EOR # + addr_I_8br + EORMacro8b +SA1COp49m16:; EOR # + addr_I_16br + EORMacro16b +SA1COp4Dm8: ; EOR a + addr_a_8br + EORMacro8b +SA1COp4Dm16:; EOR a + addr_a_16br + EORMacro16b +SA1COp4Fm8: ; EOR al + addr_al_8br + EORMacro8b +SA1COp4Fm16:; EOR al + addr_al_16br + EORMacro16b +SA1COp51m8: ; EOR(d),y + addr_BdBCy_8br + EORMacro8b +SA1COp51m16:; EOR(d),y + addr_BdBCy_16br + EORMacro16b +SA1COp52m8: ; EOR (d) + addr_BdB_8br + EORMacro8b +SA1COp52m16:; EOR (d) + addr_BdB_16br + EORMacro16b +SA1COp53m8: ; EOR(d,s),y + addr_BdCsBCy_8br + EORMacro8b +SA1COp53m16:; EOR(d,s),y + addr_BdCsBCy_16br + EORMacro16b +SA1COp55m8: ; EOR d,x + addr_dCx_8br + EORMacro8b +SA1COp55m16:; EOR d,x + addr_dCx_16br + EORMacro16b +SA1COp57m8: ; EOR [d],y + addr_LdLCy_8br + EORMacro8b +SA1COp57m16:; EOR [d],y + addr_LdLCy_16br + EORMacro16b +SA1COp59m8: ; EOR a,y + addr_aCy_8br + EORMacro8b +SA1COp59m16:; EOR a,y + addr_aCy_16br + EORMacro16b +SA1COp5Dm8: ; EORa,x + addr_aCx_8br + EORMacro8b +SA1COp5Dm16:; EORa,x + addr_aCx_16br + EORMacro16b +SA1COp5Fm8: ; EOR al,x + addr_alCx_8br + EORMacro8b +SA1COp5Fm16:; EOR al,x + addr_alCx_16br + EORMacro16b + + +SA1COp1Am8: ; INC A + addr_A_8brni + inc al + flagsetnz8bnel + addr_A_8bw + endloop +SA1COp1Am16:; INC A + addr_A_16brni + inc ax + flagsetnz16bnel + addr_A_16bw + endloop +SA1COpEEm8: ; INC a + addr_a_8brni + inc al + flagsetnz8bnel + addr_a_8bw + endloop +SA1COpEEm16:; INC a + addr_a_16brni + inc ax + flagsetnz16bnel + addr_a_16bw + endloop +SA1COpE6m8: ; INC d + addr_d_8brni + inc al + flagsetnz8bnel + addr_d_8bw + endloop +SA1COpE6m16:; INC d + addr_d_16brni + inc ax + flagsetnz16bnel + addr_d_16bw + endloop +SA1COpF6m8: ; INC d,x + addr_dCx_8brni + inc al + flagsetnz8bnel + addr_dCx_8bw + endloop +SA1COpF6m16:; INC d,x + addr_dCx_16brni + inc ax + flagsetnz16bnel + addr_dCx_16bw + endloop +SA1COpFEm8: ; INC a,x + addr_aCx_8brni + inc al + flagsetnz8bnel + addr_aCx_8bw + endloop +SA1COpFEm16:; INC a,x + addr_aCx_16brni + inc ax + flagsetnz16bnel + addr_aCx_16bw + endloop + + +SA1COpE8x8: ; INX i + inc byte[SA1xx] + mov al,[SA1xx] + flagsetnz8b + endloop +SA1COpE8x16:; INX i + inc word[SA1xx] + mov ax,[SA1xx] + flagsetnz16b + endloop +SA1COpC8x8: ; INY i + inc byte[SA1xy] + mov al,[SA1xy] + flagsetnz8b + endloop +SA1COpC8x16:; INY i + inc word[SA1xy] + mov ax,[SA1xy] + flagsetnz16b + endloop + +SA1COpDC: ; JML (a) + JMLMacro +SA1COp4C: ; JMP a + JMPMacro4C +SA1COp6C: ; JMP (a) + JMPMacro6C +SA1COp7C: ; JMP(a,x) + JMPMacro7C +SA1COp5C: ; JMP al + JMPMacro5C + +SA1COp22: ; JSL al + JSLMacro +SA1COp20: ; JSR a + JSRMacro20 +SA1COpFC: ; JSR(a,x) + JSRMacroFC + +SA1COpA1m8: ; LDA(d,x) + addr_BdCxB_8br + LDAMacro8b +SA1COpA1m16:; LDA(d,x) + addr_BdCxB_16br + LDAMacro16b +SA1COpA3m8: ; LDA d,s + addr_dCs_8br + LDAMacro8b +SA1COpA3m16:; LDA d,s + addr_dCs_16br + LDAMacro16b +SA1COpA5m8: ; LDA d + addr_d_8br + LDAMacro8b +SA1COpA5m16:; LDA d + addr_d_16br + LDAMacro16b +SA1COpA7m8: ; LDA [d] + addr_LdL_8br + LDAMacro8b +SA1COpA7m16:; LDA [d] + addr_LdL_16br + LDAMacro16b +SA1COpA9m8: ; LDA # + addr_I_8br + LDAMacro8b +SA1COpA9m16:; LDA # + addr_I_16br + LDAMacro16b +SA1COpADm8: ; LDA a + addr_a_8br + LDAMacro8b +SA1COpADm16:; LDA a + addr_a_16br + LDAMacro16b +SA1COpAFm8: ; LDA al + addr_al_8br + LDAMacro8b +SA1COpAFm16:; LDA al + addr_al_16br + LDAMacro16b +SA1COpB1m8: ; LDA(d),y + addr_BdBCy_8br + LDAMacro8b +SA1COpB1m16:; LDA(d),y + addr_BdBCy_16br + LDAMacro16b +SA1COpB2m8: ; LDA (d) + addr_BdB_8br + LDAMacro8b +SA1COpB2m16:; LDA (d) + addr_BdB_16br + LDAMacro16b +SA1COpB3m8: ; LDA(d,s),y + addr_BdCsBCy_8br + LDAMacro8b +SA1COpB3m16:; LDA(d,s),y + addr_BdCsBCy_16br + LDAMacro16b +SA1COpB5m8: ; LDA d,x + addr_dCx_8br + LDAMacro8b +SA1COpB5m16:; LDA d,x + addr_dCx_16br + LDAMacro16b +SA1COpB7m8: ; LDA [d],y + addr_LdLCy_8br + LDAMacro8b +SA1COpB7m16:; LDA [d],y + addr_LdLCy_16br + LDAMacro16b +SA1COpB9m8: ; LDA a,y + addr_aCy_8br + LDAMacro8b +SA1COpB9m16:; LDA a,y + addr_aCy_16br + LDAMacro16b +SA1COpBDm8: ; LDA a,x + addr_aCx_8br + LDAMacro8b +SA1COpBDm16:; LDA a,x + addr_aCx_16br + LDAMacro16b +SA1COpBFm8: ; LDA al,x + addr_alCx_8br + LDAMacro8b +SA1COpBFm16:; LDA al,x + addr_alCx_16br + LDAMacro16b + +SA1COpA2x8: ; LDX # + addr_I_8br + LDXMacro8b +SA1COpA2x16:; LDX # + addr_I_16br + LDXMacro16b +SA1COpA6x8: ; LDX d + addr_d_8br + LDXMacro8b +SA1COpA6x16:; LDX d + addr_d_16br + LDXMacro16b +SA1COpAEx8: ; LDX a + addr_a_8br + LDXMacro8b +SA1COpAEx16:; LDX a + addr_a_16br + LDXMacro16b +SA1COpB6x8: ; LDX d,y + addr_dCy_8br + LDXMacro8b +SA1COpB6x16:; LDX d,y + addr_dCy_16br + LDXMacro16b +SA1COpBEx8: ; LDX a,y + addr_aCy_8br + LDXMacro8b +SA1COpBEx16:; LDX a,y + addr_aCy_16br + LDXMacro16b + +SA1COpA0x8: ; LDY # + addr_I_8br + LDYMacro8b +SA1COpA0x16:; LDY # + addr_I_16br + LDYMacro16b +SA1COpA4x8: ; LDY d + addr_d_8br + LDYMacro8b +SA1COpA4x16:; LDY d + addr_d_16br + LDYMacro16b +SA1COpACx8: ; LDY a + addr_a_8br + LDYMacro8b +SA1COpACx16:; LDY a + addr_a_16br + LDYMacro16b +SA1COpB4x8: ; LDY d,x + addr_dCx_8br + LDYMacro8b +SA1COpB4x16:; LDY d,x + addr_dCx_16br + LDYMacro16b +SA1COpBCx8: ; LDY a,x + addr_aCx_8br + LDYMacro8b +SA1COpBCx16:; LDY a,x + addr_aCx_16br + LDYMacro16b + +SA1COp46m8: ; LSR d + addr_d_8brni + LSRMacro8b + addr_d_8bw + endloop +SA1COp46m16:; LSR d + addr_d_16brni + LSRMacro16b + addr_d_16bw + endloop +SA1COp4Am8: ; LSR A + addr_A_8brni + LSRMacro8b + addr_A_8bw + endloop +SA1COp4Am16:; LSR A + addr_A_16brni + LSRMacro16b + addr_A_16bw + endloop +SA1COp4Em8: ; LSR a + addr_a_8brni + LSRMacro8b + addr_a_8bw + endloop +SA1COp4Em16:; LSR a + addr_a_16brni + LSRMacro16b + addr_a_16bw + endloop +SA1COp56m8: ; LSR d,x + addr_dCx_8brni + LSRMacro8b + addr_dCx_8bw + endloop +SA1COp56m16:; LSR d,x + addr_dCx_16brni + LSRMacro16b + addr_dCx_16bw + endloop +SA1COp5Em8: ; LSRa,x + addr_aCx_8brni + LSRMacro8b + addr_aCx_8bw + endloop +SA1COp5Em16:; LSRa,x + addr_aCx_16brni + LSRMacro16b + addr_aCx_16bw + endloop + +SA1COp54: ; MVN SA1xya + MVNMacro +SA1COp44: ; MVP SA1xya + MVPMacro + +SA1COpEA: ; NOP i + endloop + +SA1COp01m8: ; ORA(d,x) + addr_BdCxB_8br + ORAMacro8b +SA1COp01m16:; ORA(d,x) + addr_BdCxB_16br + ORAMacro16b +SA1COp03m8: ; ORA d,s + addr_dCs_8br + ORAMacro8b +SA1COp03m16:; ORA d,s + addr_dCs_16br + ORAMacro16b +SA1COp05m8: ; ORA d + addr_d_8br + ORAMacro8b +SA1COp05m16:; ORA d + addr_d_16br + ORAMacro16b +SA1COp07m8: ; ORA [d] + addr_LdL_8br + ORAMacro8b +SA1COp07m16:; ORA [d] + addr_LdL_16br + ORAMacro16b +SA1COp09m8: ; ORA # + addr_I_8br + ORAMacro8b +SA1COp09m16:; ORA # + addr_I_16br + ORAMacro16b +SA1COp0Dm8: ; ORA a + addr_a_8br + ORAMacro8b +SA1COp0Dm16:; ORA a + addr_a_16br + ORAMacro16b +SA1COp0Fm8: ; ORA al + addr_al_8br + ORAMacro8b +SA1COp0Fm16:; ORA al + addr_al_16br + ORAMacro16b +SA1COp11m8: ; ORA(d),y + addr_BdBCy_8br + ORAMacro8b +SA1COp11m16:; ORA(d),y + addr_BdBCy_16br + ORAMacro16b +SA1COp12m8: ; ORA(d) + addr_BdB_8br + ORAMacro8b +SA1COp12m16:; ORA(d) + addr_BdB_16br + ORAMacro16b +SA1COp13m8: ; ORA(d,s),y + addr_BdCsBCy_8br + ORAMacro8b +SA1COp13m16:; ORA(d,s),y + addr_BdCsBCy_16br + ORAMacro16b +SA1COp15m8: ; ORA d,x + addr_dCx_8br + ORAMacro8b +SA1COp15m16:; ORA d,x + addr_dCx_16br + ORAMacro16b +SA1COp17m8: ; ORA [d],y + addr_LdLCy_8br + ORAMacro8b +SA1COp17m16:; ORA [d],y + addr_LdLCy_16br + ORAMacro16b +SA1COp19m8: ; ORA a,y + addr_aCy_8br + ORAMacro8b +SA1COp19m16:; ORA a,y + addr_aCy_16br + ORAMacro16b +SA1COp1Dm8: ; ORA a,x + addr_aCx_8br + ORAMacro8b +SA1COp1Dm16:; ORA a,x + addr_aCx_16br + ORAMacro16b +SA1COp1Fm8: ; ORA al,x + addr_alCx_8br + ORAMacro8b +SA1COp1Fm16:; ORA al,x + addr_alCx_16br + ORAMacro16b + +SA1COpF4: ; PEA s + PEAMacro +SA1COpD4: ; PEI s + PEIMacro +SA1COp62: ; PER s + PERMacro + +SA1COp48m8: ; PHA s + PUSHMacro8b [SA1xa] +SA1COp48m16:; PHA s + PUSHMacro16b [SA1xa], [SA1xa+1] +SA1COp8B: ; PHB s + PUSHMacro8b [SA1xdb] +SA1COp0B: ; PHD s + PUSHMacro16b [SA1xd], [SA1xd+1] +SA1COp4B: ; PHK s + PUSHMacro8b [SA1xpb] +SA1COp08: ; PHP s + PUSHMacro8bp +SA1COpDAx8: ; PHX s + PUSHMacro8b [SA1xx] +SA1COpDAx16:; PHX s + PUSHMacro16b [SA1xx], [SA1xx+1] +SA1COp5Ax8: ; PHY s + PUSHMacro8b [SA1xy] +SA1COp5Ax16:; PHY s + PUSHMacro16b [SA1xy], [SA1xy+1] + +SA1COp68m8: ; PLA s + POPMacro8b [SA1xa] +SA1COp68m16:; PLA s + POPMacro16b [SA1xa], [SA1xa+1] +SA1COpAB: ; PLB s + POPMacro8b [SA1xdb] +SA1COp2B: ; PLD s + POPMacro16bd [SA1xd], [SA1xd+1] +SA1COp28: ; PLP s + POPMacroP +SA1COpFAx8: ; PLX s + POPMacro8b [SA1xx] +SA1COpFAx16:; PLX s + POPMacro16b [SA1xx], [SA1xx+1] +SA1COp7Ax8: ; PLY s + POPMacro8b [SA1xy] +SA1COp7Ax16:; PLY s + POPMacro16b [SA1xy], [SA1xy+1] + +SA1COpC2: ; REP # + REPMacro + +SA1COp26m8: ; ROL d + addr_d_8brni + ROLMacro8b + addr_d_8bw + endloop +SA1COp26m16:; ROL d + addr_d_16brni + ROLMacro16b + addr_d_16bw + endloop +SA1COp2Am8: ; ROL A + addr_A_8brni + ROLMacro8b + addr_A_8bw + endloop +SA1COp2Am16:; ROL A + addr_A_16brni + ROLMacro16b + addr_A_16bw + endloop +SA1COp2Em8: ; ROL a + addr_a_8brni + ROLMacro8b + addr_a_8bw + endloop +SA1COp2Em16:; ROL a + addr_a_16brni + ROLMacro16b + addr_a_16bw + endloop +SA1COp36m8: ; ROL d,x + addr_dCx_8brni + ROLMacro8b + addr_dCx_8bw + endloop +SA1COp36m16:; ROL d,x + addr_dCx_16brni + ROLMacro16b + addr_dCx_16bw + endloop +SA1COp3Em8: ; ROL a,x + addr_aCx_8brni + ROLMacro8b + addr_aCx_8bw + endloop +SA1COp3Em16:; ROL a,x + addr_aCx_16brni + ROLMacro16b + addr_aCx_16bw + endloop + +SA1COp66m8: ; ROR d + addr_d_8brni + RORMacro8b + addr_d_8bw + endloop +SA1COp66m16:; ROR d + addr_d_16brni + RORMacro16b + addr_d_16bw + endloop +SA1COp6Am8: ; ROR A + addr_A_8brni + RORMacro8b + addr_A_8bw + endloop +SA1COp6Am16:; ROR A + addr_A_16brni + RORMacro16b + addr_A_16bw + endloop +SA1COp6Em8: ; ROR a + addr_a_8brni + RORMacro8b + addr_a_8bw + endloop +SA1COp6Em16:; ROR a + addr_a_16brni + RORMacro16b + addr_a_16bw + endloop +SA1COp76m8: ; ROR d,x + addr_dCx_8brni + RORMacro8b + addr_dCx_8bw + endloop +SA1COp76m16:; ROR d,x + addr_dCx_16brni + RORMacro16b + addr_dCx_16bw + endloop +SA1COp7Em8: ; ROR a,x + addr_aCx_8brni + RORMacro8b + addr_aCx_8bw + endloop +SA1COp7Em16:; ROR a,x + addr_aCx_16brni + RORMacro16b + addr_aCx_16bw + endloop + +SA1COp40: ; RTI s + RTIMacro +SA1COp6B: ; RTL s + RTLMacro +SA1COp60: ; RTS s + RTSMacro + +SA1COpE1m8nd: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bnd +SA1COpE1m16nd: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bnd +SA1COpE1m8d: ; SBC(d,x) + addr_BdCxB_8br + SBCMacro8bd +SA1COpE1m16d: ; SBC(d,x) + addr_BdCxB_16br + SBCMacro16bd +SA1COpE3m8nd: ; SBC d,s + addr_dCs_8br + SBCMacro8bnd +SA1COpE3m16nd: ; SBC d,s + addr_dCs_16br + SBCMacro16bnd +SA1COpE3m8d: ; SBC d,s + addr_dCs_8br + SBCMacro8bd +SA1COpE3m16d: ; SBC d,s + addr_dCs_16br + SBCMacro16bd +SA1COpE5m8nd: ; SBC d + addr_d_8br + SBCMacro8bnd +SA1COpE5m16nd: ; SBC d + addr_d_16br + SBCMacro16bnd +SA1COpE5m8d: ; SBC d + addr_d_8br + SBCMacro8bd +SA1COpE5m16d: ; SBC d + addr_d_16br + SBCMacro16bd +SA1COpE7m8nd: ; SBC [d] + addr_LdL_8br + SBCMacro8bnd +SA1COpE7m16nd: ; SBC [d] + addr_LdL_16br + SBCMacro16bnd +SA1COpE7m8d: ; SBC [d] + addr_LdL_8br + SBCMacro8bd +SA1COpE7m16d: ; SBC [d] + addr_LdL_16br + SBCMacro16bd +SA1COpE9m8nd: ; SBC # + addr_I_8br + SBCMacro8bnd +SA1COpE9m16nd: ; SBC # + addr_I_16br + SBCMacro16bnd +SA1COpE9m8d: ; SBC # + addr_I_8br + SBCMacro8bd +SA1COpE9m16d: ; SBC # + addr_I_16br + SBCMacro16bd +SA1COpEDm8nd: ; SBC a + addr_a_8br + SBCMacro8bnd +SA1COpEDm16nd: ; SBC a + addr_a_16br + SBCMacro16bnd +SA1COpEDm8d: ; SBC a + addr_a_8br + SBCMacro8bd +SA1COpEDm16d: ; SBC a + addr_a_16br + SBCMacro16bd +SA1COpEFm8nd: ; SBC al + addr_al_8br + SBCMacro8bnd +SA1COpEFm16nd: ; SBC al + addr_al_16br + SBCMacro16bnd +SA1COpEFm8d: ; SBC al + addr_al_8br + SBCMacro8bd +SA1COpEFm16d: ; SBC al + addr_al_16br + SBCMacro16bd +SA1COpF1m8nd: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bnd +SA1COpF1m16nd: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bnd +SA1COpF1m8d: ; SBC(d),y + addr_BdBCy_8br + SBCMacro8bd +SA1COpF1m16d: ; SBC(d),y + addr_BdBCy_16br + SBCMacro16bd +SA1COpF2m8nd: ; SBC (d) + addr_BdB_8br + SBCMacro8bnd +SA1COpF2m16nd: ; SBC (d) + addr_BdB_16br + SBCMacro16bnd +SA1COpF2m8d: ; SBC (d) + addr_BdB_8br + SBCMacro8bd +SA1COpF2m16d: ; SBC (d) + addr_BdB_16br + SBCMacro16bd +SA1COpF3m8nd: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bnd +SA1COpF3m16nd: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bnd +SA1COpF3m8d: ; SBC(d,s),y + addr_BdCsBCy_8br + SBCMacro8bd +SA1COpF3m16d: ; SBC(d,s),y + addr_BdCsBCy_16br + SBCMacro16bd +SA1COpF5m8nd: ; SBC d,x + addr_dCx_8br + SBCMacro8bnd +SA1COpF5m16nd: ; SBC d,x + addr_dCx_16br + SBCMacro16bnd +SA1COpF5m8d: ; SBC d,x + addr_dCx_8br + SBCMacro8bd +SA1COpF5m16d: ; SBC d,x + addr_dCx_16br + SBCMacro16bd +SA1COpF7m8nd: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bnd +SA1COpF7m16nd: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bnd +SA1COpF7m8d: ; SBC [d],y + addr_LdLCy_8br + SBCMacro8bd +SA1COpF7m16d: ; SBC [d],y + addr_LdLCy_16br + SBCMacro16bd +SA1COpF9m8nd: ; SBC a,y + addr_aCy_8br + SBCMacro8bnd +SA1COpF9m16nd: ; SBC a,y + addr_aCy_16br + SBCMacro16bnd +SA1COpF9m8d: ; SBC a,y + addr_aCy_8br + SBCMacro8bd +SA1COpF9m16d: ; SBC a,y + addr_aCy_16br + SBCMacro16bd +SA1COpFDm8nd: ; SBC a,x + addr_aCx_8br + SBCMacro8bnd +SA1COpFDm16nd: ; SBC a,x + addr_aCx_16br + SBCMacro16bnd +SA1COpFDm8d: ; SBC a,x + addr_aCx_8br + SBCMacro8bd +SA1COpFDm16d: ; SBC a,x + addr_aCx_16br + SBCMacro16bd +SA1COpFFm8nd: ; SBC al,x + addr_alCx_8br + SBCMacro8bnd +SA1COpFFm16nd: ; SBC al,x + addr_alCx_16br + SBCMacro16bnd +SA1COpFFm8d: ; SBC al,x + addr_alCx_8br + SBCMacro8bd +SA1COpFFm16d: ; SBC al,x + addr_alCx_16br + SBCMacro16bd + +SA1COp38: ; SEC i + mov dword[Sflagc],0FFh + endloop +SA1COpF8: ; SED i + or dl,08h + mov bl,dl + mov edi,[SA1tablead+ebx*4] + endloop +SA1COp78: ; SEI i + or dl,04h + endloop + +SA1COpE2: ; SEP # + SEPMacro + +SA1COp81m8: ; STA(d,x) + STAMacro8b + addr_BdCxB_8bw + endloop +SA1COp81m16:; STA(d,x) + STAMacro16b + addr_BdCxB_16bw + endloop +SA1COp83m8: ; STA d,s + STAMacro8b + addr_dCs_8bw + endloop +SA1COp83m16:; STA d,s + STAMacro16b + addr_dCs_16bw + endloop +SA1COp85m8: ; STA d + STAMacro8b + addr_d_8bw + endloop +SA1COp85m16:; STA d + STAMacro16b + addr_d_16bw + endloop +SA1COp87m8: ; STA [d] + STAMacro8b + addr_LdL_8bw + endloop +SA1COp87m16:; STA [d] + STAMacro16b + addr_LdL_16bw + endloop +SA1COp8Dm8: ; STA a + STAMacro8b + addr_a_8bw + endloop +SA1COp8Dm16:; STA a + STAMacro16b + addr_a_16bw + endloop +SA1COp8Fm8: ; STA al + STAMacro8b + addr_al_8bw + endloop +SA1COp8Fm16:; STA al + STAMacro16b + addr_al_16bw + endloop +SA1COp91m8: ; STA(d),y + STAMacro8b + addr_BdBCy_8bw + endloop +SA1COp91m16:; STA(d),y + STAMacro16b + addr_BdBCy_16bw + endloop +SA1COp92m8: ; STA (d) + STAMacro8b + addr_BdB_8bw + endloop +SA1COp92m16:; STA (d) + STAMacro16b + addr_BdB_16bw + endloop +SA1COp93m8: ; STA(d,s),y + STAMacro8b + addr_BdCsBCy_8bw + endloop +SA1COp93m16:; STA(d,s),y + STAMacro16b + addr_BdCsBCy_16bw + endloop +SA1COp95m8: ; STA d,x + STAMacro8b + addr_dCx_8bw + endloop +SA1COp95m16:; STA d,x + STAMacro16b + addr_dCx_16bw + endloop +SA1COp97m8: ; STA [d],y + STAMacro8b + addr_LdLCy_8bw + endloop +SA1COp97m16:; STA [d],y + STAMacro16b + addr_LdLCy_16bw + endloop +SA1COp99m8: ; STA a,y + STAMacro8b + addr_aCy_8bw + endloop +SA1COp99m16:; STA a,y + STAMacro16b + addr_aCy_16bw + endloop +SA1COp9Dm8: ; STA a,x + STAMacro8b + addr_aCx_8bw + endloop +SA1COp9Dm16:; STA a,x + STAMacro16b + addr_aCx_16bw + endloop +SA1COp9Fm8: ; STA al,x + STAMacro8b + addr_alCx_8bw + endloop +SA1COp9Fm16:; STA al,x + STAMacro16b + addr_alCx_16bw + endloop + +SA1COp86x8: ; STX d + STXMacro8b + addr_d_8bw + endloop +SA1COp86x16:; STX d + STXMacro16b + addr_d_16bw + endloop +SA1COp8Ex8: ; STX a + STXMacro8b + addr_a_8bw + endloop +SA1COp8Ex16:; STX a + STXMacro16b + addr_a_16bw + endloop +SA1COp96x8: ; STX d,y + STXMacro8b + addr_dCy_8bw + endloop +SA1COp96x16:; STX d,y + STXMacro16b + addr_dCy_16bw + endloop + +SA1COp84x8: ; STY d + STYMacro8b + addr_d_8bw + endloop +SA1COp84x16:; STY d + STYMacro16b + addr_d_16bw + endloop +SA1COp8Cx8: ; STY a + STYMacro8b + addr_a_8bw + endloop +SA1COp8Cx16:; STY a + STYMacro16b + addr_a_16bw + endloop +SA1COp94x8: ; STYd,x + STYMacro8b + addr_dCx_8bw + endloop +SA1COp94x16:; STYd,x + STYMacro16b + addr_dCx_16bw + endloop + +SA1COpDB: ; STP i + dec esi + endloop + +SA1COp64m8: ; STZ d + xor al,al + addr_d_8bw + endloop +SA1COp64m16:; STZ d + xor eax,eax + addr_d_16bw + endloop +SA1COp74m8: ; STZ d,x + xor al,al + addr_dCx_8bw + endloop +SA1COp74m16:; STZ d,x + xor eax,eax + addr_dCx_16bw + endloop +SA1COp9Cm8: ; STZ a + xor al,al + addr_a_8bw + endloop +SA1COp9Cm16:; STZ a + xor eax,eax + addr_a_16bw + endloop +SA1COp9Em8: ; STZ a,x + xor al,al + addr_aCx_8bw + endloop +SA1COp9Em16:; STZ a,x + xor eax,eax + addr_aCx_16bw + endloop + +SA1COp14m8: ; TRB d + addr_d_8brni + mov cl,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test cl,al + jz .zero + mov word[Sflagnz],1 + not cl + and al,cl + addr_d_8bw + endloop +.zero + mov word[Sflagnz],0 + not cl + and al,cl + addr_d_8bw + endloop +SA1COp14m16:; TRB d + addr_d_16brni + mov cx,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[Sflagnz],1 + not cx + and ax,cx + addr_d_16bw + endloop +.zero + mov word[Sflagnz],0 + not cx + and ax,cx + addr_d_16bw + endloop +SA1COp1Cm8: ; TRB a + addr_a_8brni + mov cl,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test cl,al + jz .zero + mov word[Sflagnz],1 + not cl + and al,cl + addr_a_8bw + endloop +.zero + mov word[Sflagnz],0 + not cl + and al,cl + addr_a_8bw + endloop +SA1COp1Cm16:; TRB a + addr_a_16brni + mov cx,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test cx,ax + jz .zero + mov word[Sflagnz],1 + not cx + and ax,cx + addr_a_16bw + endloop +.zero + mov word[Sflagnz],0 + not cx + and ax,cx + addr_a_16bw + endloop + +SA1COp04m8: ; TSB d + addr_d_8brni + mov cl,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test al,cl + jz .zero + mov word[Sflagnz],1 + or al,cl + addr_d_8bw + endloop +.zero + mov word[Sflagnz],0 + or al,cl + addr_d_8bw + endloop +SA1COp04m16:; TSB d + addr_d_16brni + mov cx,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[Sflagnz],1 + or ax,cx + addr_d_16bw + endloop +.zero + mov word[Sflagnz],0 + or ax,cx + addr_d_16bw + endloop +SA1COp0Cm8: ; TSB a + addr_a_8brni + mov cl,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test al,cl + jz .zero + mov word[Sflagnz],1 + or al,cl + addr_a_8bw + endloop +.zero + mov word[Sflagnz],0 + or al,cl + addr_a_8bw + endloop +SA1COp0Cm16:; TSB a + addr_a_16brni + mov cx,[SA1xa] + test dword[Sflagnz],18000h + jz .notflags + or dword[Sflagnz],10000h +.notflags + test ax,cx + jz .zero + mov word[Sflagnz],1 + or ax,cx + addr_a_16bw + endloop +.zero + mov word[Sflagnz],0 + or ax,cx + addr_a_16bw + endloop + +SA1COpAAx8: ; TAX i + mov al,[SA1xa] + mov [SA1xx],al + flagsetnz8b + endloop +SA1COpAAx16:; TAX i + mov ax,[SA1xa] + mov [SA1xx],ax + flagsetnz16b + endloop +SA1COpA8x8: ; TAY i + mov al,[SA1xa] + mov [SA1xy],al + flagsetnz8b + endloop +SA1COpA8x16:; TAY i + mov ax,[SA1xa] + mov [SA1xy],ax + flagsetnz16b + endloop +SA1COp5B: ; TCD i + mov ax,[SA1xa] + mov [SA1xd],ax + call SA1UpdateDPage + flagsetnz16b + endloop +SA1COp1B: ; TCS i + mov ax,[SA1xa] + mov [SA1xs],ax + endloop +SA1COp7B: ; TDC i + mov ax,[SA1xd] + mov [SA1xa],ax + flagsetnz16b + endloop +SA1COp3B: ; TSC i + mov ax,[SA1xs] + mov [SA1xa],ax + flagsetnz16b + endloop +SA1COpBAx8: ; TSX i + mov al,[SA1xs] + mov [SA1xx],al + flagsetnz8b + endloop +SA1COpBAx16:; TSX i + mov ax,[SA1xs] + mov [SA1xx],ax + flagsetnz16b + endloop +SA1COp8Am8: ; TSA1xa i + mov al,[SA1xx] + mov [SA1xa],al + flagsetnz8b + endloop +SA1COp8Am16:; TXA i + mov ax,[SA1xx] + mov [SA1xa],ax + flagsetnz16b + endloop +SA1COp9A: ; TXS i + mov ax,[SA1xx] + mov [SA1xs],ax + test byte[xe],1 + jnz .emul + endloop +.emul + mov byte[SA1xs+1],1 + endloop +SA1COp9Bx8: ; TSA1xy i + mov al,[SA1xx] + mov [SA1xy],al + flagsetnz8b + endloop +SA1COp9Bx16:; TSA1xy i + mov ax,[SA1xx] + mov [SA1xy],ax + flagsetnz16b + endloop +SA1COp98m8: ; TYA i + mov al,[SA1xy] + mov [SA1xa],al + flagsetnz8b + endloop +SA1COp98m16:; TYA i + mov ax,[SA1xy] + mov [SA1xa],ax + flagsetnz16b + endloop +SA1COpBBx8: ; TYX i + mov al,[SA1xy] + mov [SA1xx],al + flagsetnz8b + endloop +SA1COpBBx16:; TYX i + mov ax,[SA1xy] + mov [SA1xx],ax + flagsetnz16b + endloop + +SA1COpCB: ; WAI i + WAIMacro + +SA1COpEB: ; XBA i + mov ah,[SA1xa] + mov al,[SA1xa+1] + mov [SA1xa],ax + flagsetnz8b + endloop + +SA1COpFB: ; XCE i + XCEMacro + +SA1COp42: ; WDM + inc esi + endloop + \ No newline at end of file diff --git a/zsnes/src/cpu/spc700.asm b/zsnes/src/cpu/spc700.asm new file mode 100644 index 00000000..f619673e --- /dev/null +++ b/zsnes/src/cpu/spc700.asm @@ -0,0 +1,2695 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM DSPMem,spcWptr,debstop,disablespcclr,SPCSkipXtraROM,SPC700sh +EXTSYM cycpbl,spcRptr +EXTSYM spc700read +EXTSYM dspWptr +EXTSYM changeexecloop,curexecstate,SA1Enable,tableadb + +%include "cpu/regsw.mac" +%include "cpu/spcdef.inc" +%include "cpu/spcaddr.inc" + + + + + + +; SPC 700 Emulation by _Demo_ +; Version 2.0 + +; Little info on functions : +; Write byte : write al at [ebx] +; Read byte : read al from [ebx] +; update timer : update the timers, called every scanline + + +ALIGN32 + +;spcBuffer times 65536*4 db 0 ; The buffer of brr blocks... 4 bits -> 16 bits +;spcRamcmp times 65536 db 0 ; SPC Ram compare buffer +;spcPrevbf times 65536 db 0 ; SPC PrevX compare buffer +NEWSYM spcRam, times 65472 db 0FFh ; Pointer to the SPC's RAM +; copy #1 +; THE SPC ROM :) + db 0CDh,0EFh,0BDh,0E8h,000h,0C6h,01Dh,0D0h,0FCh,08Fh,0AAh,0F4h,08Fh,0BBh,0F5h,078h + db 0CCh,0F4h,0D0h,0FBh,02Fh,019h,0EBh,0F4h,0D0h,0FCh,07Eh,0F4h,0D0h,00Bh,0E4h,0F5h + db 0CBh,0F4h,0D7h,000h,0FCh,0D0h,0F3h,0ABh,001h,010h,0EFh,07Eh,0F4h,010h,0EBh,0BAh + db 0F6h,0DAh,000h,0BAh,0F4h,0C4h,0F4h,0DDh,05Dh,0D0h,0DBh,01Fh,000h,000h,0C0h,0FFh + db 0AAh,0BBh,0CCh,0DDh,0EEh,0FFh,000h,011h,022h,033h,044h,055h,066h,077h,088h,099h + +NEWSYM spcPCRam, + dd 0 ; Program Counter (with spcRam added) +NEWSYM spcA, + db 0 ; The A register (general purpose) + db 0 + db 0 + db 0 +NEWSYM spcX, + db 0 ; The X register (general purpose) + db 0 + db 0 + db 0 +NEWSYM spcY, + db 0 ; The Y register (general purpose) + db 0 + db 0 + db 0 +NEWSYM spcP, + db 0 ; The processor status byte (Removed for each flags) + db 0 ; NZ are not always processed... + db 0 + db 0 +NEWSYM spcNZ, + db 0 ; The processor NZ flag (little speed up hack :) ) + db 0 + db 0 + db 0 + + +;spcNF db 0 ; The Negative Flag 128 or 127 +;spcOF db 0 ; The Overflow Flag 64 or 191 +;spcDPF db 0 ; Direct Page Flag 32 or 223 +;spcUF db 0 ; The Unused Flag ? 16 or 239 +;spcHCF db 0 ; The Half Carry Flag 8 or 247 +;spcIF db 0 ; The interrupt flag 4 or 251 +;spcZF db 0 ; The Zero Flag 2 or 253 +;spcCF db 0 ; The Carry Flag 1 or 254 + +NEWSYM spcS, dd 1FFh ; The stack pointer (always from 100 to 1FF) (added Ram) +NEWSYM spcRamDP, dd 0 ; The direct page pointer +NEWSYM spcCycle, dd 0 ; The Cycle Counter +NEWSYM reg1read, db 0 ; read from 65816 +NEWSYM reg2read, db 0 ; read from 65816 +NEWSYM reg3read, db 0 ; read from 65816 +NEWSYM reg4read, db 0 ; read from 65816 +NEWSYM timeron, db 0 ; timer0 on +NEWSYM timincr0, db 0 ; # of ticks before incrementing +NEWSYM timincr1, db 0 ; # of ticks before incrementing +NEWSYM timincr2, db 0 ; # of ticks before incrementing +NEWSYM timinl0, db 0 ; ticks left before incrementing +NEWSYM timinl1, db 0 ; ticks left before incrementing +NEWSYM timinl2, db 0 ; ticks left before incrementing +NEWSYM timrcall, db 0 ; alternating bit 0 to correctly timer timer1 & 2 to 8000hz + +NEWSYM spcextraram, times 64 db 0 ; extra ram, used for tcall + +NEWSYM FutureExpandS, times 256-64 db 0 + +spcsave equ $-spcRam +; pharos equ hack *sigh* +NEWSYM PHspcsave, dd spcsave + +; copy #2 +NEWSYM SPCROM + db 0CDh,0EFh,0BDh,0E8h,000h,0C6h,01Dh,0D0h,0FCh,08Fh,0AAh,0F4h,08Fh,0BBh,0F5h,078h + db 0CCh,0F4h,0D0h,0FBh,02Fh,019h,0EBh,0F4h,0D0h,0FCh,07Eh,0F4h,0D0h,00Bh,0E4h,0F5h + db 0CBh,0F4h,0D7h,000h,0FCh,0D0h,0F3h,0ABh,001h,010h,0EFh,07Eh,0F4h,010h,0EBh,0BAh + db 0F6h,0DAh,000h,0BAh,0F4h,0C4h,0F4h,0DDh,05Dh,0D0h,0DBh,01Fh,000h,000h,0C0h,0FFh + +%macro WriteByte 0 + cmp ebx,0ffh+spcRam + ja .extramem + cmp ebx,0f0h+spcRam + jb .normalmem + sub ebx,spcRam + call dword near [spcWptr+ebx*4-0f0h*4] + jmp .finished +.extramem + cmp ebx,0ffc0h+spcRam + jb .normalmem + mov [spcextraram+ebx-0FFC0h-spcRam],al + test byte[spcRam+0F1h],80h + jnz .finished +; push ecx +; mov cl,[DSPMem+06Ch] +; test cl,20h +; pop ecx +; jz .finished +.normalmem + mov [ebx],al +.finished +%endmacro + +%macro ReadByte 0 + cmp ebx,0f0h+spcRam + jb .rnormalmem2 + cmp ebx,0ffh+spcRam + ja .rnormalmem + sub ebx,spcRam + call dword near [spcRptr+ebx*4-0f0h*4] + jmp .rfinished +.rnormalmem +; cmp ebx,0ffc0h+spcRam +; jb .rnormalmem2 +; test byte [DSPMem+6Ch],10h +; jz .rnormalmem2 +; mov al,[spcextraram+ebx-0FFC0h-spcRam] +; jmp .rfinished +.rnormalmem2 + mov al,[ebx] +.rfinished +%endmacro + +%macro ReadByte2 0 + cmp ebx,0f0h+spcRam + jb .rnormalmem2 + cmp ebx,0ffh+spcRam + ja .rnormalmem + sub ebx,spcRam + call dword near [spcRptr+ebx*4-0f0h*4] + add ebx,spcRam + jmp .rfinished +.rnormalmem +; cmp ebx,0ffc0h+spcRam +; jb .rnormalmem2 +; test byte [DSPMem+6Ch],10h +; jz .rnormalmem2 +; mov al,[spcextraram+ebx-0FFC0h-spcRam] +; jmp .rfinished +.rnormalmem2 + mov al,[ebx] +.rfinished +%endmacro + +NEWSYM timer2upd, dd 0 +; This function is called every scanline (262*60 times/sec) +; Make it call 0.9825 times (393/400) (skip when divisible by 64) +; 2 8khz, 1 64khz + +NEWSYM updatetimer +; inc dword[timer2upd] +; cmp dword[timer2upd],400 +; jne .nowrap +; mov dword[timer2upd],0 +;.nowrap +;.again +; mov eax,dword[timer2upd] +; shr eax,6 +; shl eax,6 +; cmp eax,dword[timer2upd] +; je near .noin2d + + +.another + xor byte[timrcall],01h + test byte[timrcall],01h + jz near .notimer + test byte[timeron],1 + jz .noin0 + dec byte[timinl0] + jnz .noin0 + inc byte[spcRam+0FDh] + mov al,[timincr0] + mov [timinl0],al + cmp byte[spcRam+0FDh],1 + jne .noin0 + reenablespc + mov dword[cycpbl],0 +.noin0 + test byte[timeron],2 + jz .noin1 + dec byte[timinl1] + jnz .noin1 + inc byte[spcRam+0FEh] + mov al,[timincr1] + mov [timinl1],al + cmp byte[spcRam+0FEh],1 + jne .noin1 + reenablespc + mov dword[cycpbl],0 +.noin1 +.notimer + test byte[timeron],4 + jz near .noin2d2 + dec byte[timinl2] + jnz .noin2 + inc byte[spcRam+0FFh] + mov al,[timincr2] + mov [timinl2],al + cmp byte[spcRam+0FFh],1 + jne .noin2 + reenablespc + mov dword[cycpbl],0 +.noin2 + dec byte[timinl2] + jnz .noin2b + inc byte[spcRam+0FFh] + mov al,[timincr2] + mov [timinl2],al + cmp byte[spcRam+0FFh],1 + jne .noin2b + reenablespc + mov dword[cycpbl],0 +.noin2b + dec byte[timinl2] + jnz .noin2c + inc byte[spcRam+0FFh] + mov al,[timincr2] + mov [timinl2],al + cmp byte[spcRam+0FFh],1 + jne .noin2c + reenablespc + mov dword[cycpbl],0 +.noin2c + dec byte[timinl2] + jnz .noin2d + inc byte[spcRam+0FFh] + mov al,[timincr2] + mov [timinl2],al + cmp byte[spcRam+0FFh],1 + jne .noin2d + reenablespc + mov dword[cycpbl],0 +.noin2d +.noin2d2 +; inc dword[timer2upd] +; cmp dword[timer2upd],31 +; jne .nowrap +; mov dword[timer2upd],0 +; jmp .again +;.nowrap + + inc dword[timer2upd] + cmp dword[timer2upd],60 + jne .noanother + mov dword[timer2upd],0 + jmp .another +.noanother + + ret + + +; SPC Write Registers +; DO NOT MODIFY DX OR ECX! +NEWSYM SPCRegF0 + mov [spcRam+0F0h],al + ret +NEWSYM SPCRegF1 + cmp byte[disablespcclr],1 + je .No23Clear + test al,10h + jz .No01Clear + mov byte [spcRam+0F4h],0 + mov byte [spcRam+0F5h],0 +.No01Clear + test al,20h + jz .No23Clear + mov byte [spcRam+0F6h],0 + mov byte [spcRam+0F7h],0 +.No23Clear + cmp byte[SPCSkipXtraROM],1 + je near .AfterNoROM + test al,80h + jz .NoROM + push eax + push ebx + xor eax,eax +.loopa + mov bl,[SPCROM+eax] + mov [spcRam+0FFC0h+eax],bl + inc eax + cmp eax,040h + jne .loopa + pop ebx + pop eax + jmp .AfterNoROM +.NoROM + push eax + push ebx + xor eax,eax +.loopb + mov bl,[spcextraram+eax] + mov [spcRam+0FFC0h+eax],bl + inc eax + cmp eax,040h + jne .loopb + pop ebx + pop eax +.AfterNoROM + mov [spcRam+0F1h],al + and al,0Fh + mov [timeron],al + ret +NEWSYM SPCRegF2 + mov [spcRam+0F2h],al + push eax + push ebx + xor eax,eax + mov al,[spcRam+0F2h] + mov bl,[DSPMem+eax] + mov [spcRam+0F3h],bl + pop ebx + pop eax + ret +NEWSYM SPCRegF3 + push ebx + xor ebx,ebx + mov bl,[spcRam+0F2h] + and bl,07fh + call dword near [dspWptr+ebx*4] + pop ebx + mov [spcRam+ebx],al + ret +NEWSYM SPCRegF4 + mov [reg1read],al + inc dword[spc700read] + ret +NEWSYM SPCRegF5 + mov [reg2read],al + inc dword[spc700read] + ret +NEWSYM SPCRegF6 + mov [reg3read],al + inc dword[spc700read] + ret +NEWSYM SPCRegF7 + mov [reg4read],al + inc dword[spc700read] + ret +NEWSYM SPCRegF8 + mov [spcRam+ebx],al + ret +NEWSYM SPCRegF9 + mov [spcRam+ebx],al + ret +NEWSYM SPCRegFA + mov [timincr0],al + test byte[timinl0],0FFh + jne .nowrite + mov [timinl0],al +.nowrite + mov [spcRam+ebx],al + ret +NEWSYM SPCRegFB + mov [timincr1],al + test byte[timinl1],0FFh + jne .nowrite + mov [timinl1],al +.nowrite + mov [spcRam+ebx],al + ret +NEWSYM SPCRegFC + mov [timincr2],al + test byte[timinl2],0FFh + jne .nowrite + mov [timinl2],al +.nowrite + mov [spcRam+ebx],al + ret +NEWSYM SPCRegFD + ret +NEWSYM SPCRegFE + ret +NEWSYM SPCRegFF + ret + +; SPC Read Registers +; DO NOT MODIFY ANY REG! +; return data true al +NEWSYM RSPCRegF0 + mov al,[spcRam+0f0h] + ret +NEWSYM RSPCRegF1 + mov al,[spcRam+0f1h] + ret +NEWSYM RSPCRegF2 + mov al,[spcRam+0f2h] + ret +NEWSYM RSPCRegF3 + mov al,[spcRam+0f3h] + ret +NEWSYM RSPCRegF4 + mov al,[spcRam+0f4h] + ret +NEWSYM RSPCRegF5 + mov al,[spcRam+0f5h] + ret +NEWSYM RSPCRegF6 + mov al,[spcRam+0f6h] + ret +NEWSYM RSPCRegF7 + mov al,[spcRam+0f7h] + ret +NEWSYM RSPCRegF8 + mov al,0 ;[spcRam+0f8h] + ret +NEWSYM RSPCRegF9 + mov al,0 ;[spcRam+0f9h] + ret +NEWSYM RSPCRegFA + mov al,[spcRam+0fah] + ret +NEWSYM RSPCRegFB + mov al,[spcRam+0fbh] + ret +NEWSYM RSPCRegFC + mov al,[spcRam+0fch] + ret +NEWSYM RSPCRegFD + mov al,[spcRam+0fdh] + and al,0Fh + cmp byte[spcRam+0fdh],0 + je spcnextskip + mov byte [spcRam+0fdh],0 + mov byte [spcnumread],0 + ret +NEWSYM RSPCRegFE + mov al,[spcRam+0feh] + and al,0Fh + cmp byte[spcRam+0feh],0 + je spcnextskip + mov byte [spcRam+0feh],0 + mov byte [spcnumread],0 + ret +NEWSYM RSPCRegFF + mov al,[spcRam+0ffh] + and al,0Fh + cmp byte[spcRam+0ffh],0 + je spcnextskip + mov byte [spcRam+0ffh],0 + mov byte [spcnumread],0 + ret +NEWSYM spcnextskip + inc byte[spcnumread] + cmp byte[spcnumread],5 + je near haltspc + ret + +NEWSYM haltspc + cmp byte[SPC700sh],1 + je .nochangestate + mov dword[cycpbl],0FFFFFFFFh + test byte[curexecstate],02h + jz .nochangestate + and byte[curexecstate],0FDh + push ebx + xor ebx,ebx + mov bl,dl + mov edi,[tableadb+ebx*4] + pop ebx +.nochangestate + mov byte[spcnumread],0 + ret + +NEWSYM spcnumread, db 0 + + +%macro SPCSetFlagnzc 0 + js .setsignflag + jz .setzeroflag + mov byte [spcNZ],1 + jc .setcarryflag + and byte [spcP],0FEh + ret +.setsignflag + mov byte [spcNZ],80h + jc .setcarryflag + and byte [spcP],0FEh + ret +.setzeroflag + mov byte [spcNZ],0 + jc .setcarryflag + and byte [spcP],0FEh + ret +.setcarryflag + or byte [spcP],1 + ret +%endmacro + +%macro SPCSetFlagnzcnoret 0 + js .setsignflag + jz .setzeroflag + mov byte [spcNZ],1 + jc .setcarryflag + and byte [spcP],0FEh + jmp .skipflags +.setsignflag + mov byte [spcNZ],80h + jc .setcarryflag + and byte [spcP],0FEh + jmp .skipflags +.setzeroflag + mov byte [spcNZ],0 + jc .setcarryflag + and byte [spcP],0FEh + jmp .skipflags +.setcarryflag + or byte [spcP],1 +.skipflags +%endmacro + +;spcNF db 0 ; The Negative Flag 128 or 127 80h +;spcOF db 0 ; The Overflow Flag 64 or 191 40h +;spcDPF db 0 ; Direct Page Flag 32 or 223 20h +;spcUF db 0 ; The Unused Flag ? 16 or 239 10h +;spcHCF db 0 ; The Half Carry Flag 8 or 247 08h +;spcIF db 0 ; The interrupt flag 4 or 251 04h +;spcZF db 0 ; The Zero Flag 2 or 253 02h +;spcCF db 0 ; The Carry Flag 1 or 254 01h +; test byte[spcP],08h +; jz .nohcarry +; or ah,00010000b +;.nohcarry + +%macro SPCSetFlagnvhzc 0 + lahf + js .setsignflag + jz .setzeroflag + mov byte [spcNZ],1 + jo .setoverflowflag + and byte [spcP],0BFh + jmp .skipflags +.setsignflag + mov byte [spcNZ],80h + jo .setoverflowflag + and byte [spcP],0BFh + jmp .skipflags +.setzeroflag + mov byte [spcNZ],0 + jo .setoverflowflag + and byte [spcP],0BFh + jmp .skipflags +.setoverflowflag + or byte [spcP],40h +.skipflags + and byte [spcP],0F6h + test ah,01h + jz .noCarry + or byte [spcP],1 +.noCarry + test ah,10h + jz .nohf + or byte [spcP],8 +.nohf +ret +%endmacro + +%macro SPCSetFlagnvhzcnoret 0 + lahf + js .setsignflag + jz .setzeroflag + mov byte [spcNZ],1 + jo .setoverflowflag + and byte [spcP],0BFh + jmp .skipflags +.setsignflag + mov byte [spcNZ],80h + jo .setoverflowflag + and byte [spcP],0BFh + jmp .skipflags +.setzeroflag + mov byte [spcNZ],0 + jo .setoverflowflag + and byte [spcP],0BFh + jmp .skipflags +.setoverflowflag + or byte [spcP],40h +.skipflags + and byte [spcP],0F6h + test ah,01h + jz .noCarry + or byte [spcP],1 +.noCarry + test ah,10h + jz .nohf + or byte [spcP],8 +.nohf +%endmacro + +;************************************************ +; Misc Opcodes +;************************************************ +NEWSYM Op00 ; NOP + ret +NEWSYM OpEF ; SLEEP standby SLEEP mode ......... + dec ebp + ret +NEWSYM OpFF ; STOP standby STOP mode ......... + inc dword[spc700read] + dec ebp + ret +NEWSYM Op9F ; XCN A A(7-4) <-> A(3-0) N......Z. + ror byte [spcA],4 + mov al,byte[spcA] + mov [spcNZ],al + ret + +;************************************************ +; Branch Stuff +;************************************************ +NEWSYM Op10 ; BPL Branch on N=0 + test byte [spcNZ],128 + jz .branch + spcbrancher +NEWSYM Op30 ; BMI Branch on N=1 + test byte [spcNZ],128 + jnz .branch + spcbrancher +NEWSYM Op50 ; BVC Branch on V=0 + test byte [spcP],64 + jz .branch + spcbrancher +NEWSYM Op70 ; BVS Branch on V=1 + test byte [spcP],64 + jnz .branch + spcbrancher +NEWSYM Op90 ; BCC Branc on c=0 + test byte [spcP],1 + jz .branch + spcbrancher +NEWSYM OpB0 ; BCS Branch on C=1 + test byte [spcP],1 + jnz .branch + spcbrancher +NEWSYM OpD0 ; BNE branch on Z=0 + test byte [spcNZ],255 + jnz .branch + spcbrancher +NEWSYM OpF0 ; BEQ Branch on Z=1 + test byte [spcNZ],0FFh + jz .branch + spcbrancher +NEWSYM Op2F ; BRA rel branch always ... + movsx ebx,byte [ebp] + inc ebp + add ebp,ebx + ret + +;************************************************ +; Clear/Set Flag bits +;************************************************ +; CLRP 20 1 2 clear direct page flag ..0..... +NEWSYM Op20 ; CLRP Clear direct page flag + and byte [spcP],11011111b + mov dword [spcRamDP],spcRam + ret +; SETP 40 1 2 set dorect page flag ..1..0.. +NEWSYM Op40 ; SETP Set Direct Page Flag (Also clear interupt flag?) + or byte [spcP],00100000b + and byte [spcP],11111011b + mov dword [spcRamDP],spcRam + add dword [spcRamDP],100h + ret +; CLRC 60 1 2 clear carry flag .......0 +NEWSYM Op60 ; CLRC Clear carry flag + and byte [spcP],11111110b + ret +; SETC 80 1 2 set carry flag .......1 +NEWSYM Op80 ; SETC Set carry flag + or byte [spcP],00000001b + ret +; EI A0 1 3 set interrup enable flag .....1.. +NEWSYM OpA0 ; EI set interrupt flag + or byte [spcP],00000100b + ret +; DI C0 1 3 clear interrup enable flag .....0.. +NEWSYM OpC0 ; DI clear interrupt flag + and byte [spcP],11111011b + ret +; CLRV E0 1 2 clear V and H .0..0... +NEWSYM OpE0 ; CLRV clear V and H + and byte [spcP],10110111b + ret +; NOTC ED 1 3 complement carry flag .......C +NEWSYM OpED ; NOTC complement carry flag .......C + xor byte [spcP],00000001b + ret + +;************************************************ +; TCALL instructions (Verified) +;************************************************ +NEWSYM Op01 ; TCALL 0 + spctcall 30 +NEWSYM Op11 ; TCALL 1 + spctcall 28 +NEWSYM Op21 ; TCALL 2 + spctcall 26 +NEWSYM Op31 ; TCALL 3 + spctcall 24 +NEWSYM Op41 ; TCALL 4 + spctcall 22 +NEWSYM Op51 ; TCALL 5 + spctcall 20 +NEWSYM Op61 ; TCALL 6 + spctcall 18 +NEWSYM Op71 ; TCALL 7 + spctcall 16 +NEWSYM Op81 ; TCALL 8 + spctcall 14 +NEWSYM Op91 ; TCALL 9 + spctcall 12 +NEWSYM OpA1 ; TCALL A + spctcall 10 +NEWSYM OpB1 ; TCALL B + spctcall 08 +NEWSYM OpC1 ; TCALL C + spctcall 06 +NEWSYM OpD1 ; TCALL D + spctcall 04 +NEWSYM OpE1 ; TCALL E + spctcall 02 +NEWSYM OpF1 ; TCALL F + spctcall 00 + +;************************************************ +; SET1 instructions (Verified) +;************************************************ +NEWSYM Op02 ; SET1 direct page bit 0 + set1 1 +NEWSYM Op22 ; SET1 direct page bit 1 + set1 2 +NEWSYM Op42 ; SET1 direct page bit 2 + set1 4 +NEWSYM Op62 ; SET1 direct page bit 3 + set1 8 +NEWSYM Op82 ; SET1 direct page bit 4 + set1 16 +NEWSYM OpA2 ; SET1 direct page bit 5 + set1 32 +NEWSYM OpC2 ; SET1 direct page bit 6 + set1 64 +NEWSYM OpE2 ; SET1 direct page bit 7 + set1 128 + +;************************************************ +; CLR1 instructions (Verified) +;************************************************ +NEWSYM Op12 ; CLR1 direct page bit 0 + clr1 255-1 +NEWSYM Op32 ; CLR1 direct page bit 1 + clr1 255-2 +NEWSYM Op52 ; CLR1 direct page bit 2 + clr1 255-4 +NEWSYM Op72 ; CLR1 direct page bit 3 + clr1 255-8 +NEWSYM Op92 ; CLR1 direct page bit 4 + clr1 255-16 +NEWSYM OpB2 ; CLR1 direct page bit 5 + clr1 255-32 +NEWSYM OpD2 ; CLR1 direct page bit 6 + clr1 255-64 +NEWSYM OpF2 ; CLR1 direct page bit 7 + clr1 255-128 + +;************************************************ +; BBS instructions (Verified) +;************************************************ +NEWSYM Op03 ; BBS direct page bit 0 + bbs 1 +NEWSYM Op23 ; BBS direct page bit 1 + bbs 2 +NEWSYM Op43 ; BBS direct page bit 2 + bbs 4 +NEWSYM Op63 ; BBS direct page bit 3 + bbs 8 +NEWSYM Op83 ; BBS direct page bit 4 + bbs 16 +NEWSYM OpA3 ; BBS direct page bit 5 + bbs 32 +NEWSYM OpC3 ; BBS direct page bit 6 + bbs 64 +NEWSYM OpE3 ; BBS direct page bit 7 + bbs 128 + +;************************************************ +; BBC instructions (Verified) +;************************************************ +NEWSYM Op13 ; BBC direct page bit 0 + bbc 1 +NEWSYM Op33 ; BBC direct page bit 1 + bbc 2 +NEWSYM Op53 ; BBC direct page bit 2 + bbc 4 +NEWSYM Op73 ; BBC direct page bit 3 + bbc 8 +NEWSYM Op93 ; BBC direct page bit 4 + bbc 16 +NEWSYM OpB3 ; BBC direct page bit 5 + bbc 32 +NEWSYM OpD3 ; BBC direct page bit 6 + bbc 64 +NEWSYM OpF3 ; BBC direct page bit 7 + bbc 128 + +;************************************************ +; OR A,instructions +;************************************************ +NEWSYM Op04 ; OR A,dp A <- A OR (dp) N.....Z. + SPCaddr_DP + SPC_OR_A +NEWSYM Op14 ; OR A,dp+X A <- A OR (dp+X) N.....Z. + SPCaddr_DP_X + SPC_OR_A +NEWSYM Op05 ; OR A,labs A <- A OR (abs) N.....Z. + SPCaddr_LABS + SPC_OR_A +NEWSYM Op15 ; OR A,labs+x A <- A OR (abs+X) N.....Z. + SPCaddr_LABS_X + SPC_OR_A +NEWSYM Op06 ; OR A,(X) A <- A OR (X) N.....Z. + SPCaddr__X_ + SPC_OR_A +NEWSYM Op16 ; OR A,labs+Y A <- A OR (abs+Y) N......Z. + SPCaddr_LABS_Y + SPC_OR_A +NEWSYM Op07 ; OR A,(dp+X) A <- A OR ((dp+X+1)(dp+X)) N......Z. + SPCaddr_bDP_Xb + SPC_OR_A +NEWSYM Op17 ; OR A,(dp)+Y A <- A OR ((dp+1)(dp)+Y) N......Z. + SPCaddr_bDPb_Y + SPC_OR_A +NEWSYM Op08 ; OR A,#inm A <- A OR inm N......Z. + mov al,[ebp] + inc ebp + SPC_OR_A + +;************************************************ +; AND A, instructions +;************************************************ +NEWSYM Op24 ; AND A,dp A <- A AND (dp) N.....Z. + SPCaddr_DP + SPC_AND_A +NEWSYM Op34 ; AND A,dp+x A <- A AND (dp+X) N.....Z. + SPCaddr_DP_X + SPC_AND_A +NEWSYM Op25 ; AND A,labs A <- A AND (abs) N.....Z. + SPCaddr_LABS + SPC_AND_A +NEWSYM Op35 ; AND A,labs+X A <- A AND (abs+X) N.....Z. + SPCaddr_LABS_X + SPC_AND_A +NEWSYM Op26 ; AND A,(X) A <- A AND (X) N......Z. + SPCaddr__X_ + SPC_AND_A +NEWSYM Op36 ; AND A,labs+Y A <- A AND (abs+Y) N......Z. + SPCaddr_LABS_Y + SPC_AND_A +NEWSYM Op27 ; AND A,(dp+X) A <- A AND ((dp+X+1)(dp+X)) N......Z. + SPCaddr_bDP_Xb + SPC_AND_A +NEWSYM Op37 ; AND A,(dp)+Y A <- A AND ((dp+1)(dp)+Y) N......Z. + SPCaddr_bDPb_Y + SPC_AND_A +NEWSYM Op28 ; AND A,#inm A <- A AND inm N......Z. + mov al,[ebp] + inc ebp + SPC_AND_A + +;************************************************ +; EOR A, instructions +;************************************************ +NEWSYM Op44 ; EOR A,dp A <- A EOR (dp) N.....Z. + SPCaddr_DP + SPC_EOR_A +NEWSYM Op54 ; EOR A,dp+x A <- A EOR (dp+X) N.....Z. + SPCaddr_DP_X + SPC_EOR_A +NEWSYM Op45 ; EOR A,labs A <- A EOR (abs) N.....Z. + SPCaddr_LABS + SPC_EOR_A +NEWSYM Op55 ; EOR A,labs+X A <- A EOR (abs+X) N.....Z. + SPCaddr_LABS_X + SPC_EOR_A +NEWSYM Op46 ; EOR A,(X) A <- A EOR (X) N......Z. + SPCaddr__X_ + SPC_EOR_A +NEWSYM Op56 ; EOR A,labs+Y A <- A EOR (abs+Y) N......Z. + SPCaddr_LABS_Y + SPC_EOR_A +NEWSYM Op47 ; EOR A,(dp+X) A <- A EOR ((dp+X+1)(dp+X)) N......Z. + SPCaddr_bDP_Xb + SPC_EOR_A +NEWSYM Op57 ; EOR A,(dp)+Y A <- A EOR ((dp+1)(dp)+Y) N......Z. + SPCaddr_bDPb_Y + SPC_EOR_A +NEWSYM Op48 ; EOR A,#inm A <- A EOR inm N......Z. + mov al,[ebp] + inc ebp + SPC_EOR_A + +;************************************************ +; CMP A, instructions +;************************************************ +NEWSYM Op64 ; CMP A,dp A-(dp) N.....ZC + SPCaddr_DP + SPC_CMP_A +NEWSYM Op74 ; CMP A,dp+x A-(dp+X) N.....ZC + SPCaddr_DP_X + SPC_CMP_A +NEWSYM Op65 ; CMP A,labs A-(abs) N.....ZC + SPCaddr_LABS + SPC_CMP_A +NEWSYM Op75 ; CMP A,labs+X A-(abs+X) N.....ZC + SPCaddr_LABS_X + SPC_CMP_A +NEWSYM Op66 ; CMP A,(X) A-(X) N......ZC + SPCaddr__X_ + SPC_CMP_A +NEWSYM Op76 ; CMP A,labs+Y A-(abs+Y) N......ZC + SPCaddr_LABS_Y + SPC_CMP_A +NEWSYM Op67 ; CMP A,(dp+X) A-((dp+X+1)(dp+X)) N......ZC + SPCaddr_bDP_Xb + SPC_CMP_A +NEWSYM Op77 ; CMP A,(dp)+Y A-((dp+1)(dp)+Y) N......ZC + SPCaddr_bDPb_Y + SPC_CMP_A +NEWSYM Op68 ; CMP A,#inm A-inm N......ZC + mov al,[ebp] + inc ebp + SPC_CMP_A + +;************************************************ +; ADC A, instructions +;************************************************ +NEWSYM Op84 ; ADC A,dp A <- A+(dp)+C NV..H.ZC + SPCaddr_DP + SPC_ADC_A +NEWSYM Op94 ; ADC A,dp+x A <- A+(dp+X)+C NV..H.ZC + SPCaddr_DP_X + SPC_ADC_A +NEWSYM Op85 ; ADC A,labs A <- A+(abs)+C NV..H.ZC + SPCaddr_LABS + SPC_ADC_A +NEWSYM Op95 ; ADC A,labs+X A <- A+(abs+X)+C NV..H.ZC + SPCaddr_LABS_X + SPC_ADC_A +NEWSYM Op86 ; ADC A,(X) A <- A+(X)+C NV..H..ZC + SPCaddr__X_ + SPC_ADC_A +NEWSYM Op96 ; ADC A,labs+Y A <- A+(abs+Y)+C NV..H..ZC + SPCaddr_LABS_Y + SPC_ADC_A +NEWSYM Op87 ; ADC A,(dp+X) A <- A+((dp+X+1)(dp+X)) NV..H..ZC + SPCaddr_bDP_Xb + SPC_ADC_A +NEWSYM Op97 ; ADC A,(dp)+Y A <- A+((dp+1)(dp)+Y) NV..H..ZC + SPCaddr_bDPb_Y + SPC_ADC_A +NEWSYM Op88 ; ADC A,#inm A <- A+inm+C NV..H..ZC + mov al,[ebp] + inc ebp + SPC_ADC_A + +;************************************************ +; SBC A, instructions +;************************************************ +NEWSYM OpA4 ; SBC A,dp A <- A-(dp)-!C NV..H.ZC + SPCaddr_DP + SPC_SBC_A +NEWSYM OpB4 ; SBC A,dp+x A <- A-(dp+X)-!C NV..H.ZC + SPCaddr_DP_X + SPC_SBC_A +NEWSYM OpA5 ; SBC A,labs A <- A-(abs)-!C NV..H.ZC + SPCaddr_LABS + SPC_SBC_A +NEWSYM OpB5 ; SBC A,labs+x A <- A-(abs+X)-!C NV..H.ZC + SPCaddr_LABS_X + SPC_SBC_A +NEWSYM OpA6 ; SBC A,(X) A <- A-(X)-!C NV..H..ZC + SPCaddr__X_ + SPC_SBC_A +NEWSYM OpB6 ; SBC A,labs+Y A <- A-(abs+Y)-!C NV..H..ZC + SPCaddr_LABS_Y + SPC_SBC_A +NEWSYM OpA7 ; SBC A,(dp+X) A <- A-((dp+X+1)(dp+X))-!C NV..H..ZC + SPCaddr_bDP_Xb + SPC_SBC_A +NEWSYM OpB7 ; SBC A,(dp)+Y A <- A-((dp+1)(dp)+Y)-!C NV..H..ZC + SPCaddr_bDPb_Y + SPC_SBC_A +NEWSYM OpA8 ; SBC A,#inm A <- A-inm-!C NV..H..ZC + mov al,[ebp] + inc ebp + SPC_SBC_A + +;************************************************ +; MOV A, instructions +;************************************************ +NEWSYM OpE4 ; MOV A,dp A <- (dp) N......Z + SPCaddr_DP + SPC_MOV_A +NEWSYM OpF4 ; MOV A,dp+x A <- (dp+X) N......Z + SPCaddr_DP_X + SPC_MOV_A +NEWSYM OpE5 ; MOV A,labs A <- (abs) N......Z + SPCaddr_LABS + SPC_MOV_A +NEWSYM OpF5 ; MOV A,labs+X A <- (abs+X) N......Z + SPCaddr_LABS_X + SPC_MOV_A +NEWSYM OpE6 ; MOV A,(X) A <- (X) N......Z + SPCaddr__X_ + SPC_MOV_A +NEWSYM OpF6 ; MOV A,labs+Y A <- (abs+Y) N......Z + SPCaddr_LABS_Y + SPC_MOV_A +NEWSYM OpE7 ; MOV A,(dp+X) A <- ((dp+X+1)(dp+X)) N......Z + SPCaddr_bDP_Xb + SPC_MOV_A +NEWSYM OpF7 ; MOV A,(dp)+Y A <- ((dp+1)(dp)+Y) N......Z + SPCaddr_bDPb_Y + SPC_MOV_A +NEWSYM OpE8 ; MOV A,#inm A <- inm N......Z + mov al,[ebp] + inc ebp + SPC_MOV_A + +;************************************************ +; DP,#imm instructions +;************************************************ + +%macro spcgetdp_imm 0 + mov bl,[ebp+1] + mov ah,[ebp] + add ebx,[spcRamDP] + ReadByte2 + add ebp,2 +%endmacro + +NEWSYM OpB8 ; SBC dp,#inm (dp) <- (dp)-inm-!C NV..H..ZC + spcgetdp_imm ; bl<-[ebp+1], ah<-[ebp], ebx+[spcRamDP],Readbyte,ebp+2 + mov cl,[spcP] + xor cl,1 + shr cl,1 + sbb al,ah + cmc + SPCSetFlagnvhzcnoret + WriteByte + ret + +NEWSYM Op98 ; ADC dp,#inm (dp) <- (dp)+inm+C NV..H..ZC + spcgetdp_imm ; bl<-[ebp+1], ah<-[ebp], ebx+[spcRamDP],Readbyte,ebp+2 + mov cl,[spcP] + shr cl,1 + adc al,ah + SPCSetFlagnvhzcnoret + WriteByte + ret + +NEWSYM Op78 ; CMP dp,#inm (dp)-inm N......ZC + mov bl,[ebp+1] + mov ah,[ebp] + add ebx,[spcRamDP] + ReadByte + add ebp,2 + cmp al,ah + cmc + SPCSetFlagnzcnoret + ret + +NEWSYM Op58 ; EOR dp,#inm (dp) <- (dp) EOR inm N......Z. + spcgetdp_imm ; bl<-[ebp+1], ah<-[ebp], ebx+[spcRamDP],Readbyte,ebp+2 + xor al,ah + mov [spcNZ], al + WriteByte + ret + +NEWSYM Op38 ; AND dp,#inm (dp) <- (dp) AND inm N......Z. + spcgetdp_imm ; bl<-[ebp+1], ah<-[ebp], ebx+[spcRamDP],Readbyte,ebp+2 + and al,ah + mov [spcNZ], al + WriteByte + ret + +NEWSYM Op18 ; OR dp,#inm (dp) <- (dp) OR inm N......Z. + spcgetdp_imm ; bl<-[ebp+1], ah<-[ebp], ebx+[spcRamDP],Readbyte,ebp+2 + or al,ah + mov [spcNZ],al + WriteByte + ret + +;************************************************ +; DP(D),DP(S) instructions +;************************************************ +%macro spcaddrDPbDb_DPbSb 1 + xor ecx,ecx + mov bl,[ebp+1] + mov cl,[ebp] + add ebx,[spcRamDP] + add ebp,2 + add ecx,[spcRamDP] + push ebx + ReadByte + mov ebx,ecx + mov cl,al +%1 + ReadByte + mov ah,al + mov al,cl + pop ebx +%endmacro + +NEWSYM Op09 ; OR dp(d),dp(s) (dp(d))<-(dp(d)) OR (dp(s)) N......Z. + spcaddrDPbDb_DPbSb Op09b: + or al,ah + mov [spcNZ], al + WriteByte + xor ecx,ecx + ret + +NEWSYM Op29 ; AND dp(d),dp(s) (dp(d))<-(dp(d)) AND (dp(s)) N......Z. + spcaddrDPbDb_DPbSb Op29b: + and al,ah + mov [spcNZ], al + WriteByte + xor ecx,ecx + ret + +NEWSYM Op49 ; EOR dp(d),dp(s) (dp(d))<-(dp(d)) EOR (dp(s)) N......Z. + spcaddrDPbDb_DPbSb Op49b: + xor al,ah + mov [spcNZ], al + WriteByte + xor ecx,ecx + ret + +NEWSYM Op69 ; CMP dp(d),dp(s) (dp(d))-(dp(s)) N......ZC + spcaddrDPbDb_DPbSb Op69b: + cmp al,ah + cmc + SPCSetFlagnzcnoret + xor ecx,ecx + ret + +NEWSYM Op89 ; ADC dp(d),dp(s) (dp(d))<-(dp(d))+(dp(s))+C NV..H..ZC + spcaddrDPbDb_DPbSb Op89b + mov cl,[spcP] + shr cl,1 + adc al,ah + SPCSetFlagnvhzcnoret + WriteByte + xor ecx,ecx + ret + +NEWSYM OpA9 ; SBC dp(d),dp(s) (dp(d))<-(dp(d))-(dp(s))-!C NV..H..ZC + spcaddrDPbDb_DPbSb OpA9b + mov cl,[spcP] + xor cl,1 + shr cl,1 + sbb al,ah + cmc + SPCSetFlagnvhzcnoret + WriteByte + xor ecx,ecx + ret + +NEWSYM OpFA ; MOV dp(d),dp(s) (dp(d)) <- (dp(s)) ........ + xor ecx,ecx + mov bl,[ebp+1] + mov cl,[ebp] + add ebx,[spcRamDP] + add ecx,[spcRamDP] + add ebp,2 + push ebx + mov ebx,ecx + ReadByte + pop ebx + WriteByte + xor ecx,ecx + ret + +;************************************************ +; (X),(Y) instructions +;************************************************ +%macro spcaddrDPbXb_bYb 1 + mov bl,[spcY] + add ebx,[spcRamDP] + ReadByte + xor ebx,ebx + mov ah,al + mov bl,[spcX] + add ebx,[spcRamDP] +%1 + ReadByte +%endmacro + +NEWSYM Op19 ; OR (X),(Y) (X) <- (X) OR (Y) N......Z. + spcaddrDPbXb_bYb Op19b: + or al, ah + mov [spcNZ],al + WriteByte + ret + +NEWSYM Op39 ; AND (X),(Y) (X) <- (X) AND (Y) N......Z. + spcaddrDPbXb_bYb Op39b: + and al, ah + mov [spcNZ],al + WriteByte + ret + + +NEWSYM Op59 ; EOR (X),(Y) (X) <- (X) EOR (Y) N......Z. + spcaddrDPbXb_bYb Op59b: + xor al, ah + mov [spcNZ],al + WriteByte + ret + +NEWSYM Op79 ; CMP (X),(Y) (X)-(Y) N......ZC + spcaddrDPbXb_bYb Op79b: + cmp al, ah + cmc + SPCSetFlagnzc + +NEWSYM Op99 ; ADC (X),(Y) (X) <- (X)+(Y)+C NV..H..ZC + spcaddrDPbXb_bYb Op99b: + mov cl,[spcP] + shr cl,1 + adc al,ah + SPCSetFlagnvhzcnoret + WriteByte + ret + +NEWSYM OpB9 ; SBC (X),(Y) (X) <- (X)-(Y)-!C NV..H..ZC + spcaddrDPbXb_bYb OpB9b: + mov cl,[spcP] + xor cl,1 + shr cl,1 + sbb al,ah + cmc + SPCSetFlagnvhzcnoret + WriteByte + ret + +;************************************************ +; MOV ,A instructions (Verified) +;************************************************ + +NEWSYM OpC4 ; MOV dp,A A -> (dp) ........ + mov bl,[ebp] + mov al, byte [spcA] + add ebx,[spcRamDP] + inc ebp + WriteByte + ret + +NEWSYM OpD4 ; MOV dp+x,A A -> (dp+X) ........ + mov bl,[ebp] + add bl,[spcX] + mov al, byte [spcA] + add ebx,[spcRamDP] + inc ebp + WriteByte + ret + +NEWSYM OpC5 ; MOV labs,A A -> (abs) ........ + mov bx,[ebp] + mov al, byte [spcA] + add ebp,2 + add ebx,spcRam + WriteByte + ret + +NEWSYM OpD5 ; MOV labs+X,A A -> (abs+X) ........ + mov bl,[spcX] + add bx,[ebp] + mov al, byte [spcA] + add ebp,2 + add ebx,spcRam + WriteByte + ret + +NEWSYM OpC6 ; MOV (X),A A -> (X) ........ + mov bl,[spcX] + add ebx,[spcRamDP] + mov al, byte [spcA] + WriteByte + ret + +NEWSYM OpD6 ; MOV labs+Y,A A -> (abs+Y) ........ + mov bl,[spcY] + mov al, byte [spcA] + add bx,[ebp] + add ebp,2 + add ebx,spcRam + WriteByte + ret + +NEWSYM OpC7 ; MOV (dp+X),A A -> ((dp+X+1)(dp+X)) ........ + mov bl,[ebp] + add bl,[spcX] + xor eax,eax + add ebx,[spcRamDP] + inc ebp + mov ax, word [ebx] + mov ebx,eax + add ebx,spcRam + mov al, byte [spcA] + WriteByte + ret + +NEWSYM OpD7 ; MOV (dp)+Y,A A -> ((dp+1)(dp)+Y) ........ + mov bl,[ebp] + xor eax,eax + add ebx,[spcRamDP] + inc ebp + mov ax, word [ebx] + add ax,[spcY] + mov ebx,eax + add ebx,spcRam + mov al, byte [spcA] + WriteByte + ret + +;************************************************ +; MOV instructions (Verified) +;************************************************ + +NEWSYM OpD8 ; MOV dp,X X -> (dp) ........ + mov bl,[ebp] + mov al, byte [spcX] + add ebx,[spcRamDP] + inc ebp + WriteByte + ret + +NEWSYM OpF8 ; MOV X,dp X <- (dp) N......Z + mov bl,[ebp] + inc ebp + add ebx,[spcRamDP] + ReadByte + mov byte [spcX], al + mov [spcNZ],al + ret + +NEWSYM OpC9 ; MOV labs,X X -> (abs) ........ + mov bx,[ebp] + mov al, byte [spcX] + add ebp,2 + add ebx,spcRam + WriteByte + ret + +NEWSYM OpE9 ; MOV X,labs X <- (abs) N......Z + mov bx,[ebp] + add ebx,spcRam + ReadByte + add ebp,2 + mov byte [spcX], al + mov [spcNZ],al + ret + +NEWSYM OpD9 ; MOV dp+Y,X X -> (dp+Y) ........ + mov bl,[ebp] + mov al, byte [spcX] + add bl,[spcY] + inc ebp + add ebx,[spcRamDP] + WriteByte + ret + +NEWSYM OpF9 ; MOV X,dp+Y X <- (dp+Y) N......Z + mov bl,[ebp] + add bl,[spcY] + inc ebp + add ebx,[spcRamDP] + ReadByte + mov byte [spcX], al + mov [spcNZ],al + ret + +NEWSYM OpCB ; MOV dp,Y Y -> (dp) ........ + mov bl,[ebp] + mov al, byte [spcY] + add ebx,[spcRamDP] + inc ebp + WriteByte + ret + +NEWSYM OpEB ; MOV Y,dp Y <- (dp) N......Z + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + ReadByte + mov byte [spcY], al + mov [spcNZ],al + ret + +NEWSYM OpDB ; MOV dp+X,Y X -> (dp+X) ........ + mov bl,[ebp] + add bl,[spcX] + mov al, byte [spcY] + add ebx,[spcRamDP] + inc ebp + WriteByte + ret + +NEWSYM OpFB ; MOV Y,dp+X Y <- (dp+X) N......Z + mov bl,[ebp] + add bl,[spcX] + inc ebp + add ebx,[spcRamDP] + ReadByte + mov byte [spcY], al + mov [spcNZ],al + ret + +NEWSYM OpCC ; MOV labs,Y Y -> (abs) ........ + mov bx,[ebp] + mov al, byte [spcY] + add ebp,2 + add ebx,spcRam + WriteByte + ret + +NEWSYM OpEC ; MOV Y,labs Y <- (abs) N......Z + mov bx,[ebp] + add ebx,spcRam + ReadByte + add ebp,2 + mov byte [spcY],al + mov [spcNZ],al + ret + +NEWSYM Op5D ; MOV X,A X <- A N......Z + mov al,[spcA] + mov [spcX],al + mov [spcNZ],al + ret + +NEWSYM Op7D ; MOV A,X A <- X N......Z + mov al,[spcX] + mov [spcA],al + mov [spcNZ],al + ret + +NEWSYM Op8D ; MOV Y,#inm Y <- inm N......Z + mov bl,[ebp] + mov [spcY],bl + inc ebp + mov [spcNZ],bl + ret + +NEWSYM OpCD ; MOV X,#inm X <- inm N......Z + mov bl,[ebp] + mov [spcX],bl + inc ebp + mov [spcNZ],bl + ret + +NEWSYM Op8F ; MOV dp,#inm (dp) <- inm ........ + mov bl,[ebp+1] + mov al,[ebp] + add ebx,[spcRamDP] + add ebp,2 + WriteByte + ret + +NEWSYM Op9D ; MOV X,SP X <- SP N......Z + mov al,[spcS] + mov [spcX],al + mov [spcNZ],al + ret + +NEWSYM OpBD ; MOV SP,X SP <- X ........ + mov al,[spcX] + mov [spcS],al + ret + +NEWSYM OpDD ; MOV A,Y A <- Y N......Z + mov al,[spcY] + mov [spcA],al + mov [spcNZ],al + ret + + +NEWSYM OpFD ; MOV Y,A Y <- A N......Z + mov al,[spcA] + mov [spcY],al + mov [spcNZ],al + ret + +NEWSYM OpAF ; MOV (X)+,A A -> (X) with auto inc ........ + mov bl,[spcX] + add ebx,[spcRamDP] + mov al, byte [spcA] + inc byte [spcX] + WriteByte + ret + +NEWSYM OpBF ; MOV A,(X)+ A <- (X) with auto inc N......Z + mov bl,[spcX] + add ebx,[spcRamDP] + ReadByte + inc byte [spcX] + mov byte [spcA],al + mov [spcNZ],al + ret + + +;************************************************ +; CMP instructions (Verified) +;************************************************ + +NEWSYM OpC8 ; CMP X,#inm X-inm N......ZC + mov bl,[ebp] + inc ebp + cmp [spcX],bl + cmc + SPCSetFlagnzc + +NEWSYM OpAD ; CMP Y,#inm Y-inm N......ZC + mov bl,[ebp] + inc ebp + cmp [spcY],bl + cmc + SPCSetFlagnzc + +NEWSYM Op1E ; CMP X,labs X-(abs) N......ZC + mov bx,[ebp] + add ebp,2 + add ebx,spcRam + ReadByte + cmp byte [spcX], al + cmc + SPCSetFlagnzc + +NEWSYM Op3E ; CMP X,dp X-(dp) N......ZC + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + ReadByte + cmp byte [spcX], al + cmc + SPCSetFlagnzc + +NEWSYM Op5E ; CMP Y,labs Y-(abs) N......ZC + mov bx,[ebp] + add ebx,spcRam + ReadByte + add ebp,2 + cmp byte [spcY], al + cmc + SPCSetFlagnzc + +NEWSYM Op7E ; CMP Y,dp Y-(dp) N......ZC + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + ReadByte + cmp byte [spcY], al + cmc + SPCSetFlagnzc + +;************************************************ +; Word Instructions (Verified) +;************************************************ + +NEWSYM Op1A ; DECW dp Decrement dp memory pair N......Z. + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + inc ebx + ReadByte2 + mov ah,al + dec ebx +NEWSYM Op1AB + ReadByte2 + dec ax + test ax,8000h + jnz .YesNeg + cmp ax,0000h + je .YesZero + mov byte [spcNZ],1 + jmp .SkipFlag +.YesNeg + mov byte [spcNZ],80h + jmp .SkipFlag +.YesZero + mov byte [spcNZ],0 +.SkipFlag + push ebx + WriteByte + pop ebx +NEWSYM Op1Ab + inc ebx + mov al,ah + WriteByte + ret + +NEWSYM Op3A ; INCW dp Increment dp memory pair N......Z. + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + inc ebx + ReadByte2 + mov ah,al + dec ebx +NEWSYM Op3AB + ReadByte2 + inc ax + test ax,8000h + jnz .YesNeg + cmp ax,0000h + je .YesZero + mov byte [spcNZ],1 + jmp .SkipFlag +.YesNeg + mov byte [spcNZ],80h + jmp .SkipFlag +.YesZero + mov byte [spcNZ],0 +.SkipFlag + push ebx + WriteByte + pop ebx +NEWSYM Op3Ab + inc ebx + mov al,ah + WriteByte + ret + +; looks like there is the Carry flag checked in op5a.. + +NEWSYM Op5A ; CMPW YA,dp YA - (dp+1)(dp) N......ZC + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + inc ebx + ReadByte2 + mov ah,al + dec ebx +NEWSYM Op5AB + ReadByte + mov bl,[spcA] + mov bh,[spcY] + cmp bx,ax + cmc + SPCSetFlagnzc + +NEWSYM Op7A ; ADDW YA,dp YA <- YA + (dp+1)(dp) NV..H..ZC + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + inc ebx + ReadByte2 + mov ah,al + dec ebx +NEWSYM Op7AB + ReadByte + mov bl,[spcA] + mov bh,[spcY] + add bx,ax + mov [spcA],bl + mov [spcY],bh + SPCSetFlagnvhzc + +NEWSYM Op9A ; SUBW YA,dp YA <- YA - (dp+1)(dp) NV..H..ZC + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + inc ebx + ReadByte2 + mov ah,al + dec ebx +NEWSYM Op9AB + ReadByte + mov bl,[spcA] + mov bh,[spcY] + sub bx,ax + cmc + mov [spcA],bl + mov [spcY],bh + SPCSetFlagnvhzc + +NEWSYM OpBA ; MOVW YA,dp YA - (dp+1)(dp) N......Z. + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + inc ebx + ReadByte2 + mov ah,al + dec ebx +NEWSYM OpBAb + ReadByte + mov [spcA],al + mov [spcY],ah + test ax,8000h + jnz .YesNeg + cmp ax,0000h + je .YesZero + mov byte [spcNZ],1 + ret +.YesNeg + mov byte [spcNZ],80h + ret +.YesZero + mov byte [spcNZ],0 + ret + +NEWSYM OpDA ; MOVW dp,YA (dp+1)(dp) - YA ......... + mov bl,[ebp] + mov al,[spcA] + add ebx,[spcRamDP] + inc ebp + push ebx + WriteByte + pop ebx + inc ebx + mov al,[spcY] +NEWSYM OpDAb + WriteByte + ret + +;************************************************ +; mem.bit instructions (Verified) +;************************************************ + +%macro spcaddrmembit 0 + mov bx,[ebp] + + mov cl,bh + add ebp,2 + shr cl,5 + and bx,1FFFh + +; mov cl,bl +; add ebp,2 +; shr bx,3 +; and cl,00000111b + + add ebx,spcRam + ReadByte + shr al,cl + and al,01h +%endmacro + +NEWSYM Op0A ; OR1 C,mem.bit C <- C OR (mem.bit) ........C + spcaddrmembit + or [spcP],al + ret + +NEWSYM Op2A ; OR1 C,/mem.bit C <- C OR !(mem.bit) ........C + spcaddrmembit + xor al,01h + or [spcP],al + ret + +NEWSYM Op4A ; AND1 C,mem.bit C <- C AND (mem.bit) ........C + mov bx,[ebp] + + mov cl,bh + add ebp,2 + shr cl,5 + and bx,1FFFh + +; mov cl,bl +; add ebp,2 +; shr bx,3 +; and cl,00000111b + + add ebx,spcRam + ReadByte + shr al,cl + or al,0FEh + and [spcP],al + ret + +NEWSYM Op6A ; AND1 C,/mem.bit C <- C AND !(mem.bit) ........C + mov bx,[ebp] + + mov cl,bh + add ebp,2 + shr cl,5 + and bx,1FFFh + +; mov cl,bl +; add ebp,2 +; shr bx,3 +; and cl,00000111b + + add ebx,spcRam + ReadByte + shr al,cl + or al,0FEh + xor al,01h + and [spcP],al + ret + +NEWSYM Op8A ; EOR1 C,mem.bit C <- C EOR (mem.bit) ........C + spcaddrmembit + xor [spcP],al + ret + +NEWSYM OpAA ; MOV1 C,mem.bit C <- (mem.bit) + spcaddrmembit + and byte[spcP],0FEh + or [spcP],al + ret + +NEWSYM OpCA ; MOV1 mem.bit,C C -> (mem.bit) ......... + mov bx,[ebp] + mov al,[spcP] + + mov cl,bh + mov ah,01h + shr cl,5 + and bx,1FFFh + +; mov cl,bl +; mov ah,01h +; and cl,00000111b +; shr bx,3 + + shl ah,cl + and al,01h + add ebp,2 + shl al,cl + add ebx,spcRam + ; al = carry flag positioned in correct location, ah = 1 positioned + mov cl,al + xor ah,0FFh + ReadByte2 + and al,ah + or al,cl + WriteByte + ret + +NEWSYM OpEA ; NOT1 mem.bit complement (mem.bit) ......... + mov bx,[ebp] + + mov cl,bh + mov ah,01h + shr cl,5 + and bx,1FFFh + +; mov cl,bl +; mov ah,01h +; and cl,00000111b +; shr bx,3 + + shl ah,cl + add ebp,2 + add ebx,spcRam + ReadByte2 + xor al,ah + WriteByte + ret + +;************************************************ +; Shift Instructions (Verified) +;************************************************ + +NEWSYM Op0B ; ASL dp C << (dp) <<0 N......ZC + mov bl,[ebp] + add ebx,[spcRamDP] + inc ebp + ReadByte2 + shl al,1 + SPCSetFlagnzcnoret + WriteByte + ret + +NEWSYM Op4B ; LSR dp 0 >> (dp) <> (dp+X) <> (abs) <> A <> (dp) <> (dp+X) <> (abs) <> A < ',' / ','RSH',' * ' + db 'ALT','SPC','CAP','F1 ','F2 ','F3 ','F4 ','F5 ' + db 'F6 ','F7 ','F8 ','F9 ','F10','NUM','SCR','HOM' + db 'UP ','PUP',' - ','LFT',' 5 ','RGT',' + ','END' + db 'DWN','PDN','INS','DEL',' ',' ',' ','F11' + db 'F12',' ',' ',' ',' ',' ',' ',' ' + db ' ',' ',' ',' ',' ',' ',' ',' ' + db ' ',' ',' ',' ',' ',' ',' ',' ' + db ' ',' ',' ',' ',' ',' ',' ',' ' + db ' ',' ',' ',' ',' ',' ',' ',' ' + ; Joystick Stuff, Port 201h (80h) + db 'JB7','JB8','JB1','JB2','JB3','JB4','JB5','JB6' + db 'SWA','SWB','SWC','SWX','SWY','SWZ','SWL','SWR' + db 'S2A','S2B','S2C','S2X','S2Y','S2Z','S2L','S2R' + db 'S3A','S3B','S3C','S3X','S3Y','S3Z','S3L','S3R' + db 'S4A','S4B','S4C','S4X','S4Y','S4Z','S4L','S4R' + db 'GRR','GRB','GRY','GRG','GL1','GL2','GR1','GR2' + db 'G2R','G2B','G2Y','G2G','2L1','2L2','2R1','2R2' + db 'G3R','G3B','G3Y','G3G','3L1','3L2','3R1','3R2' + db 'G4R','G4B','G4Y','G4G','4L1','4L2','4R1','4R2' + db 'SWS','SWM','GSL','GST','JUP','JDN','JLF','JRG' + db 'S2S','S2M','2SL','2ST','SWU','SWD','SWL','SWR' + db 'S3S','S3M','3SL','3ST','S2U','S2D','S2L','S2R' + db 'S4S','S4M','4SL','4ST','S3U','S3D','S3L','S3R' + db 'J2U','J2D','J2L','J2R','S4U','S4D','S4L','S4R' + db 'GRU','GRD','GRL','GRR','G2U','G2D','G2L','G2R' + db 'G3U','G3D','G3L','G3R','G4U','G4D','G4L','G4R' + ; Joystick Stuff, Port 209h (100h) + db 'JB7','JB8','JB1','JB2','JB3','JB4','JB5','JB6' + db 'SWA','SWB','SWC','SWX','SWY','SWZ','SWL','SWR' + db 'S2A','S2B','S2C','S2X','S2Y','S2Z','S2L','S2R' + db 'S3A','S3B','S3C','S3X','S3Y','S3Z','S3L','S3R' + db 'S4A','S4B','S4C','S4X','S4Y','S4Z','S4L','S4R' + db 'GRR','GRB','GRY','GRG','GL1','GL2','GR1','GR2' + db 'G2R','G2B','G2Y','G2G','2L1','2L2','2R1','2R2' + db 'G3R','G3B','G3Y','G3G','3L1','3L2','3R1','3R2' + db 'G4R','G4B','G4Y','G4G','4L1','4L2','4R1','4R2' + db 'SWS','SWM','GSL','GST','JUP','JDN','JLF','JRG' + db 'S2S','S2M','2SL','2ST','SWU','SWD','SWL','SWR' + db 'S3S','S3M','3SL','3ST','S2U','S2D','S2L','S2R' + db 'S4S','S4M','4SL','4ST','S3U','S3D','S3L','S3R' + db 'J2U','J2D','J2L','J2R','S4U','S4D','S4L','S4R' + db 'GRU','GRD','GRL','GRR','G2U','G2D','G2L','G2R' + db 'G3U','G3D','G3L','G3R','G4U','G4D','G4L','G4R' + ; Extra Stuff (180h) (Parallel Port) + db 'PPB','PPY','PSL','PST','PUP','PDN','PLT','PRT' + db 'PPA','PPX','PPL','PPR',' ',' ',' ',' ' + db 'P2B','P2Y','P2S','P2T','P2U','P2D','P2L','P2R' + db 'P2A','P2X','P2L','P2R',' ',' ',' ',' ' + db 'PPB','PPY','PSL','PST','PUP','PDN','PLT','PRT' + db 'PPA','PPX','PPL','PPR',' ',' ',' ',' ' + db 'P2B','P2Y','P2S','P2T','P2U','P2D','P2L','P2R' + db 'P2A','P2X','P2L','P2R',' ',' ',' ',' ' + +SECTION .text + +SECTION .data +NEWSYM ZSNESBase, dd 0 +cpuidfname db 'nocpuzid.dat',0 +cpuidtext db 'NOTE: If ZSNES crashes here, then please re-run. ',0 +cpuidtext2 db 13,' ',13,0 +YesMMX db 'MMX support enabled.',13,10,13,10,0 +TempVarSeek dd 0 +gotoroot db '\',0 +SECTION .text + +; **************************** +; Mouse Stuff +; **************************** + +NEWSYM Init_Mouse + ; return non-zero if successful + mov eax,00h + int 33h + cmp ax,0 + je .nomouse + mov eax,07h + mov ecx,0 + mov edx,255 + int 33h + mov eax,08h + mov ecx,0 + mov edx,223 + int 33h + mov eax,0Fh + mov ecx,8 + mov edx,8 + int 33h + mov eax,04h + mov ecx,0 + mov edx,0 + int 33h + mov ax,1 +.nomouse + ret + +NEWSYM Get_MouseData ; Returns both pressed and coordinates + mov eax,03h + int 33h + ; bx : bit 0 = left button, bit 1 = right button + ; cx = Mouse X Position, dx = Mouse Y Position + ret + +NEWSYM Set_MouseXMax ; Sets the X boundaries (ecx = left, edx = right) + mov eax,07h + int 33h + ret + +NEWSYM Set_MouseYMax ; Sets the Y boundaries (ecx = left, edx = right) + mov eax,08h + int 33h + ret + +NEWSYM Set_MousePosition ; Sets Mouse Position (x:cx,y:dx) + mov eax,04h + int 33h + ret + +NEWSYM Get_MousePositionDisplacement + ; returns x,y displacement in pixel in cx,dx + mov eax,0Bh + int 33h + ret + +NEWSYM MouseWindow + ret + +; **************************** +; Sound Stuff +; **************************** + +NEWSYM StopSound + ret + +NEWSYM StartSound + ret + + +NEWSYM SoundProcess ; This function is called ~60 times/s at full speed + cmp byte[OSPort],1 ; Do not call in the dos port +; ja .notdos +.nosound + ret +.notdos + cmp byte[soundon],0 + je .nosound + cmp byte[DSPDisable],1 + je .nosound + mov eax,200 ; Size of 32-bit buffer in dwords + add eax,eax + mov dword[BufferSizeW],eax + add eax,eax + mov dword[BufferSizeB],eax + pushad + call ProcessSoundBuffer + popad + ; DSPBuffer should contain the processed buffer in the specified size + ; You will have to convert/clip it to 16-bit for actual sound process + ret + + + +NEWSYM Check60hz + ; Call the timer update function here + ret + +; **************************** +; TCP/IP Stuff +; **************************** + +; TCPIPPortNum +NEWSYM TCPIPStatus, db 0 +NEWSYM PacketSendSize, dd 0 +NEWSYM PacketRecvSize, dd 0 +NEWSYM PacketRecvPtr, dd 0 +NEWSYM PacketSendArray, times 256 db 0 +NEWSYM PacketRecvArray, times 256 db 0 +NEWSYM IPAddrStr, times 20 db 0 +NEWSYM RemoteDisconnect, db 0 + +NEWSYM TCPIPStartServer + mov dword[PacketSendSize],0 + mov dword[PacketRecvSize],0 +; call InitTCP + or eax,eax + jnz .failed + mov byte[TCPIPStatus],1 +; StartServer(unsigned short port) + mov ax,[TCPIPPortNum] + push ax +; call StartServer + add esp,2 + or eax,eax + jnz .noserver + mov byte[TCPIPStatus],2 +.noserver + ret +.failed + mov eax,1 + ret + +NEWSYM TCPIPInitConnectToServer + mov dword[PacketSendSize],0 + mov dword[PacketRecvSize],0 +; call InitTCP + or eax,eax + jnz .failed + mov byte[TCPIPStatus],1 + ; Convert GUINetTextk2 to IPAddrStr + mov ebx,GUINetTextk2 + mov edx,IPAddrStr +.notend + mov al,[ebx] + cmp al,' ' + je .dontinclude + mov [edx],al + inc edx +.dontinclude + inc ebx + cmp al,0 + jne .notend +; int ConnectServer(char *servername, unsigned short port) + mov ax,[TCPIPPortNum] + push ax + mov eax,IPAddrStr + push eax +; call ConnectServer + add esp,6 + or eax,eax + jnz .noclient + mov byte[TCPIPStatus],3 +.noclient + xor eax,eax + ret +.failed + mov eax,1 + ret + +NEWSYM TCPIPStoreByte + ; Store al into the array + cmp dword[PacketSendSize],256 + je .packeterror + push ebx + mov ebx,[PacketSendSize] + mov [PacketSendArray+ebx],al + pop ebx + inc dword[PacketSendSize] + ret +.packeterror + jmp OSExit + +NEWSYM TCPIPGetByte + ; dh = 0 : No bytes in buffer + ; dl = resulting character + cmp dword[PacketRecvSize],0 + jne .bytereceived + mov dword[PacketRecvPtr],0 + call TCPIPRecvPacket + cmp dword[PacketRecvSize],0 + jne .bytereceived + xor dh,dh + ret +.bytereceived + push eax + mov eax,[PacketRecvPtr] + mov dl,[PacketRecvArray+eax] + mov dh,1 + inc dword[PacketRecvPtr] + mov eax,[PacketRecvPtr] + cmp [PacketRecvSize],eax + jne .notequal + mov dword[PacketRecvSize],0 +.notequal + pop eax + ret + +NEWSYM TCPIPSendPacket + cmp dword[PacketSendSize],0 + je .nopacket + pushad + ; Send PacketSendArray with size of PacketSendSize + ; SendData(int dsize,char *dptr) + mov eax,PacketSendArray + push eax + mov eax,[PacketSendSize] + push eax +; call SendData + or eax,eax + jnz .failed + add esp,8 + popad +.nopacket + ret +.failed + add esp,8 + popad + call TCPIPDisconnect + jmp OSExit + +NEWSYM TCPIPRecvPacket + pushad + ; Store packet to PacketRecvArray, size at PacketRecvSize + ; int GetData(int dsize,char *dptr) + mov eax,PacketRecvArray + push eax + mov eax,256 + push eax +; call GetData + cmp eax,-1 + je .failed + mov [PacketRecvSize],eax + add esp,8 + popad + ret +.failed + add esp,8 + popad + call TCPIPDisconnect + jmp OSExit + +NEWSYM TCPIPDisconnect +; call DeInitTCP + cmp byte[TCPIPStatus],3 + jne .notserver +; call StopServer +.notserver + cmp byte[TCPIPStatus],3 + jne .notclient +; call Disconnect +.notclient + ret + +NEWSYM TCPIPPreparePacket + mov dword[PacketSendSize],0 + ret + +NEWSYM TCPIPConnectToServer + ret + +NEWSYM TCPIPWaitForConnection + ret + +NEWSYM TCPIPSendPacketUDP + ret + +NEWSYM TCPIPConnectToServerW + ret + +NEWSYM GetHostName + ret + +NEWSYM hostname +NEWSYM UDPConfig +NEWSYM tcperr, dd 0,0,0,0 + +NEWSYM ClearUDPStuff +NEWSYM Wait1SecWin +NEWSYM EnableSUDPPacket +NEWSYM DisableSUDPPacket +NEWSYM WinErrorA +NEWSYM WinErrorB +NEWSYM GotoHomepage + ret + +NEWSYM GetTimeInSeconds + push es + mov ax,[selc0040] + mov es,ax + mov eax,[es:108] + and eax,0FFFFFFh + xor edx,edx + mov ebx,86400 + mul ebx + mov ebx,1573039 + div ebx + pop es + ret + \ No newline at end of file diff --git a/zsnes/src/dos/gppro.asm b/zsnes/src/dos/gppro.asm new file mode 100644 index 00000000..37331fed --- /dev/null +++ b/zsnes/src/dos/gppro.asm @@ -0,0 +1,156 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +section .data +sample times 60 db 0 +clock_mask db 0 +data_mask db 0 + +section .text + +NEWSYM read_gpp + push ebx + push ecx + push edx + push edi + push esi + + cmp al,0 + jne GPP_L14 + mov byte [clock_mask],0x10 + mov byte [data_mask],0x20 + jmp GPP_L15 +GPP_L14: + mov byte [clock_mask],0x40 + mov byte [data_mask],0x80 +GPP_L15: + + + xor ebx,ebx + xor edi,edi + + cli + in al,dx + mov ah,al + +GPP_L4: + xor ecx,ecx +GPP_L0: + nop + nop + nop + nop + nop + nop + in al,dx + cmp al,ah + jne GPP_L1 + inc ecx + cmp ecx,255 + jl GPP_L0 +GPP_L1: + cmp ecx,255 + je near GPP_ERR + + test [clock_mask],ah + jz GPP_L2 + test [clock_mask],al + jnz GPP_L2 + + test [data_mask],al + jz GPP_L3 + mov byte [sample+edi],1 + jmp GPP_L12 +GPP_L3: + mov byte [sample+edi],0 +GPP_L12: + inc edi + +GPP_L2: + mov ah,al + cmp ebx,200 + je GPP_L13 + inc ebx + cmp edi,50 + jl GPP_L4 + +GPP_L13: + sti + xor ecx,ecx + mov esi,1 +GPP_L7: + cmp byte [sample+esi],1 + jg GPP_ERR + jne GPP_L6 + inc ecx + jmp GPP_L5 +GPP_L6: + xor ecx,ecx + +GPP_L5: + cmp ecx,5 + je GPP_L8 + cmp esi,edi + je GPP_L8 + inc esi + jmp GPP_L7 + +GPP_L8: + cmp ecx,5 + jne GPP_ERR + add esi,2 + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + +GPP_L10: + inc ecx + cmp ecx,5 + jne GPP_L11 + mov ecx,1 + inc esi +GPP_L11: + mov dl,[sample+esi] + or eax,edx + shl eax,1 + cmp ebx,13 + je GPP_L9 + inc ebx + inc esi + jmp GPP_L10 + +GPP_L9: + pop esi + pop edi + pop edx + pop ecx + pop ebx + ret + +GPP_ERR: + sti + pop esi + pop edi + pop edx + pop ecx + pop ebx + mov eax,1 + ret + \ No newline at end of file diff --git a/zsnes/src/dos/initvid.asm b/zsnes/src/dos/initvid.asm new file mode 100644 index 00000000..24a7a75e --- /dev/null +++ b/zsnes/src/dos/initvid.asm @@ -0,0 +1,621 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM AddSub256,InitVesa2,cbitmode,cvidmode,makepal +EXTSYM scanlines,selcA000,vesa2_bits,vesa2_bpos,vesa2_clbit +EXTSYM vesa2_gpos,vesa2_rpos,vesa2_usbit,vesa2_x,vesa2_y +EXTSYM vesa2selec,InitVesa12,videotroub + + + + + + +NEWSYM clearfilter, dw 0 +NEWSYM res640, db 0 +NEWSYM res480, db 0 + +NEWSYM dosinitvideo2 + jmp dosinitvideo.noaddsub + +;******************************************************* +; InitVideo +;******************************************************* +NEWSYM dosinitvideo + mov byte[cbitmode],0 + mov byte[res640],0 + mov byte[res480],0 + cmp byte[cvidmode],0 + je near .initmodex + cmp byte[cvidmode],1 + je near .initmodeq + cmp byte[cvidmode],2 + je near .initvesa2320x240x8 + cmp byte[cvidmode],3 + je near .initvesa2320x240x16 + cmp byte[cvidmode],4 + je near .initvesa2640x480x8 + cmp byte[cvidmode],5 + je near .initvesa2640x480x16 + cmp byte[cvidmode],6 + je near .initvesa2512x384x8 + cmp byte[cvidmode],7 + je near .initvesa2512x384x16 + cmp byte[cvidmode],8 + je near .initvesa12640x480x16 + cmp byte[cvidmode],9 + je near .initvesa2320x480x8 + cmp byte[cvidmode],10 + je near .initvesa2320x480x16 + ret + +;******************************************************* +; InitModeX Sets up 320x240 unchained mode +;******************************************************* + +.initmodex + mov byte[cbitmode],0 + mov ax,0013h + int 10h + + mov dx,03C4h + mov ax,0604h + out dx,ax + mov dx,03D4h + mov ax,0E317h + out dx,ax + mov ax,0014h + out dx,ax + mov dx,03C4h + mov ax,0F02h + out dx,ax + + mov dx,03C2h + mov al,0E3h + out dx,al + mov dx,03D4h + mov ax,2C11h + out dx,ax + mov ax,0D06h + out dx,ax + mov ax,3E07h + out dx,ax + mov ax,0EA10h + out dx,ax + mov ax,0AC11h + out dx,ax + mov ax,0DF12h + out dx,ax + mov ax,0E715h + out dx,ax + mov ax,0616h + out dx,ax + + mov dx,03C6h + mov al,0FFh + out dx,al + mov dx,03C4h + ; select all 4 planes and clear + mov ax,0F02h + out dx,ax + push es + mov ax,[selcA000] + mov es,ax + xor edi,edi + mov ecx,65536/4 + xor eax,eax + rep stosd + pop es + call makepal + ret + +;******************************************************* +; InitModeQ Sets up 256x256 chained mode +;******************************************************* + +.initmodeq + mov byte[cbitmode],0 + cmp byte[AddSub256],1 + jne .noaddsub + mov byte[cbitmode],1 +.noaddsub + mov byte[vesa2_rpos],11 ; Red bit position 128,256,512,1024,2048 + mov byte[vesa2_gpos],6 ; Green bit position 2^6 = 64 + mov byte[vesa2_bpos],0 ; Blue bit position + mov word[vesa2_usbit],0020h ; Unused bit in proper bit location + mov word[vesa2_clbit],0F7DFh ; clear all bit 0's if AND is used + mov word[clearfilter],0F7DFh ; Filter out unnecessary bits + + cmp byte[scanlines],1 + je near .scanlines + mov ax,0013h + int 10h + mov dx,03D4h + mov al,11h + out dx,al + + inc dx + in al,dx + and al,7Fh + mov ah,al + dec dx + mov al,11h + out dx,al + inc dx + mov al,ah + out dx,al + + mov dx,03C2h + mov al,0E3h + out dx,al + mov dx,03D4h + mov ax,5F00h + out dx,ax + mov ax,3F01h + out dx,ax + mov ax,4002h + out dx,ax + mov ax,8203h + out dx,ax + mov ax,4A04h + out dx,ax + mov ax,9A05h + out dx,ax + mov ax,2306h + out dx,ax + mov ax,0B207h + out dx,ax + mov ax,0008h + out dx,ax + mov ax,6109h + out dx,ax + mov ax,0A10h + out dx,ax + mov ax,0AC11h + out dx,ax + mov ax,0FF12h + out dx,ax + mov ax,2013h + out dx,ax + mov ax,4014h + out dx,ax + mov ax,0715h + out dx,ax + mov ax,1A16h + out dx,ax + mov ax,0A317h + out dx,ax + mov dx,03C4h + mov ax,0101h + out dx,ax + mov ax,0E04h + out dx,ax + mov dx,03CEh + mov ax,4005h + out dx,ax + mov ax,0506h + out dx,ax + + mov dx,03DAh + in al,dx + mov dx,03C0h + mov al,30h + out dx,al + mov al,41h + out dx,al + + mov dx,03DAh + in al,dx + mov dx,03C0h + mov al,33h + out dx,al + mov al,0h + out dx,al + + mov dx,03C6h + mov al,0FFh + out dx,al + cmp byte[cbitmode],1 + je .nopal + call makepal +.nopal + ; clear screen + push es + mov ax,[selcA000] + mov es,ax + xor edi,edi + mov ecx,256*64 + xor eax,eax + rep stosd + pop es + ret + +.scanlines + mov ax,0013h + int 10h + mov dx,03D4h + mov al,11h + out dx,al + + inc dx + in al,dx + and al,7Fh + mov ah,al + dec dx + mov al,11h + out dx,al + inc dx + mov al,ah + out dx,al + + mov dx,03C2h + mov al,0E3h + out dx,al + mov dx,03D4h + mov ax,5F00h + out dx,ax + mov ax,3F01h + out dx,ax + mov ax,4002h + out dx,ax + mov ax,8203h + out dx,ax + mov ax,4A04h + out dx,ax + mov ax,9A05h + out dx,ax + mov ax,2306h + out dx,ax + mov ax,01D07h + out dx,ax + mov ax,0008h + out dx,ax + mov ax,6009h + out dx,ax + mov ax,0A10h + out dx,ax + mov ax,0AC11h + out dx,ax + mov ax,0FF12h + out dx,ax + mov ax,2013h + out dx,ax + mov ax,4014h + out dx,ax + mov ax,0715h + out dx,ax + mov ax,1A16h + out dx,ax + mov ax,0A317h + out dx,ax + mov dx,03C4h + mov ax,0101h + out dx,ax + mov ax,0E04h + out dx,ax + mov dx,03CEh + mov ax,4005h + out dx,ax + mov ax,0506h + out dx,ax + + mov dx,03DAh + in al,dx + mov dx,03C0h + mov al,30h + out dx,al + mov al,41h + out dx,al + + mov dx,03DAh + in al,dx + mov dx,03C0h + mov al,33h + out dx,al + mov al,0h + out dx,al + + mov dx,03C6h + mov al,0FFh + out dx,al + cmp byte[cbitmode],1 + je .nopalb + call makepal +.nopalb + ; clear screen + push es + mov ax,[selcA000] + mov es,ax + xor edi,edi + mov ecx,256*64 + xor eax,eax + rep stosd + pop es + ret + +;******************************************************* +; InitVESA2 320x240x8 Set up Linear 320x240x8b +;******************************************************* + +.initvesa2320x240x8 + mov byte[cbitmode],0 + mov word[vesa2_x],320 + mov word[vesa2_y],240 + mov byte[vesa2_bits],8 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble + ret +.notrouble + call makepal + ; clear screen (320*240 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,320*240 +.loop + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loop + pop es + ret + +;******************************************************* +; InitVESA2 320x240x16 Set up Linear 320x240x16b +;******************************************************* + +.initvesa2320x240x16 + mov byte[cbitmode],1 + mov word[vesa2_x],320 + mov word[vesa2_y],240 + mov byte[vesa2_bits],16 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble2 + ret +.notrouble2 + ; clear screen (320*240*2 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,320*240*2 +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + +;******************************************************* +; InitVESA2 640x480x8 Set up Linear 640x480x8b +;******************************************************* + +.initvesa2640x480x8 + mov byte[res640],1 + mov byte[res480],1 + mov word[vesa2_x],640 + mov word[vesa2_y],480 + mov byte[vesa2_bits],8 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble3 + ret +.notrouble3 + call makepal + ; clear screen (640*480 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,640*480 +.loopc3 + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopc3 + pop es + ret + +;******************************************************* +; InitVESA2 640x480x16 Set up Linear 640x480x16b +;******************************************************* + +.initvesa2640x480x16 + mov byte[res640],1 + mov byte[res480],1 + mov byte[cbitmode],1 + mov word[vesa2_x],640 + mov word[vesa2_y],480 + mov byte[vesa2_bits],16 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble4 + ret +.notrouble4 + ; clear screen (640*480*2 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,640*480*2 +.loopd3 + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopd3 + pop es + ret + +;******************************************************* +; InitVESA2 320x480x8 Set up Linear 320x480x8b +;******************************************************* + +.initvesa2320x480x8 + mov byte[res480],1 + mov word[vesa2_x],320 + mov word[vesa2_y],480 + mov byte[vesa2_bits],8 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble5 + ret +.notrouble5 + call makepal + ; clear screen (320*480 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,320*480 +.loopc + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopc + pop es + ret + +;******************************************************* +; InitVESA2 320x480x16 Set up Linear 320x480x16b +;******************************************************* + +.initvesa2320x480x16 + mov byte[res480],1 + mov byte[cbitmode],1 + mov word[vesa2_x],320 + mov word[vesa2_y],480 + mov byte[vesa2_bits],16 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble6 + ret +.notrouble6 + ; clear screen (320*480*2 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,320*480*2 +.loopd + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopd + pop es + ret + +;******************************************************* +; InitVESA2 512x384x8 Set up Linear 512x384x8b +;******************************************************* + +.initvesa2512x384x8 + mov byte[res640],2 + mov word[vesa2_x],512 + mov word[vesa2_y],384 + mov byte[vesa2_bits],8 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble7 + ret +.notrouble7 + call makepal + ; clear screen (512*384 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,512*384 +.loope + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loope + pop es + ret + +;******************************************************* +; InitVESA2 512x384x16 Set up Linear 512x384x16b +;******************************************************* + +.initvesa2512x384x16 + mov byte[res640],2 + mov byte[cbitmode],1 + mov word[vesa2_x],512 + mov word[vesa2_y],384 + mov byte[vesa2_bits],16 + call InitVesa2 + cmp byte[videotroub],1 + jne .notrouble8 + ret +.notrouble8 + ; clear screen (512*384*2 bytes) + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,0 + mov ecx,512*384*2 +.loopf + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopf + pop es + ret + + +;******************************************************* +; InitVESA1.2 640x480x16 Set up 640x480x16b +;******************************************************* + +.initvesa12640x480x16 + mov byte[res640],1 + mov byte[cbitmode],1 + mov word[vesa2_x],640 + mov word[vesa2_y],480 + mov byte[vesa2_bits],16 + call InitVesa12 + ret + + ; clear screen (640*480*2 bytes) + push es + mov ax,[selcA000] + mov es,ax + mov ebx,9 + xor edx,edx +.loopbanks + + xor edi,edi + mov ecx,16384 +.loopg + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopg + dec ebx + jnz .loopbanks + + mov ecx,6144 + pop es + ret + + \ No newline at end of file diff --git a/zsnes/src/dos/joy.asm b/zsnes/src/dos/joy.asm new file mode 100644 index 00000000..8297d05c --- /dev/null +++ b/zsnes/src/dos/joy.asm @@ -0,0 +1,1617 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM JoyAC,JoyBC,JoyLC,JoyRC,JoySelec,JoyStart,JoyXC,JoyYC,WhichSW,_SW1 +EXTSYM _SW2,_readSideWinder,delay,numjoy,pl1Ak,pl1Bk,pl1Lk,pl1Rk,pl1Xk +EXTSYM pl1Yk,pl1contrl,pl1downk,pl1leftk,pl1rightk,pl1selk,pl1startk +EXTSYM pl1upk,pl2Ak,pl2Bk,pl2Lk,pl2Rk,pl2Xk,pl2Yk,pl2contrl,pl2downk +EXTSYM pl2leftk,pl2rightk,pl2selk,pl2startk,pl2upk,_SWCount,_SW3,_SW4 +EXTSYM pl3Ak,pl3Bk,pl3Lk,pl3Rk,pl3Xk,pl1p209,pl2p209,pl3p209,pl4p209 +EXTSYM pl3Yk,pl3contrl,pl3downk,pl3leftk,pl3rightk,pl3selk,pl3startk +EXTSYM pl3upk,pl4Ak,pl4Bk,pl4Lk,pl4Rk,pl4Xk,pl4Yk,pl4contrl,pl4downk +EXTSYM pl4leftk,pl4rightk,pl4selk,pl4startk,pl4upk,pressed,read_gpp +EXTSYM pl5contrl,pl5p209 +EXTSYM CalibXmin, CalibYmin, CalibXmax, CalibYmax, CalibXmin209 +EXTSYM CalibYmin209, CalibXmax209, CalibYmax209 + + +NEWSYM joy4218, db 0 +NEWSYM joy4219, db 0 +NEWSYM joy4218j, db 0 +NEWSYM joy4219j, db 0 +NEWSYM joy421A, db 0 +NEWSYM joy421B, db 0 +NEWSYM joy421Aj, db 0 +NEWSYM joy421Bj, db 0 + +NEWSYM JoyCenterX, dd 0 +NEWSYM JoyCenterY, dd 0 +NEWSYM JoyMaxX, dd 0 +NEWSYM JoyMaxY, dd 0 +NEWSYM JoyMinX, dd 0 +NEWSYM JoyMinY, dd 0 +NEWSYM JoyExists, db 0 +NEWSYM JoyX, dd 0 +NEWSYM JoyY, dd 0 +NEWSYM JoyCenterX2, dd 0 +NEWSYM JoyCenterY2, dd 0 +NEWSYM JoyMaxX2, dd 0 +NEWSYM JoyMaxY2, dd 0 +NEWSYM JoyMinX2, dd 0 +NEWSYM JoyMinY2, dd 0 +NEWSYM JoyExists2, db 0 +NEWSYM JoyX2, dd 0 +NEWSYM JoyY2, dd 0 +NEWSYM JoyAltrn, db 0 +NEWSYM JoyAltrn2, db 2 +NEWSYM JoyCenterX209, dd 0 +NEWSYM JoyCenterY209, dd 0 +NEWSYM JoyMaxX209, dd 0 +NEWSYM JoyMaxY209, dd 0 +NEWSYM JoyMinX209, dd 0 +NEWSYM JoyMinY209, dd 0 +NEWSYM JoyCenterX2209, dd 0 +NEWSYM JoyCenterY2209, dd 0 +NEWSYM JoyMaxX2209, dd 0 +NEWSYM JoyMaxY2209, dd 0 +NEWSYM JoyMinX2209, dd 0 +NEWSYM JoyMinY2209, dd 0 + +JoyQuant db 0 +JoyBQuant db 0 +NumSWs db 0 +NumGRiPs db 0 +PPad db 0 ; b0 = pp0, b1 = pp1 + +JoyQuant209 db 0 +JoyBQuant209 db 0 +NumSWs209 db 0 +NumGRiPs209 db 0 +Buttons6 db 0 +Buttons6209 db 0 + +;NEWSYM pl3selk, dd 0 ; 3SELECT = SHIFT +;NEWSYM pl3startk, dd 0 ; 3START = ENTER +;NEWSYM pl3upk, dd 0 ; 3UP = up +;NEWSYM pl3downk, dd 0 ; 3DOWN = down +;NEWSYM pl3leftk, dd 0 ; 3LEFT = left +;NEWSYM pl3rightk, dd 0 ; 3RIGHT = right +;NEWSYM pl3Yk, dd 0 ; 3X = INS +;NEWSYM pl3Xk, dd 0 ; 3A = HOME +;NEWSYM pl3Lk, dd 0 ; 3L = PAGE UP +;NEWSYM pl3Bk, dd 0 ; 3Y = DELETE +;NEWSYM pl3Ak, dd 0 ; 3B = END +;NEWSYM pl3Rk, dd 0 ; 3R = PAGE DOWN + + +NEWSYM GetCoords + mov dword[JoyX],0 + mov dword[JoyY],0 + cli + mov al,0 + out dx,al + mov ecx,00FFFFh +.loopa + in al,dx + test al,01H + jz .YAxis + test al,02H + jz .XAxis + inc dword[JoyX] + inc dword[JoyY] + loop .loopa + mov byte [JoyExists], 0 + mov dword[JoyX],0 + mov dword[JoyY],0 + jmp .End +.YAxis + in al,dx + test al,02h + jz .YAxisOk + nop + nop + inc dword[JoyY] + nop + loop .YAxis + mov byte [JoyExists], 0 + mov dword[JoyX],0 + mov dword[JoyY],0 +.YAxisOk + jmp .End +.XAxis + in al,dx + test al,01h + jz .XAxisOk + nop + nop + inc dword[JoyX] + nop + loop .XAxis + mov byte [JoyExists], 0 + mov dword[JoyX],0 + mov dword[JoyY],0 +.XAxisOk +.End + sti + ret + +; Dual Joysticks + +NEWSYM GetCoords3 + mov dword[JoyX],0 + mov dword[JoyY],0 + mov dword[JoyX2],0 + mov dword[JoyY2],0 + cli + mov al,0 + out dx,al + mov ecx,01FFFFh +.loopa + in al,dx + test al,01H + jz .YAxis + inc dword[JoyX] + nop +.YAxis + test al,02H + jz .XAxis + inc dword[JoyY] + nop +.XAxis + test al,04H + jz .YAxis2 + inc dword[JoyX2] + nop +.YAxis2 + test al,08H + jz .XAxis2 + inc dword[JoyY2] + nop +.XAxis2 + test al,0Fh + jz .nomore + dec ecx + jnz .loopa + mov byte [JoyExists], 0 + mov dword[JoyX],0 + mov dword[JoyY],0 + mov byte [JoyExists2], 0 + mov dword[JoyX2],0 + mov dword[JoyY2],0 +.nomore + sti + ret + +NEWSYM DosUpdateDevices + mov byte[PPad],0 + mov byte[JoyQuant],0 + mov byte[JoyBQuant],0 + mov byte[NumSWs],0 + mov byte[NumGRiPs],0 + mov byte[JoyQuant209],0 + mov byte[JoyBQuant209],0 + mov byte[NumSWs209],0 + mov byte[NumGRiPs209],0 + mov byte[Buttons6],0 + mov byte[Buttons6209],0 + ; Check for button #'s, joystick types, etc. + mov al,[pl1contrl] + mov ah,[pl1p209] + call .checkdevice + mov al,[pl2contrl] + mov ah,[pl2p209] + call .checkdevice + mov al,[pl3contrl] + mov ah,[pl3p209] + call .checkdevice + mov al,[pl4contrl] + mov ah,[pl4p209] + call .checkdevice + mov al,[pl5contrl] + mov ah,[pl5p209] + call .checkdevice + ; Auto-Calibrate the joysticks + cmp byte[JoyQuant],2 + jne .no2joyst + mov dx,201h + mov byte[JoyExists2],1 + call GetCoords3 + mov ecx,1000 + call delay + cmp byte[JoyExists2],0 + jne .no2joyst + mov byte[JoyQuant],1 +.no2joyst + cmp byte[JoyQuant],1 + jne .no1joyst + mov dx,201h + mov byte[JoyExists],1 + call GetCoords + mov ecx,1000 + call delay + cmp byte[JoyExists],0 + jne .no1joyst + mov byte[JoyQuant],0 +.no1joyst + ; set max & mins + mov ecx,[JoyX2] + mov [JoyCenterX2], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinX2],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxX2],eax + mov ecx,[JoyY2] + mov [JoyCenterY2], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinY2],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxY2],eax + mov ecx,[JoyX] + mov [JoyCenterX], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinX],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxX],eax + mov ecx,[JoyY] + mov [JoyCenterY], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinY],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxY],eax + ; Port 209 + ; Auto-Calibrate the joysticks + cmp byte[JoyQuant209],2 + jne .no2joyst2 + mov dx,209h + mov byte[JoyExists2],1 + call GetCoords3 + mov ecx,1000 + call delay + cmp byte[JoyExists2],0 + jne .no2joyst2 + mov byte[JoyQuant209],1 +.no2joyst2 + cmp byte[JoyQuant209],1 + jne .no1joyst2 + mov dx,209h + mov byte[JoyExists],1 + call GetCoords + mov ecx,1000 + call delay + cmp byte[JoyExists],0 + jne .no1joyst2 + mov byte[JoyQuant209],0 +.no1joyst2 + ; set max & mins + mov ecx,[JoyX2] + mov [JoyCenterX2209], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinX2209],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxX2209],eax + mov ecx,[JoyY2] + mov [JoyCenterY2209], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinY2209],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxY2209],eax + mov ecx,[JoyX] + mov [JoyCenterX209], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinX209],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxX209],eax + mov ecx,[JoyY] + mov [JoyCenterY209], ecx + mov eax,ecx + shr ecx,1 + sub eax,ecx + mov dword[JoyMinY209],eax + add eax,ecx + add eax,ecx + mov dword[JoyMaxY209],eax + cmp dword[CalibXmin],0 + je .nocalib + mov eax,[CalibXmin] + mov [JoyMinX],eax + mov eax,[CalibYmin] + mov [JoyMinY],eax + mov eax,[CalibXmax] + mov [JoyMaxX],eax + mov eax,[CalibYmax] + mov [JoyMaxY],eax +.nocalib + cmp dword[CalibXmin209],0 + je .nocalib209 + mov eax,[CalibXmin209] + mov [JoyMinX209],eax + mov eax,[CalibYmin209] + mov [JoyMinY209],eax + mov eax,[CalibXmax209] + mov [JoyMaxX209],eax + mov eax,[CalibYmax209] + mov [JoyMaxY209],eax +.nocalib209 + ret +.checkdevice + ; 1 = keyboard, 2 = 2b joystick, 3,4 = 4b joystick, 5 = 6b joystick + ; 6 = Sidewinder1, 7 = Sidewinder2, 8 = Sidewinder3, 9 = Sidewiner4 + ; 10 = Grip0, 11 = Grip1, 12 = Grip2, 13 = Grip3, 14 = Parallel pad0 + ; 15 = Parallel pad1, 16 = PPad LPT2, 17 = PPad2 LPT2, 18 = 8b joystick + cmp al,1 + ja .joyokay + ret +.joyokay + cmp al,14 + jne .nopp0 + or byte[PPad],1 + ret +.nopp0 + cmp al,15 + jne .nopp1 + or byte[PPad],2 + ret +.nopp1 + cmp al,16 + jne .nopp2 + or byte[PPad],4 + ret +.nopp2 + cmp al,17 + jne .nopp3 + or byte[PPad],8 + ret +.nopp3 + cmp ah,0 + jne near .port209 + cmp al,2 + jne .nojoy2b + inc byte[JoyQuant] + add byte[JoyBQuant],2 + ret +.nojoy2b + cmp al,3 + je .joy4b + cmp al,4 + jne .nojoy4b +.joy4b + mov byte[JoyQuant],1 + mov byte[JoyBQuant],4 + ret +.nojoy4b + cmp al,5 + jne .nojoy6b + mov byte[JoyQuant],2 + mov byte[JoyBQuant],6 + mov byte[Buttons6],1 + ret +.nojoy6b + cmp al,18 + jne .nojoy8b + mov byte[JoyQuant],2 + mov byte[JoyBQuant],8 + mov byte[Buttons6],2 + ret +.nojoy8b + cmp al,9 + ja .grip + sub al,5 + cmp byte[NumSWs],al + ja .skipswc + mov byte[NumSWs],al +.skipswc + ret +.grip + cmp al,13 + ja .none + sub al,9 + cmp byte[NumGRiPs],al + ja .skipgripc + mov byte[NumGRiPs],al +.skipgripc +.none + ret +.port209 + cmp al,2 + jne .nojoy2b2 + inc byte[JoyQuant209] + add byte[JoyBQuant209],2 + ret +.nojoy2b2 + cmp al,3 + je .joy4b2 + cmp al,4 + jne .nojoy4b2 +.joy4b2 + mov byte[JoyQuant209],1 + mov byte[JoyBQuant209],4 + ret +.nojoy4b2 + cmp al,5 + jne .nojoy6b2 + mov byte[JoyQuant209],2 + mov byte[JoyBQuant209],6 + mov byte[Buttons6209],1 + ret +.nojoy6b2 + cmp al,18 + jne .nojoy8b2 + mov byte[JoyQuant209],2 + mov byte[JoyBQuant209],8 + mov byte[Buttons6209],2 + ret +.nojoy8b2 + cmp al,9 + ja .grip2 + sub al,5 + cmp byte[NumSWs209],al + ja .skipswc2 + mov byte[NumSWs209],al +.skipswc2 + ret +.grip2 + cmp al,13 + ja .none2 + sub al,9 + cmp byte[NumGRiPs209],al + ja .skipgripc2 + mov byte[NumGRiPs209],al +.skipgripc2 +.none2 + ret + +NEWSYM JoyReadControl, db 0 + +JoyRead209: + cmp byte[JoyAltrn],1 + jne near .noanalog + + ; Clear Joystick buttons and movements + mov word[pressed+100h],0 ; B7-8 + mov word[pressed+106h],0 ; B5-6 + mov dword[pressed+14Ch],0 ; Up,Down,Left,Right, pl1 + mov dword[pressed+168h],0 ; Up,Down,Left,Right, pl2 + + ; Process Joystick(s) + cmp byte[JoyQuant209],2 + jne near .no2joyst + mov dx,209h + call GetCoords3 + + ; Set button 5-6 + 2player Control + cmp byte[Buttons6209],0 + jne near .6button + mov eax,[JoyX2] + cmp eax,[JoyMinX2209] + jae .noleft2 + mov byte[pressed+16Ah],1 +.noleft2 + mov eax,[JoyX2] + cmp eax,[JoyMaxX2209] + jbe .noright2 + mov byte[pressed+16Bh],1 +.noright2 + mov eax,[JoyY2] + cmp eax,[JoyMinY2209] + jae .noup2 + mov byte[pressed+168h],1 +.noup2 + mov eax,[JoyY2] + cmp eax,[JoyMaxY2209] + jbe .nodown2 + mov byte[pressed+169h],1 +.nodown2 + jmp .1pcoord +.6button + mov eax,[JoyY2] + cmp eax,[JoyMinY2209] + jae .nob5 + mov byte[pressed+106h],1 +.nob5 + mov eax,[JoyX2] + cmp eax,[JoyMinX2209] + jae .nob6 + mov byte[pressed+107h],1 +.nob6 + cmp byte[Buttons6209],2 + jne .no8b + mov eax,[JoyY2] + cmp eax,[JoyMaxY2209] + jbe .nob7 + mov byte[pressed+100h],1 +.nob7 + mov eax,[JoyX2] + cmp eax,[JoyMaxX2209] + jbe .nob8 + mov byte[pressed+101h],1 +.nob8 +.no8b + jmp .1pcoord +.no2joyst + + ; Set 1 player control + cmp byte[JoyQuant209],1 + jne near .no1joyst + mov dx,209h + call GetCoords +.1pcoord + mov eax,[JoyX] + cmp eax,[JoyMinX209] + jae .noleft + mov byte[pressed+14Eh],1 +.noleft + mov eax,[JoyX] + cmp eax,[JoyMaxX209] + jbe .noright + mov byte[pressed+14Fh],1 +.noright + mov eax,[JoyY] + cmp eax,[JoyMinY209] + jae .noup + mov byte[pressed+14Ch],1 +.noup + mov eax,[JoyY] + cmp eax,[JoyMaxY209] + jbe .nodown + mov byte[pressed+14Dh],1 +.nodown +.no1joyst +.noanalog + test byte[JoyAltrn],1 + jne near .joynotexist + mov dword[pressed+102h],0 ; B1-4 + cmp byte[JoyQuant209],0 + je .joynotexist + ; Set buttons 1-4 + mov dx, 0209h + xor al,al + out dx, al + in al, dx + not al + test al,10h + jz .nob1 + mov byte[pressed+102h],1 +.nob1 + test al,20h + jz .nob2 + mov byte[pressed+103h],1 +.nob2 + cmp byte[JoyBQuant209],2 + je .joynotexist + test al,40h + jz .nob3 + mov byte[pressed+104h],1 +.nob3 + test al,80h + jz .nob4 + mov byte[pressed+105h],1 +.nob4 +.joynotexist + ret + +NEWSYM DOSJoyRead + push edx + push ebx + push ecx + + inc byte[JoyAltrn] + and byte[JoyAltrn],3 + + cmp byte[JoyAltrn],0 + jne near .noanalog + + ; Clear Joystick buttons and movements + mov word[pressed+86h],0 ; B5-6 + mov word[pressed+80h],0 ; B7-8 + mov dword[pressed+0CCh],0 ; Up,Down,Left,Right, pl1 + mov dword[pressed+0E8h],0 ; Up,Down,Left,Right, pl2 + + ; Process Joystick(s) + cmp byte[JoyQuant],2 + jne near .no2joyst + mov dx,201h + call GetCoords3 + + ; Set button 5-6 + 2player Control + cmp byte[Buttons6],0 + jne near .6button + mov eax,[JoyX2] + cmp eax,[JoyMinX2] + jae .noleft2 + mov byte[pressed+0EAh],1 +.noleft2 + mov eax,[JoyX2] + cmp eax,[JoyMaxX2] + jbe .noright2 + mov byte[pressed+0EBh],1 +.noright2 + mov eax,[JoyY2] + cmp eax,[JoyMinY2] + jae .noup2 + mov byte[pressed+0E8h],1 +.noup2 + mov eax,[JoyY2] + cmp eax,[JoyMaxY2] + jbe .nodown2 + mov byte[pressed+0E9h],1 +.nodown2 + jmp .1pcoord +.6button + mov eax,[JoyY2] + cmp eax,[JoyMinY2] + jae .nob5 + mov byte[pressed+086h],1 +.nob5 + mov eax,[JoyX2] + cmp eax,[JoyMinX2] + jae .nob6 + mov byte[pressed+087h],1 +.nob6 + cmp byte[Buttons6],2 + jne .no8b + mov eax,[JoyY2] + cmp eax,[JoyMaxY2] + jbe .nob7 + mov byte[pressed+80h],1 +.nob7 + mov eax,[JoyX2] + cmp eax,[JoyMaxX2] + jbe .nob8 + mov byte[pressed+81h],1 +.nob8 +.no8b + jmp .1pcoord +.no2joyst + + ; Set 1 player control + cmp byte[JoyQuant],1 + jne near .no1joyst + mov dx,201h + call GetCoords +.1pcoord + mov eax,[JoyX] + cmp eax,[JoyMinX] + jae .noleft + mov byte[pressed+0CEh],1 +.noleft + mov eax,[JoyX] + cmp eax,[JoyMaxX] + jbe .noright + mov byte[pressed+0CFh],1 +.noright + mov eax,[JoyY] + cmp eax,[JoyMinY] + jae .noup + mov byte[pressed+0CCh],1 +.noup + mov eax,[JoyY] + cmp eax,[JoyMaxY] + jbe .nodown + mov byte[pressed+0CDh],1 +.nodown +.no1joyst +.noanalog + test byte[JoyAltrn],1 + jz .joynotexist + mov dword[pressed+82h],0 ; B1-4 + cmp byte[JoyQuant],0 + je .joynotexist + ; Set buttons 1-4 + mov dx, 0201h + xor al,al + out dx, al + in al, dx + not al + test al,10h + jz .nob1 + mov byte[pressed+82h],1 +.nob1 + test al,20h + jz .nob2 + mov byte[pressed+83h],1 +.nob2 + cmp byte[JoyBQuant],2 + je .joynotexist + test al,40h + jz .nob3 + mov byte[pressed+84h],1 +.nob3 + test al,80h + jz .nob4 + mov byte[pressed+85h],1 +.nob4 +.joynotexist + ; Process Joystick Buttons + cmp byte[JoyQuant209],0 + je .no209 + call JoyRead209 +.no209 + test byte[JoyAltrn],1 + jz near .noport4 + cmp byte[NumSWs],0 + je .nosw + call SideWinder +.nosw + cmp byte[NumSWs209],0 + je .nosw209 + call SideWinder209 +.nosw209 + test byte[JoyAltrn],2 + jz .nogrip209 + cmp byte[NumGRiPs],0 + je .nogrip + call GamePadPro +.nogrip + cmp byte[NumGRiPs209],0 + je .nogrip209 + call GamePadPro209 +.nogrip209 + test byte[PPad],1 + jz .noport1 + call GetParallelPlayer1 +.noport1 + test byte[PPad],2 + jz .noport2 + call GetParallelPlayer2 +.noport2 + test byte[PPad],4 + jz .noport3 + call GetParallelPlayer3 +.noport3 + test byte[PPad],8 + jz .noport4 + call GetParallelPlayer4 +.noport4 + cmp byte[JoyAltrn],0 + je .nogpp2209 + cmp byte[NumGRiPs],2 + jne .nogpp2 + call GamePadPro2 +.nogpp2 + cmp byte[NumGRiPs209],2 + jne .nogpp2209 + call GamePadPro2209 +.nogpp2209 + pop ecx + pop ebx + pop edx + ret + +;bit 1 - left,2 - right,3 - down,4 - up,5 - r1,6 - l1,7 - red,8 - yellow +; 9 - green,10 - l2,11 - blue,12 - r2,13 - start,14 - select + +%macro GPProHelp 2 + test eax,%1 + jz %%nope + mov byte[pressed+ebx+%2],1 +%%nope +%endmacro + +;A8=buttons, CA=select/start, F0=movement (inc by 4) +GamePadPro: + mov al,0 + mov dx,201h + call read_gpp + cmp eax,1 + je near .error + xor ebx,ebx + mov byte[pressed+ebx+0F0h],0 + mov byte[pressed+ebx+0F1h],0 + mov byte[pressed+ebx+0F2h],0 + mov byte[pressed+ebx+0F3h],0 + mov byte[pressed+ebx+0A8h],0 + mov byte[pressed+ebx+0A9h],0 + mov byte[pressed+ebx+0AAh],0 + mov byte[pressed+ebx+0ABh],0 + mov byte[pressed+ebx+0ACh],0 + mov byte[pressed+ebx+0ADh],0 + mov byte[pressed+ebx+0AEh],0 + mov byte[pressed+ebx+0AFh],0 + mov byte[pressed+ebx+0CAh],0 + mov byte[pressed+ebx+0CBh],0 + GPProHelp 0002h,0F2h ; left + GPProHelp 0004h,0F3h ; right + GPProHelp 0008h,0F1h ; down + GPProHelp 0010h,0F0h ; up + GPProHelp 0020h,0AEh ; r1 + GPProHelp 0040h,0ACh ; l1 + GPProHelp 0080h,0A8h ; red + GPProHelp 0100h,0AAh ; yellow + GPProHelp 0200h,0ABh ; green + GPProHelp 0400h,0ADh ; l2 + GPProHelp 0800h,0A9h ; blue + GPProHelp 1000h,0AFh ; r2 + GPProHelp 2000h,0CBh ; start + GPProHelp 4000h,0CAh ; select +.error + ret + +GamePadPro2: + mov al,1 + mov dx,201h + call read_gpp + cmp eax,1 + je near .error + mov ebx,4 + mov byte[pressed+ebx+0F0h],0 + mov byte[pressed+ebx+0F1h],0 + mov byte[pressed+ebx+0F2h],0 + mov byte[pressed+ebx+0F3h],0 + mov ebx,8 + mov byte[pressed+ebx+0A8h],0 + mov byte[pressed+ebx+0A9h],0 + mov byte[pressed+ebx+0AAh],0 + mov byte[pressed+ebx+0ABh],0 + mov byte[pressed+ebx+0ACh],0 + mov byte[pressed+ebx+0ADh],0 + mov byte[pressed+ebx+0AEh],0 + mov byte[pressed+ebx+0AFh],0 + mov byte[pressed+ebx+0CAh],0 + mov byte[pressed+ebx+0CBh],0 + mov ebx,4 + GPProHelp 0002h,0F2h ; left + GPProHelp 0004h,0F3h ; right + GPProHelp 0008h,0F1h ; down + GPProHelp 0010h,0F0h ; up + mov ebx,8 + GPProHelp 0020h,0AEh ; r1 + GPProHelp 0040h,0ACh ; l1 + GPProHelp 0080h,0A8h ; red + GPProHelp 0100h,0AAh ; yellow + GPProHelp 0200h,0ABh ; green + GPProHelp 0400h,0ADh ; l2 + GPProHelp 0800h,0A9h ; blue + GPProHelp 1000h,0AFh ; r2 + GPProHelp 2000h,0CBh ; start + GPProHelp 4000h,0CAh ; select +.error + ret + +NEWSYM SideWinder + mov al,[NumSWs] + mov [_SWCount],al + mov dx,201h + call _readSideWinder + ;bit 0=error 1=up 2=dn 3=rt 4=lt 5=A 6=B 7=C 8=X 9=Y 10=Z 11=L 12=R 13=St 14=M + ;k....L=L, R=R, start=start, M=select, X=y, Y=x, B=a, A=b + ;sidewinder=snes +.loop + mov eax,[_SW1] + xor ebx,ebx + cmp byte[WhichSW],2 + jne .noSW2 + mov eax,[_SW2] + mov ebx,08h +.noSW2 + cmp byte[WhichSW],3 + jne .noSW3 + mov eax,[_SW3] + mov ebx,10h +.noSW3 + cmp byte[WhichSW],4 + jne .noSW4 + mov eax,[_SW4] + mov ebx,18h +.noSW4 + inc byte[WhichSW] + mov byte[pressed+ebx+0D4h],0 + mov byte[pressed+ebx+0D5h],0 + mov byte[pressed+ebx+0D6h],0 + mov byte[pressed+ebx+0D7h],0 + mov byte[pressed+ebx+088h],0 + mov byte[pressed+ebx+089h],0 + mov byte[pressed+ebx+08Ah],0 + mov byte[pressed+ebx+08Bh],0 + mov byte[pressed+ebx+08Ch],0 + mov byte[pressed+ebx+08Dh],0 + mov byte[pressed+ebx+08Eh],0 + mov byte[pressed+ebx+08Fh],0 + mov byte[pressed+ebx+0C8h],0 + mov byte[pressed+ebx+0C9h],0 + test ax,02h ; up + jz .noup + mov byte[pressed+ebx+0D4h],1 +.noup + test ax,04h ; down + jz .nodown + mov byte[pressed+ebx+0D5h],1 +.nodown + test ax,08h ; right + jz .noright + mov byte[pressed+ebx+0D7h],1 +.noright + test ax,10h ; left + jz .noleft + mov byte[pressed+ebx+0D6h],1 +.noleft + test ax,20h ; A + jz .noa + mov byte[pressed+ebx+088h],1 +.noa + test ax,40h ; B + jz .nob + mov byte[pressed+ebx+089h],1 +.nob + test ax,80h ; C + jz .noc + mov byte[pressed+ebx+08Ah],1 +.noc + test ax,100h ; X + jz .nox + mov byte[pressed+ebx+08Bh],1 +.nox + test ax,200h ; Y + jz .noy + mov byte[pressed+ebx+08Ch],1 +.noy + test ax,400h ; Z + jz .noz + mov byte[pressed+ebx+08Dh],1 +.noz + test ax,800h ; L + jz .nol + mov byte[pressed+ebx+08Eh],1 +.nol + test ax,1000h ; R + jz .nor + mov byte[pressed+ebx+08Fh],1 +.nor + test ax,2000h ; start + jz .nostart + mov byte[pressed+ebx+0C8h],1 +.nostart + test ax,4000h ; M + jz .noselect + mov byte[pressed+ebx+0C9h],1 +.noselect + mov al,[WhichSW] + cmp al,[NumSWs] + jbe near .loop + ret ;return to calling procedure + +;A8=buttons, CA=select/start, F0=movement (inc by 4) +GamePadPro209: + mov al,0 + mov dx,209h + call read_gpp + cmp eax,1 + je near .error + xor ebx,ebx + mov byte[pressed+ebx+170h],0 + mov byte[pressed+ebx+171h],0 + mov byte[pressed+ebx+172h],0 + mov byte[pressed+ebx+173h],0 + mov byte[pressed+ebx+128h],0 + mov byte[pressed+ebx+129h],0 + mov byte[pressed+ebx+12Ah],0 + mov byte[pressed+ebx+12Bh],0 + mov byte[pressed+ebx+12Ch],0 + mov byte[pressed+ebx+12Dh],0 + mov byte[pressed+ebx+12Eh],0 + mov byte[pressed+ebx+12Fh],0 + mov byte[pressed+ebx+14Ah],0 + mov byte[pressed+ebx+14Bh],0 + GPProHelp 0002h,1F2h ; left + GPProHelp 0004h,1F3h ; right + GPProHelp 0008h,1F1h ; down + GPProHelp 0010h,1F0h ; up + GPProHelp 0020h,1AEh ; r1 + GPProHelp 0040h,1ACh ; l1 + GPProHelp 0080h,1A8h ; red + GPProHelp 0100h,1AAh ; yellow + GPProHelp 0200h,1ABh ; green + GPProHelp 0400h,1ADh ; l2 + GPProHelp 0800h,1A9h ; blue + GPProHelp 1000h,1AFh ; r2 + GPProHelp 2000h,1CBh ; start + GPProHelp 4000h,1CAh ; select +.error + ret + +GamePadPro2209: + mov al,1 + mov dx,209h + call read_gpp + cmp eax,1 + je near .error + mov ebx,4 + mov byte[pressed+ebx+170h],0 + mov byte[pressed+ebx+171h],0 + mov byte[pressed+ebx+172h],0 + mov byte[pressed+ebx+173h],0 + mov ebx,8 + mov byte[pressed+ebx+128h],0 + mov byte[pressed+ebx+129h],0 + mov byte[pressed+ebx+12Ah],0 + mov byte[pressed+ebx+12Bh],0 + mov byte[pressed+ebx+12Ch],0 + mov byte[pressed+ebx+12Dh],0 + mov byte[pressed+ebx+12Eh],0 + mov byte[pressed+ebx+12Fh],0 + mov byte[pressed+ebx+14Ah],0 + mov byte[pressed+ebx+14Bh],0 + mov ebx,4 + GPProHelp 0002h,1F2h ; left + GPProHelp 0004h,1F3h ; right + GPProHelp 0008h,1F1h ; down + GPProHelp 0010h,1F0h ; up + mov ebx,8 + GPProHelp 0020h,1AEh ; r1 + GPProHelp 0040h,1ACh ; l1 + GPProHelp 0080h,1A8h ; red + GPProHelp 0100h,1AAh ; yellow + GPProHelp 0200h,1ABh ; green + GPProHelp 0400h,1ADh ; l2 + GPProHelp 0800h,1A9h ; blue + GPProHelp 1000h,1AFh ; r2 + GPProHelp 2000h,1CBh ; start + GPProHelp 4000h,1CAh ; select +.error + ret + +NEWSYM SideWinder209 + mov al,[NumSWs209] + mov [_SWCount],al + mov dx,209h + call _readSideWinder + ;bit 0=error 1=up 2=dn 3=rt 4=lt 5=A 6=B 7=C 8=X 9=Y 10=Z 11=L 12=R 13=St 14=M + ;k....L=L, R=R, start=start, M=select, X=y, Y=x, B=a, A=b + ;sidewinder=snes +.loop + mov eax,[_SW1] + xor ebx,ebx + cmp byte[WhichSW],2 + jne .noSW2 + mov eax,[_SW2] + mov ebx,08h +.noSW2 + cmp byte[WhichSW],3 + jne .noSW3 + mov eax,[_SW3] + mov ebx,10h +.noSW3 + cmp byte[WhichSW],4 + jne .noSW4 + mov eax,[_SW4] + mov ebx,18h +.noSW4 + inc byte[WhichSW] + mov byte[pressed+ebx+154h],0 + mov byte[pressed+ebx+155h],0 + mov byte[pressed+ebx+156h],0 + mov byte[pressed+ebx+157h],0 + mov byte[pressed+ebx+108h],0 + mov byte[pressed+ebx+109h],0 + mov byte[pressed+ebx+10Ah],0 + mov byte[pressed+ebx+10Bh],0 + mov byte[pressed+ebx+10Ch],0 + mov byte[pressed+ebx+10Dh],0 + mov byte[pressed+ebx+10Eh],0 + mov byte[pressed+ebx+10Fh],0 + mov byte[pressed+ebx+148h],0 + mov byte[pressed+ebx+149h],0 + test ax,02h ; up + jz .noup + mov byte[pressed+ebx+154h],1 +.noup + test ax,04h ; down + jz .nodown + mov byte[pressed+ebx+155h],1 +.nodown + test ax,08h ; right + jz .noright + mov byte[pressed+ebx+157h],1 +.noright + test ax,10h ; left + jz .noleft + mov byte[pressed+ebx+156h],1 +.noleft + test ax,20h ; A + jz .noa + mov byte[pressed+ebx+108h],1 +.noa + test ax,40h ; B + jz .nob + mov byte[pressed+ebx+109h],1 +.nob + test ax,80h ; C + jz .noc + mov byte[pressed+ebx+10Ah],1 +.noc + test ax,100h ; X + jz .nox + mov byte[pressed+ebx+10Bh],1 +.nox + test ax,200h ; Y + jz .noy + mov byte[pressed+ebx+10Ch],1 +.noy + test ax,400h ; Z + jz .noz + mov byte[pressed+ebx+10Dh],1 +.noz + test ax,800h ; L + jz .nol + mov byte[pressed+ebx+10Eh],1 +.nol + test ax,1000h ; R + jz .nor + mov byte[pressed+ebx+10Fh],1 +.nor + test ax,2000h ; start + jz .nostart + mov byte[pressed+ebx+148h],1 +.nostart + test ax,4000h ; M + jz .noselect + mov byte[pressed+ebx+149h],1 +.noselect + mov al,[WhichSW] + cmp al,[NumSWs209] + jbe near .loop + ret ;return to calling procedure + +; Parallel SNES pad reader routines by Karl Stenerud +; Original design by Benji York: +; + +%macro PPortHelp 3 + mov al, %1 + out dx, al + mov al, 0F8h + out dx, al + inc dx + in al, dx + dec dx + and ax, %2 + jnz %%nobutton + mov byte[pressed+%3], 1 +%%nobutton +%endmacro + +NEWSYM GetParallelPlayer1 + mov dx, 0378h ; may want to make this configurable + mov byte[pressed+180h],0 + mov byte[pressed+181h],0 + mov byte[pressed+182h],0 + mov byte[pressed+183h],0 + mov byte[pressed+184h],0 + mov byte[pressed+185h],0 + mov byte[pressed+186h],0 + mov byte[pressed+187h],0 + mov byte[pressed+188h],0 + mov byte[pressed+189h],0 + mov byte[pressed+18Ah],0 + mov byte[pressed+18Bh],0 + PPortHelp 0FAh, 40h, 180h + PPortHelp 0F9h, 40h, 181h + PPortHelp 0F9h, 40h, 182h + PPortHelp 0F9h, 40h, 183h + PPortHelp 0F9h, 40h, 184h + PPortHelp 0F9h, 40h, 185h + PPortHelp 0F9h, 40h, 186h + PPortHelp 0F9h, 40h, 187h + PPortHelp 0F9h, 40h, 188h + PPortHelp 0F9h, 40h, 189h + PPortHelp 0F9h, 40h, 18Ah + PPortHelp 0F9h, 40h, 18Bh + ret + +NEWSYM GetParallelPlayer2 + mov dx, 0378h ; may want to make this configurable + mov byte[pressed+190h],0 + mov byte[pressed+191h],0 + mov byte[pressed+192h],0 + mov byte[pressed+193h],0 + mov byte[pressed+194h],0 + mov byte[pressed+195h],0 + mov byte[pressed+196h],0 + mov byte[pressed+197h],0 + mov byte[pressed+198h],0 + mov byte[pressed+199h],0 + mov byte[pressed+19Ah],0 + mov byte[pressed+19Bh],0 + PPortHelp 0FAh, 20h, 190h + PPortHelp 0F9h, 20h, 191h + PPortHelp 0F9h, 20h, 192h + PPortHelp 0F9h, 20h, 193h + PPortHelp 0F9h, 20h, 194h + PPortHelp 0F9h, 20h, 195h + PPortHelp 0F9h, 20h, 196h + PPortHelp 0F9h, 20h, 197h + PPortHelp 0F9h, 20h, 198h + PPortHelp 0F9h, 20h, 199h + PPortHelp 0F9h, 20h, 19Ah + PPortHelp 0F9h, 20h, 19Bh + ret + +NEWSYM GetParallelPlayer3 + mov dx, 0278h ; may want to make this configurable + mov byte[pressed+1A0h],0 + mov byte[pressed+1A1h],0 + mov byte[pressed+1A2h],0 + mov byte[pressed+1A3h],0 + mov byte[pressed+1A4h],0 + mov byte[pressed+1A5h],0 + mov byte[pressed+1A6h],0 + mov byte[pressed+1A7h],0 + mov byte[pressed+1A8h],0 + mov byte[pressed+1A9h],0 + mov byte[pressed+1AAh],0 + mov byte[pressed+1ABh],0 + PPortHelp 0FAh, 40h, 1A0h + PPortHelp 0F9h, 40h, 1A1h + PPortHelp 0F9h, 40h, 1A2h + PPortHelp 0F9h, 40h, 1A3h + PPortHelp 0F9h, 40h, 1A4h + PPortHelp 0F9h, 40h, 1A5h + PPortHelp 0F9h, 40h, 1A6h + PPortHelp 0F9h, 40h, 1A7h + PPortHelp 0F9h, 40h, 1A8h + PPortHelp 0F9h, 40h, 1A9h + PPortHelp 0F9h, 40h, 1AAh + PPortHelp 0F9h, 40h, 1ABh + ret + +NEWSYM GetParallelPlayer4 + mov dx, 0278h ; may want to make this configurable + mov byte[pressed+1B0h],0 + mov byte[pressed+1B1h],0 + mov byte[pressed+1B2h],0 + mov byte[pressed+1B3h],0 + mov byte[pressed+1B4h],0 + mov byte[pressed+1B5h],0 + mov byte[pressed+1B6h],0 + mov byte[pressed+1B7h],0 + mov byte[pressed+1B8h],0 + mov byte[pressed+1B9h],0 + mov byte[pressed+1BAh],0 + mov byte[pressed+1BBh],0 + PPortHelp 0FAh, 20h, 1B0h + PPortHelp 0F9h, 20h, 1B1h + PPortHelp 0F9h, 20h, 1B2h + PPortHelp 0F9h, 20h, 1B3h + PPortHelp 0F9h, 20h, 1B4h + PPortHelp 0F9h, 20h, 1B5h + PPortHelp 0F9h, 20h, 1B6h + PPortHelp 0F9h, 20h, 1B7h + PPortHelp 0F9h, 20h, 1B8h + PPortHelp 0F9h, 20h, 1B9h + PPortHelp 0F9h, 20h, 1BAh + PPortHelp 0F9h, 20h, 1BBh + ret + +NEWSYM SetInputDevice209 + ; eax = pointer to devices, bl = device #, bh = player # (0-3) + ; Sets keys according to input device selected + cmp bl,0 + jne near .nozero + mov dword[eax],0 + mov dword[eax+4],0 + mov dword[eax+8],0 + mov dword[eax+12],0 + mov dword[eax+16],0 + mov dword[eax+20],0 + mov dword[eax+24],0 + mov dword[eax+28],0 + mov dword[eax+32],0 + mov dword[eax+36],0 + mov dword[eax+40],0 + mov dword[eax+44],0 + ret +.nozero + cmp bl,1 + jne near .nokeyb + cmp bh,1 + ja near .exit + cmp bh,1 + je near .input2 + mov dword[eax],54 + mov dword[eax+4],28 + mov dword[eax+8],72 + mov dword[eax+12],80 + mov dword[eax+16],75 + mov dword[eax+20],77 + mov dword[eax+24],82 + mov dword[eax+28],71 + mov dword[eax+32],73 + mov dword[eax+36],83 + mov dword[eax+40],79 + mov dword[eax+44],81 + ret +.input2 + mov dword[eax],56 + mov dword[eax+4],29 + mov dword[eax+8],37 + mov dword[eax+12],50 + mov dword[eax+16],49 + mov dword[eax+20],51 + mov dword[eax+24],31 + mov dword[eax+28],32 + mov dword[eax+32],33 + mov dword[eax+36],44 + mov dword[eax+40],45 + mov dword[eax+44],46 + ret +.nokeyb + cmp bl,2 + jne near .no2buttons + xor bl,bl + cmp byte[pl1contrl],2 + jne .nopl2a + inc bl +.nopl2a + cmp byte[pl2contrl],2 + jne .nopl2b + inc bl +.nopl2b + cmp byte[pl3contrl],2 + jne .nopl2c + inc bl +.nopl2c + cmp byte[pl4contrl],2 + jne .nopl2d + inc bl +.nopl2d + cmp byte[pl5contrl],2 + jne .nopl2e + inc bl +.nopl2e + cmp bl,2 + jae .2ndjoyst + mov dword[eax+40],103h + mov dword[eax+36],102h + mov dword[eax+8],14Ch + mov dword[eax+12],14Dh + mov dword[eax+16],14Eh + mov dword[eax+20],14Fh + ret +.2ndjoyst + mov dword[eax+40],105h + mov dword[eax+36],104h + mov dword[eax+8],168h + mov dword[eax+12],169h + mov dword[eax+16],16Ah + mov dword[eax+20],16Bh + ret +.no2buttons + cmp bl,3 + je .4buttons + cmp bl,4 + jne near .no4buttons +.4buttons + mov dword[eax+40],103h + mov dword[eax+36],102h + mov dword[eax+28],105h + mov dword[eax+24],104h + mov dword[eax+8],14Ch + mov dword[eax+12],14Dh + mov dword[eax+16],14Eh + mov dword[eax+20],14Fh + ret +.no4buttons + cmp bl,18 + je .6buttons + cmp bl,5 + jne near .no6buttons +.6buttons + mov dword[eax+40],103h + mov dword[eax+36],102h + mov dword[eax+28],105h + mov dword[eax+24],104h + mov dword[eax+32],106h + mov dword[eax+44],107h + mov dword[eax+8],14Ch + mov dword[eax+12],14Dh + mov dword[eax+16],14Eh + mov dword[eax+20],14Fh + cmp bl,5 + je .skip8b + mov dword[eax+4],100h + mov dword[eax],101h + mov dword[eax+44],106h + mov dword[eax+32],107h +.skip8b + ret +.no6buttons + cmp bl,6 + jne near .nosw1 + mov dword[eax+0],149h + mov dword[eax+4],148h + mov dword[eax+8],154h + mov dword[eax+12],155h + mov dword[eax+16],156h + mov dword[eax+20],157h + mov dword[eax+24],10Ch + mov dword[eax+28],109h + mov dword[eax+32],10Eh + mov dword[eax+36],10Bh + mov dword[eax+40],108h + mov dword[eax+44],10Fh + ret +.nosw1 + cmp bl,7 + jne near .nosw2 + mov dword[eax+0],149h+8 + mov dword[eax+4],148h+8 + mov dword[eax+8],154h+8 + mov dword[eax+12],155h+8 + mov dword[eax+16],156h+8 + mov dword[eax+20],157h+8 + mov dword[eax+24],10Ch+8 + mov dword[eax+28],109h+8 + mov dword[eax+32],10Eh+8 + mov dword[eax+36],10Bh+8 + mov dword[eax+40],108h+8 + mov dword[eax+44],10Fh+8 + ret +.nosw2 + cmp bl,8 + jne near .nosw3 + mov dword[eax+0],149h+8*2 + mov dword[eax+4],148h+8*2 + mov dword[eax+8],154h+8*2 + mov dword[eax+12],155h+8*2 + mov dword[eax+16],156h+8*2 + mov dword[eax+20],157h+8*2 + mov dword[eax+24],10Ch+8*2 + mov dword[eax+28],109h+8*2 + mov dword[eax+32],10Eh+8*2 + mov dword[eax+36],10Bh+8*2 + mov dword[eax+40],108h+8*2 + mov dword[eax+44],10Fh+8*2 + ret +.nosw3 + cmp bl,9 + jne near .nosw4 + mov dword[eax+0],149h+8*3 + mov dword[eax+4],148h+8*3 + mov dword[eax+8],154h+8*3 + mov dword[eax+12],155h+8*3 + mov dword[eax+16],156h+8*3 + mov dword[eax+20],157h+8*3 + mov dword[eax+24],10Ch+8*3 + mov dword[eax+28],109h+8*3 + mov dword[eax+32],10Eh+8*3 + mov dword[eax+36],10Bh+8*3 + mov dword[eax+40],108h+8*3 + mov dword[eax+44],10Fh+8*3 + ret +.nosw4 + cmp bl,10 + jne near .nogrip0 + mov dword[eax+0],14Ah + mov dword[eax+4],14Bh + mov dword[eax+8],170h + mov dword[eax+12],171h + mov dword[eax+16],172h + mov dword[eax+20],173h + mov dword[eax+24],129h + mov dword[eax+28],12Bh + mov dword[eax+32],12Ch + mov dword[eax+36],128h + mov dword[eax+40],12Ah + mov dword[eax+44],12Eh + ret +.nogrip0 + cmp bl,11 + jne near .nogrip1 + mov dword[eax+0],14Ah+8 + mov dword[eax+4],14Bh+8 + mov dword[eax+8],170h+4 + mov dword[eax+12],171h+4 + mov dword[eax+16],172h+4 + mov dword[eax+20],173h+4 + mov dword[eax+24],129h+8 + mov dword[eax+28],12Bh+8 + mov dword[eax+32],12Ch+8 + mov dword[eax+36],128h+8 + mov dword[eax+40],12Ah+8 + mov dword[eax+44],12Eh+8 + ret +.nogrip1 + cmp bl,14 + jne near .nopp1 + mov dword[eax+40],180h + mov dword[eax+36],181h + mov dword[eax+0],182h + mov dword[eax+4],183h + mov dword[eax+8],184h + mov dword[eax+12],185h + mov dword[eax+16],186h + mov dword[eax+20],187h + mov dword[eax+28],188h + mov dword[eax+24],189h + mov dword[eax+32],18Ah + mov dword[eax+44],18Bh + ret +.nopp1 + cmp bl,15 + jne near .nopp2 + mov dword[eax+40],190h + mov dword[eax+36],191h + mov dword[eax+0],192h + mov dword[eax+4],193h + mov dword[eax+8],194h + mov dword[eax+12],195h + mov dword[eax+16],196h + mov dword[eax+20],197h + mov dword[eax+28],198h + mov dword[eax+24],199h + mov dword[eax+32],19Ah + mov dword[eax+44],19Bh + ret +.nopp2 + cmp bl,16 + jne near .nopp3 + mov dword[eax+40],1A0h + mov dword[eax+36],1A1h + mov dword[eax+0],1A2h + mov dword[eax+4],1A3h + mov dword[eax+8],1A4h + mov dword[eax+12],1A5h + mov dword[eax+16],1A6h + mov dword[eax+20],1A7h + mov dword[eax+28],1A8h + mov dword[eax+24],1A9h + mov dword[eax+32],1AAh + mov dword[eax+44],1ABh + ret +.nopp3 + cmp bl,17 + jne near .nopp4 + mov dword[eax+40],1B0h + mov dword[eax+36],1B1h + mov dword[eax+0],1B2h + mov dword[eax+4],1B3h + mov dword[eax+8],1B4h + mov dword[eax+12],1B5h + mov dword[eax+16],1B6h + mov dword[eax+20],1B7h + mov dword[eax+28],1B8h + mov dword[eax+24],1B9h + mov dword[eax+32],1BAh + mov dword[eax+44],1BBh + ret +.nopp4 +.exit + ret + + \ No newline at end of file diff --git a/zsnes/src/dos/modemrtn.asm b/zsnes/src/dos/modemrtn.asm new file mode 100644 index 00000000..3cda02ee --- /dev/null +++ b/zsnes/src/dos/modemrtn.asm @@ -0,0 +1,437 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM ComNum, ComIRQ, BaudRate +EXTSYM dssel,FossilUse +EXTSYM GUIinit18_2hz,GUIinit36_4hz +EXTSYM GUIMenuItem + EXTSYM delay + + + + + + + + + +NEWSYM UartType, db 0 +NEWSYM cantinitmodem, db 1 +NEWSYM ModemInited, db 0 + +ComPort dw 2E8h ; 1=3F8,2=2F8,3=3E8,4=2E8 +PortData dw 0,3F8h,2F8h,3E8h,2E8h +ComInt db 0 +BRateSel dw 000Ch,0008h,0006h,0004h,0003h,0002h,0001h +oldhandmodems dw 0 +oldhandmodemo dd 0 +PICMaskPm db 21h +PortNum dw 0 +CharStore db 0 + +NEWSYM ModemGetChar + cmp byte[UartType],2 + je near FossilGetChar + xor dh,dh + mov eax,[modemhead] + cmp eax,[modemtail] + je .nonewchar + mov dh,1 + mov dl,[modembuffer+eax] + inc dword[modemhead] + and dword[modemhead],2047 +.nonewchar + ret + +FossilGetChar: + pushad + mov ah,0Ch + mov dx,[PortNum] + int 14h + cmp ax,0FFFFh + je .nochar + mov ah,02h + mov dx,[PortNum] + int 14h + mov [CharStore],al + popad + mov dh,1 + mov dl,[CharStore] + ret +.nochar + popad + xor dh,dh + ret + +NEWSYM ModemCheckRing + cmp byte[UartType],2 + je near .fossil + mov dx,[ComPort] + add dx,6 + in al,dx + shr al,6 + and al,01h + ret +.fossil + pushad + mov ah,03h + mov dx,[PortNum] + int 14h + test al,40h + jnz .ring + popad + xor al,al + ret +.ring + popad + mov al,1 + ret + +NEWSYM ModemCheckDCD + cmp byte[UartType],2 + je near .fossil + mov dx,[ComPort] + add dx,6 + in al,dx + shr al,7 + and al,01h + ret +.fossil + pushad + mov ah,03h + mov dx,[PortNum] + int 14h + test al,80h + jnz .dcd + popad + xor al,al + ret +.dcd + popad + mov al,1 + ret + +NEWSYM ModemSendChar + cmp byte[UartType],2 + je near FossilSendChar + push ecx + push edx + push ebx + mov ecx,1000000 + mov bl,al +.loop + mov dx,[ComPort] + add dx,5 + in al,dx + test al,00100000b + jnz .transokay + loop .loop + xor al,al + pop ebx + pop edx + pop ecx + ret +.transokay + mov al,bl + mov dx,[ComPort] ; Send the char through the modem + out dx,al + pop ebx + pop edx + pop ecx + ret + +FossilSendChar: + pushad + mov ah,01h + mov dx,[PortNum] + int 14h + popad + ret + + +NEWSYM InitModem + mov byte[ModemInited],1 + cmp byte[FossilUse],0 + jne near InitFossil + mov byte[cantinitmodem],0 + cli + ; Get Port value + xor eax,eax + mov al,[ComNum] + mov ax,[PortData+eax*2] + mov [ComPort],ax + + mov dx,[ComPort] + add dx,2 + xor al,al + out dx,al + + ; Set IRQ PIC Mask Port + mov byte[PICMaskPm],21h + mov bl,[ComIRQ] + cmp bl,7 + jbe .noupper + add bl,60h + add byte[PICMaskPm],80h +.noupper + add bl,8 + mov [ComInt],bl + + ; Get IRQ handler + mov ax,204h + mov bl,[ComInt] + int 31h + mov [oldhandmodems],cx + mov [oldhandmodemo],edx + ; Set IRQ handler + mov ax,205h + mov bl,[ComInt] + mov cx,cs + mov edx,modemhandler + int 31h + + mov dx,[ComPort] + add dx,3 + mov al,00000011b + out dx,al + + ; Set Normal Modem functioning, User2 bit, and DTR + mov dx,[ComPort] + add dx,4 + mov al,00001011b + out dx,al + + ; Enable IRQ + xor dh,dh + mov dl,[PICMaskPm] ; Output to IRQ PIC Mask Port + mov cl,[ComIRQ] ; Get proper bit + and cl,07h + mov al,01h + shl al,cl + not al ; Complement since clear bit = enable + mov bl,al + in al,dx ; input to preserve other bits + and al,bl + xor al,al + out dx,al + + ; Enable interrupt to execute only on data available + mov dx,[ComPort] + inc dx + mov al,00000001b + out dx,al + sti + + ; Write baudrate + mov dx,[ComPort] + add dx,3 + in al,dx + or al,10000000b + out dx,al + mov eax,[BaudRate] + mov ax,[BRateSel+eax*2] + mov dx,[ComPort] + inc dx + push eax + mov al,ah + out dx,al + pop eax + dec dx + out dx,al + mov dx,[ComPort] + add dx,3 + in al,dx + and al,01111111b + out dx,al + + ; Initialize 16550A UART chip + mov dx,[ComPort] + add dx,2 + mov al,0C7h + out dx,al + nop + nop + in al,dx + mov byte[UartType],1 + test al,40h + jnz .passed16550a + xor al,al + out dx,al + mov byte[UartType],0 +.passed16550a + ret + +InitFossil: + xor edx,edx + mov dl,[ComNum] + dec dl + mov [PortNum],dx + mov byte[cantinitmodem],0 + mov byte[UartType],2 + mov ah,04h + mov dx,[PortNum] + int 14h + cmp ax,1954h + jne .notsuccess + xor ah,ah + mov al,00000011b ; 19200 baud, 81N + mov dx,[PortNum] + int 14h + ret +.notsuccess + mov byte[cantinitmodem],1 + ret + +modemhandler: + push ds + push eax + mov ax,[cs:dssel] + mov ds,ax + push edx + mov dx,[ComPort] + add dx,4 + in al,dx + and al,11111101b + out dx,al + +.next + mov dx,[ComPort] + in al,dx + mov edx,[modemtail] + mov [modembuffer+edx],al + inc dword[modemtail] + and dword[modemtail],2047 + mov dx,[ComPort] + add dx,2 + in al,dx + test al,1 + jz .next + + mov al,20h + out 20h,al + + cmp byte[ComIRQ],7 + jbe .nohighirq + mov al,20h + out 0A0h,al +.nohighirq + + mov dx,[ComPort] + add dx,4 + in al,dx + or al,00000010b + out dx,al + + pop edx + pop eax + pop ds + iretd + +NEWSYM ModemClearBuffer + mov dword[modemhead],0 + mov dword[modemtail],0 + ret + +NEWSYM modembuffer, times 2048 db 0 +NEWSYM modemhead, dd 0 +NEWSYM modemtail, dd 0 + +NEWSYM DeInitModem + cmp byte[ModemInited],1 + je .okaydeinit + ret +.okaydeinit + mov byte[ModemInited],0 + cmp byte[UartType],2 + je near DeInitFossil + cli + mov dx,[ComPort] + add dx,2 + xor al,al + out dx,al + + xor dh,dh + mov dl,[PICMaskPm] + mov cl,[ComIRQ] + and cl,07h + mov al,01h + shl al,cl + mov bl,al + in al,dx + or al,bl + xor al,al + out dx,al + mov dx,[ComPort] + inc dx + mov al,00h + out dx,al + mov dx,[ComPort] + add dx,4 + out dx,al + + mov cx,[oldhandmodems] + mov edx,[oldhandmodemo] + mov ax,205h + mov bl,[ComInt] + int 31h + sti + ret + +DeInitFossil: + mov byte[cantinitmodem],0 + jne .nodeinit + mov ax,0600h + mov dx,[PortNum] + int 14h ; Lower DTR + mov ah,05h + mov dx,[PortNum] + int 14h +.nodeinit + ret + +NEWSYM DeInitModemC + cmp byte[ModemInited],1 + je .okaydeinit + ret +.okaydeinit + cmp byte[UartType],2 + je near DeInitFossil + cli + mov al,00h + mov dx,[ComPort] + add dx,4 + out dx,al + + mov al,13 + mov dx,[ComPort] + out dx,al + + mov ecx,16384 + call delay + + out dx,al + + mov al,00001001b + mov dx,[ComPort] + add dx,4 + out dx,al + sti + ret + + \ No newline at end of file diff --git a/zsnes/src/dos/sw.asm b/zsnes/src/dos/sw.asm new file mode 100644 index 00000000..67944622 --- /dev/null +++ b/zsnes/src/dos/sw.asm @@ -0,0 +1,226 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM SidewinderFix + + + + + + +%macro ParityCheckSW 1 + mov ecx,ebx + xor cl,ch + jpe %%ParChkSW + mov [%1],ebx + %%ParChkSW: +%endmacro + +section .data +gDump times 256 db 0 +bDump times 128 db 0 +NEWSYM _SW1, dd 0 +NEWSYM _SW2, dd 0 +NEWSYM _SW3, dd 0 +NEWSYM _SW4, dd 0 +NEWSYM _SWCount, dd 0 + +section .text +NEWSYM _readSideWinder + pushad + + mov ecx,200 + mov ebx,gDump + + cli + cmp byte[SidewinderFix],0 + je .write + out dx,al +.write +GetSWDataLoop: + cmp byte[SidewinderFix],0 + jne .nowrite + out dx,al +.nowrite + nop + nop + nop + nop + nop + nop + in al,dx + mov [ebx],al + inc ebx + dec ecx + jnz GetSWDataLoop + sti + + xor ebx,ebx + xor ecx,ecx + xor edi,edi + mov esi,1 + +FindCycle: + mov al,[gDump+edi] + inc edi + cmp edi,200 + je SMWError + test al,00010000b + jnz WMFCS1 + xor ecx,ecx + jmp FindCycle +WMFCS1: + inc ecx + cmp ecx,15 + jne FindCycle + + xor ebp,ebp + +FindStrobeLow: + mov al,[gDump+edi] + inc edi + cmp edi,200 + je SMWError + test al,00010000b + jnz FindStrobeLow + xor ecx,ecx + +FindStrobeHigh: + inc ecx + cmp ecx,15 + je SWModeCheck + mov al,[gDump+edi] + inc edi + cmp edi,200 + je SMWError + test al,00010000b + jz FindStrobeHigh + + mov [bDump+ebp],al + inc ebp + jmp FindStrobeLow + +SMWDone: + popad + mov eax,0 + ret + +SMWError: + popad + mov eax,1 + ret + +SWModeCheck: + cmp ebp,5 + je near ModeB1 + cmp ebp,15 + je near ModeA1 + cmp ebp,10 + je near ModeB2 + cmp ebp,30 + je near ModeA2 + cmp ebp,45 + je near ModeA3 + cmp ebp,20 + je near ModeB4 + cmp ebp,60 + je near ModeA4 + jmp short SMWError + +ModeA1: + cmp dword [_SWCount],3 + je near ModeB3 + xor ebp,ebp + call DoModeA + ParityCheckSW _SW1 + jmp SMWDone + +ModeA4: + mov ebp,45 + call DoModeA + ParityCheckSW _SW4 +ModeA3: + mov ebp,30 + call DoModeA + ParityCheckSW _SW3 +ModeA2: + mov ebp,15 + call DoModeA + ParityCheckSW _SW2 + xor ebp,ebp + call DoModeA + ParityCheckSW _SW1 + jmp SMWDone + +ModeB4: + mov ebp,15 + call DoModeB + ParityCheckSW _SW4 +ModeB3: + mov ebp,10 + call DoModeB + ParityCheckSW _SW3 +ModeB2: + mov ebp,5 + call DoModeB + ParityCheckSW _SW2 +ModeB1: + xor ebp,ebp + call DoModeB + ParityCheckSW _SW1 + jmp SMWDone + +DoModeB: + xor ebx,ebx + mov eax,2 + mov ecx,5 + add ebp,bDump +ModeBLoop: + test byte [ebp],00100000b + jnz $+4 + or ebx,eax + shl eax,1 + test byte [ebp],01000000b + jnz $+4 + or ebx,eax + shl eax,1 + test byte [ebp],10000000b + jnz $+4 + or ebx,eax + shl eax,1 + inc ebp + dec ecx + jnz ModeBLoop + ret + +DoModeA: + xor ebx,ebx + mov eax,2 + mov ecx,15 + add ebp,bDump +ModeALoop: + test byte [ebp],00100000b + jnz $+4 + or ebx,eax + shl eax,1 + inc ebp + dec ecx + jnz ModeALoop + ret + \ No newline at end of file diff --git a/zsnes/src/dos/sw32.asm b/zsnes/src/dos/sw32.asm new file mode 100644 index 00000000..16e43cff --- /dev/null +++ b/zsnes/src/dos/sw32.asm @@ -0,0 +1,330 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +;32-bit DOS-Mode driver for the Microsoft Sidewinder Gamepad +;Multi-SW Version 1.5 +;(C) 1997, 1998 Robert William Grubbs, All Rights Reserved +;Latest revision 1/20/98 +; Driver Source code Include file + +;C-linkable, rewrote decoder -sardu + +;Flat memory mode (Protected mode extender required! Tested with DOS32) +;Tested with TASM 4.0+ + + +SW1 dd 0 ;SW #1's button status +SW2 dd 0 ;SW #2's button status +SW3 dd 0 ;SW #3's button status +SW4 dd 0 ;SW #4's button status +SWCount dd 1 ;Tell the driver how many sidewinders are present +SWSetup dd 0 ;Tell the driver what polling mode to use + ; 0=Interrupts disabled, Multiple OUT statements + ; 1=Interrupts disabled, Single OUT statement + ; 2=Interrupts enabled, Multiple OUT statements + ; 3=Interrupts enabled, Single OUT statement + +gDump times 100h db 0 ;SW Status dump buffer (space for 256 bytes, uses 200) +bDump times 80h db 0 ;buffer to hold button data (Modes A and B, all SW) + +;This macro calculates parity for the buttons and compares it to the SW's +; parity bit. If they don't match, the button data is discarded. +%macro ParityCheckSW 1 + mov ecx,ebx ;duplicate button status + xor cl,ch ; + jpe %%ParChkSW + mov [%1],ebx ;update button status for SW #n +%%ParChkSW ;done +%endmacro + +;The main subroutine; this is the important one; bow down before it +;IN: None +;Out: SWx=buttons (bit 0=null 1=up 2=dn 3=rt 4=lt 5=A 6=B 7=C 8=X) +; (9=Y 10=Z 11=L 12=R 13=St 14=M 15=Parity) +;No registers destroyed + +readSideWinder: + pushad + + mov ecx,200 ;dump buffer fill size + mov ebx,gDump ;initial dump pointer + mov edx,0201h ;joystick port + + cmp dword[SWSetup],0 + jne NotSW0 + cli ;Disable interrupts (required to avoid jitter) + GetSWDataLoop: ; + out dx,al ;trigger joystick port + in al,dx ;read SW status byte + mov [ebx],al ;dump status byte + inc ebx ;increment dump pointer + dec ecx + jnz GetSWDataLoop + sti ;Re-enable interrupts + jmp SWPollDone + + NotSW0: + cmp dword[SWSetup],1 + jne NotSW1 + cli ;Disable interrupts (required to avoid jitter) + out dx,al ;trigger joystick port + GetSWDataLoop1: ; + in al,dx ;read SW status byte + mov [ebx],al ;dump status byte + inc ebx ;increment dump pointer + dec ecx + jnz GetSWDataLoop1 + sti ;Re-enable interrupts + jmp SWPollDone + + NotSW1: + cmp dword[SWSetup],2 + jne NotSW2 + GetSWDataLoop2: ; + out dx,al ;trigger joystick port + in al,dx ;read SW status byte + mov [ebx],al ;dump status byte + inc ebx ;increment dump pointer + dec ecx + jnz GetSWDataLoop2 + jmp SWPollDone + + NotSW2: + ;default all others to SWStatus=3 + out dx,al ;trigger joystick port + GetSWDataLoop3: ; + in al,dx ;read SW status byte + mov [ebx],al ;dump status byte + inc ebx ;increment dump pointer + dec ecx + jnz GetSWDataLoop3 + + SWPollDone: + + mov ecx,0 ;tick count + mov esi,1 ;initialize output mask + mov ebx,0 ;initialize output + mov edi,0 ;initialize input pointer + + ;My current method of cycle detection is to look for 15 highs in a row on + ; the strobe line. Cycle ends is detected by 15 lows in a row. + ;Mode A has 15 strobes in a cycle, Mode B has 5. + ; Note that the 15 highs/lows for cycle detection may be too high for slow + ; machines. I havn't seen a problem yet, but it may exist... + ;Multiple Sidewinder data complicates things. Each additional SW tags + ; another set of strobes to the cycle, 5 more in mode B, 15 more in mode A. + ; Detecting extra SW gamepad data is fairly simple: count the number of + ; strobes. If it is a multiple of 5, you're in mode B and can divide by 5 + ; to get the total number of gamepads. If it's divisible by 15, use mode A. + ; However, this method cannot distinguish between mode A for one SW and mode + ; B for three SW. In that case, the SWCount variable must be set correctly. + + FindCycle: + mov al,[gDump+edi] ;get next status byte + inc edi ;increment input pointer + cmp edi,200 ;test for end of status block + je SWNoFind ;if it's the end, quit sub with error + test al,00010000b ;Check for nonzero bits + jnz WMFCS1 ; + xor ecx,ecx ;if zero, reset tick count + jmp FindCycle ;can't be pre-cycle + WMFCS1: ;Possibly pre-cycle + inc ecx ;increment tick count + cmp ecx,15 ;test for sufficient ticks for cycle start + jne FindCycle ;if insufficient, get next status byte + ;Yippie! it found a (probable) cycle! + + mov ebp,0 ;initialize bDump index (strobe count) + + FindStrobeLow: ;Search for leading edge of data strobe + mov al,[gDump+edi] ;get next status byte + inc edi ;increment input pointer + cmp edi,200 ;test for end of status block + je SWNoFind ;if it's the end, quit sub with error + test al,00010000b ;get "strobe" bit + jnz SHORT FindStrobeLow ;if it isn't zero, we're not there yet + xor ecx,ecx ;initialize cycle end test count + + FindStrobeHigh: + inc ecx ;increment zero count + cmp ecx,0fh ;is it 15? + je SWModeCheck ;if so, goto mode check + mov al,[gDump+edi] ;get next status byte + inc edi ;increment input pointer + cmp edi,200 ;test for end of status block + je SWNoFind ;if it's the end, quit sub with error + test al,00010000b ;get "strobe" bit + jz FindStrobeHigh ;if it is zero, we're not there yet + ;if not, we're there! data bit is valid (probably) + mov [bDump+ebp],al ;preserve data for button decoding + inc ebp ;increment strobe count/bDump index + jmp FindStrobeLow ;wait for the next button + + SMWDone: + SWNoFind: + popad + ret ;return to calling procedure + + SWModeCheck: ;Check strobe count to identify mode and # of SW + cmp ebp,15 ;Is it Mode A with 1 Sidewinder or B with 3? + je ModeA1 + cmp ebp,5 ;Is it Mode B with 1 Sidewinders? + je ModeB1 + cmp ebp,30 ;Is it Mode A with 2 Sidewinders? + je ModeA2 + cmp ebp,10 ;Is it Mode B with 2 Sidewinders? + je near ModeB2 + cmp ebp,45 ;Is it Mode A with 3 Sidewinders? + je near ModeA3 + cmp ebp,60 ;Is it Mode A with 4 Sidewinders? + je near ModeA4 + cmp ebp,20 ;Is it Mode B with 4 Sidewinders? + je near ModeB4 + jmp SHORT SWNoFind ;Any other # of strobes is invalid data + + ModeB1: + xor ebp,ebp + call DoModeB + ParityCheckSW SW1 + jmp SMWDone + + ModeA1: + cmp dword [SWCount],3 + je near ModeB3 + xor ebp,ebp + call DoModeA + ParityCheckSW SW1 + jmp SMWDone + + ModeA2: + xor ebp,ebp + call DoModeA + ParityCheckSW SW1 + mov ebp,15 + call DoModeA + ParityCheckSW SW2 + jmp SMWDone + + ModeA3: + xor ebp,ebp + call DoModeA + ParityCheckSW SW1 + mov ebp,15 + call DoModeA + ParityCheckSW SW2 + mov ebp,30 + call DoModeA + ParityCheckSW SW3 + jmp SMWDone + + ModeA4: + xor ebp,ebp + call DoModeA + ParityCheckSW SW1 + mov ebp,15 + call DoModeA + ParityCheckSW SW2 + mov ebp,30 + call DoModeA + ParityCheckSW SW3 + mov ebp,45 + call DoModeA + ParityCheckSW SW4 + jmp SMWDone + + ModeB2: + xor ebp,ebp + call DoModeB + ParityCheckSW SW1 + mov ebp,5 + call DoModeB + ParityCheckSW SW2 + jmp SMWDone + + ModeB3: + xor ebp,ebp + call DoModeB + ParityCheckSW SW1 + mov ebp,5 + call DoModeB + ParityCheckSW SW2 + mov ebp,10 + call DoModeB + ParityCheckSW SW3 + jmp SMWDone + + ModeB4: + xor ebp,ebp + call DoModeB + ParityCheckSW SW1 + mov ebp,5 + call DoModeB + ParityCheckSW SW2 + mov ebp,10 + call DoModeB + ParityCheckSW SW3 + mov ebp,15 + call DoModeB + ParityCheckSW SW4 + jmp SMWDone +ENDP + +%macro SWRepeat 1 + mov al,[bDump+ebp+%1] + shr al,5 ;get upper 3 bits + shl eax,1+3*%1 ;shift into place + or ebx,eax ;or into output +%endmacro + +DoModeB: + xor ebx,ebx ;Initialize output + xor eax,eax + + SWRepeat 0 + SWRepeat 1 + SWRepeat 2 + SWRepeat 3 + SWRepeat 4 + + xor ebx,0FFFEh + ret + +DoModeA: + xor ebx,ebx ;Clear output + mov ecx,15 ;bit count + +ALP: + mov al,[bDump+ebp] + inc ebp + shl al,3 + rcr ebx,1 + dec ecx + jg ALP + + shr ebx,16 + xor ebx,0FFFEh + ret + + + \ No newline at end of file diff --git a/zsnes/src/dos/vesa12.asm b/zsnes/src/dos/vesa12.asm new file mode 100644 index 00000000..0e22fa0b --- /dev/null +++ b/zsnes/src/dos/vesa12.asm @@ -0,0 +1,555 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM vesa2_usbit,vesa2_clbit,vesa2_clbitng,vesa2_clbitng2,vesa2_clbitng3 +EXTSYM vesa2_x,vesa2_y,vesa2selec,vesa2_bits,vesa2_rpos,vesa2_gpos,vesa2_bpos +EXTSYM vesa2_rposng,vesa2_gposng,vesa2_bposng,vesa2_rtrcl,vesa2_rtrcla,vesa2_rfull +EXTSYM vesa2_gtrcl,vesa2_gtrcla,vesa2_gfull,vesa2_btrcl,vesa2_btrcla,vesa2_bfull +EXTSYM vesa2red10,dcolortab,videotroub,Change_Dir +EXTSYM genfulladdtab,genfulladdtabng,DosExit +EXTSYM InitDrive,gotoroot,InitDir,fulladdtab +; EXTSYM printnum,DosExit +EXTSYM LFBpointer,noblocks,bytesperscanline,vesamode,VESAmodelist + + + + + + +; add 0214h video mode + +NEWSYM granularity, dw 0 +NEWSYM granadd, dd 0 + +NEWSYM VESA12EXITTODOS + mov ax,0003h + int 10h + push edx + mov edx,.exitfromvesa12 + mov ah,9 + int 21h + pop edx + mov ah,9 + int 21h + mov edx,.return + mov ah,9 + int 21h + + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + + mov byte[videotroub],1 + jmp DosExit + +.exitfromvesa12 db 'Unable to Initialize VESA1.2 $' +.return db 10,13,'$' + +;******************************************************* +; Set up Vesa 2 +;******************************************************* + +NEWSYM InitVesa12 + ;-------------------------------------------------; + ; First - allocate some bytes in DOS memory for ; + ; communication with VBE ; + ;-------------------------------------------------; + + mov eax,0100h + mov ebx,512/16 ; 512 bytes + int 31h ; Function 31h,100h - Allocate + ; DOS memory (512 bytes) + jnc .gotmem + mov edx,.nomemmessage + jmp VESA12EXITTODOS + .nomemmessage + db ': Unable to locate DOS memory.$' + + .gotmem + mov fs,dx ; FS now points to the DOS + ; buffer + + + ;--------------------------------------------------; + ; Now, get information about the video card into ; + ; a data structure ; + ;--------------------------------------------------; + + mov edi,RMREGS + mov dword[fs:0],'VBE1' ; Request VBE 2.0 info + mov dword[RMREGS.eax],4f00h + mov word[RMREGS.es],ax ; Real mode segment of DOS + ; buffer + mov dword[RMREGS.edi],0 + + push es + push ds + pop es + mov eax,300h + mov ebx,10h + xor ecx,ecx + int 31h ; Simulate real mode interrupt + pop es + + jnc .int1ok + mov edx,.noint1message + jmp VESA12EXITTODOS + .noint1message + db ': Simulated real mode interrupt failed.$' + + .int1ok ; Real mode int successful!!! + mov eax,[RMREGS.eax] + cmp al,4fh ; Check vbe interrupt went OK + jz .vbedetected + mov edx,.novbemessage + jmp VESA12EXITTODOS + .novbemessage + db ': VBE not detected!!$' + + .vbedetected + cmp dword[fs:0000],'VESA' + jz .vesadetected ; Check for presence of vesa + mov edx,.novesamessage + jmp VESA12EXITTODOS + .novesamessage + db ': VESA not detected!$' + + .vesadetected + cmp word[fs:0004],102h + jae .vesa12detected ; Check we've got VESA 1.2 or greater + mov edx,.novesa2message + jmp VESA12EXITTODOS + .novesa2message + db ': VESA 1.2 or greater required!$' + + + ;-----------------------------------------------------; + ; OK - vesa 2.0 or greater has been detected. Copy ; + ; mode information into VESAmodelist ; + ;-----------------------------------------------------; + + .vesa12detected + mov ax,[fs:12h] ; Get no. of 64k blocks + mov [noblocks],ax + mov ax, 2 + mov bx,[fs:10h] + int 31h + + jnc .wegottheselector + mov edx, .oopsnoselector + jmp VESA12EXITTODOS + .oopsnoselector + db ': Failed to allocate vesa display selector!$' + + .wegottheselector + + mov gs,ax + xor eax,eax + mov ebp,VESAmodelist + mov ecx,512 + mov ax,[fs:0eh] + + .loopcopymodes + mov bx,[gs:eax] + mov [ebp],bx + cmp bx,0ffffh + jz .copiedmodes + add ebp,2 + add eax,2 + dec ecx + jz .outofmodelistspace + jmp .loopcopymodes + + .outofmodelistspace + mov edx,.outofmodelistspacemessage + jmp VESA12EXITTODOS + .outofmodelistspacemessage + db ': Out of VESA mode list space!$' + + ;----------------------------------------------; + ; OK - Scan the mode list to find a matching ; + ; mode for vesa2_x, vesa2_y and vesa2_depth ; + ;----------------------------------------------; + + .copiedmodes + + mov ebp,VESAmodelist + xor ecx,ecx + + .loopcheckmodes + mov cx, [ebp] + cmp cx, 0ffffh + jnz .notendoflist + + mov edx,.endoflist + jmp VESA12EXITTODOS + + .endoflist db ': VESA 1.2 mode does not work on your video card/driver.$' + .whichwin db 0 + + .notendoflist + + mov edi, RMREGS + mov dword[RMREGS.eax],4f01h + mov dword[RMREGS.ebx],0 + mov dword[RMREGS.ecx],ecx + mov dword[RMREGS.edi],0 + + push es + push ds + pop es + mov eax,300h + mov ebx,10h + xor ecx,ecx + int 31h ; Simulate real mode interrupt + pop es + jnc .modecheckok + mov edx,.modecheckfail + jmp VESA12EXITTODOS + .modecheckfail + db ': Real mode interrupt failure while checking vesa mode$' + + .modecheckok + add ebp,2 + + test word[fs:0000h],1b + jz near .loopcheckmodes ; If mode is not available + +; +; xor eax,eax +; mov ax,[fs:12h] +; call printnum +; mov ah,02h +; mov dl,'x' +; int 21h +; mov ax,[fs:14h] +; call printnum +; mov ah,02h +; mov dl,'x' +; int 21h +; xor ah,ah +; mov al,[fs:19h] +; call printnum +; mov ah,02h +; mov dl,13 +; int 21h +; mov dl,10 +; int 21h + + mov eax,[vesa2_x] + cmp [fs:12h],ax ; Check that the height matches + jnz near .loopcheckmodes + mov eax,[vesa2_y] + cmp [fs:14h],ax ; Check that the width matches + jnz near .loopcheckmodes + mov al,[vesa2_bits] + cmp [fs:19h],al ; Check bits/pixel for match + jnz near .loopcheckmodes + +; mov ah,07h +; int 21h + +; D0 = Window supported +; 0 = Window is not supported +; 1 = Window is supported +; D1 = Window readable +; 0 = Window is not readable +; 1 = Window is readable +; D2 = Window writeable +; 0 = Window is not writeable +; 1 = Window is writeable +; D3-D7 = Reserved + + mov byte[.whichwin],0 + mov al,[fs:2] ; Get window A attributes + and al,0100b + cmp al,0100b + je .foundwin ; Mode supported + mov al,[fs:3] ; Get window B attributes + and al,0100b + cmp al,0100b + jne .foundwin ; Mode not supported + mov byte[.whichwin],1 +.foundwin + + ; Success - a match has been found!! + + sub ebp,2 + mov ax,[ebp] + mov [vesamode],ax ; Store vesa 1.2 mode number +; and eax,0FFFFh +; push eax +; mov ax,0003h +; int 10h +; pop eax +; call printnum +; jmp DosExit + + mov ax,[fs:10h] + mov byte[vesa2red10],0 + mov byte[vesa2_rposng],11 + mov byte[vesa2_gposng],6 + mov byte[vesa2_bposng],0 + mov dword[vesa2_clbitng],1111011111011110b + mov dword[vesa2_clbitng2],11110111110111101111011111011110b + mov dword[vesa2_clbitng2+4],11110111110111101111011111011110b + mov dword[vesa2_clbitng3],0111101111101111b + mov [bytesperscanline],ax ; Store bytes per scan line + cmp byte[fs:20h],10 + jne .nored10 + mov byte[fs:20h],11 + mov byte[vesa2red10],1 + mov byte[vesa2_rposng],10 + mov byte[vesa2_gposng],5 + mov dword[vesa2_clbitng],0111101111011110b + mov dword[vesa2_clbitng2],01111011110111100111101111011110b + mov dword[vesa2_clbitng2+4],01111011110111100111101111011110b + mov dword[vesa2_clbitng3],0011110111101111b +.nored10 + ; fix up bit lengths + mov al,16 + sub al,[fs:20h] + mov ah,[fs:22h] + sub ah,[fs:20h] + mov bl,[fs:24h] + sub bl,[fs:20h] + mov bh,al + cmp bh,ah + jb .scheck1 + mov bh,ah + .scheck1 + cmp bh,bl + jb .scheck2 + mov bh,bl + .scheck2 + mov byte[fs:19h],5 + + mov al,16 + sub al,[fs:22h] + mov ah,[fs:20h] + sub ah,[fs:22h] + mov bl,[fs:24h] + sub bl,[fs:22h] + mov bh,al + cmp bh,ah + jb .scheck1b + mov bh,ah + .scheck1b + cmp bh,bl + jb .scheck2b + mov bh,bl + .scheck2b + mov [fs:21h],bh + + mov al,16 + sub al,[fs:24h] + mov ah,[fs:20h] + sub ah,[fs:24h] + mov bl,[fs:22h] + sub bl,[fs:24h] + mov bh,al + cmp bh,ah + jb .scheck1c + mov bh,ah + .scheck1c + cmp bh,bl + jb .scheck2c + mov bh,bl + .scheck2c + mov [fs:23h],bh + + mov word[vesa2_clbit],0 + + cmp byte[fs:20h],10 + jne .nottopbit + mov word[vesa2_usbit],8000h +.nottopbit + + ; Process Red Stuff + mov al,[fs:20h] ; bit sizes = [fs:19h,21h,23h] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[fs:19h],6 + jne .no6bit + mov [vesa2_usbit],bx + inc al +.no6bit + or [vesa2_clbit],bx + mov [vesa2_rpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrr + shl bx,cl + jmp .shlr +.shrr + shr bx,1 +.shlr + mov word[vesa2_rfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_rtrcl],bx + xor bx,0FFFFh + mov word[vesa2_rtrcla],bx + + ; Process Green Stuff + mov al,[fs:22h] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[fs:21h],6 + jne .no6bitb + mov [vesa2_usbit],bx + inc al +.no6bitb + or [vesa2_clbit],bx + mov [vesa2_gpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrg + shl bx,cl + jmp .shlg +.shrg + shr bx,1 +.shlg + mov word[vesa2_gfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_gtrcl],bx + xor bx,0FFFFh + mov word[vesa2_gtrcla],bx + + ; Process Blue Stuff + mov al,[fs:24h] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[fs:23h],6 + jne .no6bitc + mov [vesa2_usbit],bx + inc al +.no6bitc + or [vesa2_clbit],bx + mov [vesa2_bpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrb + shl bx,cl + jmp .shlb +.shrb + shr bx,1 +.shlb + mov word[vesa2_bfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_btrcl],bx + xor bx,0FFFFh + mov word[vesa2_btrcla],bx + + xor word[vesa2_clbit],0FFFFh + + mov ax,[fs:4] + mov [granularity],ax + xor edx,edx + mov ax,64 + mov bx,[granularity] + div bx + mov [granadd],ax + + +;vesa2_rtrcl dw 0 ; red transparency clear (bit+4) +;vesa2_rtrcla dw 0 ; red transparency (AND) clear (not(bit+4)) +;vesa2_rfull dw 0 ; red max (or (bit-1)*1Fh) + + call genfulladdtab + + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov ax,4f02h + mov bx,[vesamode] + int 10h ; Set the vesa mode + cmp ax,004fh + jz .modesetok + mov edx,.unableset + jmp VESA12EXITTODOS ; Failure!!! + .unableset db 'Unable to initialize video mode.$' + + .modesetok +;******************************* EXTRA BIT **************************** + + ret + + ; Check logical scanline length + mov eax,4f06h + mov ebx,1 + int 10h + cmp cx,[vesa2_x] + je .correctwidth + + mov eax,4f06h ; VBE Set/Get logical scan line + ; length + mov ebx,0 ; Set scan line length in + ; pixels + mov ecx, [vesa2_x] ; Desired screen width + int 10h + cmp ax,04fh + jz .correctwidth + mov edx, .unablescan + jmp VESA12EXITTODOS ; Failure!!! + .unablescan db 'Unable to set scan line length.$' + + .correctwidth + + ret + + +RMREGS +.edi dd 0 +.esi dd 0 +.ebp dd 0 +.esp dd 0 +.ebx dd 0 +.edx dd 0 +.ecx dd 0 +.eax dd 0 +.flags dw 0 +.es dw 0 +.ds dw 0 +.fs dw 0 +.gs dw 0 +.ip dw 0 +.cs dw 0 +.sp dw 0 +.ss dw 0 +.spare times 20 dd 0 + \ No newline at end of file diff --git a/zsnes/src/dos/vesa2.asm b/zsnes/src/dos/vesa2.asm new file mode 100644 index 00000000..df450eb2 --- /dev/null +++ b/zsnes/src/dos/vesa2.asm @@ -0,0 +1,802 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM printnum +EXTSYM DosExit,ZSNESBase,Change_Dir,PrintStr,newengen +EXTSYM HalfTransB,HalfTransC +EXTSYM InitDrive,gotoroot,InitDir,fulladdtab +; EXTSYM printhex +; EXTSYM printhex +EXTSYM UnusedBit,HalfTrans,UnusedBitXor,ngrposng,nggposng,ngbposng +; EXTSYM printhex +EXTSYM Init_2xSaIMMX,Init_2xSaI + + + + + + +; add 0214h video mode +anticrash times 10 db 0 + + +ALIGN32 +NEWSYM vesa2_usbit, dd 0 ; Unused bit in proper bit location +NEWSYM vesa2_clbit, dd 0 ; clear all bit 0's if AND is used +NEWSYM vesa2_clbitng, dd 0 ; clear all bit 0's if AND is used +NEWSYM vesa2_clbitng2, dd 0,0 ; clear all bit 0's if AND is used +NEWSYM vesa2_clbitng3, dd 0 ; clear all bit 0's if AND is used +NEWSYM vesa2_x, dd 320 ; Desired screen width +NEWSYM vesa2_y, dd 240 ; Height +NEWSYM vesa2selec, dd 0 ; VESA2 Selector Location +NEWSYM vesa2_bits, dd 8 ; Bits per pixel +NEWSYM vesa2_rpos, dd 0 ; Red bit position +NEWSYM vesa2_gpos, dd 0 ; Green bit position +NEWSYM vesa2_bpos, dd 0 ; Blue bit position +NEWSYM vesa2_rposng, dd 0 ; Red bit position +NEWSYM vesa2_gposng, dd 0 ; Green bit position +NEWSYM vesa2_bposng, dd 0 ; Blue bit position + +NEWSYM vesa2_rtrcl, dd 0 ; red transparency clear (bit+4) +NEWSYM vesa2_rtrcla, dd 0 ; red transparency (AND) clear (not(bit+4)) +NEWSYM vesa2_rfull, dd 0 ; red max (or bit*1Fh) +NEWSYM vesa2_gtrcl, dd 0 ; red transparency clear (bit+4) +NEWSYM vesa2_gtrcla, dd 0 ; red transparency (AND) clear (not(bit+4)) +NEWSYM vesa2_gfull, dd 0 ; red max (or bit*1Fh) +NEWSYM vesa2_btrcl, dd 0 ; red transparency clear (bit+4) +NEWSYM vesa2_btrcla, dd 0 ; red transparency (AND) clear (not(bit+4)) +NEWSYM vesa2_bfull, dd 0 ; red max (or bit*1Fh) +NEWSYM vesa2red10, dd 0 ; red position at bit 10 +NEWSYM videotroub, dd 0 ; red position at bit 10 +NEWSYM vesa3en, dd 0 +NEWSYM VESAAddr, dd 0 +NEWSYM ExitFromGUI, db 0 +NEWSYM ErrorPointer, dd 0 +NEWSYM TripBufAvail, db 0 + + +NEWSYM dcolortab, times 256 dd 0 + +NEWSYM genfulladdtab + ; Write to buffer + cmp byte[newengen],1 + jne .notneweng + cmp byte[vesa2red10],0 + jne near genfulladdtabred +.notneweng + xor ecx,ecx +.loopers + mov ax,cx + test [vesa2_rtrcl],cx + jz .nor + and ax,[vesa2_rtrcla] + or ax,[vesa2_rfull] +.nor + test [vesa2_gtrcl],cx + jz .nog + and ax,[vesa2_gtrcla] + or ax,[vesa2_gfull] +.nog + test [vesa2_btrcl],cx + jz .nob + and ax,[vesa2_btrcla] + or ax,[vesa2_bfull] +.nob + shl ax,1 + mov [fulladdtab+ecx*2],ax + dec cx + jnz .loopers + ret + +NEWSYM genfulladdtabred +NEWSYM genfulladdtabng + ; Write to buffer + xor ecx,ecx +.loopers + mov ax,cx + test cx,0100000000000000b + jz .nor + and ax,1011111111111111b + or ax, 0011110000000000b +.nor + test cx,0000001000000000b + jz .nog + and ax,1111110111111111b + or ax, 0000000111100000b +.nog + test cx,0000000000010000b + jz .nob + and ax,1111111111101111b + or ax, 0000000000001111b +.nob + shl ax,1 + mov [fulladdtab+ecx*2],ax + dec cx + jnz .loopers + ret + +NEWSYM VESA2EXITTODOS + mov byte[videotroub],1 + cmp byte[ExitFromGUI],0 + je .nogui + mov [ErrorPointer],edx + ret +.nogui + mov ax,0003h + int 10h + push edx + mov edx,.exitfromvesa2 + call PrintStr + pop edx + call PrintStr + mov edx,.return + call PrintStr + + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + jmp DosExit + +.exitfromvesa2 db 'Unable to Initialize VESA2 : ',0 +.return db 10,13,0 + +;******************************************************* +; Set up Vesa 2 +;******************************************************* + +NEWSYM InitVesa2 + ;-------------------------------------------------; + ; First - allocate some bytes in DOS memory for ; + ; communication with VBE ; + ;-------------------------------------------------; + + mov eax,0100h + mov ebx,512/16 ; 512 bytes + int 31h ; Function 31h,100h - Allocate + ; DOS memory (512 bytes) + jnc .gotmem + mov edx,.nomemmessage + jmp VESA2EXITTODOS + .nomemmessage + db 'Unable to locate DOS memory.',0 + + .gotmem + mov fs,dx ; FS now points to the DOS + ; buffer + + + ;--------------------------------------------------; + ; Now, get information about the video card into ; + ; a data structure ; + ;--------------------------------------------------; + + mov edi,RMREGS + mov dword[fs:0],'VBE2' ; Request VBE 2.0 info + mov dword[RMREGS.eax],4f00h + mov word[RMREGS.es],ax ; Real mode segment of DOS + ; buffer + mov dword[RMREGS.edi],0 + + push es + push ds + pop es + mov eax,300h + mov ebx,10h + xor ecx,ecx + int 31h ; Simulate real mode interrupt + pop es + + jnc .int1ok + mov edx,.noint1message + jmp VESA2EXITTODOS + .noint1message + db 'Simulated real mode interrupt failed.',0 + + .int1ok ; Real mode int successful!!! + mov eax,[RMREGS.eax] + cmp al,4fh ; Check vbe interrupt went OK + jz .vbedetected + mov edx,.novbemessage + jmp VESA2EXITTODOS + .novbemessage + db 'VBE not detected!!',0 + + .vbedetected + cmp dword[fs:0000],'VESA' + jz .vesadetected ; Check for presence of vesa + mov edx,.novesamessage + jmp VESA2EXITTODOS + .novesamessage + db 'VESA not detected!',0 + + .vesadetected + cmp word[fs:0004],200h + jae .vesa2detected ; Check we've got VESA 2.0 or greater + mov edx,.novesa2message + jmp VESA2EXITTODOS + .novesa2message + db 'VESA 2.0 or greater required!',0 + + + ;-----------------------------------------------------; + ; OK - vesa 2.0 or greater has been detected. Copy ; + ; mode information into VESAmodelist ; + ;-----------------------------------------------------; + + .vesa2detected + mov dword[vesa3en],0 + cmp word[fs:004],300h + jb .notvbe3 + mov dword[vesa3en],1 + .notvbe3 + mov ax,[fs:12h] ; Get no. of 64k blocks + mov [noblocks],ax + mov ax, 2 + mov bx,[fs:10h] + int 31h + + jnc .wegottheselector + mov edx, .oopsnoselector + jmp VESA2EXITTODOS + .oopsnoselector + db 'Failed to allocate vesa display selector!',0 + + .wegottheselector + + mov gs,ax + xor eax,eax + mov ebp,VESAmodelist + mov ecx,512 + mov ax,[fs:0eh] + + .loopcopymodes + mov bx,[gs:eax] + mov [ebp],bx + cmp bx,0ffffh + jz .copiedmodes + add ebp,2 + add eax,2 + dec ecx + jz .outofmodelistspace + jmp .loopcopymodes + + .outofmodelistspace + mov edx,.outofmodelistspacemessage + jmp VESA2EXITTODOS + .outofmodelistspacemessage + db 'Out of VESA2 mode list space!',0 + + ;----------------------------------------------; + ; OK - Scan the mode list to find a matching ; + ; mode for vesa2_x, vesa2_y and vesa2_depth ; + ;----------------------------------------------; + + .copiedmodes + + mov ebp,VESAmodelist + xor ecx,ecx + + .loopcheckmodes + mov cx, [ebp] + cmp cx, 0ffffh + jnz .notendoflist + + mov edx,.endoflist + jmp VESA2EXITTODOS + + .endoflist db 'This VESA2 mode does not work on your video card / driver.',0 + .whichwin db 0 + + .notendoflist + + mov edi, RMREGS + mov dword[RMREGS.eax],4f01h + mov dword[RMREGS.ebx],0 + mov dword[RMREGS.ecx],ecx + mov dword[RMREGS.edi],0 + + push es + push ds + pop es + mov eax,300h + mov ebx,10h + xor ecx,ecx + int 31h ; Simulate real mode interrupt + pop es + jnc .modecheckok + mov edx,.modecheckfail + jmp VESA2EXITTODOS + .modecheckfail + db 'Real mode interrupt failure while checking vesa mode',0 + + .modecheckok + add ebp,2 + + test word[fs:0000h],1b + jz near .loopcheckmodes ; If mode is not available + +; +; xor eax,eax +; mov ax,[fs:12h] +; call printnum +; mov ah,02h +; mov dl,'x' +; int 21h +; mov ax,[fs:14h] +; call printnum +; mov ah,02h +; mov dl,'x' +; int 21h +; xor ah,ah +; mov al,[fs:19h] +; call printnum +; mov ah,02h +; mov dl,13 +; int 21h +; mov dl,10 +; int 21h + + mov eax,[vesa2_x] + cmp [fs:12h],ax ; Check that the height matches + jnz near .loopcheckmodes + mov eax,[vesa2_y] + cmp [fs:14h],ax ; Check that the width matches + jnz near .loopcheckmodes + mov al,[vesa2_bits] + cmp [fs:19h],al ; Check bits/pixel for match + jnz near .loopcheckmodes + +; mov ax,3 +; int 10h +; xor eax,eax +; mov ax,[fs:0h] +; call printnum +; jmp DosExit + + mov byte[TripBufAvail],1 + test word[fs:0000h],400h + jz .notbuf + mov byte[TripBufAvail],1 +.notbuf + +; jz .notvesa3 +; xor eax,eax +; mov ax,[fs:0000h] +; call printhex +; jmp DosExit +.notvesa3 + +; mov ah,07h +; int 21h + +; D0 = Window supported +; 0 = Window is not supported +; 1 = Window is supported +; D1 = Window readable +; 0 = Window is not readable +; 1 = Window is readable +; D2 = Window writeable +; 0 = Window is not writeable +; 1 = Window is writeable +; D3-D7 = Reserved + + mov byte[.whichwin],0 + mov al,[fs:2] ; Get window A attributes + and al,0100b + cmp al,0100b + je .foundwin ; Mode supported + mov al,[fs:3] ; Get window B attributes + and al,0100b + cmp al,0100b + jne .foundwin ; Mode not supported + mov byte[.whichwin],1 +.foundwin + + ; Success - a match has been found!! + + sub ebp,2 + mov ax,[ebp] + mov [vesamode],ax ; Store vesa 2 mode number + +; call printhex +; jmp DosExit + + mov ax,[fs:10h] + mov byte[vesa2red10],0 + mov byte[vesa2_rposng],11 + mov byte[vesa2_gposng],6 + mov byte[vesa2_bposng],0 + mov dword[vesa2_clbitng],1111011111011110b + mov dword[vesa2_clbitng2],11110111110111101111011111011110b + mov dword[vesa2_clbitng2+4],11110111110111101111011111011110b + mov dword[vesa2_clbitng3],0111101111101111b + mov [bytesperscanline],ax ; Store bytes per scan line + cmp byte[fs:20h],10 + jne near .nored10 + mov byte[fs:20h],11 + mov byte[vesa2red10],1 + mov byte[vesa2_rposng],10 + mov byte[vesa2_gposng],5 + mov dword[vesa2_clbitng],0111101111011110b + mov dword[vesa2_clbitng2],01111011110111100111101111011110b + mov dword[vesa2_clbitng2+4],01111011110111100111101111011110b + mov dword[vesa2_clbitng3],0011110111101111b + + mov dword[UnusedBit], 10000000000000001000000000000000b + mov dword[HalfTrans], 01111011110111100111101111011110b + mov dword[UnusedBitXor], 01111111111111110111111111111111b + mov dword[UnusedBit+4], 10000000000000001000000000000000b + mov dword[HalfTrans+4], 01111011110111100111101111011110b + mov dword[UnusedBitXor+4],01111111111111110111111111111111b + mov dword[HalfTransB], 00000100001000010000010000100001b + mov dword[HalfTransB+4], 00000100001000010000010000100001b + mov dword[HalfTransC], 01111011110111100111101111011110b + mov dword[HalfTransC+4], 01111011110111100111101111011110b + mov dword[ngrposng],10 + mov dword[nggposng],5 + mov dword[ngbposng],0 + +.nored10 + ; fix up bit lengths + mov al,16 + sub al,[fs:20h] + mov ah,[fs:22h] + sub ah,[fs:20h] + mov bl,[fs:24h] + sub bl,[fs:20h] + mov bh,al + cmp bh,ah + jb .scheck1 + mov bh,ah + .scheck1 + cmp bh,bl + jb .scheck2 + mov bh,bl + .scheck2 + mov byte[fs:19h],5 + + mov al,16 + sub al,[fs:22h] + mov ah,[fs:20h] + sub ah,[fs:22h] + mov bl,[fs:24h] + sub bl,[fs:22h] + mov bh,al + cmp bh,ah + jb .scheck1b + mov bh,ah + .scheck1b + cmp bh,bl + jb .scheck2b + mov bh,bl + .scheck2b + mov [fs:21h],bh + + mov al,16 + sub al,[fs:24h] + mov ah,[fs:20h] + sub ah,[fs:24h] + mov bl,[fs:22h] + sub bl,[fs:24h] + mov bh,al + cmp bh,ah + jb .scheck1c + mov bh,ah + .scheck1c + cmp bh,bl + jb .scheck2c + mov bh,bl + .scheck2c + mov [fs:23h],bh + + mov word[vesa2_clbit],0 + + cmp byte[fs:20h],10 + jne .nottopbit + mov word[vesa2_usbit],8000h +.nottopbit + + ; Process Red Stuff + mov al,[fs:20h] ; bit sizes = [fs:19h,21h,23h] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[fs:19h],6 + jne .no6bit + mov [vesa2_usbit],bx + inc al +.no6bit + or [vesa2_clbit],bx + mov [vesa2_rpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrr + shl bx,cl + jmp .shlr +.shrr + shr bx,1 +.shlr + mov word[vesa2_rfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_rtrcl],bx + xor bx,0FFFFh + mov word[vesa2_rtrcla],bx + +; mov ax,03h +; int 10h +; mov ax,[vesa2_rfull] +; call printhex +; jmp DosExit + + ; Process Green Stuff + mov al,[fs:22h] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[fs:21h],6 + jne .no6bitb + mov [vesa2_usbit],bx + inc al +.no6bitb + or [vesa2_clbit],bx + mov [vesa2_gpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrg + shl bx,cl + jmp .shlg +.shrg + shr bx,1 +.shlg + mov word[vesa2_gfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_gtrcl],bx + xor bx,0FFFFh + mov word[vesa2_gtrcla],bx + + ; Process Blue Stuff + mov al,[fs:24h] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[fs:23h],6 + jne .no6bitc + mov [vesa2_usbit],bx + inc al +.no6bitc + or [vesa2_clbit],bx + mov [vesa2_bpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrb + shl bx,cl + jmp .shlb +.shrb + shr bx,1 +.shlb + mov word[vesa2_bfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_btrcl],bx + xor bx,0FFFFh + mov word[vesa2_btrcla],bx + + xor word[vesa2_clbit],0FFFFh + +;vesa2_rtrcl dw 0 ; red transparency clear (bit+4) +;vesa2_rtrcla dw 0 ; red transparency (AND) clear (not(bit+4)) +;vesa2_rfull dw 0 ; red max (or (bit-1)*1Fh) + + call genfulladdtab + + test word[fs:0h],10000000b ; Check if linear available + jnz .linearavailable + mov edx,.nolframebuffer + jmp VESA2EXITTODOS ; None available + .nolframebuffer db 'Linear Frame Buffer not Detected.',0 + + ;---------------------------------------------; + ; OK - now set the vesa 2 mode based on the ; + ; information gleaned... ; + ;---------------------------------------------; + + .linearavailable + or word[vesamode],4000h ; Convert mode to its LFB + ; equivalent + mov ebx,[fs:28h] ; Read in physical base ptr + + mov cx,bx + shr ebx,16 + mov si,[noblocks] + xor edi,edi ; Since noblocks = number of + ; 64k blocks, these lines leave + ; si:di holding byte size + mov eax,800h + int 31h + jnc .mappedphysicalarea + mov edx,.unablemap + jmp VESA2EXITTODOS ; Failure!!! + .unablemap db 'Unable to map physical area.',0 + + .mappedphysicalarea + shl ebx,16 + mov bx,cx + mov [LFBpointer],ebx + mov eax,ebx + sub eax,[ZSNESBase] + mov [VESAAddr],eax + + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov ax,4f02h + mov bx,[vesamode] + int 10h ; Set the vesa mode + cmp ax,004fh + jz .modesetok + mov edx,.unableset + jmp VESA2EXITTODOS ; Failure!!! + .unableset db 'Unable to initialize video mode.',0 + + .modesetok +;******************************* EXTRA BIT **************************** + +; cmp byte[.whichwin],1 ; Check if Write is at Window B +; jne .nowinB +; +; mov ax,4F05h +; mov bx,1 +; mov dx,0 +; int 10h +; +;.nowinB + + ; Check logical scanline length + mov eax,4f06h + mov ebx,1 + int 10h + cmp cx,[vesa2_x] + je .correctwidth + + mov eax,4f06h ; VBE Set/Get logical scan line + ; length + mov ebx,0 ; Set scan line length in + ; pixels + mov ecx, [vesa2_x] ; Desired screen width + int 10h + cmp ax,04fh + jz .correctwidth + mov edx, .unablescan + jmp VESA2EXITTODOS ; Failure!!! + .unablescan db 'Unable to set scan line length.',0 + + .correctwidth + +;*************************** END OF EXTRA BIT ************************* + + xor eax,eax + mov ecx,1 + int 31h ; Allocate a descriptor + + mov bx,ax ; Move our selector into bx + + mov ecx,[LFBpointer] + mov dx,cx + shr ecx,16 + mov eax,7 + int 31h ; Set our selector to LFB + jnc .selectornowset + mov edx,.unablelfb + jmp VESA2EXITTODOS ; Failure!!! + .unablelfb db 'Unable to set selector to LFB.',0 + + .selectornowset + + xor ecx,ecx + mov cx,[noblocks] + shl ecx,6 ; Multiply by 64 + shl ecx,10 ; And again by 1024 + sub ecx,1 ; Necessary!!! + mov dx,cx + shr ecx,16 ; CX:DX size of screen + mov eax,8 + int 31h ; Set size of selector + jnc .ok + mov edx,.unablesets + jmp VESA2EXITTODOS ; Failure!!! + .unablesets db 'Unable to set size of selector.',0 + + .ok + lar ecx,ebx + shr ecx,8 + and cl,60h + or cl,93h + and ch,0c0h ; Keep granularity bit + mov ax,9 + int 31h ; Set selector access rights + jnc .accessrightsset + mov edx,.unablesetar + jmp VESA2EXITTODOS + .unablesetar db 'Unable to set selector access rights.',0 + + .accessrightsset + mov [vesa2selec],bx + + cmp byte[vesa2red10],1 + je .red10 + mov eax,565 + jmp .red11 +.red10 + mov eax,555 +.red11 + push eax + call Init_2xSaIMMX + call Init_2xSaI + pop eax + ret + +NEWSYM LFBpointer + dd 0 +NEWSYM noblocks + dw 0 +NEWSYM bytesperscanline + dw 0 +NEWSYM vesamode + dw 0 +;---------------------------------------------------------------------- +NEWSYM VESAmodelist + times 512 dw 0 +;---------------------------------------------------------------------- +NEWSYM RMREGS +.edi dd 0 +.esi dd 0 +.ebp dd 0 +.esp dd 0 +.ebx dd 0 +.edx dd 0 +.ecx dd 0 +.eax dd 0 + +.flags dw 0 +.es dw 0 +.ds dw 0 +.fs dw 0 +.gs dw 0 +.ip dw 0 +.cs dw 0 +.sp dw 0 +.ss dw 0 +.spare times 20 dd 0 +;---------------------------------------------------------------------- + \ No newline at end of file diff --git a/zsnes/src/dos/zfile.c b/zsnes/src/dos/zfile.c new file mode 100644 index 00000000..8c038ff3 --- /dev/null +++ b/zsnes/src/dos/zfile.c @@ -0,0 +1,267 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include + +#ifdef ZDOS +#include +#endif + + +#define DWORD unsigned int +#define BYTE unsigned char + +FILE *FILEHANDLE[16]; +DWORD CurrentHandle=0; + + + +// ZFileSystemInit +// return 0 + +// ZOpenFile info : +BYTE * ZOpenFileName; +DWORD ZOpenMode; +// Open modes : 0 read/write in +// 1 write (create file, overwrite) +// return file handle if success, 0xFFFFFFFF if error + +// ZCloseFile info : +DWORD ZCloseFileHandle; +// return 0 + +// ZFileSeek info : +DWORD ZFileSeekHandle; +DWORD ZFileSeekPos; +DWORD ZFileSeekMode; // 0 start, 1 end +// return 0 + +// ZFileReadBlock info : +BYTE * ZFileReadBlock; +DWORD ZFileReadSize; +DWORD ZFileReadHandle; +// return 0 + +// ZFileWriteBlock info : +BYTE * ZFileWriteBlock; +DWORD ZFileWriteSize; +DWORD ZFileWriteHandle; +// return 0 + +// ZFileTell +DWORD ZFileTellHandle; + +// ZFileGetftime +BYTE * ZFFTimeFName; +DWORD ZFTimeHandle; +DWORD ZFDate; +DWORD ZFTime; + +// MKDir/CHDir +BYTE * MKPath; +BYTE * CHPath; +BYTE * RMPath; + +// GetDir +BYTE * DirName; +DWORD DriveNumber; + +// ZFileDelete +BYTE * ZFileDelFName; +// return current position + +DWORD ZFileSystemInit() +{ + CurrentHandle=0; + return(0); +} + +DWORD ZOpenFile() +{ + if(ZOpenMode==0) + { + if((FILEHANDLE[CurrentHandle]=fopen(ZOpenFileName,"rb"))!=NULL) + { + CurrentHandle+=1; + return(CurrentHandle-1); + } + return(0xFFFFFFFF); + } + if(ZOpenMode==1) + { + if((FILEHANDLE[CurrentHandle]=fopen(ZOpenFileName,"wb"))!=NULL) + { + CurrentHandle+=1; + return(CurrentHandle-1); + } + return(0xFFFFFFFF); + } + if(ZOpenMode==2) + { + if((FILEHANDLE[CurrentHandle]=fopen(ZOpenFileName,"r+b"))!=NULL) + { + CurrentHandle+=1; + return(CurrentHandle-1); + } + return(0xFFFFFFFF); + } + return(0xFFFFFFFF); +} + +DWORD ZCloseFile() +{ + fclose(FILEHANDLE[ZCloseFileHandle]); + CurrentHandle-=1; + return(0); +} + +DWORD ZFileSeek() +{ + if(ZFileSeekMode==0) + { + fseek(FILEHANDLE[ZFileSeekHandle],ZFileSeekPos,SEEK_SET); + return(0); + } + if(ZFileSeekMode==1) + { + fseek(FILEHANDLE[ZFileSeekHandle],ZFileSeekPos,SEEK_END); + return(0); + } + return(0xFFFFFFFF); +} + +DWORD ZFileRead() +{ + return(fread(ZFileReadBlock,1,ZFileReadSize,FILEHANDLE[ZFileReadHandle])); +} + + +DWORD ZFileWrite() +{ + if((fwrite(ZFileWriteBlock,1,ZFileWriteSize,FILEHANDLE[ZFileWriteHandle]))!=ZFileWriteSize) return(0xFFFFFFFF); + return(0); +} + +DWORD ZFileTell() +{ + return(ftell(FILEHANDLE[ZFileTellHandle])); +} + +DWORD ZFileDelete() +{ + return(remove(ZFileDelFName)); +} + + +DWORD ZFileGetFTime() +{ + _dos_open(ZFFTimeFName, 0,&ZFTimeHandle); + _dos_getftime(ZFTimeHandle,&ZFDate,&ZFTime); + _dos_close(ZFTimeHandle); + return(0); +} + +DWORD ZFileMKDir() +{ + return(mkdir(MKPath)); +} + +DWORD ZFileCHDir() +{ + return(chdir(CHPath)); +} + +DWORD ZFileRMDir() +{ + return(rmdir(RMPath)); +} + +DWORD ZFileGetDir() +{ + return(getcwd(DirName,128)); +} + +BYTE * ZFileFindPATH; +DWORD ZFileFindATTRIB; +DWORD DTALocPos; + +//struct _find_t { +// char reserved[21] __attribute__((packed)); +// unsigned char attrib __attribute__((packed)); +// unsigned short wr_time __attribute__((packed)); +// unsigned short wr_date __attribute__((packed)); +// unsigned long size __attribute__((packed)); +// char name[256] __attribute__((packed)); +//}; + +DWORD ZFileFindFirst() +{ + return(_dos_findfirst(ZFileFindPATH,ZFileFindATTRIB,DTALocPos)); +} + +DWORD ZFileFindNext() +{ + return(_dos_findnext(DTALocPos)); +} + +DWORD ZFileFindEnd() // for compatibility with windows later +{ + return(0); +} + + +//BYTE * DirName; +//DWORD DriveNumber; + +//unsigned int _dos_findfirst(char *_name, unsigned int _attr, struct _find_t *_result); +//unsigned int _dos_findnext(struct _find_t *_result); + + +DWORD GetTime() +{ + + DWORD value; + struct tm *newtime; + time_t long_time; + + time( &long_time ); + newtime = localtime( &long_time ); + + value = ((newtime->tm_sec) % 10)+((newtime->tm_sec)/10)*16 + +((((newtime->tm_min) % 10)+((newtime->tm_min)/10)*16) << 8) + +((((newtime->tm_hour) % 10)+((newtime->tm_hour)/10)*16) << 16); + return(value); +} + +DWORD GetDate() +{ + + DWORD value; + struct tm *newtime; + time_t long_time; + + time( &long_time ); + newtime = localtime( &long_time ); + value = ((newtime->tm_mday) % 10)+((newtime->tm_mday)/10)*16 + +(((newtime->tm_mon)+1) << 8) + +((((newtime->tm_year) % 10)+((newtime->tm_year)/10)*16) << 16); + +((newtime->tm_wday) << 28); + + return(value); +} \ No newline at end of file diff --git a/zsnes/src/dos/zloader.c b/zsnes/src/dos/zloader.c new file mode 100644 index 00000000..20388e48 --- /dev/null +++ b/zsnes/src/dos/zloader.c @@ -0,0 +1,396 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include + +extern void zstart(void); +extern void DosExit(void); +extern void ConvertJoyMap1(void); +extern void ConvertJoyMap2(void); +extern void displayparams(void); +extern void makeextension(void); + +extern unsigned char Palette0, SPC700sh, OffBy1Line, DSPDisable, + FPUCopy, Force8b, ForcePal, GUIClick, MouseDis, + MusicRelVol, ScreenScale, SoundCompD, SoundQuality, + StereoSound, V8Mode, antienab, cvidmode, debugdisble, + debugger, enterpress, finterleave, frameskip, + gammalevel, guioff, per2exec, pl1contrl, pl2contrl, + romtype, scanlines, showallext, smallscreenon, soundon, + spcon, vsyncon, DisplayS, fname, filefound, SnowOn; + +void ccmdline(void); + +char *ers[] = +{ + "Frame Skip must be a value of 0 to 9!\n", + "Gamma Correction Level must be a value of 0 to 5!\n", + "Sound Sampling Rate must be a value of 0 to 6!\n", + "Invalid Video Mode!\n", + "Percentage of instructions to execute must be a number from 50 to 150!\n", + "Player Input must be a value from 0 to 6!\n", + "Volume must be a number from 0 to 100!\n" + +}; + + + +int argc; +char **argv; +int main(int margc, char **margv) +{ + argc=margc; + argv=margv; + zstart(); +} + + +int my_atoi(char *nptr) +{ + int p,c; + c=0; + for(p=0;nptr[p];p++) + { + if( !isdigit(nptr[p]) ) c+=1; + } + if(c) return -1; + else return atoi(nptr); + +} + + +void ccmdline(void) +{ + int p=0; + p=pccmdline(); + if(p == 0) return; + + if(p == 9) + { + displayparams(); + } + if(p == 4) + { +// printf("Mangled command line, did you forget a parm?\n"); + printf("Invalid Commandline!\n"); + DosExit(); + } + + if((p > 9) && (p < 17)) + { + printf(ers[p-10]); + DosExit(); + } + if(p == 2) + { + DosExit(); + } + + + printf("cmdline returned %i\n",p); + DosExit(); + +} + +int pccmdline(void) +{ + int p; + int gfnm=0; + + for(p=1;p 6) return 15; + p++; + ConvertJoyMap1(); + break; + } + case '2': /* Player 2 Input */ + { + if(!hasroom) return 4; + pl2contrl=my_atoi(argv[p+1]); + if(pl2contrl > 6) return 15; + p++; + ConvertJoyMap2(); + break; + } + case 'f': + { + if(!hasroom) return 4; + frameskip=my_atoi(argv[p+1]); + if(frameskip > 9) return 10; + p++; + break; + } + case 'g': + { + if(!hasroom) return 4; + gammalevel=my_atoi(argv[p+1]); + if(gammalevel > 5) return 11; + p++; + break; + } + case 'p': + { + if(!hasroom) return 4; + per2exec=my_atoi(argv[p+1]); + if(per2exec > 150) return 14; + if(per2exec < 50) return 14; + p++; + break; + } + case 'r': + { + if(!hasroom) return 4; + SoundQuality=my_atoi(argv[p+1]); + if(SoundQuality > 6) return 12; + p++; + break; + } + case 'v': + { + if(nn == '8') + { + V8Mode=1; + pp++; + } + else + { + if(!hasroom) return 4; + cvidmode=my_atoi(argv[p+1]); + if(cvidmode > 10) return 13; + p++; + } + break; + } + case 'k': + { + if(!hasroom) return 4; + MusicRelVol=my_atoi(argv[p+1]); + if(MusicRelVol > 100) return 16; + p++; + break; + } + case '8': + { + Force8b=1; + break; + } + case '0': /* Palette 0 disable */ + { + Palette0=1; + break; + } + case '7': /* SPC700 speed hack disable */ + { + SPC700sh=1; + break; + } + case '9': /* Off by 1 line */ + { + OffBy1Line=1; + break; + } + case 'e': + { + enterpress=1; + break; + } + case 'h': + { + romtype=2; + break; + } + case 'l': + { + romtype=1; + break; + } + case 'm': + { + guioff=1; /* disables GUI */ + break; + } + case 'n': + { + scanlines=1; + break; + } + case 's': + { + if(nn == 'p') + { + DisplayS=1; + pp++; + } + else + if(nn == 'a') + { + showallext=1; + pp++; + } + else + if(nn == 'n') + { + SnowOn=1; + pp++; + } + else + { + spcon=1; + soundon=1; + } + break; + } + case 't': + { + ForcePal=1; + break; + } + case 'u': + { + ForcePal=2; + break; + } + case 'w': + { + vsyncon=1; + break; + } + case 'z': + { + StereoSound=1; + break; + } + case 'd': + { + if(nn == 'd') + { + DSPDisable=1; + pp++; + } + else + { + debugger=1; + debugdisble=0; + } + break; + } + case 'b': + { + SoundCompD=1; + break; + } + + case 'c': + { + if(nn == 'c') + { + smallscreenon=1; + pp++; + } + else + { + ScreenScale=1; + } + break; + } + + case 'y': + { + antienab=1; + break; + } + case 'o': + { + if(nn == 'm') + { + FPUCopy=2; + pp++; + } + else + { + FPUCopy=0; + } + break; + } + case 'i': + { + finterleave=1; + break; + } + case 'j': + { + GUIClick=0; + MouseDis=1; + break; + } + case '?': + { + return 9; + } + } + + } + + } + else + { + if(gfnm > 0) + { + printf("Limit yourself to one filename\n"); + return 2; + } + else + { + char *fvar; + fvar=&fname; + fvar[0] = strlen(argv[p]); + strncpy(&fvar[1],argv[p],127); + gfnm++; + } + } + } + if(gfnm == 1) + { + filefound=0; + makeextension(); + } + return 0; +} + \ No newline at end of file diff --git a/zsnes/src/dos/zsipx.asm b/zsnes/src/dos/zsipx.asm new file mode 100644 index 00000000..061454de --- /dev/null +++ b/zsnes/src/dos/zsipx.asm @@ -0,0 +1,212 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM ipx_init ; To init ipx +EXTSYM ipx_initcode ; return 0 if everything is ok (int) +EXTSYM ipx_packet ; 80 bytes buffer to send +EXTSYM ipx_packet_size ; size to send (max 80 bytes) (dword) +EXTSYM sendpacket ; to send a packet +EXTSYM checkpacket ; check if a packet is ready to receive +EXTSYM ipx_packet_ready ; return 1 if there is a packet ready (byte) +EXTSYM read_packet ; to read an incoming packet +EXTSYM ipx_read_packet ; 80 bytes buffer of received packet +EXTSYM ipx_deinit ; to deinit the ipx +EXTSYM IPXInfoStr,IPXInfoStrR +EXTSYM modembuffer, modemhead, modemtail + + + + + + + + + + + + +NEWSYM ipxinited, db 0 + +NEWSYM initipx + mov dword[modemhead],0 + mov dword[modemtail],0 + xor ax,ax + cmp byte[ipxinited],1 + je .notokay + call ipx_init + mov ax,[ipx_initcode] + cmp ax,0 + jne .notokay + mov byte[ipxinited],1 +.notokay + ret + +NEWSYM deinitipx + cmp byte[ipxinited],0 + je .notinitialized + mov byte[ipxinited],0 + call ipx_deinit +.notinitialized + ret + +NEWSYM PacketPointer, dd 0 + +NEWSYM PreparePacketIPX + cmp byte[ipxinited],1 + jne .noipx + call ipxpp +.noipx + ret + +NEWSYM SendPacketIPX + cmp byte[ipxinited],1 + jne .noipx + call ipxsp +.noipx + ret + +NEWSYM ipxsendchar ; prepare packet + push esi + mov esi,[PacketPointer] + mov [esi],al + inc dword[PacketPointer] + pop esi + ret + +NEWSYM IPXSearchval, db 0 +NEWSYM ipxlookforconnect + cmp byte[ipxinited],0 + je .initialized + ret +.initialized + pushad + call checkpacket + cmp byte[ipx_packet_ready],1 + jne near .nopacket + call read_packet + cmp dword[ipx_read_packet],'ZZ|Z' + jne .nopacketf + cmp byte[ipx_read_packet+6],'L' + jne .nopacketf + mov ax,[ipx_read_packet+4] + cmp ax,[IPXInfoStr] + je .nopacketf + mov [IPXInfoStrR],ax + mov eax,ipx_packet + mov dword[eax],'ZY|Z' + mov bx,[IPXInfoStr] + mov [eax+4],bx + mov bx,[IPXInfoStrR] + mov [eax+6],bx + mov dword[ipx_packet_size],8 + call sendpacket + mov byte[IPXSearchval],1 + jmp .skipall +.nopacketf + cmp dword[ipx_read_packet],'ZY|Z' + jne .nopacket + mov bx,[IPXInfoStr] + cmp [eax+6],bx + jne .nopacket + mov bx,[eax+4] + cmp bx,[IPXInfoStr] + je .nopacket + mov [IPXInfoStrR],bx + mov byte[IPXSearchval],1 + jmp .skipall +.nopacket + mov eax,ipx_packet + mov dword[eax],'ZZ|Z' + mov bx,[IPXInfoStr] + mov [eax+4],bx + mov byte[eax+6],'L' + mov dword[ipx_packet_size],7 + call sendpacket +.skipall + popad + ret + +NEWSYM ipxpp ; prepare packet + pushad + mov eax,ipx_packet + mov byte[eax],'Z' + mov byte[eax+1],'|' + mov byte[eax+2],'S' + mov bx,[IPXInfoStr] + mov [eax+3],bx + add eax,6 + mov [PacketPointer],eax + popad + ret + +NEWSYM ipxsp ; send packet + pushad + mov eax,[PacketPointer] + sub eax,ipx_packet + mov [ipx_packet+5],al + mov [ipx_packet_size],eax + call sendpacket + popad + ret + +NEWSYM ipxgetchar + pushad + call checkpacket + cmp byte[ipx_packet_ready],1 + jne .nopacket + call read_packet + cmp byte[ipx_read_packet],'Z' + jne .nopacket + cmp byte[ipx_read_packet+1],'|' + jne .nopacket + cmp byte[ipx_read_packet+2],'S' + jne .nopacket + mov bx,[IPXInfoStrR] + cmp [ipx_read_packet+3],bx + jne .nopacket + mov cl,[ipx_read_packet+5] + sub cl,6 + mov esi,ipx_read_packet+6 + cmp cl,0 + je .nopacket +.loop + mov edi,[modemtail] + mov al,[esi] + mov [modembuffer+edi],al + inc dword[modemtail] + inc esi + and dword[modemtail],2047 + dec cl + jnz .loop +.nopacket + popad + push eax + xor dh,dh + mov eax,[modemhead] + cmp eax,[modemtail] + je .nonewchar + mov dh,1 + mov dl,[modembuffer+eax] + inc dword[modemhead] + and dword[modemhead],2047 +.nonewchar + pop eax + ret + + \ No newline at end of file diff --git a/zsnes/src/endmem.asm b/zsnes/src/endmem.asm new file mode 100644 index 00000000..b1b0cc00 --- /dev/null +++ b/zsnes/src/endmem.asm @@ -0,0 +1,250 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + + + + + + + +NEWSYM romdatahere + +; Much of this used to be in uninitialized space, until I discovered that +; ZSNES was unstable because of them... Odd. + +Stuff db 'ZSNES v?.??? / Freeware, programmed by zsKnight, _Demo_, and Pharos',13,10,0 + +ALIGN32 + +NEWSYM wramdataa, times 65536 db 0 +NEWSYM ram7fa, times 65536 db 0 +NEWSYM Inbetweendat, dd 0,0,0,0 +NEWSYM opcjmptab, times 256 dd 0 + +NEWSYM Bank0datr8 ,times 256 dd 0 +NEWSYM Bank0datr16,times 256 dd 0 +NEWSYM Bank0datw8 ,times 256 dd 0 +NEWSYM Bank0datw16,times 256 dd 0 + +NEWSYM tableA, times 256 dd 0 +NEWSYM tableB, times 256 dd 0 +NEWSYM tableC, times 256 dd 0 +NEWSYM tableD, times 256 dd 0 +NEWSYM tableE, times 256 dd 0 +NEWSYM tableF, times 256 dd 0 +NEWSYM tableG, times 256 dd 0 +NEWSYM tableH, times 256 dd 0 + +NEWSYM tableAb, times 256 dd 0 +NEWSYM tableBb, times 256 dd 0 +NEWSYM tableCb, times 256 dd 0 +NEWSYM tableDb, times 256 dd 0 +NEWSYM tableEb, times 256 dd 0 +NEWSYM tableFb, times 256 dd 0 +NEWSYM tableGb, times 256 dd 0 +NEWSYM tableHb, times 256 dd 0 + +NEWSYM tableAc, times 256 dd 0 +NEWSYM tableBc, times 256 dd 0 +NEWSYM tableCc, times 256 dd 0 +NEWSYM tableDc, times 256 dd 0 +NEWSYM tableEc, times 256 dd 0 +NEWSYM tableFc, times 256 dd 0 +NEWSYM tableGc, times 256 dd 0 +NEWSYM tableHc, times 256 dd 0 + +NEWSYM SA1tableA, times 256 dd 0 +NEWSYM SA1tableB, times 256 dd 0 +NEWSYM SA1tableC, times 256 dd 0 +NEWSYM SA1tableD, times 256 dd 0 +NEWSYM SA1tableE, times 256 dd 0 +NEWSYM SA1tableF, times 256 dd 0 +NEWSYM SA1tableG, times 256 dd 0 +NEWSYM SA1tableH, times 256 dd 0 + +NEWSYM tablead, times 256 dd 0 +NEWSYM tableadb, times 256 dd 0 +NEWSYM tableadc, times 256 dd 0 +NEWSYM SA1tablead, times 256 dd 0 + +NEWSYM memtabler8, times 256 dd 0 +NEWSYM memtablew8, times 256 dd 0 +NEWSYM memtabler16, times 256 dd 0 +NEWSYM memtablew16, times 256 dd 0 +NEWSYM vidmemch2, times 4096 db 0 +NEWSYM vidmemch4, times 4096 db 0 +NEWSYM vidmemch8, times 4096 db 0 +NEWSYM snesmmap, times 256 dd 0 +NEWSYM snesmap2, times 256 dd 0 +NEWSYM cachebg1, times 64 db 0 +NEWSYM cachebg2, times 64 db 0 +NEWSYM cachebg3, times 64 db 0 +NEWSYM cachebg4, times 64 db 0 +NEWSYM sprlefttot, times 256 db 0 +NEWSYM sprleftpr, times 256 db 0 +NEWSYM sprleftpr1, times 256 db 0 +NEWSYM sprleftpr2, times 256 db 0 +NEWSYM sprleftpr3, times 256 db 0 +NEWSYM sprpriodata, times 288 db 0 +NEWSYM sprprtabc, times 64 db 0 +NEWSYM sprprtabu, times 64 db 0 +NEWSYM prevpal, times 256 dw 0 ; previous palette buffer +NEWSYM winbgdata, times 288 db 0 ; window buffer for backgrounds +NEWSYM winspdata, times 288 db 0 ; window buffer for sprites +NEWSYM FxTable, times 256 dd 0 +NEWSYM FxTableA1, times 256 dd 0 +NEWSYM FxTableA2, times 256 dd 0 +NEWSYM FxTableA3, times 256 dd 0 +NEWSYM FxTableb, times 256 dd 0 +NEWSYM FxTablebA1, times 256 dd 0 +NEWSYM FxTablebA2, times 256 dd 0 +NEWSYM FxTablebA3, times 256 dd 0 +NEWSYM FxTablec, times 256 dd 0 +NEWSYM FxTablecA1, times 256 dd 0 +NEWSYM FxTablecA2, times 256 dd 0 +NEWSYM FxTablecA3, times 256 dd 0 +NEWSYM FxTabled, times 256 dd 0 +NEWSYM FxTabledA1, times 256 dd 0 +NEWSYM FxTabledA2, times 256 dd 0 +NEWSYM FxTabledA3, times 256 dd 0 +NEWSYM SfxMemTable, times 256 dd 0 +NEWSYM fxxand, times 256 dd 0 +NEWSYM fxbit01, times 256 dd 0 +NEWSYM fxbit23, times 256 dd 0 +NEWSYM fxbit45, times 256 dd 0 +NEWSYM fxbit67, times 256 dd 0 +NEWSYM PLOTJmpa, times 64 dd 0 +NEWSYM PLOTJmpb, times 64 dd 0 + +NEWSYM pal16b, times 256 dd 0 +NEWSYM pal16bcl, times 256 dd 0 +NEWSYM pal16bclha, times 256 dd 0 +NEWSYM pal16bxcl, times 256 dd 0 +NEWSYM xtravbuf, times 576 db 0 +NEWSYM BG1SXl, times 256 dw 0 +NEWSYM BG2SXl, times 256 dw 0 +NEWSYM BG3SXl, times 256 dw 0 +NEWSYM BG4SXl, times 256 dw 0 +NEWSYM BG1SYl, times 256 dw 0 +NEWSYM BG2SYl, times 256 dw 0 +NEWSYM BG3SYl, times 256 dw 0 +NEWSYM BG4SYl, times 256 dw 0 +NEWSYM BGMA, times 256 db 0 +NEWSYM BGFB, times 256 db 0 +NEWSYM BG3PRI, times 256 db 0 +NEWSYM BGOPT1, times 256 dw 0 +NEWSYM BGOPT2, times 256 dw 0 +NEWSYM BGOPT3, times 256 dw 0 +NEWSYM BGOPT4, times 256 dw 0 +NEWSYM BGPT1, times 256 dw 0 +NEWSYM BGPT2, times 256 dw 0 +NEWSYM BGPT3, times 256 dw 0 +NEWSYM BGPT4, times 256 dw 0 +NEWSYM BGPT1X, times 256 dw 0 +NEWSYM BGPT2X, times 256 dw 0 +NEWSYM BGPT3X, times 256 dw 0 +NEWSYM BGPT4X, times 256 dw 0 +NEWSYM BGPT1Y, times 256 dw 0 +NEWSYM BGPT2Y, times 256 dw 0 +NEWSYM BGPT3Y, times 256 dw 0 +NEWSYM BGPT4Y, times 256 dw 0 +NEWSYM BGMS1, times 1024 dw 0 +NEWSYM prdata, times 256 db 0 +NEWSYM prdatb, times 256 db 0 +NEWSYM prdatc, times 256 db 0 +NEWSYM ngpalcon2b, times 20h dd 0 +NEWSYM ngpalcon4b, times 20h dd 0 +NEWSYM ngpalcon8b, times 20h dd 0 +NEWSYM tltype2b, times 4096 db 0 +NEWSYM tltype4b, times 2048 db 0 +NEWSYM tltype8b, times 1024 db 0 + +NEWSYM ngptrdat, times 1024 dd 0 +NEWSYM ngceax, times 1024 dd 0 +NEWSYM ngcedi, times 1024 dd 0 +NEWSYM bgtxad, times 1024 dw 0 +NEWSYM sprtbng, times 256 dd 0 +NEWSYM sprtlng, times 256 db 0 +NEWSYM mosszng, times 256 db 0 +NEWSYM mosenng, times 256 db 0 + +NEWSYM vidmemch2s, times 4096 db 0FFh +NEWSYM vidmemch4s, times 2048 db 0FFh +NEWSYM vidmemch8s, times 1024 db 0FFh + +NEWSYM mode7ab, times 256 dd 0 +NEWSYM mode7cd, times 256 dd 0 +NEWSYM mode7xy, times 256 dd 0 +NEWSYM mode7st, times 256 db 0 + +NEWSYM t16x161, times 256 db 0 +NEWSYM t16x162, times 256 db 0 +NEWSYM t16x163, times 256 db 0 +NEWSYM t16x164, times 256 db 0 + +NEWSYM intrlng, times 256 db 0 +NEWSYM mode7hr, times 256 db 0 + +NEWSYM scadsng, times 256 db 0 +NEWSYM scadtng, times 256 db 0 + +NEWSYM scbcong, times 256 dw 0 + +NEWSYM cpalval, times 256 dd 0 +NEWSYM cgfxmod, times 256 db 0 + +NEWSYM winboundary, times 256 dd 0 +NEWSYM winbg1enval, times 256 db 0 +NEWSYM winbg2enval, times 256 db 0 +NEWSYM winbg3enval, times 256 db 0 +NEWSYM winbg4enval, times 256 db 0 +NEWSYM winbgobjenval, times 256 db 0 +NEWSYM winbgbackenval, times 256 db 0 +NEWSYM winlogicaval, times 256 dw 0 + +NEWSYM winbg1envals, times 256 db 0 +NEWSYM winbg2envals, times 256 db 0 +NEWSYM winbg3envals, times 256 db 0 +NEWSYM winbg4envals, times 256 db 0 +NEWSYM winbgobjenvals, times 256 db 0 +NEWSYM winbgbackenvals, times 256 db 0 +NEWSYM winbg1envalm, times 256 db 0 +NEWSYM winbg2envalm, times 256 db 0 +NEWSYM winbg3envalm, times 256 db 0 +NEWSYM winbg4envalm, times 256 db 0 +NEWSYM winbgobjenvalm, times 256 db 0 +NEWSYM winbgbackenvalm, times 256 db 0 + +NEWSYM FillSubScr, times 256 db 0 + +NEWSYM objclineptr, times 256 dd 0 ; l1,r1,l2,r2,en,log,ptr +NEWSYM objwlrpos , times 256 dd 0FFFFFFFFh +NEWSYM objwen , times 256 dw 0FFFFh ; en,log + +NEWSYM SpecialLine, times 256 db 0 + +NEWSYM bgallchange, times 256 db 0 +NEWSYM bg1change, times 256 db 0 +NEWSYM bg2change, times 256 db 0 +NEWSYM bg3change, times 256 db 0 +NEWSYM bg4change, times 256 db 0 +NEWSYM bgwinchange, times 256 db 0 + +NEWSYM PrevPicture, times 64*56*2 db 0 + \ No newline at end of file diff --git a/zsnes/src/fixsin.c b/zsnes/src/fixsin.c new file mode 100644 index 00000000..2aa1d755 --- /dev/null +++ b/zsnes/src/fixsin.c @@ -0,0 +1,411 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +int FSinTab[2048] = +{ +0, 201, 402, 603, 804, 1005, 1206, 1407, 1608, 1809, 2010, 2211, 2412, 2613, +2814, 3014, 3215, 3416, 3617, 3818, 4018, 4219, 4420, 4620, 4821, 5021, 5222, +5422, 5622, 5823, 6023, 6223, 6423, 6623, 6823, 7023, 7223, 7423, 7623, 7822, +8022, 8221, 8421, 8620, 8819, 9019, 9218, 9417, 9616, 9814, 10013, 10212, 10410, +10609, 10807, 11006, 11204, 11402, 11600, 11797, 11995, 12193, 12390, 12588, +12785, 12982, 13179, 13376, 13573, 13769, 13966, 14162, 14359, 14555, 14751, +14946, 15142, 15338, 15533, 15728, 15923, 16118, 16313, 16508, 16702, 16897, +17091, 17285, 17479, 17672, 17866, 18059, 18253, 18446, 18638, 18831, 19024, +19216, 19408, 19600, 19792, 19983, 20175, 20366, 20557, 20748, 20938, 21129, +21319, 21509, 21699, 21889, 22078, 22267, 22456, 22645, 22833, 23022, 23210, +23398, 23586, 23773, 23960, 24147, 24334, 24521, 24707, 24893, 25079, 25265, +25450, 25635, 25820, 26005, 26189, 26373, 26557, 26741, 26925, 27108, 27291, +27473, 27656, 27838, 28020, 28201, 28383, 28564, 28745, 28925, 29105, 29285, +29465, 29645, 29824, 30003, 30181, 30360, 30538, 30715, 30893, 31070, 31247, +31424, 31600, 31776, 31952, 32127, 32302, 32477, 32651, 32826, 32999, 33173, +33346, 33519, 33692, 33864, 34036, 34208, 34379, 34550, 34721, 34891, 35061, +35231, 35400, 35569, 35738, 35906, 36074, 36242, 36409, 36576, 36743, 36909, +37075, 37241, 37406, 37571, 37736, 37900, 38064, 38227, 38390, 38553, 38716, +38878, 39039, 39201, 39362, 39522, 39682, 39842, 40002, 40161, 40319, 40478, +40636, 40793, 40950, 41107, 41263, 41419, 41575, 41730, 41885, 42040, 42194, +42347, 42501, 42653, 42806, 42958, 43110, 43261, 43412, 43562, 43712, 43862, +44011, 44160, 44308, 44456, 44603, 44750, 44897, 45043, 45189, 45335, 45480, +45624, 45768, 45912, 46055, 46198, 46340, 46482, 46624, 46765, 46906, 47046, +47186, 47325, 47464, 47602, 47740, 47878, 48015, 48151, 48288, 48423, 48558, +48693, 48828, 48961, 49095, 49228, 49360, 49492, 49624, 49755, 49886, 50016, +50146, 50275, 50403, 50532, 50660, 50787, 50914, 51040, 51166, 51291, 51416, +51541, 51665, 51788, 51911, 52033, 52155, 52277, 52398, 52518, 52639, 52758, +52877, 52996, 53114, 53231, 53348, 53465, 53581, 53696, 53811, 53926, 54040, +54153, 54266, 54379, 54491, 54602, 54713, 54823, 54933, 55043, 55152, 55260, +55368, 55475, 55582, 55688, 55794, 55899, 56004, 56108, 56212, 56315, 56417, +56519, 56621, 56722, 56822, 56922, 57022, 57120, 57219, 57316, 57414, 57510, +57606, 57702, 57797, 57892, 57986, 58079, 58172, 58264, 58356, 58447, 58538, +58628, 58718, 58807, 58895, 58983, 59070, 59157, 59243, 59329, 59414, 59499, +59583, 59666, 59749, 59831, 59913, 59994, 60075, 60155, 60235, 60313, 60392, +60470, 60547, 60624, 60700, 60775, 60850, 60924, 60998, 61071, 61144, 61216, +61288, 61359, 61429, 61499, 61568, 61637, 61705, 61772, 61839, 61905, 61971, +62036, 62100, 62164, 62228, 62291, 62353, 62414, 62475, 62536, 62596, 62655, +62714, 62772, 62829, 62886, 62942, 62998, 63053, 63108, 63162, 63215, 63268, +63320, 63371, 63422, 63473, 63522, 63571, 63620, 63668, 63715, 63762, 63808, +63854, 63899, 63943, 63987, 64030, 64073, 64115, 64156, 64197, 64237, 64276, +64315, 64353, 64391, 64428, 64465, 64501, 64536, 64571, 64605, 64638, 64671, +64703, 64735, 64766, 64796, 64826, 64855, 64884, 64912, 64939, 64966, 64992, +65018, 65043, 65067, 65091, 65114, 65136, 65158, 65179, 65200, 65220, 65239, +65258, 65276, 65294, 65311, 65327, 65343, 65358, 65372, 65386, 65400, 65412, +65424, 65436, 65446, 65457, 65466, 65475, 65483, 65491, 65498, 65505, 65511, +65516, 65520, 65524, 65528, 65531, 65533, 65534, 65535, 65536, 65535, 65534, +65533, 65531, 65528, 65524, 65520, 65516, 65511, 65505, 65498, 65491, 65483, +65475, 65466, 65457, 65446, 65436, 65424, 65412, 65400, 65386, 65372, 65358, +65343, 65327, 65311, 65294, 65276, 65258, 65239, 65220, 65200, 65179, 65158, +65136, 65114, 65091, 65067, 65043, 65018, 64992, 64966, 64939, 64912, 64884, +64855, 64826, 64796, 64766, 64735, 64703, 64671, 64638, 64605, 64571, 64536, +64501, 64465, 64428, 64391, 64353, 64315, 64276, 64237, 64197, 64156, 64115, +64073, 64030, 63987, 63943, 63899, 63854, 63808, 63762, 63715, 63668, 63620, +63571, 63522, 63473, 63422, 63371, 63320, 63268, 63215, 63162, 63108, 63053, +62998, 62942, 62886, 62829, 62772, 62714, 62655, 62596, 62536, 62475, 62414, +62353, 62291, 62228, 62164, 62100, 62036, 61971, 61905, 61839, 61772, 61705, +61637, 61568, 61499, 61429, 61359, 61288, 61216, 61144, 61071, 60998, 60924, +60850, 60775, 60700, 60624, 60547, 60470, 60392, 60313, 60235, 60155, 60075, +59994, 59913, 59831, 59749, 59666, 59583, 59499, 59414, 59329, 59243, 59157, +59070, 58983, 58895, 58807, 58718, 58628, 58538, 58447, 58356, 58264, 58172, +58079, 57986, 57892, 57797, 57702, 57606, 57510, 57414, 57316, 57219, 57120, +57022, 56922, 56822, 56722, 56621, 56519, 56417, 56315, 56212, 56108, 56004, +55899, 55794, 55688, 55582, 55475, 55368, 55260, 55152, 55043, 54933, 54823, +54713, 54602, 54491, 54379, 54266, 54153, 54040, 53926, 53811, 53696, 53581, +53465, 53348, 53231, 53114, 52996, 52877, 52758, 52639, 52518, 52398, 52277, +52155, 52033, 51911, 51788, 51665, 51541, 51416, 51291, 51166, 51040, 50914, +50787, 50660, 50532, 50403, 50275, 50146, 50016, 49886, 49755, 49624, 49492, +49360, 49228, 49095, 48961, 48828, 48693, 48558, 48423, 48288, 48151, 48015, +47878, 47740, 47602, 47464, 47325, 47186, 47046, 46906, 46765, 46624, 46482, +46340, 46198, 46055, 45912, 45768, 45624, 45480, 45335, 45189, 45043, 44897, +44750, 44603, 44456, 44308, 44160, 44011, 43862, 43712, 43562, 43412, 43261, +43110, 42958, 42806, 42653, 42501, 42347, 42194, 42040, 41885, 41730, 41575, +41419, 41263, 41107, 40950, 40793, 40636, 40478, 40319, 40161, 40002, 39842, +39682, 39522, 39362, 39201, 39039, 38878, 38716, 38553, 38390, 38227, 38064, +37900, 37736, 37571, 37406, 37241, 37075, 36909, 36743, 36576, 36409, 36242, +36074, 35906, 35738, 35569, 35400, 35231, 35061, 34891, 34721, 34550, 34379, +34208, 34036, 33864, 33692, 33519, 33346, 33173, 32999, 32826, 32651, 32477, +32302, 32127, 31952, 31776, 31600, 31424, 31247, 31070, 30893, 30715, 30538, +30360, 30181, 30003, 29824, 29645, 29465, 29285, 29105, 28925, 28745, 28564, +28383, 28201, 28020, 27838, 27656, 27473, 27291, 27108, 26925, 26741, 26557, +26373, 26189, 26005, 25820, 25635, 25450, 25265, 25079, 24893, 24707, 24521, +24334, 24147, 23960, 23773, 23586, 23398, 23210, 23022, 22833, 22645, 22456, +22267, 22078, 21889, 21699, 21509, 21319, 21129, 20938, 20748, 20557, 20366, +20175, 19983, 19792, 19600, 19408, 19216, 19024, 18831, 18638, 18446, 18253, +18059, 17866, 17672, 17479, 17285, 17091, 16897, 16702, 16508, 16313, 16118, +15923, 15728, 15533, 15338, 15142, 14946, 14751, 14555, 14359, 14162, 13966, +13769, 13573, 13376, 13179, 12982, 12785, 12588, 12390, 12193, 11995, 11797, +11600, 11402, 11204, 11006, 10807, 10609, 10410, 10212, 10013, 9814, 9616, 9417, +9218, 9019, 8819, 8620, 8421, 8221, 8022, 7822, 7623, 7423, 7223, 7023, 6823, +6623, 6423, 6223, 6023, 5823, 5622, 5422, 5222, 5021, 4821, 4620, 4420, 4219, +4018, 3818, 3617, 3416, 3215, 3014, 2814, 2613, 2412, 2211, 2010, 1809, 1608, +1407, 1206, 1005, 804, 603, 402, 201, 0, -201, -402, -603, -804, -1005, -1206, +-1407, -1608, -1809, -2010, -2211, -2412, -2613, -2814, -3014, -3215, -3416, +-3617, -3818, -4018, -4219, -4420, -4620, -4821, -5021, -5222, -5422, -5622, +-5823, -6023, -6223, -6423, -6623, -6823, -7023, -7223, -7423, -7623, -7822, +-8022, -8221, -8421, -8620, -8819, -9019, -9218, -9417, -9616, -9814, -10013, +-10212, -10410, -10609, -10807, -11006, -11204, -11402, -11600, -11797, -11995, +-12193, -12390, -12588, -12785, -12982, -13179, -13376, -13573, -13769, -13966, +-14162, -14359, -14555, -14751, -14946, -15142, -15338, -15533, -15728, -15923, +-16118, -16313, -16508, -16702, -16897, -17091, -17285, -17479, -17672, -17866, +-18059, -18253, -18446, -18638, -18831, -19024, -19216, -19408, -19600, -19792, +-19983, -20175, -20366, -20557, -20748, -20938, -21129, -21319, -21509, -21699, +-21889, -22078, -22267, -22456, -22645, -22833, -23022, -23210, -23398, -23586, +-23773, -23960, -24147, -24334, -24521, -24707, -24893, -25079, -25265, -25450, +-25635, -25820, -26005, -26189, -26373, -26557, -26741, -26925, -27108, -27291, +-27473, -27656, -27838, -28020, -28201, -28383, -28564, -28745, -28925, -29105, +-29285, -29465, -29645, -29824, -30003, -30181, -30360, -30538, -30715, -30893, +-31070, -31247, -31424, -31600, -31776, -31952, -32127, -32302, -32477, -32651, +-32826, -32999, -33173, -33346, -33519, -33692, -33864, -34036, -34208, -34379, +-34550, -34721, -34891, -35061, -35231, -35400, -35569, -35738, -35906, -36074, +-36242, -36409, -36576, -36743, -36909, -37075, -37241, -37406, -37571, -37736, +-37900, -38064, -38227, -38390, -38553, -38716, -38878, -39039, -39201, -39362, +-39522, -39682, -39842, -40002, -40161, -40319, -40478, -40636, -40793, -40950, +-41107, -41263, -41419, -41575, -41730, -41885, -42040, -42194, -42347, -42501, +-42653, -42806, -42958, -43110, -43261, -43412, -43562, -43712, -43862, -44011, +-44160, -44308, -44456, -44603, -44750, -44897, -45043, -45189, -45335, -45480, +-45624, -45768, -45912, -46055, -46198, -46340, -46482, -46624, -46765, -46906, +-47046, -47186, -47325, -47464, -47602, -47740, -47878, -48015, -48151, -48288, +-48423, -48558, -48693, -48828, -48961, -49095, -49228, -49360, -49492, -49624, +-49755, -49886, -50016, -50146, -50275, -50403, -50532, -50660, -50787, -50914, +-51040, -51166, -51291, -51416, -51541, -51665, -51788, -51911, -52033, -52155, +-52277, -52398, -52518, -52639, -52758, -52877, -52996, -53114, -53231, -53348, +-53465, -53581, -53696, -53811, -53926, -54040, -54153, -54266, -54379, -54491, +-54602, -54713, -54823, -54933, -55043, -55152, -55260, -55368, -55475, -55582, +-55688, -55794, -55899, -56004, -56108, -56212, -56315, -56417, -56519, -56621, +-56722, -56822, -56922, -57022, -57120, -57219, -57316, -57414, -57510, -57606, +-57702, -57797, -57892, -57986, -58079, -58172, -58264, -58356, -58447, -58538, +-58628, -58718, -58807, -58895, -58983, -59070, -59157, -59243, -59329, -59414, +-59499, -59583, -59666, -59749, -59831, -59913, -59994, -60075, -60155, -60235, +-60313, -60392, -60470, -60547, -60624, -60700, -60775, -60850, -60924, -60998, +-61071, -61144, -61216, -61288, -61359, -61429, -61499, -61568, -61637, -61705, +-61772, -61839, -61905, -61971, -62036, -62100, -62164, -62228, -62291, -62353, +-62414, -62475, -62536, -62596, -62655, -62714, -62772, -62829, -62886, -62942, +-62998, -63053, -63108, -63162, -63215, -63268, -63320, -63371, -63422, -63473, +-63522, -63571, -63620, -63668, -63715, -63762, -63808, -63854, -63899, -63943, +-63987, -64030, -64073, -64115, -64156, -64197, -64237, -64276, -64315, -64353, +-64391, -64428, -64465, -64501, -64536, -64571, -64605, -64638, -64671, -64703, +-64735, -64766, -64796, -64826, -64855, -64884, -64912, -64939, -64966, -64992, +-65018, -65043, -65067, -65091, -65114, -65136, -65158, -65179, -65200, -65220, +-65239, -65258, -65276, -65294, -65311, -65327, -65343, -65358, -65372, -65386, +-65400, -65412, -65424, -65436, -65446, -65457, -65466, -65475, -65483, -65491, +-65498, -65505, -65511, -65516, -65520, -65524, -65528, -65531, -65533, -65534, +-65535, -65536, -65535, -65534, -65533, -65531, -65528, -65524, -65520, -65516, +-65511, -65505, -65498, -65491, -65483, -65475, -65466, -65457, -65446, -65436, +-65424, -65412, -65400, -65386, -65372, -65358, -65343, -65327, -65311, -65294, +-65276, -65258, -65239, -65220, -65200, -65179, -65158, -65136, -65114, -65091, +-65067, -65043, -65018, -64992, -64966, -64939, -64912, -64884, -64855, -64826, +-64796, -64766, -64735, -64703, -64671, -64638, -64605, -64571, -64536, -64501, +-64465, -64428, -64391, -64353, -64315, -64276, -64237, -64197, -64156, -64115, +-64073, -64030, -63987, -63943, -63899, -63854, -63808, -63762, -63715, -63668, +-63620, -63571, -63522, -63473, -63422, -63371, -63320, -63268, -63215, -63162, +-63108, -63053, -62998, -62942, -62886, -62829, -62772, -62714, -62655, -62596, +-62536, -62475, -62414, -62353, -62291, -62228, -62164, -62100, -62036, -61971, +-61905, -61839, -61772, -61705, -61637, -61568, -61499, -61429, -61359, -61288, +-61216, -61144, -61071, -60998, -60924, -60850, -60775, -60700, -60624, -60547, +-60470, -60392, -60313, -60235, -60155, -60075, -59994, -59913, -59831, -59749, +-59666, -59583, -59499, -59414, -59329, -59243, -59157, -59070, -58983, -58895, +-58807, -58718, -58628, -58538, -58447, -58356, -58264, -58172, -58079, -57986, +-57892, -57797, -57702, -57606, -57510, -57414, -57316, -57219, -57120, -57022, +-56922, -56822, -56722, -56621, -56519, -56417, -56315, -56212, -56108, -56004, +-55899, -55794, -55688, -55582, -55475, -55368, -55260, -55152, -55043, -54933, +-54823, -54713, -54602, -54491, -54379, -54266, -54153, -54040, -53926, -53811, +-53696, -53581, -53465, -53348, -53231, -53114, -52996, -52877, -52758, -52639, +-52518, -52398, -52277, -52155, -52033, -51911, -51788, -51665, -51541, -51416, +-51291, -51166, -51040, -50914, -50787, -50660, -50532, -50403, -50275, -50146, +-50016, -49886, -49755, -49624, -49492, -49360, -49228, -49095, -48961, -48828, +-48693, -48558, -48423, -48288, -48151, -48015, -47878, -47740, -47602, -47464, +-47325, -47186, -47046, -46906, -46765, -46624, -46482, -46340, -46198, -46055, +-45912, -45768, -45624, -45480, -45335, -45189, -45043, -44897, -44750, -44603, +-44456, -44308, -44160, -44011, -43862, -43712, -43562, -43412, -43261, -43110, +-42958, -42806, -42653, -42501, -42347, -42194, -42040, -41885, -41730, -41575, +-41419, -41263, -41107, -40950, -40793, -40636, -40478, -40319, -40161, -40002, +-39842, -39682, -39522, -39362, -39201, -39039, -38878, -38716, -38553, -38390, +-38227, -38064, -37900, -37736, -37571, -37406, -37241, -37075, -36909, -36743, +-36576, -36409, -36242, -36074, -35906, -35738, -35569, -35400, -35231, -35061, +-34891, -34721, -34550, -34379, -34208, -34036, -33864, -33692, -33519, -33346, +-33173, -32999, -32826, -32651, -32477, -32302, -32127, -31952, -31776, -31600, +-31424, -31247, -31070, -30893, -30715, -30538, -30360, -30181, -30003, -29824, +-29645, -29465, -29285, -29105, -28925, -28745, -28564, -28383, -28201, -28020, +-27838, -27656, -27473, -27291, -27108, -26925, -26741, -26557, -26373, -26189, +-26005, -25820, -25635, -25450, -25265, -25079, -24893, -24707, -24521, -24334, +-24147, -23960, -23773, -23586, -23398, -23210, -23022, -22833, -22645, -22456, +-22267, -22078, -21889, -21699, -21509, -21319, -21129, -20938, -20748, -20557, +-20366, -20175, -19983, -19792, -19600, -19408, -19216, -19024, -18831, -18638, +-18446, -18253, -18059, -17866, -17672, -17479, -17285, -17091, -16897, -16702, +-16508, -16313, -16118, -15923, -15728, -15533, -15338, -15142, -14946, -14751, +-14555, -14359, -14162, -13966, -13769, -13573, -13376, -13179, -12982, -12785, +-12588, -12390, -12193, -11995, -11797, -11600, -11402, -11204, -11006, -10807, +-10609, -10410, -10212, -10013, -9814, -9616, -9417, -9218, -9019, -8819, -8620, +-8421, -8221, -8022, -7822, -7623, -7423, -7223, -7023, -6823, -6623, -6423, +-6223, -6023, -5823, -5622, -5422, -5222, -5021, -4821, -4620, -4420, -4219, +-4018, -3818, -3617, -3416, -3215, -3014, -2814, -2613, -2412, -2211, -2010, +-1809, -1608, -1407, -1206, -1005, -804, -603, -402, -201 +}; +int FCosTab[2048] = +{ +65536, 65535, 65534, 65533, 65531, 65528, 65524, 65520, 65516, 65511, 65505, +65498, 65491, 65483, 65475, 65466, 65457, 65446, 65436, 65424, 65412, 65400, +65386, 65372, 65358, 65343, 65327, 65311, 65294, 65276, 65258, 65239, 65220, +65200, 65179, 65158, 65136, 65114, 65091, 65067, 65043, 65018, 64992, 64966, +64939, 64912, 64884, 64855, 64826, 64796, 64766, 64735, 64703, 64671, 64638, +64605, 64571, 64536, 64501, 64465, 64428, 64391, 64353, 64315, 64276, 64237, +64197, 64156, 64115, 64073, 64030, 63987, 63943, 63899, 63854, 63808, 63762, +63715, 63668, 63620, 63571, 63522, 63473, 63422, 63371, 63320, 63268, 63215, +63162, 63108, 63053, 62998, 62942, 62886, 62829, 62772, 62714, 62655, 62596, +62536, 62475, 62414, 62353, 62291, 62228, 62164, 62100, 62036, 61971, 61905, +61839, 61772, 61705, 61637, 61568, 61499, 61429, 61359, 61288, 61216, 61144, +61071, 60998, 60924, 60850, 60775, 60700, 60624, 60547, 60470, 60392, 60313, +60235, 60155, 60075, 59994, 59913, 59831, 59749, 59666, 59583, 59499, 59414, +59329, 59243, 59157, 59070, 58983, 58895, 58807, 58718, 58628, 58538, 58447, +58356, 58264, 58172, 58079, 57986, 57892, 57797, 57702, 57606, 57510, 57414, +57316, 57219, 57120, 57022, 56922, 56822, 56722, 56621, 56519, 56417, 56315, +56212, 56108, 56004, 55899, 55794, 55688, 55582, 55475, 55368, 55260, 55152, +55043, 54933, 54823, 54713, 54602, 54491, 54379, 54266, 54153, 54040, 53926, +53811, 53696, 53581, 53465, 53348, 53231, 53114, 52996, 52877, 52758, 52639, +52518, 52398, 52277, 52155, 52033, 51911, 51788, 51665, 51541, 51416, 51291, +51166, 51040, 50914, 50787, 50660, 50532, 50403, 50275, 50146, 50016, 49886, +49755, 49624, 49492, 49360, 49228, 49095, 48961, 48828, 48693, 48558, 48423, +48288, 48151, 48015, 47878, 47740, 47602, 47464, 47325, 47186, 47046, 46906, +46765, 46624, 46482, 46340, 46198, 46055, 45912, 45768, 45624, 45480, 45335, +45189, 45043, 44897, 44750, 44603, 44456, 44308, 44160, 44011, 43862, 43712, +43562, 43412, 43261, 43110, 42958, 42806, 42653, 42501, 42347, 42194, 42040, +41885, 41730, 41575, 41419, 41263, 41107, 40950, 40793, 40636, 40478, 40319, +40161, 40002, 39842, 39682, 39522, 39362, 39201, 39039, 38878, 38716, 38553, +38390, 38227, 38064, 37900, 37736, 37571, 37406, 37241, 37075, 36909, 36743, +36576, 36409, 36242, 36074, 35906, 35738, 35569, 35400, 35231, 35061, 34891, +34721, 34550, 34379, 34208, 34036, 33864, 33692, 33519, 33346, 33173, 32999, +32826, 32651, 32477, 32302, 32127, 31952, 31776, 31600, 31424, 31247, 31070, +30893, 30715, 30538, 30360, 30181, 30003, 29824, 29645, 29465, 29285, 29105, +28925, 28745, 28564, 28383, 28201, 28020, 27838, 27656, 27473, 27291, 27108, +26925, 26741, 26557, 26373, 26189, 26005, 25820, 25635, 25450, 25265, 25079, +24893, 24707, 24521, 24334, 24147, 23960, 23773, 23586, 23398, 23210, 23022, +22833, 22645, 22456, 22267, 22078, 21889, 21699, 21509, 21319, 21129, 20938, +20748, 20557, 20366, 20175, 19983, 19792, 19600, 19408, 19216, 19024, 18831, +18638, 18446, 18253, 18059, 17866, 17672, 17479, 17285, 17091, 16897, 16702, +16508, 16313, 16118, 15923, 15728, 15533, 15338, 15142, 14946, 14751, 14555, +14359, 14162, 13966, 13769, 13573, 13376, 13179, 12982, 12785, 12588, 12390, +12193, 11995, 11797, 11600, 11402, 11204, 11006, 10807, 10609, 10410, 10212, +10013, 9814, 9616, 9417, 9218, 9019, 8819, 8620, 8421, 8221, 8022, 7822, 7623, +7423, 7223, 7023, 6823, 6623, 6423, 6223, 6023, 5823, 5622, 5422, 5222, 5021, +4821, 4620, 4420, 4219, 4018, 3818, 3617, 3416, 3215, 3014, 2814, 2613, 2412, +2211, 2010, 1809, 1608, 1407, 1206, 1005, 804, 603, 402, 201, 0, -201, -402, +-603, -804, -1005, -1206, -1407, -1608, -1809, -2010, -2211, -2412, -2613, -2814, +-3014, -3215, -3416, -3617, -3818, -4018, -4219, -4420, -4620, -4821, -5021, +-5222, -5422, -5622, -5823, -6023, -6223, -6423, -6623, -6823, -7023, -7223, +-7423, -7623, -7822, -8022, -8221, -8421, -8620, -8819, -9019, -9218, -9417, +-9616, -9814, -10013, -10212, -10410, -10609, -10807, -11006, -11204, -11402, +-11600, -11797, -11995, -12193, -12390, -12588, -12785, -12982, -13179, -13376, +-13573, -13769, -13966, -14162, -14359, -14555, -14751, -14946, -15142, -15338, +-15533, -15728, -15923, -16118, -16313, -16508, -16702, -16897, -17091, -17285, +-17479, -17672, -17866, -18059, -18253, -18446, -18638, -18831, -19024, -19216, +-19408, -19600, -19792, -19983, -20175, -20366, -20557, -20748, -20938, -21129, +-21319, -21509, -21699, -21889, -22078, -22267, -22456, -22645, -22833, -23022, +-23210, -23398, -23586, -23773, -23960, -24147, -24334, -24521, -24707, -24893, +-25079, -25265, -25450, -25635, -25820, -26005, -26189, -26373, -26557, -26741, +-26925, -27108, -27291, -27473, -27656, -27838, -28020, -28201, -28383, -28564, +-28745, -28925, -29105, -29285, -29465, -29645, -29824, -30003, -30181, -30360, +-30538, -30715, -30893, -31070, -31247, -31424, -31600, -31776, -31952, -32127, +-32302, -32477, -32651, -32826, -32999, -33173, -33346, -33519, -33692, -33864, +-34036, -34208, -34379, -34550, -34721, -34891, -35061, -35231, -35400, -35569, +-35738, -35906, -36074, -36242, -36409, -36576, -36743, -36909, -37075, -37241, +-37406, -37571, -37736, -37900, -38064, -38227, -38390, -38553, -38716, -38878, +-39039, -39201, -39362, -39522, -39682, -39842, -40002, -40161, -40319, -40478, +-40636, -40793, -40950, -41107, -41263, -41419, -41575, -41730, -41885, -42040, +-42194, -42347, -42501, -42653, -42806, -42958, -43110, -43261, -43412, -43562, +-43712, -43862, -44011, -44160, -44308, -44456, -44603, -44750, -44897, -45043, +-45189, -45335, -45480, -45624, -45768, -45912, -46055, -46198, -46340, -46482, +-46624, -46765, -46906, -47046, -47186, -47325, -47464, -47602, -47740, -47878, +-48015, -48151, -48288, -48423, -48558, -48693, -48828, -48961, -49095, -49228, +-49360, -49492, -49624, -49755, -49886, -50016, -50146, -50275, -50403, -50532, +-50660, -50787, -50914, -51040, -51166, -51291, -51416, -51541, -51665, -51788, +-51911, -52033, -52155, -52277, -52398, -52518, -52639, -52758, -52877, -52996, +-53114, -53231, -53348, -53465, -53581, -53696, -53811, -53926, -54040, -54153, +-54266, -54379, -54491, -54602, -54713, -54823, -54933, -55043, -55152, -55260, +-55368, -55475, -55582, -55688, -55794, -55899, -56004, -56108, -56212, -56315, +-56417, -56519, -56621, -56722, -56822, -56922, -57022, -57120, -57219, -57316, +-57414, -57510, -57606, -57702, -57797, -57892, -57986, -58079, -58172, -58264, +-58356, -58447, -58538, -58628, -58718, -58807, -58895, -58983, -59070, -59157, +-59243, -59329, -59414, -59499, -59583, -59666, -59749, -59831, -59913, -59994, +-60075, -60155, -60235, -60313, -60392, -60470, -60547, -60624, -60700, -60775, +-60850, -60924, -60998, -61071, -61144, -61216, -61288, -61359, -61429, -61499, +-61568, -61637, -61705, -61772, -61839, -61905, -61971, -62036, -62100, -62164, +-62228, -62291, -62353, -62414, -62475, -62536, -62596, -62655, -62714, -62772, +-62829, -62886, -62942, -62998, -63053, -63108, -63162, -63215, -63268, -63320, +-63371, -63422, -63473, -63522, -63571, -63620, -63668, -63715, -63762, -63808, +-63854, -63899, -63943, -63987, -64030, -64073, -64115, -64156, -64197, -64237, +-64276, -64315, -64353, -64391, -64428, -64465, -64501, -64536, -64571, -64605, +-64638, -64671, -64703, -64735, -64766, -64796, -64826, -64855, -64884, -64912, +-64939, -64966, -64992, -65018, -65043, -65067, -65091, -65114, -65136, -65158, +-65179, -65200, -65220, -65239, -65258, -65276, -65294, -65311, -65327, -65343, +-65358, -65372, -65386, -65400, -65412, -65424, -65436, -65446, -65457, -65466, +-65475, -65483, -65491, -65498, -65505, -65511, -65516, -65520, -65524, -65528, +-65531, -65533, -65534, -65535, -65536, -65535, -65534, -65533, -65531, -65528, +-65524, -65520, -65516, -65511, -65505, -65498, -65491, -65483, -65475, -65466, +-65457, -65446, -65436, -65424, -65412, -65400, -65386, -65372, -65358, -65343, +-65327, -65311, -65294, -65276, -65258, -65239, -65220, -65200, -65179, -65158, +-65136, -65114, -65091, -65067, -65043, -65018, -64992, -64966, -64939, -64912, +-64884, -64855, -64826, -64796, -64766, -64735, -64703, -64671, -64638, -64605, +-64571, -64536, -64501, -64465, -64428, -64391, -64353, -64315, -64276, -64237, +-64197, -64156, -64115, -64073, -64030, -63987, -63943, -63899, -63854, -63808, +-63762, -63715, -63668, -63620, -63571, -63522, -63473, -63422, -63371, -63320, +-63268, -63215, -63162, -63108, -63053, -62998, -62942, -62886, -62829, -62772, +-62714, -62655, -62596, -62536, -62475, -62414, -62353, -62291, -62228, -62164, +-62100, -62036, -61971, -61905, -61839, -61772, -61705, -61637, -61568, -61499, +-61429, -61359, -61288, -61216, -61144, -61071, -60998, -60924, -60850, -60775, +-60700, -60624, -60547, -60470, -60392, -60313, -60235, -60155, -60075, -59994, +-59913, -59831, -59749, -59666, -59583, -59499, -59414, -59329, -59243, -59157, +-59070, -58983, -58895, -58807, -58718, -58628, -58538, -58447, -58356, -58264, +-58172, -58079, -57986, -57892, -57797, -57702, -57606, -57510, -57414, -57316, +-57219, -57120, -57022, -56922, -56822, -56722, -56621, -56519, -56417, -56315, +-56212, -56108, -56004, -55899, -55794, -55688, -55582, -55475, -55368, -55260, +-55152, -55043, -54933, -54823, -54713, -54602, -54491, -54379, -54266, -54153, +-54040, -53926, -53811, -53696, -53581, -53465, -53348, -53231, -53114, -52996, +-52877, -52758, -52639, -52518, -52398, -52277, -52155, -52033, -51911, -51788, +-51665, -51541, -51416, -51291, -51166, -51040, -50914, -50787, -50660, -50532, +-50403, -50275, -50146, -50016, -49886, -49755, -49624, -49492, -49360, -49228, +-49095, -48961, -48828, -48693, -48558, -48423, -48288, -48151, -48015, -47878, +-47740, -47602, -47464, -47325, -47186, -47046, -46906, -46765, -46624, -46482, +-46340, -46198, -46055, -45912, -45768, -45624, -45480, -45335, -45189, -45043, +-44897, -44750, -44603, -44456, -44308, -44160, -44011, -43862, -43712, -43562, +-43412, -43261, -43110, -42958, -42806, -42653, -42501, -42347, -42194, -42040, +-41885, -41730, -41575, -41419, -41263, -41107, -40950, -40793, -40636, -40478, +-40319, -40161, -40002, -39842, -39682, -39522, -39362, -39201, -39039, -38878, +-38716, -38553, -38390, -38227, -38064, -37900, -37736, -37571, -37406, -37241, +-37075, -36909, -36743, -36576, -36409, -36242, -36074, -35906, -35738, -35569, +-35400, -35231, -35061, -34891, -34721, -34550, -34379, -34208, -34036, -33864, +-33692, -33519, -33346, -33173, -32999, -32826, -32651, -32477, -32302, -32127, +-31952, -31776, -31600, -31424, -31247, -31070, -30893, -30715, -30538, -30360, +-30181, -30003, -29824, -29645, -29465, -29285, -29105, -28925, -28745, -28564, +-28383, -28201, -28020, -27838, -27656, -27473, -27291, -27108, -26925, -26741, +-26557, -26373, -26189, -26005, -25820, -25635, -25450, -25265, -25079, -24893, +-24707, -24521, -24334, -24147, -23960, -23773, -23586, -23398, -23210, -23022, +-22833, -22645, -22456, -22267, -22078, -21889, -21699, -21509, -21319, -21129, +-20938, -20748, -20557, -20366, -20175, -19983, -19792, -19600, -19408, -19216, +-19024, -18831, -18638, -18446, -18253, -18059, -17866, -17672, -17479, -17285, +-17091, -16897, -16702, -16508, -16313, -16118, -15923, -15728, -15533, -15338, +-15142, -14946, -14751, -14555, -14359, -14162, -13966, -13769, -13573, -13376, +-13179, -12982, -12785, -12588, -12390, -12193, -11995, -11797, -11600, -11402, +-11204, -11006, -10807, -10609, -10410, -10212, -10013, -9814, -9616, -9417, +-9218, -9019, -8819, -8620, -8421, -8221, -8022, -7822, -7623, -7423, -7223, +-7023, -6823, -6623, -6423, -6223, -6023, -5823, -5622, -5422, -5222, -5021, +-4821, -4620, -4420, -4219, -4018, -3818, -3617, -3416, -3215, -3014, -2814, +-2613, -2412, -2211, -2010, -1809, -1608, -1407, -1206, -1005, -804, -603, -402, +-201, 0, 201, 402, 603, 804, 1005, 1206, 1407, 1608, 1809, 2010, 2211, 2412, +2613, 2814, 3014, 3215, 3416, 3617, 3818, 4018, 4219, 4420, 4620, 4821, 5021, +5222, 5422, 5622, 5823, 6023, 6223, 6423, 6623, 6823, 7023, 7223, 7423, 7623, +7822, 8022, 8221, 8421, 8620, 8819, 9019, 9218, 9417, 9616, 9814, 10013, 10212, +10410, 10609, 10807, 11006, 11204, 11402, 11600, 11797, 11995, 12193, 12390, +12588, 12785, 12982, 13179, 13376, 13573, 13769, 13966, 14162, 14359, 14555, +14751, 14946, 15142, 15338, 15533, 15728, 15923, 16118, 16313, 16508, 16702, +16897, 17091, 17285, 17479, 17672, 17866, 18059, 18253, 18446, 18638, 18831, +19024, 19216, 19408, 19600, 19792, 19983, 20175, 20366, 20557, 20748, 20938, +21129, 21319, 21509, 21699, 21889, 22078, 22267, 22456, 22645, 22833, 23022, +23210, 23398, 23586, 23773, 23960, 24147, 24334, 24521, 24707, 24893, 25079, +25265, 25450, 25635, 25820, 26005, 26189, 26373, 26557, 26741, 26925, 27108, +27291, 27473, 27656, 27838, 28020, 28201, 28383, 28564, 28745, 28925, 29105, +29285, 29465, 29645, 29824, 30003, 30181, 30360, 30538, 30715, 30893, 31070, +31247, 31424, 31600, 31776, 31952, 32127, 32302, 32477, 32651, 32826, 32999, +33173, 33346, 33519, 33692, 33864, 34036, 34208, 34379, 34550, 34721, 34891, +35061, 35231, 35400, 35569, 35738, 35906, 36074, 36242, 36409, 36576, 36743, +36909, 37075, 37241, 37406, 37571, 37736, 37900, 38064, 38227, 38390, 38553, +38716, 38878, 39039, 39201, 39362, 39522, 39682, 39842, 40002, 40161, 40319, +40478, 40636, 40793, 40950, 41107, 41263, 41419, 41575, 41730, 41885, 42040, +42194, 42347, 42501, 42653, 42806, 42958, 43110, 43261, 43412, 43562, 43712, +43862, 44011, 44160, 44308, 44456, 44603, 44750, 44897, 45043, 45189, 45335, +45480, 45624, 45768, 45912, 46055, 46198, 46340, 46482, 46624, 46765, 46906, +47046, 47186, 47325, 47464, 47602, 47740, 47878, 48015, 48151, 48288, 48423, +48558, 48693, 48828, 48961, 49095, 49228, 49360, 49492, 49624, 49755, 49886, +50016, 50146, 50275, 50403, 50532, 50660, 50787, 50914, 51040, 51166, 51291, +51416, 51541, 51665, 51788, 51911, 52033, 52155, 52277, 52398, 52518, 52639, +52758, 52877, 52996, 53114, 53231, 53348, 53465, 53581, 53696, 53811, 53926, +54040, 54153, 54266, 54379, 54491, 54602, 54713, 54823, 54933, 55043, 55152, +55260, 55368, 55475, 55582, 55688, 55794, 55899, 56004, 56108, 56212, 56315, +56417, 56519, 56621, 56722, 56822, 56922, 57022, 57120, 57219, 57316, 57414, +57510, 57606, 57702, 57797, 57892, 57986, 58079, 58172, 58264, 58356, 58447, +58538, 58628, 58718, 58807, 58895, 58983, 59070, 59157, 59243, 59329, 59414, +59499, 59583, 59666, 59749, 59831, 59913, 59994, 60075, 60155, 60235, 60313, +60392, 60470, 60547, 60624, 60700, 60775, 60850, 60924, 60998, 61071, 61144, +61216, 61288, 61359, 61429, 61499, 61568, 61637, 61705, 61772, 61839, 61905, +61971, 62036, 62100, 62164, 62228, 62291, 62353, 62414, 62475, 62536, 62596, +62655, 62714, 62772, 62829, 62886, 62942, 62998, 63053, 63108, 63162, 63215, +63268, 63320, 63371, 63422, 63473, 63522, 63571, 63620, 63668, 63715, 63762, +63808, 63854, 63899, 63943, 63987, 64030, 64073, 64115, 64156, 64197, 64237, +64276, 64315, 64353, 64391, 64428, 64465, 64501, 64536, 64571, 64605, 64638, +64671, 64703, 64735, 64766, 64796, 64826, 64855, 64884, 64912, 64939, 64966, +64992, 65018, 65043, 65067, 65091, 65114, 65136, 65158, 65179, 65200, 65220, +65239, 65258, 65276, 65294, 65311, 65327, 65343, 65358, 65372, 65386, 65400, +65412, 65424, 65436, 65446, 65457, 65466, 65475, 65483, 65491, 65498, 65505, +65511, 65516, 65520, 65524, 65528, 65531, 65533, 65534, 65535 +}; + \ No newline at end of file diff --git a/zsnes/src/fixsin.h b/zsnes/src/fixsin.h new file mode 100644 index 00000000..8eaea69b --- /dev/null +++ b/zsnes/src/fixsin.h @@ -0,0 +1,25 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +extern int FSinTab[2048]; +extern int FCosTab[2048]; +#define FSINMAX 2047 +#define FSin(x) FSinTab[(x)&FSINMAX] +#define FCos(x) FCosTab[(x)&FSINMAX] + + \ No newline at end of file diff --git a/zsnes/src/gui/gui.asm b/zsnes/src/gui/gui.asm new file mode 100644 index 00000000..4bbc9f69 --- /dev/null +++ b/zsnes/src/gui/gui.asm @@ -0,0 +1,4898 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +; Sorry. The GUI code is a total mess. One problem I encountered is that +; there seems to be a bug in nasm with using math calculations combined +; with macros within macros, so in some macro definitions, I had to +; add/subtract extra values in certain macros to get the GUI to align +; correctly. +; The GUI is drawn is mostly manually. What I mean is such as +; coding 5 boxes to represent a shaded box for each box. Although that +; can be simplified using macros to draw 5 boxes, that unknown bug in nasm +; showed up which prevented me from using macros extensively. I was +; thinking of changing it to an object-based GUI for easier coding, +; but that was decided far into the development of the GUI itself +; and that I also never expected this code to become open-source, so I +; decided not to proceed with it. + +; Routine StartGUI is the function called to start the GUI and also +; contains the execution main loop of the GUI. If you want to completely +; replace the GUI, just add a function call from that function, then +; jump to endprog to exit ZSNES or continueprog to continue with the +; gameplay. Do not replace StartGUI with a function since it is not +; a function, but rather a label that is being jumped to. + +; ************************************** +; GUI.ASM +; ************************************** +; +; Associated files : +; GUIWinDp.inc - Window Display Routines +; GUITools.inc - Misc routines for the GUI + + +; Quick Searches : +; DisplayMenu - routines to display top menu bar +; Incomp - Search for start of modem processing +; ProcessModem +; GUIgetcurrentinput +; GUITryMenuItem - Processes the menu item when user clicks item +; Mouseimplementation +; DGUIDisplayer +; LGUILoadData +; SetInputDevice +; CalibrateDev1 +; ButtonProcess - routines that processes boxed buttons +; CheatCodeSearchInit +; guiwincontrol + + +%include "macros.mac" + +EXTSYM dssel, curblank, vidpastecopyscr, frameskip, newengen, vsyncon, cantinitmodem +EXTSYM FPUCopy, cvidmode, antienab, smallscreenon, smallscreence,NetQuit +EXTSYM soundon, StereoSound, SoundCompD, SoundQuality, MusicRelVol,UartType +EXTSYM endprog, continueprog, spcBuffera, spcRamcmp, cbitmode, makepal +EXTSYM t1cc, LoadDir, SRAMDir, LoadDrive,SRAMDrive, initsnes, romloadskip +EXTSYM fname, makeextension, sram, clearmem2, loadfileGUI, GUIloadfailed +EXTSYM CheckROMType, romdata, ForcePal, ramsize, ramsizeand, curromsize +EXTSYM romispal, totlines, cfgloadsdir, init65816, procexecloop +EXTSYM spcRam, spcPCRam, spcS, spcRamDP, spcA, spcX, spcY, spcP, spcNZ +EXTSYM Voice0Status, Voice1Status, Voice2Status, Voice3Status, Voice4Status +EXTSYM Voice5Status, Voice6Status, Voice7Status, romtype, SetIRQVectors +EXTSYM ClearScreen, statesaver, loadstate2, vidbuffer, ASCII2Font, hirestiledat +EXTSYM showallext, ROMTypeNOTFound, scanlines,statefileloc,pl1selk,pl2selk +EXTSYM fnamest,sprlefttot,spritetablea,fnames,SFXSRAM,sfxramdata,cgram,srama +EXTSYM tempco0,prevbright,maxbr,prevpal,coladdr,coladdg,coladdb +EXTSYM scaddtype,ScreenScale,vesa2red10,initvideo2,initvideo,pressed,UpdateDevices +EXTSYM memtabler8,memtablew8,writeon,pl1contrl,pl2contrl,JoyRead,SetInputDevice +EXTSYM SetInputDevice209,FPSOn,RevStereo,initrevst,WDSPReg0C,WDSPReg1C,WDSPReg2C +EXTSYM WDSPReg3C,pl12s34,resolutn,delay,chaton,chatstrL,chatLpos,chatstrR,chatRTL +EXTSYM InitDrive,InitDir,createnewcfg,Makemode7Table,SnowOn,MovieBuffSize +EXTSYM MovieBuffFrame,vidbufferofsb,ZipSupport,wramdata,bgfixer,cfgnewgfx +EXTSYM cfgdontsave,videotroub,Open_File,Read_File,Close_File,Write_File,Create_File +EXTSYM File_Seek,File_Seek_End,Open_File_Write,Get_Date,Check_Key,Get_Key +EXTSYM Change_Drive,Change_Single_Dir,Change_Dir,Get_Dir,Get_First_Entry +EXTSYM Get_Next_Entry,Set_DTA_Address,timer2upd,curexecstate,TripBufAvail +EXTSYM nmiprevaddrl,nmiprevaddrh,nmirept,nmiprevline,nmistatus,spcnumread +EXTSYM NextLineCache,OSPort,VidStartDraw,ResetTripleBuf,GUINGVID +EXTSYM ScanCodeListing,AdjustFrequency,GUISaveVars,Init_Mouse +EXTSYM Get_MouseData,Set_MouseXMax,Set_MouseYMax,Set_MousePosition,Get_MousePositionDisplacement +EXTSYM GUIInit,GUIDeInit,SpecialLine +EXTSYM DrawWater,RemoteDisconnect,loadstate3 +EXTSYM ModemClearBuffer,IPXSearchval +EXTSYM ipxlookforconnect +EXTSYM SA1Enable,SA1RAMArea +EXTSYM GUIFName,GUICName +EXTSYM printnum +EXTSYM SaveCombFile +EXTSYM NetSent,valuea +EXTSYM welcome +EXTSYM BackupCVFrame +EXTSYM Wait1SecWin,ClearUDPStuff +EXTSYM DisableSUDPPacket,EnableSUDPPacket +EXTSYM ModemGetChar +EXTSYM BackStateSize +EXTSYM ResetExecStuff +EXTSYM RestoreCVFrame +EXTSYM CurRecv,BackState,CBackupPos,PBackupPos,PPValue,DPValue,NetQuitter +EXTSYM LatencyV +EXTSYM LatencyRecvPtr,LatencySendPtr +EXTSYM NumofBanks +EXTSYM WinErrorA,WinErrorB,WinErrorC +EXTSYM ErrorPointer +EXTSYM MessageOn,Msgptr,MsgCount +EXTSYM PJoyAOrig,PJoyBOrig,PJoyCOrig,PJoyDOrig,PJoyEOrig +EXTSYM GetHostName +EXTSYM vramaddr,curypos,ClearRegs,vram,sndrot,regsbackup +EXTSYM GetScreen + +EXTSYM MouseWindow +EXTSYM GotoHomepage +EXTSYM cfgcvidmode, ExitFromGUI +EXTSYM GUIWFVID +EXTSYM cfgvsync,cfgcopymethod,newgfx16b +EXTSYM cfgscanline,cfginterp +EXTSYM NumVideoModes +EXTSYM cfgvolume, MusicVol, DSPMem +EXTSYM NumInputDevices,GUIInputNames +EXTSYM GUIVideoModeNames +EXTSYM GUISLVID,GUIINVID,GUIEAVID,GUIIEVID,GUIFSVID,GUISSVID,GUITBVID +EXTSYM GUIHSVID,GUI2xVID,GUII2VID,GUIM7VID +EXTSYM cfgsoundon, cfgSoundQuality, cfgStereoSound +EXTSYM convertnum,converthex +EXTSYM per2exec +EXTSYM hostname +EXTSYM UDPConfig +EXTSYM DeInitModem +EXTSYM snesmouse +EXTSYM pl1upk,pl1downk,pl1leftk,pl1rightk,pl1Lk,pl1Rk,pl1Ak,pl1Bk +EXTSYM deinitipx +EXTSYM InitModem +EXTSYM outofmemfix,yesoutofmemory + +EXTSYM CReadHead,ReadHead,CFWriteHead,CFWriteStart +EXTSYM JoyX,JoyY,JoyMinX,JoyMinY,JoyMaxX,JoyMaxY,JoyMinX209,JoyMaxX209 +EXTSYM JoyMinY209,JoyMaxY209,GetCoords,GetCoords3 +EXTSYM MultiTap,SFXEnable +EXTSYM RestoreSystemVars + +EXTSYM TCPIPStartServer +EXTSYM TCPIPInitConnectToServer +EXTSYM TCPIPWaitForConnection +EXTSYM tcperr +EXTSYM TCPIPConnectToServer +EXTSYM TCPIPConnectToServerW +EXTSYM initipx +EXTSYM selc0040 +EXTSYM ModemCheckRing +EXTSYM ModemCheckDCD +EXTSYM PreparePacketIPX,TCPIPPreparePacket +EXTSYM SendPacketIPX,TCPIPSendPacket,TCPIPSendPacketUDP +EXTSYM TCPIPDisconnect,TCPIPStatus +EXTSYM DeInitModemC +EXTSYM ipxgetchar,ipxsendchar,TCPIPStoreByte +EXTSYM TCPIPGetByte +EXTSYM ModemSendChar + + + + +%include "gui/guitools.inc" +%include "gui/GUIMisc.inc" +%include "gui/GUIMouse.inc" +%include "gui/GUIWinDp.inc" +%include "gui/guinetpl.inc" +%include "gui/GUIKeys.inc" +%include "gui/GUICheat.inc" +%include "gui/GUICombo.inc" +%include "gui/GUILoad.inc" + + + + + +; ProcessRemoteCommand +; NetLoadStuff ; Send 14 to initiate, Send 15 to cancel (either way) +; call PreparePacket +; mov al,253 +; call RemoteSendChar +; call SendPacket +; NetAddChar + + + +NEWSYM WaterOn, db 1 + + +; Things to do : +; +; .checkmenuboxclick +; gray scale = 32 .. 63 +; shadow = 96 .. 127 +; blue scale = 148 .. 167, 168 .. 187 +; gray scale = 189 .. 220 (32+137) + + +; | Game Config Cheat MultiPlay Misc +;------------------------------------------------------- +; Load Input#1 Add Code Modem Game Keys +; Run Input#2 Browse IPX GUI Opns +; Reset Input#3 Search About +; ----- Input#4 +; Save State ------- +; Load State Options +; Chose State Video +; ----- Sound +; Quit + +; Windows : 1 = Save/Load Confirmation +; 2 = Chose State +; 3 = Input Device Window +; 4 = Options +; 5 = Video +; 6 = Sound +; 7 = Cheat +; 8 = IPX/Modem +; 9 = GameOptions +; 10 = GUI Options +; 11 = About + +MenuDat1 db 12,3,1,1,1,1,1,1,1,1,1,0,1,2,0 +MenuDat2 db 8, 3,1,1,0,1,1,1,0,2,0,0 +MenuDat3 db 10, 3,1,1,1,1,0,1,0,1,1,2,0 +MenuDat4 db 2, 3,1,2,0 +MenuDat5 db 1, 3,2,0 +MenuDat6 db 6, 3,1,1,1,1,0,2,0 + +GUIPrevMenuData + db 1,'1. ',0 + db 1,'2. ',0 + db 1,'3. ',0 + db 1,'4. ',0 + db 1,'5. ',0 + db 1,'6. ',0 + db 1,'7. ',0 + db 1,'8. ',0 + db 1,'9. ',0 + db 1,'0. ',0 + db 0,'------------',0 +.onoff db 1,'FREEZE DATA : OFF ',0 + db 1,'CLEAR ALL DATA ',0 +GUIGameMenuData + db 1,'LOAD ',0 + db 1,'RUN [ESC] ',0 + db 1,'RESET ',0 + db 0,'------------',0 + db 1,'SAVE STATE ',0 + db 1,'OPEN STATE ',0 + db 1,'PICK STATE ',0 + db 0,'------------',0 + db 1,'QUIT ',0 +GUIConfigMenuData + db 1,'INPUT #1 ',0 + db 1,'INPUT #2 ',0 + db 1,'INPUT #3 ',0 + db 1,'INPUT #4 ',0 + db 1,'INPUT #5 ',0 + db 0,'------------',0 + db 1,'ADD-ONS ',0 + db 0,'------------',0 + db 1,'OPTIONS ',0 + db 1,'VIDEO ',0 + db 1,'SOUND ',0 +GUICheatMenuData + db 1,'ADD CODE ',0 + db 1,'BROWSE ',0 + db 1,'SEARCH ',0 +GUINetPlayMenuData + db 1,'MODEM ',0 + db 1,'IPX ',0 +GUIMiscMenuData + db 1,'GAME KEYS ',0 + db 1,'GUI OPNS ',0 + db 1,'MOVIE OPN ',0 + db 1,'KEY COMB. ',0 + db 1,'SAVE CFG ',0 + db 0,'------------',0 + db 1,'ABOUT ',0 + +; Config, Options -> New Gfx Engine, Frame Rate, Fast Forward FrameRate, etc. +; Config, Video -> Video Mode, Interpolation, etc. +; Config, Options -> Set up Save and/or Load State Confirmation +; Select Different game key assignments +; If menu should go to Load or last position when ESC +; is pressed from game + +GUIRAdd db 15 +GUIGAdd db 10 +GUIBAdd db 31 +mousewrap db 0 ; 0 = mouse boundries, 1 = mouse wrap +mouseshad db 1 ; 0 = no mouse shadow, 1 = mouse shadow +lastcursres db 0 ; 0 = go to load, 1 = go to previous menu, 2 = no menu +resetposn db 1 ; 0 = no window reset, 1 = window reset +NEWSYM GUIClick, db 0 ; 1 = mouse click enters/exits gui +GUIwinposx2 dd 0,5 ,60 ,30 ,55 ,50 ,65 ,5 ,30 ,20 ,10 ,80 ,65 ,20 ,70 ,50 ,3 ,0 +GUIwinposy2 dd 0,20 ,70 ,30 ,20 ,22 ,36 ,20 ,30 ,20 ,40 ,70 ,60 ,30 ,65 ,50 ,22 ,0 + +; Default keys +; Sound Channels 0 .. 7, Save/Select/Load States, Fast Forward +; Exit, Load, Reset, BG Disables, Reset, Windowing, New Gfx, OffsetMode +; State Selection 0 .. 9 + +NEWSYM KeyDisableSC0, dd 63 +NEWSYM KeyDisableSC1, dd 64 +NEWSYM KeyDisableSC2, dd 65 +NEWSYM KeyDisableSC3, dd 66 +NEWSYM KeyDisableSC4, dd 67 +NEWSYM KeyDisableSC5, dd 68 +NEWSYM KeyDisableSC6, dd 87 +NEWSYM KeyDisableSC7, dd 88 +NEWSYM KeySaveState, dd 60 +NEWSYM KeyStateSelct, dd 61 +NEWSYM KeyLoadState, dd 62 +NEWSYM KeyFastFrwrd, dd 41 +NEWSYM KeyQuickExit, dd 0 +NEWSYM KeyQuickLoad, dd 0 +NEWSYM KeyQuickRst, dd 0 +NEWSYM KeyBGDisble0, dd 2 +NEWSYM KeyBGDisble1, dd 3 +NEWSYM KeyBGDisble2, dd 4 +NEWSYM KeyBGDisble3, dd 5 +NEWSYM KeySprDisble, dd 6 +NEWSYM KeyResetAll, dd 7 +NEWSYM KeyExtraEnab, dd 8 +NEWSYM KeyNewGfxSwt, dd 9 +NEWSYM KeyWinDisble, dd 10 +NEWSYM KeyOffsetMSw, dd 11 +NEWSYM KeyStateSlc0, dd 0 +NEWSYM KeyStateSlc1, dd 0 +NEWSYM KeyStateSlc2, dd 0 +NEWSYM KeyStateSlc3, dd 0 +NEWSYM KeyStateSlc4, dd 0 +NEWSYM KeyStateSlc5, dd 0 +NEWSYM KeyStateSlc6, dd 0 +NEWSYM KeyStateSlc7, dd 0 +NEWSYM KeyStateSlc8, dd 0 +NEWSYM KeyStateSlc9, dd 0 + +GUIshowallext db 0 +GUIloadfntype db 0 + +NEWSYM pl3selk, dd 0 ; 3SELECT = SHIFT +NEWSYM pl3startk, dd 0 ; 3START = ENTER +NEWSYM pl3upk, dd 0 ; 3UP = up +NEWSYM pl3downk, dd 0 ; 3DOWN = down +NEWSYM pl3leftk, dd 0 ; 3LEFT = left +NEWSYM pl3rightk, dd 0 ; 3RIGHT = right +NEWSYM pl3Xk, dd 0 ; 3X = INS +NEWSYM pl3Ak, dd 0 ; 3A = HOME +NEWSYM pl3Lk, dd 0 ; 3L = PAGE UP +NEWSYM pl3Yk, dd 0 ; 3Y = DELETE +NEWSYM pl3Bk, dd 0 ; 3B = END +NEWSYM pl3Rk, dd 0 ; 3R = PAGE DOWN +NEWSYM pl4selk, dd 0 ; 4SELECT = SHIFT +NEWSYM pl4startk, dd 0 ; 4START = ENTER +NEWSYM pl4upk, dd 0 ; 4UP = up +NEWSYM pl4downk, dd 0 ; 4DOWN = down +NEWSYM pl4leftk, dd 0 ; 4LEFT = left +NEWSYM pl4rightk, dd 0 ; 4RIGHT = right +NEWSYM pl4Xk, dd 0 ; 4X = INS +NEWSYM pl4Ak, dd 0 ; 4A = HOME +NEWSYM pl4Lk, dd 0 ; 4L = PAGE UP +NEWSYM pl4Yk, dd 0 ; 4Y = DELETE +NEWSYM pl4Bk, dd 0 ; 4B = END +NEWSYM pl4Rk, dd 0 ; 4R = PAGE DOWN +NEWSYM TimeChecker, db 0 ; Future Reserved +GUISoundBuffer db 1 ; Sound Buffer Disabled +prevloadnames times 16*10 db 32 +prevloaddname times 128*10 db 0 +prevloadfname times 16*10 db 32 +prevlfreeze db 0 +GUIsmallscreenon db 0 +GUIScreenScale db 0 + +;FIXME: pl1contrl and pl2contrl are extern to this file +;but pl3contrl, pl4contrl and pl5contrl are defined here! +;strange... (Christophe 2001/03/10) +NEWSYM pl3contrl, db 0 +NEWSYM pl4contrl, db 0 +NEWSYM pl1p209b, db 0 +NEWSYM pl2p209b, db 0 +NEWSYM pl3p209b, db 0 +NEWSYM pl4p209b, db 0 +JoyPad1Move db 0 +FirstTimeData db 0 +NEWSYM PrevSWFix, db 0 +NEWSYM CalibXmin, dd 0 +NEWSYM CalibYmin, dd 0 +NEWSYM CalibXmax, dd 0 +NEWSYM CalibYmax, dd 0 +NEWSYM CalibXmin209, dd 0 +NEWSYM CalibYmin209, dd 0 +NEWSYM CalibXmax209, dd 0 +NEWSYM CalibYmax209, dd 0 +NEWSYM maxskip, db 9 +FPSAtStart db 0 +NEWSYM SidewinderFix, db 0 +GUIInitSt1 db 'ATZ' +.rest times 47 db 0 +GUIInitSt2 db 'AT S0=0' +.rest times 43 db 0 +GUIDialSt db 'ATDT ',0 +NEWSYM ComNum, db 2 +NEWSYM ComIRQ, db 3 +NEWSYM BaudRate, dd 3 +NEWSYM pl1Atk, dd 0 ; Turbo A +NEWSYM pl1Btk, dd 0 ; Turbo B +NEWSYM pl1Xtk, dd 0 ; Turbo X +NEWSYM pl1Ytk, dd 0 ; Turbo Y +NEWSYM pl2Atk, dd 0 ; Turbo A +NEWSYM pl2Btk, dd 0 ; Turbo B +NEWSYM pl2Xtk, dd 0 ; Turbo X +NEWSYM pl2Ytk, dd 0 ; Turbo Y +NEWSYM pl3Atk, dd 0 ; Turbo A +NEWSYM pl3Btk, dd 0 ; Turbo B +NEWSYM pl3Xtk, dd 0 ; Turbo X +NEWSYM pl3Ytk, dd 0 ; Turbo Y +NEWSYM pl4Atk, dd 0 ; Turbo A +NEWSYM pl4Btk, dd 0 ; Turbo B +NEWSYM pl4Xtk, dd 0 ; Turbo X +NEWSYM pl4Ytk, dd 0 ; Turbo Y +NEWSYM Turbo30hz, db 0 ; Turbo at 30hz instead of 60hz + +NEWSYM KeyVolUp, dd 0 +NEWSYM KeyVolDown, dd 0 +NEWSYM KeyFRateUp, dd 0 +NEWSYM KeyFRateDown, dd 0 + +NEWSYM KeyQuickChat, dd 20 +NEWSYM FossilUse, db 0 +NEWSYM TimerEnable, db 0 + +NEWSYM Surround, db 0 +NEWSYM InterSound, db 1 +NEWSYM FastFwdToggle, db 0 +NEWSYM En2xSaI, db 0 +NEWSYM AutoLoadCht, db 0 +NEWSYM KeyQuickSnapShot, dd 0 + +CheatSrcByteSize db 0 +CheatSrcByteBase db 0 +CheatSrcSearchType db 0 +CheatUpperByteOnly db 0 +NEWSYM SRAMSave5Sec, db 0 +NEWSYM ReInitSoundC, db 0 +NEWSYM OldGfxMode2 , db 0 +NEWSYM PitchModEn , db 0 +NEWSYM LatestSave , db 0 +NEWSYM AutoState , db 0 +NEWSYM OldVolume , db 1 +NEWSYM BlankVar , db 1 + +NEWSYM pl1ULk, dd 0 +NEWSYM pl1URk, dd 0 +NEWSYM pl1DLk, dd 0 +NEWSYM pl1DRk, dd 0 +NEWSYM pl2ULk, dd 0 +NEWSYM pl2URk, dd 0 +NEWSYM pl2DLk, dd 0 +NEWSYM pl2DRk, dd 0 +NEWSYM pl3ULk, dd 0 +NEWSYM pl3URk, dd 0 +NEWSYM pl3DLk, dd 0 +NEWSYM pl3DRk, dd 0 +NEWSYM pl4ULk, dd 0 +NEWSYM pl4URk, dd 0 +NEWSYM pl4DLk, dd 0 +NEWSYM pl4DRk, dd 0 + +NEWSYM LowPassFilter, db 0 +NEWSYM DontSavePath, db 0 +NEWSYM ReCalib, db 1 +NEWSYM GUIComboGameSpec, db 0 +NEWSYM SoundNoiseDis, db 0 ; Disable Noise +NEWSYM Triplebufen, db 0 +NEWSYM SoundBufEn, db 0 +NEWSYM SPCDisable, db 0 +NEWSYM RaisePitch, db 0 + +prevloadl db 0 +prevloaddnamel times 512*10 db 0 +prevloadfnamel times 512*10 db 0 + +PrevWinMode db 1 +PrevFSMode db 5 + +OldWinPos db 0 +GUIwinposx dd 0,5 ,60 ,30 ,55 ,50 ,65 ,5 ,30 ,20 ,10 ,80 ,65 ,20 ,70 ,50 ,3 ,50 +GUIwinposxexp times 30 dd 0 +GUIwinposy dd 0,20 ,70 ,30 ,20 ,22 ,36 ,20 ,30 ,20 ,30 ,70 ,60 ,30 ,65 ,50 ,22 ,60 +GUIwinposyexp times 30 dd 0 + +GUIEffect db 0 + +NEWSYM pl5selk, dd 0 ; 4SELECT = SHIFT +NEWSYM pl5startk, dd 0 ; 4START = ENTER +NEWSYM pl5upk, dd 0 ; 4UP = up +NEWSYM pl5downk, dd 0 ; 4DOWN = down +NEWSYM pl5leftk, dd 0 ; 4LEFT = left +NEWSYM pl5rightk, dd 0 ; 4RIGHT = right +NEWSYM pl5Xk, dd 0 ; 4X = INS +NEWSYM pl5Ak, dd 0 ; 4A = HOME +NEWSYM pl5Lk, dd 0 ; 4L = PAGE UP +NEWSYM pl5Yk, dd 0 ; 4Y = DELETE +NEWSYM pl5Bk, dd 0 ; 4B = END +NEWSYM pl5Rk, dd 0 ; 4R = PAGE DOWN +NEWSYM pl5ULk, dd 0 +NEWSYM pl5URk, dd 0 +NEWSYM pl5DLk, dd 0 +NEWSYM pl5DRk, dd 0 +NEWSYM pl5Atk, dd 0 ; Turbo A +NEWSYM pl5Btk, dd 0 ; Turbo B +NEWSYM pl5Xtk, dd 0 ; Turbo X +NEWSYM pl5Ytk, dd 0 ; Turbo Y +NEWSYM pl5contrl, db 0 +NEWSYM pl1p209, db 0 +NEWSYM pl2p209, db 0 +NEWSYM pl3p209, db 0 +NEWSYM pl4p209, db 0 +NEWSYM pl5p209, db 0 + +NEWSYM GUIEnableTransp, db 0 +NEWSYM Mode7HiRes16b, dd 0 +NEWSYM NewEngEnForce, db 1 +NEWSYM KeyRewind, dd 0 +NEWSYM ChatNick, times 16 db 0 +NEWSYM KeySlowDown, dd 0 + +GUIsave equ $-GUIRAdd + +NEWSYM CombinDataGlob, times 3300 db 0 ; 20-name, 42-combo, 2-key#, 1-P#, 1-ff +NEWSYM CombinDataLocl, times 3300 db 0 + +GUIwinorder db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +GUIwinpos db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +GUIwinactiv db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +DialNumber times 40 db 0 +ViewBuffer times 50*32 db 0 +NEWSYM ModemInitStat, db 0 +ModemProcess db 0 ; Shows current dial/answer process +ModemPTimer dd 0 ; Timer for modem process +ModemOKStat db 0 ; OK is detected on modem status + +; LOAD STAT INPT OPT VID SND CHT NET GMKEY GUIOP ABT RSET SRC STCN MOVE CMBO ADDO +GUIwinposxo dd 0,5 ,60 ,30 ,55 ,50 ,65 ,5 ,30 ,20 ,10 ,80 ,65 ,20 ,70 ,50 ,3 ,50 +GUIwinposyo dd 0,20 ,70 ,30 ,20 ,22 ,36 ,20 ,30 ,20 ,30 ,70 ,60 ,30 ,65 ,50 ,22 ,60 +GUIwinsizex dd 0,244 ,126 ,189 ,167 ,170 ,148 ,244 ,8*16,13*16,176 ,7*16,9*16,8*16,9*16,140 ,250 ,160 +GUIwinsizey dd 0,190 ,3*16,166 ,190 ,186 ,158 ,191 ,40 ,189 ,152 ,68 ,42 ,40 ,42 ,70 ,190 ,60 +GUIwinptr db 0 + +GUItextcolor db 0,0,0,0,0 +GUIcmenupos db 0 +GUIescpress db 0 +GUIcwinpress db 0 +GUIpmenupos db 0 +GUIcrowpos dd 0 +GUIpclicked db 0 +GUImouseposx dd 0 +GUImouseposy dd 0 +GUICYLocPtr dd 0 +GUIMenuL dd 0 +GUIMenuR dd 0 +GUIMenuD dd 0 +GUIOnMenuItm db 0 +NEWSYM GUIQuit, db 0 +GUIHold db 0 +GUIHoldx dd 0 +GUIHoldy dd 0 +GUIHoldxm dd 0 +GUIHoldym dd 0 +GUIcolscaleval dd 0 +cwindrawn db 0 +GUIWincol dd 0 +GUIWincoladd dd 0 +GUITemp dd 0 +GUIHoldXlimL dd 0 +GUIHoldXlimR dd 0 +GUIHoldYlim dd 0 +GUIHoldYlimR dd 0 +cloadnpos dd 0 +cloadnposb dd 0 +cloadmaxlen dd 0 +cloadnleft dd 0 +cplayernum db 0 +vbuflimtop dd 0 +vbuflimbot dd 0 +GUIScrolTim1 dd 0 +GUIScrolTim2 dd 0 +GUICHold dd 0 +GUICBHold dd 0 +GUICBHold2 dd 0 +GUIDClickTL dd 0 +GUIDClCWin dd 0 +GUIDClCEntry dd 0 +GUICResetPos dd 0 +GUICStatePos dd 0 +GUICCFlash db 0 +GUILDFlash db 0 +GUIPalConv dd 0 +PrevResoln dw 0 +SnowMover dd 0 +keycontrolval dd 0 +NEWSYM ShowTimer, db 0 +NEWSYM MousePRClick, db 0 +NEWSYM MouseDis, db 0 +NetPlayNoMore db 0 +RestoreValues db 0 +NEWSYM NetChatFirst, db 0 +NEWSYM NetServer, db 0 +NEWSYM NetQuitAfter, db 0 +NEWSYM NetNewNick, times 16 db 0 +NEWSYM NetFilename, times 512 db 0 + +NEWSYM CheatOn, dd 0 +NEWSYM NumCheats, dd 0 +NEWSYM cheatdataprev, times 28 db 0 ; leave contents blank +NEWSYM cheatdata, times 28*255+56 db 0 ; toggle, value, address, pvalue, name(22) + +NEWSYM GUIcurrentdir, times 131 db 0 + +numdrives dd 26 +gotoroot db '\',0 +curgsval db 0 +SubPalTable times 256 db 1 ; Corresponding Gray Scale Color +WhichRemote dd 0 ; Modem = 1, IPX = 2, TCP/IP = 4 +Connected dd 0 +IDCheckPos dd 0 + +NEWSYM pl1neten, db 0 +NEWSYM pl2neten, db 0 +NEWSYM pl3neten, db 0 +NEWSYM pl4neten, db 0 +NEWSYM pl5neten, db 0 +NEWSYM cnetplaybuf, times 512 db 0 +NEWSYM cnetptrhead, dd 0 +NEWSYM cnetptrtail, dd 0 +NEWSYM prevp1net, dd 0 +NEWSYM prevp2net, dd 0 +NEWSYM prevp3net, dd 0 +NEWSYM prevp4net, dd 0 +NEWSYM prevp5net, dd 0 +NEWSYM netdelayed, db 0 +NEWSYM ChatProgress,dd 0 +NEWSYM RecvProgress,dd 0 +NEWSYM IPXInfoStr, dw 0 +NEWSYM IPXInfoStrR, dw 0 +NEWSYM GUICMessage, dd 0 +NEWSYM GUICTimer, dd 0 +NEWSYM GUIOn, db 0 +NEWSYM GUIOn2, db 0 +GOSPort db 0 + +NEWSYM StartLL, dd 0 +NEWSYM StartLR, dd 0 +NEWSYM LatencyVal, times 32 db 0 + +NEWSYM NetLoadState, db 0 + + +;ModemProcess db 0 ; Shows current dial/answer process +;ModemPTimer db 0 ; Timer for modem process + +%macro stim 0 + cmp byte[OSPort],1 + ja %%nosti + sti +%%nosti +%endmacro + +%macro clim 0 + cmp byte[OSPort],1 + ja %%nocli + cli +%%nocli +%endmacro + + + +clearsram: + push eax + push ecx + mov eax,srama + mov ecx,65536 +.loop + mov byte[eax],0FFh + inc eax + loop .loop + cmp byte[SFXSRAM],0 + je .nosfxsram + mov eax,[sfxramdata] + mov ecx,65536 +.loop2 + mov byte[eax],0FFh + inc eax + loop .loop2 +.nosfxsram + cmp byte[SA1Enable],1 + jne .nosa1 + mov eax,[SA1RAMArea] + mov ecx,65536*2 +.loop3 + mov byte[eax],0FFh + inc eax + loop .loop3 +.nosa1 + pop ecx + pop eax + ret + +GUIQuickLoadUpdate: + cmp byte[prevlfreeze],0 + je .off + mov byte[GUIPrevMenuData.onoff+15],'O' + mov byte[GUIPrevMenuData.onoff+16],'N' + mov byte[GUIPrevMenuData.onoff+17],' ' + jmp .on +.off + mov byte[GUIPrevMenuData.onoff+15],'O' + mov byte[GUIPrevMenuData.onoff+16],'F' + mov byte[GUIPrevMenuData.onoff+17],'F' +.on + mov esi,prevloadfnamel + cmp byte[OSPort],2 + jae .notdos + mov esi,prevloadnames +.notdos + mov edi,GUIPrevMenuData+3 + mov edx,10 +.mainloop + mov ecx,25 + cmp byte[OSPort],2 + jae .notdos3 + mov ecx,16 +.notdos3 + + push edi + push esi + cmp byte[esi],32 + je near .fin2 +.loop + mov al,[esi] + cmp al,0 + je .zero + mov [edi],al + inc esi + inc edi + dec ecx + jnz .loop + cmp byte[esi],0 + je .zero + mov byte[edi],'.' + mov byte[edi+1],'.' + mov byte[edi+2],'.' + jmp .fin +.zero + add ecx,3 +.loop2 + mov byte[edi],32 + inc edi + dec ecx + jnz .loop2 + jmp .fin +.fin2 + mov ecx,18 +.loop3 + mov byte[edi],32 + inc edi + dec ecx + jnz .loop3 +.fin + pop esi + pop edi + add esi,512 ;16 + cmp byte[OSPort],2 + jae .notdos2 + sub esi,512-16 +.notdos2 + add edi,32 + dec edx + jnz near .mainloop + ret + + + +CalcChecksum: + mov eax,GUIRAdd + mov ecx,100 + xor edx,edx + xor ebx,ebx +.loop + mov bl,[eax] + add edx,ebx + inc eax + loop .loop + mov ebx,edx + xor bx,1011001011101101b + xor eax,eax + test bh,08h + jz .nb + mov al,1 +.nb + and bh,0F7h + test bl,10h + jz .nb2 + or bh,08h +.nb2 + and bl,0EFh + test al,1 + jz .nb3 + or bl,10h +.nb3 + xor bl,bh + or bl,80h + ret + +NEWSYM GUIRestoreVars + mov edx,GUIFName + call Open_File + jc .fail + mov bx,ax + mov edx,GUIRAdd + mov ecx,GUIsave + call Read_File + call Close_File +.fail + mov al,[GUIsmallscreenon] + mov [smallscreenon],al + mov al,[GUIScreenScale] + mov [ScreenScale],al + mov al,[FPSAtStart] + mov [FPSOn],al + call CalcChecksum + cmp byte[TimeChecker],bl + jne .nottimer + mov byte[ShowTimer],1 + mov dword[NumSnow],200 + mov dword[SnowTimer],0 +.nottimer + cmp byte[ReCalib],0 + je .nocal + mov byte[ReCalib],0 + mov dword[CalibXmin],0 + mov dword[CalibXmax],0 + mov dword[CalibYmin],0 + mov dword[CalibYmax],0 + mov dword[CalibXmin209],0 + mov dword[CalibXmax209],0 + mov dword[CalibYmin209],0 + mov dword[CalibYmax209],0 +.nocal + + mov dword[NumComboGlob],0 + mov edx,GUICName + call Open_File + jc .failb + mov bx,ax + mov edx,ComboBlHeader + mov ecx,23 + call Read_File + mov al,byte[ComboBlHeader+22] + or al,al + jz .done + mov [NumComboGlob],al + mov ecx,[NumComboGlob] + mov edx,ecx + shl ecx,6 + add ecx,edx + add ecx,edx + mov edx,CombinDataGlob + call Read_File +.done + call Close_File +.failb + ret + +NEWSYM ComboHeader, db 'Key Combination File',26,1,0 +NEWSYM ComboBlHeader, times 23 db 0 + + +NEWSYM ExecGUISaveVars + cmp byte[ShowTimer],1 + jne .nottimer + call CalcChecksum + mov byte[TimeChecker],bl +.nottimer + cmp byte[cfgdontsave],1 + je .failed + mov edx,GUIFName + call Create_File + jc .failed + mov bx,ax + mov edx,GUIRAdd + mov ecx,GUIsave + call Write_File + call Close_File +.failed + + mov al,[NumComboGlob] + or al,al + jz .failb + mov [ComboHeader+22],al + mov edx,GUICName + call Create_File + jc .failb + mov bx,ax + mov edx,ComboHeader + mov ecx,23 + call Write_File + mov ecx,[NumComboGlob] + mov edx,ecx + shl ecx,6 + add ecx,edx + add ecx,edx + mov edx,CombinDataGlob + call Write_File + call Close_File +.failb + ret + +%macro GUIInitIRQs 0 + call GUIInit + mov esi,pressed + mov ecx,256 + mov al,0 +.loopa + mov [esi],al + inc esi + loop .loopa +%endmacro + +%macro GUIDeInitIRQs 0 + call GUIDeInit +%endmacro + +NEWSYM GUIoldhand9o, dd 0 +NEWSYM GUIoldhand9s, dw 0 +NEWSYM GUIoldhand8o, dd 0 +NEWSYM GUIoldhand8s, dw 0 +GUIt1cc dd 0 +GUIt1ccSwap db 0 +GUIskipnextkey42 db 0 + +NEWSYM GUIinit18_2hz + mov al,00110110b + out 43H,al + mov ax,0 + out 40H,al + mov al,ah + out 40H,al + ret + +NEWSYM GUIinit36_4hz + mov al,00110110b + out 43H,al + mov ax,32768 + out 40H,al + mov al,ah + out 40H,al + ret + +NEWSYM GUI36hzcall + inc dword[GUIt1cc] + inc dword[SnowMover] + cmp dword[ModemPTimer],0 + je .nodec5 + dec dword[ModemPTimer] +.nodec5 + cmp dword[GUIEditStringLTxt],0 + je .nodec + dec dword[GUIEditStringLTxt] +.nodec + cmp dword[GUIScrolTim1],0 + je .nodec4 + dec dword[GUIScrolTim1] +.nodec4 + cmp dword[GUIDClickTL],0 + je .nodec2 + dec dword[GUIDClickTL] +.nodec2 + cmp dword[GUIkeydelay],0 + je .nodec3 + dec dword[GUIkeydelay] +.nodec3 + cmp dword[GUIkeydelay2],0 + je .nodec3b + dec dword[GUIkeydelay2] +.nodec3b + cmp dword[GUICTimer],0 + je .nodec6 + dec dword[GUICTimer] +.nodec6 + inc byte[GUICCFlash] + and byte[GUICCFlash],0Fh + inc byte[GUILDFlash] + and byte[GUILDFlash],0Fh + inc byte[GUINetTextm2+2] + and byte[GUINetTextm2+2],0Fh + ret + +NEWSYM GUIhandler8h + cli + push ds + push eax + mov ax,[cs:dssel] + mov ds,ax + call GUI36hzcall + xor byte[GUIt1ccSwap],1 + cmp byte[GUIt1ccSwap],0 + je .nocall + pushf + call far [GUIoldhand8o] +.nocall + mov al,20h + out 20h,al + pop eax + pop ds + sti + iretd + +NEWSYM GUIhandler9h + cli + push ds + push eax + push ebx + mov ax,[cs:dssel] + mov ds,ax + + xor ebx,ebx + in al,60H ; get keyboard scan code + cmp al,42 + jne .no42 + cmp byte[GUIskipnextkey42],0 + je .no42 + mov byte[GUIskipnextkey42],0 + jmp .skipkeyrel +.no42 + cmp al,0E0h + jne .noE0 + mov byte[GUIskipnextkey42],1 + jmp .skipkeyrel +.noE0 + mov byte[GUIskipnextkey42],0 + mov bl,al + xor bh,bh + test bl,80h ; check if bit 7 is on (key released) + jnz .keyrel + cmp byte[pressed+ebx],0 + jne .skipa + mov byte[pressed+ebx],1 ; if not, set key to pressed +.skipa + jmp .skipkeyrel +.keyrel + and bl,7Fh + mov byte[pressed+ebx],0 ; if not, set key to pressed +.skipkeyrel + mov byte[pressed],0 + + pushf + call far [GUIoldhand9o] + mov al,20h + out 20h,al + pop ebx + pop eax + pop ds + sti + iretd + +%macro loadmenuopen 1 + mov al,[GUIcmenupos] + mov [GUIpmenupos],al + mov byte[GUIcmenupos],0 + cmp byte[GUIwinactiv+%1],1 + je %%menuontop + xor eax,eax + mov al,[GUIwinptr] + inc byte[GUIwinptr] + mov byte[GUIwinorder+eax],%1 + mov byte[GUIwinactiv+%1],1 + cmp byte[resetposn],1 + jne %%nomenuitem + mov eax,[GUIwinposxo+%1*4] + mov [GUIwinposx+%1*4],eax + mov eax,[GUIwinposyo+%1*4] + mov [GUIwinposy+%1*4],eax + jmp %%nomenuitem +%%menuontop + xor eax,eax + ; look for match +%%notfoundyet + mov bl,byte[GUIwinorder+eax] + cmp bl,%1 + je %%nextfind + inc eax + jmp %%notfoundyet +%%nextfind + inc eax + cmp al,[GUIwinptr] + je %%foundend + mov cl,[GUIwinorder+eax] + mov [GUIwinorder+eax-1],cl + jmp %%nextfind +%%foundend + mov byte[GUIpclicked],0 + mov [GUIwinorder+eax-1],bl +%%nomenuitem +%endmacro + +loadnetopen: + loadmenuopen 8 + ret + +MouseInitOkay db 0 + +LoadDetermine: + mov byte[GUIGameMenuData+14],1 + mov byte[GUIGameMenuData+14*2],1 + mov byte[GUIGameMenuData+14*4],1 + mov byte[GUIGameMenuData+14*5],1 + mov byte[GUIGameMenuData+14*6],1 + mov byte[GUICheatMenuData],1 + mov byte[GUICheatMenuData+14],1 + mov byte[GUICheatMenuData+14*2],1 + mov byte[GUIMiscMenuData+14*2],1 + cmp byte[CNetType],21 + je .modem + cmp byte[CNetType],22 + je .modem + cmp byte[CNetType],20 + jne .nomodem +.modem + mov byte[GUICheatMenuData],2 + mov byte[GUICheatMenuData+14],2 + mov byte[GUICheatMenuData+14*2],2 +.nomodem + cmp byte[romloadskip],0 + je .noromloaded2 + mov byte[GUIGameMenuData+14],2 + mov byte[GUIGameMenuData+14*2],2 + mov byte[GUIGameMenuData+14*4],2 + mov byte[GUIGameMenuData+14*5],2 + mov byte[GUIGameMenuData+14*6],2 + mov byte[GUIMiscMenuData+14*2],2 +.noromloaded2 +.noromloaded + ret + +SantaData: +db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +db 0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0 +db 0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0 +db 1,0,0,1,0,0,1,0,0,0,1,1,1,0,1,1 +db 1,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1 +db 1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1 +db 1,1,0,1,1,0,1,1,0,0,1,1,1,1,1,1 + +SantaPos dd 272 +SantaNextT dd 36*15 +NumSnow dd 0 +NEWSYM SnowTimer, dd 36*30 +MsgGiftLeft dd 0 + +DrawSnow: + cmp byte[OkaySC],0 + je near .nosanta + cmp dword[MsgGiftLeft],0 + je .nodec + mov edx,20 + mov ebx,210 + mov byte[GUItextcolor],228 + GUIOuttextwin .giftmsg +.nodec + mov esi,[vidbuffer] + add esi,[SantaPos] + add esi,60*288 + mov edx,SantaData + mov ebx,8 +.sloop2 + mov ecx,16 +.sloop + cmp byte[edx],0 + je .transp + mov byte[esi],0 +.transp + inc esi + inc edx + loop .sloop + add esi,272 + dec ebx + jnz .sloop2 +.nosanta + mov esi,[vidbuffer] + mov ecx,200 + xor edx,edx +.loop + xor eax,eax + mov al,[SnowData+edx*4+3] + mov ebx,eax + shl eax,8 + shl ebx,5 + add eax,ebx + xor ebx,ebx + mov bl,[SnowData+edx*4+1] + add eax,ebx + add eax,16 + mov bl,[SnowVelDist+edx*2] + and bl,03h + add bl,228 + test byte[SnowVelDist+edx*2],8 + jz .nosnow + mov byte[esi+eax],bl +.nosnow + inc edx + loop .loop + ; Change Snow Displacement Values +.next + cmp dword[SnowMover],0 + je .nomore + call ProcessSnowVelocity + dec dword[SnowMover] + jmp .next +.nomore + ret + +.giftmsg db 'A GIFT TO YOU IN THE OPTIONS!',0 + +ProcessSnowVelocity: + cmp dword[MsgGiftLeft],0 + je .nodec + dec dword[MsgGiftLeft] +.nodec + cmp dword[NumSnow],200 + jne .snowincr + cmp dword[SantaNextT],0 + je .skip + dec dword[SantaNextT] + jmp .notsreset +.skip + dec dword[SantaPos] + cmp dword[SantaPos],0 + jne .notsreset + mov dword[SantaPos],272 + mov dword[SantaNextT],36*60 + jmp .notsreset +.snowincr + dec dword[SnowTimer] + jnz .notsreset + inc dword[NumSnow] + mov dword[SnowTimer],18 +.notsreset + + mov ecx,[NumSnow] + cmp ecx,0 + jne .okay + ret +.okay + xor edx,edx +.loop + xor eax,eax + mov al,[SnowVelDist+edx*2] + mov ebx,100 + sub bl,[MusicRelVol] + add bx,bx + add ax,bx + add ax,bx + add word[SnowData+edx*4],ax + xor eax,eax + mov al,[SnowVelDist+edx*2+1] + add ax,256 + add word[SnowData+edx*4+2],ax + cmp word[SnowData+edx*4+2],200h + ja .nosdata + or byte[SnowVelDist+edx*2],8 +.nosdata + inc edx + loop .loop + ret + +OkaySC db 0 +cstempfname db 'tmpchtsr.___',0 + + +NEWSYM SaveSramData + ; save sram + cmp byte[sramsavedis],1 + je .nosram + cmp dword[ramsize],0 + je .nosram + clim + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + xor esi,esi + xor edi,edi + mov edx,fnames+1 + call Create_File + jc .failed + mov bx,ax + mov ecx,[ramsize] + mov edx,[sram] + call Write_File + call Close_File +.failed + stim +.nosram + call SaveCombFile + ret + +NEWSYM ProcRewind + mov eax,KeyRewind + add eax,4 + mov ebx,8 +.loop + cmp byte[eax],'a' + jb .b + cmp byte[eax],'z' + ja .b + sub byte[eax],'a'-'A' +.b + inc eax + dec ebx + jnz .loop + sub eax,8 + ; 90,83,75,78,73,71 + mov dword[.temp],44*65536*256+24*65536+72*256+40 + mov word[.temp+4],41*256+50 + add dword[.temp],34*65536*256+51*65536+11*256+50 + add word[.temp+4],30*256+23 + call .c + ; 95,68,69,77,79,95 + mov dword[.temp],25*65536*256+29*65536+31*256+62 + mov word[.temp+4],43*256+18 + add dword[.temp],52*65536*256+40*65536+37*256+33 + add word[.temp+4],52*256+61 + call .c + ; 80,72,65,82,79,83 + mov dword[.temp],11*65536*256+33*65536+24*256+35 + mov word[.temp+4],52*256+30 + add dword[.temp],71*65536*256+32*65536+48*256+45 + add word[.temp+4],31*256+49 + call .c + ret +.c + mov ebx,[.temp] + cmp [eax],ebx + jne .noteq + mov bx,[.temp+4] + cmp [eax+4],bx + jne .noteq + mov dword[eax],0 + mov dword[eax+4],0 + mov dword[eax+8],0 +.noteq + ret +.temp dd 0,0 + +%macro ProcessOneDigit 1 + cmp dl,9 + jbe %%notover + add dl,65-48-10 +%%notover + add dl,48 + mov byte[.message+%1],dl + xor edx,edx + div ebx +%endmacro + +NEWSYM TestSent + mov eax,[NetSent] + xor edx,edx + mov ebx,16 + div ebx + ProcessOneDigit 3 + ProcessOneDigit 2 + ProcessOneDigit 1 + ProcessOneDigit 0 + + mov eax,[valuea] + xor edx,edx + mov ebx,16 + div ebx + ProcessOneDigit 8 + ProcessOneDigit 7 + ProcessOneDigit 6 + ProcessOneDigit 5 + + mov dword[GUICMessage],.message + mov dword[GUICTimer],100000 + ret +.message db 0,0,0,0,' ',0,0,0,0,0,0,0 + + +NEWSYM StartGUI + cmp byte[OSPort],1 + jbe .dosport + mov byte[sampratenext+3],0 +.dosport + mov ecx,64 + mov eax,SpecialLine +.slloop + mov dword[eax],0 + add eax,4 + loop .slloop + ; Change GUI to suit the Win32 port + cmp byte[OSPort],3 + jne .nowinport + mov dword[GUIGUIOptnsText8+12],' GUI' + mov byte[GUIGUIOptnsText8+16],0 +.nowinport + cmp byte[OldWinPos],0 + jne .okayow + xor esi,esi + mov ecx,17 +.nextow + mov eax,[GUIwinposx2+esi*4] + mov [GUIwinposx+esi*4],eax + mov eax,[GUIwinposy2+esi*4] + mov [GUIwinposy+esi*4],eax + inc esi + loop .nextow + mov byte[OldWinPos],1 + mov eax,[pl1p209b] + mov [pl1p209],eax +.okayow + + mov al,[OSPort] + mov [GOSPort],al + cmp byte[GOSPort],3 + jne .notwinport + mov dword[GUINetPlayMenuData+1],'INTE' + mov dword[GUINetPlayMenuData+5],'RNET' + mov dword[GUINetPlayMenuData+1+14],'----' + mov dword[GUINetPlayMenuData+5+14],'----' + mov byte[MenuDat5],0 + mov byte[MenuDat5+1],2 +.notwinport + ; copy old quickfilename to new quickfilename + cmp byte[prevloadl],0 + jne .noconvertlfqm + mov byte[prevloadl],1 + mov ecx,10 + xor edx,edx +.convlfnlp + mov eax,ecx + dec eax + mov edx,eax + shl eax,9 + shl edx,4 + mov bl,16 +.convlfnlp2 + mov bh,[prevloadfname+edx] + mov [prevloadfnamel+eax],bh + inc edx + inc eax + dec bl + jnz .convlfnlp2 + mov eax,ecx + dec eax + mov edx,eax + shl eax,9 + shl edx,7 + mov bl,128 +.convlfnlp2b + mov bh,[prevloaddname+edx] + mov [prevloaddnamel+eax],bh + inc edx + inc eax + dec bl + jnz .convlfnlp2b + loop .convlfnlp +.noconvertlfqm + + mov byte[GUIOn],1 + mov byte[GUIOn2],1 + mov eax,[NumComboLocl] + cmp byte[GUIComboGameSpec],0 + jne .local + mov eax,[NumComboGlob] +.local + mov [NumCombo],eax + call ResetTripleBuf + + cmp dword[GUIwinposx+16*4],0 + jne .notzero + mov dword[GUIwinposx+16*4],3 + mov dword[GUIwinposy+16*4],22 +.notzero + xor ecx,ecx +.joysloop + cmp dword[pl1ULk+ecx*4],80h + jbe .nojoystick + mov dword[pl1ULk+ecx*4],0 +.nojoystick + inc ecx + cmp ecx,16 + jne .joysloop + + mov dword[GUICTimer],0 + cmp byte[OldVolume],1 + jne .notold + mov byte[OldVolume],0 + mov byte[MusicRelVol],100 + mov byte[cfgvolume],100 + ; Initialize volume + xor eax,eax + xor edx,edx + mov al,[MusicRelVol] + shl eax,7 + mov ebx,100 + div ebx + cmp al,127 + jb .noofb + mov al,127 +.noofb + mov [MusicVol],al +.notold + mov byte[CheatSearchStatus],0 + cmp byte[newgfx16b],0 + je .nong + mov ecx,255*296 + mov eax,[vidbufferofsb] +.loop + mov dword[eax],0 + add eax,4 + loop .loop +.nong + mov byte[ShowTimer],1 + call Get_Date + cmp dh,12 + jne .noxmas + cmp dl,25 + jne .noxmas + mov byte[OkaySC],1 +.noxmas + mov byte[lastmouseholded],1 + mov eax,[welcome+8] + mov [GUIGUIAboutText1+8],eax + mov al,[welcome+12] + mov [GUIGUIAboutText1+12],al + mov al,[welcome+7] + mov [GUIGUIAboutText1+7],al + cmp dword[GUIwinposx+15*4],0 + jne .nomoviemenufix + mov dword[GUIwinposx+15*4],50 + mov dword[GUIwinposy+15*4],50 +.nomoviemenufix + mov ax,[resolutn] + mov [PrevResoln],ax + mov word[resolutn],224 + + mov byte[GUIPalConv],0 + mov byte[GUIGUIAboutText1],'Z'-86 + add byte[GUIGUIAboutText1],86 + mov byte[GUIGUIAboutText1+3],'E'-89 + add byte[GUIGUIAboutText1+3],89 + mov byte[MousePRClick],1 + + pushad + cmp byte[MouseInitOkay],1 + je near .mousedone + mov byte[MouseInitOkay],1 + cmp byte[MouseDis],1 + je .mousedone + call Init_Mouse + cmp ax,0 + jne .mousedone + mov byte[MouseDis],1 +.mousedone + popad + + mov eax,[KeyQuickLoad] + test byte[pressed+eax],1 + jz near .noquickload + mov byte[GUIcmenupos],2 + loadmenuopen 1 +.noquickload + mov esi,pressed + mov ecx,64+32+8 +.pclear + mov dword[esi],0 + add esi,4 + loop .pclear + mov byte[pressed+1],2 + mov byte[GUIescpress],1 + + ; set Video cursor location + xor eax,eax + mov al,[cvidmode] + mov [GUIcurrentvideocursloc],eax + mov ebx,[NumVideoModes] + sub ebx,5 + cmp eax,ebx + jbe .noof + mov eax,ebx +.noof + mov [GUIcurrentvideoviewloc],eax + + ; change to sram dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + call SaveSramData + + cmp byte[SFXSRAM],0 + je .nosfxsram + clim + mov edx,fnames+1 + call Create_File + jc .nosfxramwrite + mov bx,ax + mov ecx,65536 + mov edx,[sfxramdata] + call Write_File + call Close_File +.nosfxramwrite + stim +.nosfxsram + call GUIQuickLoadUpdate + call LoadDetermine + ; change dir to LoadDrive/LoadDir + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir + + cmp byte[NetFilename],0 + je near .nofilenamenet + cmp byte[NetChatFirst],0 + je near .filenamenetb + mov ebx,NetFilename + xor ecx,ecx +.fnetloop + cmp byte[ebx],'\' + jne .fnetloopb + mov ecx,ebx +.fnetloopb + inc ebx + cmp byte[ebx],0 + jne .fnetloop + or ecx,ecx + jz near .nofilenamenet + mov byte[ecx],0 + push ecx + mov dl,[LoadDrive] + cmp byte[NetFilename+1],':' + jne .nodrivenetb + mov dl,[NetFilename] + sub dl,'A' +.nodrivenetb + mov ebx,NetFilename + call Change_Dir + pop ecx + mov ebx,NetFilename + inc ecx +.nextnetl + mov al,[ecx] + mov [ebx],al + inc ecx + inc ebx + or al,al + jnz .nextnetl + jmp .nofilenamenet +.filenamenetb + mov dl,[LoadDrive] + cmp byte[NetFilename+1],':' + jne .nodrivenet + mov dl,[NetFilename] + sub dl,'A' +.nodrivenet + mov ebx,NetFilename + call Change_Dir + mov byte[NetFilename],0 +.nofilenamenet + cmp byte[NetServer],0 + je .noserverclient + mov byte[CNetType],15 + mov byte[ModemProcess],40 + cmp byte[NetServer],2 + jne .noclient + mov byte[ModemProcess],41 +.noclient + mov byte[NetServer],0 + mov byte[WhichRemote],4 + mov byte[GUIcmenupos],0 + mov byte[GUIcrowpos],0 + call loadnetopen +.noserverclient + cmp byte[NetNewNick],0 + je .nonewnick + mov ebx,NetNewNick + mov ecx,ChatNick +.nickloop + mov al,[ebx] + mov [ecx],al + inc ebx + inc ecx + or al,al + jnz .nickloop + mov byte[NetNewNick],0 +.nonewnick + +;NEWSYM NetChatFirst, db 0 +;NEWSYM NetServer, db 0 +;NEWSYM NetQuitAfter, db 0 +;NEWSYM NetNewNick, times 16 db 0 +;NEWSYM NetFilename, times 512 db 0 + + cmp byte[CNetType],20 + je near .noautostate + cmp byte[AutoState],0 + je .noautostate + cmp byte[romloadskip],0 + jne .noautostate + call SaveSecondState +.noautostate + + GUIInitIRQs + + cmp byte[CNetType],20 + jne near .nostat20 + test byte[NetQuit],80h + jnz near .nostat20 + mov byte[GUIcmenupos],0 + mov byte[GUIcrowpos],0 + call loadnetopen + cmp byte[WhichRemote],1 + jne .yesdcd + call ModemCheckDCD + cmp al,1 + jne near .nostat20 +.yesdcd + + mov byte[RestoreValues],1 + pushad + mov dword[CBackupPos],0 + call BackupCVFrame + popad + + call DisableSUDPPacket + call Wait1SecWin + ; sync + call PreparePacket + mov al,254 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,254 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,254 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,254 + call RemoteSendChar + call SendPacket + mov dword[ModemPTimer],4*32 +.nochar + pushad + call JoyRead + popad + call RemoteGetChar + cmp dword[ModemPTimer],0 + je near .nostat20 + cmp dh,0 + je .nochar + cmp dl,254 + jne .nochar + call PreparePacket + mov al,253 + call RemoteSendChar + call SendPacket +.nocharc + pushad + call JoyRead + popad + call RemoteGetChar + cmp dword[ModemPTimer],0 + je near .nostat20 + cmp dh,0 + je .nocharc + cmp dl,253 + jne .nocharc + call PreparePacket + mov al,1 + call RemoteSendChar + call SendPacket + call ClearUDPStuff + + mov byte[RemoteCommand],1 + mov byte[HoldCommand],1 + cmp byte[NetLoadState],1 + jne .notreceive + mov byte[CNetType],22 +.noreceivestate + pushad + call JoyRead + popad + call RemoteGetChar + cmp dh,0 + je .noreceivestate + cmp dl,14 + jne .noreceivestate + call loadstaterecvinit +.notreceive + cmp byte[NetLoadState],2 + jne .notsend + call NetLoadStuff +.notsend +.nostat20 + + cmp byte[GUIwinptr],0 + jne .nomenuopen + cmp byte[lastcursres],1 + je .nomenuchange + mov byte[GUIcmenupos],2 + mov byte[GUIcrowpos],0 + mov dword[GUICYLocPtr],MenuDat2 + cmp byte[lastcursres],0 + je .nomenuchange +.nomenuopen + mov byte[GUIcmenupos],0 +.nomenuchange + cmp byte[GUIwinactiv+1],0 + je .noloadrefresh + call GetLoadData +.noloadrefresh + mov byte[GUIHold],0 + ; clear 256 bytes from hirestiledat + mov esi,hirestiledat + mov ecx,256 +.loophires + mov byte[esi],0 + inc esi + dec ecx + jnz .loophires + mov byte[curblank],00h + call InitGUI + + cmp byte[CheatWinMode],0 + je near .csskip + ; change to sram dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + ; Load Cheat Search File + mov edx,cstempfname + call Open_File + jc .csskipb + mov bx,ax + mov edx,[vidbuffer] + add edx,129600 + mov ecx,65536*2+32768 + call Read_File + call Close_File + +.csskipb + ; change dir to LoadDrive/LoadDir + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir +.csskip + + mov byte[GUIQuit],0 +.nokey + cmp byte[CNetType],21 + je .noquit + cmp byte[CNetType],22 + jne .yesquit +.noquit + mov byte[GUIQuit],0 +.yesquit + cmp byte[GUIQuit],2 + je near .exit + cmp byte[GUIQuit],1 + je near .exitgui + mov byte[GUIQuit],0 + cmp byte[MouseDis],1 + je .mousedis2 + call ProcessMouse + cmp byte[videotroub],1 + jne .notrouble + ret +.notrouble +.mousedis2 + call GUIUnBuffer + cmp byte[CNetType],20 + je .nowater + cmp byte[CNetType],21 + je .nowater + cmp byte[CNetType],22 + je .nowater + cmp byte[GUIEffect],1 + jne .nosnow + call DrawSnow +.nosnow + cmp byte[GUIEffect],2 + jne .nowater + call DrawWater +.nowater +; call TestSent + cmp byte[CNetType],20 + jne .noreceive + + cmp byte[NetChatFirst],0 + je .noloadbeforechat + mov eax,NetFilename + call GUIloadfilename.nocnettype + mov byte[sramsavedis],1 + call transfersram + mov byte[NetChatFirst],0 +.noloadbeforechat + + cmp byte[GUIcmenupos],0 + jne .nomenuout2 + cmp byte[GUIwinptr],0 + jne .nomenuout2 + cmp byte[netlastloaded],1 + je .openmenu + mov byte[GUIcmenupos],2 + mov byte[GUIcrowpos],0 + jmp .nomenuout2 +.openmenu + mov byte[netlastloaded],0 + call loadnetopen +.nomenuout2 + call RemoteGetChar + cmp dh,0 + jne .received + mov dl,1 +.received + call ProcessRemoteCommand + jmp .noreceive2 +.noreceive + mov byte[HoldCommand],0 +.noreceive2 + + cmp byte[CNetType],21 + jne .noloadstatesend + call loadstatesend +.noloadstatesend + cmp byte[CNetType],22 + jne .noloadstaterecv + call loadstaterecv +.noloadstaterecv + + cmp byte[CNetType],15 + je .modem + cmp byte[CNetType],12 + je .modem + cmp byte[CNetType],11 + je .modem + cmp byte[CNetType],10 + jne near .nomodem +.modem + call ProcessModem + cmp byte[Connected],1 + je near .nomodem + call ModemGetChar + cmp dh,0 + je .nomodem + cmp byte[ModemOKStat],0 + jne .foundokay + mov byte[ModemOKStat],1 + jmp .skipstat +.foundokay + cmp byte[ModemOKStat],1 + jne .nostat0 + cmp dl,13 + jne .nostat0 + inc byte[ModemOKStat] + jmp .skipstat +.nostat0 + cmp byte[ModemOKStat],2 + jne .nostat1 + cmp dl,'O' + jne .nostat1 + inc byte[ModemOKStat] + jmp .skipstat +.nostat1 + cmp byte[ModemOKStat],3 + jne .nostat2 + cmp dl,'K' + jne .nostat2 + inc byte[ModemOKStat] + jmp .skipstat +.nostat2 +.skipstat + mov dh,0 + call NetAddChar +.nomodem + + cmp dword[GUIEditStringcWin],0 + je .noblink + cmp dword[GUIEditStringcLen],0 + je .noblink + mov eax,[GUIEditStringcLen] + cmp dword[GUIEditStringLTxt],8 + jb .noblinka + mov byte[eax],'_' + mov byte[eax+1],0 + mov dword[GUIEditStringLstb],1 +.noblinka + cmp dword[GUIEditStringLTxt],0 + jne .noblink + mov dword[GUIEditStringLTxt],16 +.noblink + + call DisplayBoxes + + cmp dword[GUIEditStringLstb],1 + jne .notblinked + mov dword[GUIEditStringLstb],0 + mov eax,[GUIEditStringcLen] + mov byte[eax],0 +.notblinked + + call DisplayMenu + cmp byte[MouseDis],1 + je .mousedis3 + call DrawMouse +.mousedis3 + cmp byte[FirstTimeData],0 + jne .nofirsttime + call guifirsttimemsg + mov byte[FirstTimeData],1 +.nofirsttime + cmp dword[GUICTimer],0 + je .notimer + GUIOuttext 21,211,[GUICMessage],50 + GUIOuttext 20,210,[GUICMessage],63 +.notimer + call vidpastecopyscr + call GUIgetcurrentinput + jmp .nokey + +.exitgui + cmp byte[CNetType],20 + jne near .nostat20b2 + call PreparePacket + mov al,255 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,255 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,255 + call RemoteSendChar + call SendPacket +.nostat20b2 + + GUIDeInitIRQs + + mov ax,[PrevResoln] + mov [resolutn],ax + jmp endprog +.exit + mov edi,[spcBuffera] + mov ecx,65536 + xor eax,eax + rep stosd + mov edi,spcRamcmp + mov ecx,65536/4 + xor eax,eax + rep stosd + GUIDeInitIRQs + call ClearScreen + cmp byte[cbitmode],0 + jne .nomakepal + call makepal +.nomakepal + mov word[t1cc],1 + + mov byte[chaton],0 + mov dword[chatstrL],0 + mov dword[chatLpos],0 + mov dword[chatstrR],0 + mov dword[chatRTL],0 + + cmp byte[CNetType],20 + jne near .nostat20b + + mov al,10 + sub al,[Latency] + cmp byte[Latency],4 + jb .nolatency + mov al,7 +.nolatency + mov [BackStateSize],al + + call ResetExecStuff + + mov byte[MultiTap],1 + cmp byte[pl3neten],0 + jne .mtap + cmp byte[pl4neten],0 + jne .mtap + cmp byte[pl5neten],0 + jne .mtap +.nomtap + mov byte[MultiTap],0 +.mtap + + cmp byte[RestoreValues],1 + jne .norestoreval + pushad + mov dword[PBackupPos],0 + call RestoreCVFrame + popad +.norestoreval + + mov dword[nmiprevaddrl],0 + mov dword[nmiprevaddrh],0 + mov dword[nmirept],0 + mov dword[nmiprevline],224 + mov dword[nmistatus],0 + mov byte[spcnumread],0 + mov byte[NextLineCache],0 + mov byte[DSPMem+08h],0 + mov byte[DSPMem+18h],0 + mov byte[DSPMem+28h],0 + mov byte[DSPMem+38h],0 + mov byte[DSPMem+48h],0 + mov byte[DSPMem+58h],0 + mov byte[DSPMem+68h],0 + mov byte[DSPMem+78h],0 + + + mov byte[netdelayed],0 + mov dword[cnetptrhead],0 + mov dword[cnetptrtail],0 + mov dword[prevp1net],0 + mov dword[prevp2net],0 + mov dword[prevp3net],0 + mov dword[prevp4net],0 + mov dword[prevp5net],0 + mov byte[BackState],1 + mov dword[CBackupPos],0 + mov dword[PBackupPos],0 + mov dword[PPValue],0 + mov dword[DPValue],0 + mov byte[CurRecv],0 + mov dword[NetQuitter],0 + mov dword[LatencyV],0 + mov dword[LatencyV+4],0 + mov dword[LatencyV+8],0 + mov dword[LatencyV+12],0 + mov dword[LatencyRecvPtr],0 + mov dword[LatencySendPtr],0 + + mov eax,cnetplaybuf + mov ecx,512 +.loop20 + mov byte[eax],0 + inc eax + loop .loop20 + mov al,[Latency] + mov [LatencyLeft],al + mov byte[NetSwap],0 + + mov dword[CBackupPos],0 + mov dword[PBackupPos],0 + + + mov ebx,[romdata] + mov ecx,[NumofBanks] + shl ecx,15 + xor eax,eax + or ecx,ecx + jz .nocsumloop +.csumloop + add al,[ebx] + adc ah,0 + inc ebx + loop .csumloop +.nocsumloop + mov [CheckSumVal],eax + + mov ebx,eax + ; sync with modem + call PreparePacket + mov al,30 + call RemoteSendChar + mov al,230 + call RemoteSendChar + mov al,[CheckSumVal] + call RemoteSendChar + mov al,[CheckSumVal+1] + call RemoteSendChar + call SendPacket +.nocharb + pushad + call JoyRead + popad +; cmp byte[pressed+1],1 +; je near .faileda + + call RemoteGetChar + cmp dh,0 + je .nocharb + cmp dl,230 + jne .nocharb +.nocharb2 + call RemoteGetChar + cmp dh,0 + je .nocharb2 + cmp dl,[CheckSumVal] + jne .wrongcs +.nocharb3 + call RemoteGetChar + cmp dh,0 + je .nocharb3 + cmp dl,[CheckSumVal+1] + je .okaychat +.wrongcs + mov esi,WrongCheckSum + call WritetochatBuffer + jmp StartGUI +.okaychat + call PreparePacket + mov al,229 + call RemoteSendChar + call SendPacket +.nocharb5 + pushad + call JoyRead + popad +; cmp byte[pressed+1],1 +; je near .failedb + + call RemoteGetChar + cmp dh,0 + je .nocharb5 + cmp dl,229 + jne .nocharb5 +.nostat20b + call EnableSUDPPacket + + mov byte[ChatProgress],0 + mov dword[RecvProgress],0 + + ; get LoadDrive/LoadDir + mov ebx,LoadDir + mov edx,LoadDrive + call Get_Dir + + ; change dir to InitDrive/InitDir + mov dl,[InitDrive] + mov ebx,InitDir + ; save config + call Change_Dir + call createnewcfg + call GUISaveVars + + ; change dir to SRAMDrive/SRAMDir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + mov byte[MousePRClick],1 + mov byte[prevbright],0 + mov ax,[PrevResoln] + mov [resolutn],ax + + mov byte[CheatOn],0 + cmp dword[NumCheats],0 + je .nocheats + mov byte[CheatOn],1 +.nocheats + + cmp byte[CopyRamToggle],1 + jne .nocopyram + mov byte[CopyRamToggle],0 + mov eax,dword[vidbuffer] + add eax,129600 + ; copy 128k ram + mov ebx,[wramdata] + mov ecx,32768 +.loopcr + mov edx,[ebx] + mov [eax],edx + add ebx,4 + add eax,4 + loop .loopcr +.nocopyram + + cmp byte[CheatWinMode],2 + jne .notview + mov byte[CheatWinMode],1 +.notview + + cmp byte[CheatWinMode],0 + je .csskip2 + ; Save Cheat Search File + mov edx,cstempfname + call Create_File + jc .csskip2 + mov bx,ax + mov edx,[vidbuffer] + add edx,129600 + mov ecx,65536*2+32768 + call Write_File + call Close_File +.csskip2 + + mov edi,[vidbuffer] + mov ecx,288*120 + xor eax,eax + rep stosd + + mov ecx,256*296 + mov eax,[vidbufferofsb] +.loopcl + mov dword[eax],0 + add eax,4 + loop .loopcl + + mov al,[cfgsoundon] + mov [soundon],al + mov al,[cfgStereoSound] + mov [StereoSound],al + mov al,[cfgSoundQuality] + mov [SoundQuality],al + call AdjustFrequency + mov byte[GUIOn],0 + mov byte[GUIOn2],0 + mov dword[StartLL],0 + mov dword[StartLR],0 + mov byte[NetLoadState],0 + jmp continueprog + +.faileda + call WinErrorA + jmp continueprog +.failedb + call WinErrorB + jmp continueprog + +CheckSumVal dd 0 +WrongCheckSum db 10,13,'ROM Data Mismatch',10,13,10,13,0 + + +SRAMDirc: + ; get LoadDrive/LoadDir + mov ebx,LoadDir + mov edx,LoadDrive + call Get_Dir + ; change to sram dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + ret + +LOADDir: + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir + ret + +guifirsttimemsg: + xor ebx,ebx + mov ecx,256 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + mov byte[pressed+2Ch],0 +.again + GUIBox 43,75,213,163,160 + GUIBox 43,75,213,75,162 + GUIBox 43,75,43,163,161 + GUIBox 213,75,213,163,159 + GUIBox 43,163,213,163,158 + GUIOuttext 56,81,guiftimemsg1,220-15 + GUIOuttext 55,80,guiftimemsg1,220 + GUIOuttext 56,96,guiftimemsg2,220-15 + GUIOuttext 55,95,guiftimemsg2,220 + GUIOuttext 56,104,guiftimemsg3,220-15 + GUIOuttext 55,103,guiftimemsg3,220 + GUIOuttext 56,112,guiftimemsg4,220-15 + GUIOuttext 55,111,guiftimemsg4,220 + GUIOuttext 56,120,guiftimemsg5,220-15 + GUIOuttext 55,119,guiftimemsg5,220 + GUIOuttext 56,128,guiftimemsg6,220-15 + GUIOuttext 55,127,guiftimemsg6,220 + GUIOuttext 56,136,guiftimemsg7,220-15 + GUIOuttext 55,135,guiftimemsg7,220 + GUIOuttext 56,151,guiftimemsg8,220-15 + GUIOuttext 55,150,guiftimemsg8,220 + call vidpastecopyscr + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + call JoyRead + cmp byte[pressed+2Ch],0 + jne .pressedokay + jmp .again +.pressedokay +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey + cmp byte[MouseDis],1 + je .mousedis2 + push ebx +; mov eax,0Bh +; int 33h + pop ebx +.mousedis2 + ret + +guiftimemsg1 db 'ONE TIME USER REMINDER :',0 +guiftimemsg2 db 'PLEASE BE SURE TO READ',0 +guiftimemsg3 db 'GUINOTES.TXT FOR AN',0 +guiftimemsg4 db 'IMPORTANT REMINDER.',0 +guiftimemsg5 db 'ALSO, WHENEVER YOU HAVE',0 +guiftimemsg6 db 'PROBLEMS, BE SURE TO READ',0 +guiftimemsg7 db 'ZSNES.FAQ AND README.TXT',0 +guiftimemsg8 db 'PRESS "Z" TO CONTINUE.',0 + +guiprevideo: + xor ebx,ebx + mov ecx,256 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 43,90,213,163,160 + GUIBox 43,90,213,90,162 + GUIBox 43,90,43,163,161 + GUIBox 213,90,213,163,159 + GUIBox 43,163,213,163,158 + GUIOuttext 56,96,guiprevidmsg1,220-15 + GUIOuttext 55,95,guiprevidmsg1,220 + GUIOuttext 56,104,guiprevidmsg2,220-15 + GUIOuttext 55,103,guiprevidmsg2,220 + GUIOuttext 56,112,guiprevidmsg3,220-15 + GUIOuttext 55,111,guiprevidmsg3,220 + GUIOuttext 56,120,guiprevidmsg4,220-15 + GUIOuttext 55,119,guiprevidmsg4,220 + GUIOuttext 56,128,guiprevidmsg5,220-15 + GUIOuttext 55,127,guiprevidmsg5,220 + GUIOuttext 56,136,guiprevidmsg6,220-15 + GUIOuttext 55,135,guiprevidmsg6,220 + GUIOuttext 56,151,guiprevidmsg7,220-15 + GUIOuttext 55,150,guiprevidmsg7,220 + call vidpastecopyscr + mov byte[pressed+2Ch],0 +.again + call JoyRead + xor ebx,ebx + mov ecx,256+128+64 +.b + cmp byte[pressed+ebx],0 + jne .pressedokay + inc ebx + loop .b + cmp byte[MouseDis],1 + je .mousedis + call Get_MouseData + test bx,01h + jnz .pressedokay +.mousedis + jmp .again +.pressedokay +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey + cmp byte[MouseDis],1 + je .mousedis2 + push ebx +; mov eax,0Bh +; int 33h + pop ebx +.mousedis2 + ret + +guiprevidmsg1 db 'ZSNES WILL NOW ATTEMPT',0 +guiprevidmsg2 db 'TO CHANGE YOUR VIDEO',0 +guiprevidmsg3 db 'MODE. IF THE CHANGE',0 +guiprevidmsg4 db 'IS UNSUCCESSFUL, WAIT',0 +guiprevidmsg5 db '10 SECONDS AND VIDEO',0 +guiprevidmsg6 db 'MODE WILL BE RESET',0 +guiprevidmsg7 db 'PRESS ANY KEY',0 + +guipostvideo: + xor ebx,ebx + mov ecx,256 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + mov dword[GUIkeydelay],36*10 + +.pressedfail + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 43,90,213,163,160 + GUIBox 43,90,213,90,162 + GUIBox 43,90,43,163,161 + GUIBox 213,90,213,163,159 + GUIBox 43,163,213,163,158 + GUIOuttext 56,96,guipostvidmsg1,220-15 + GUIOuttext 55,95,guipostvidmsg1,220 + GUIOuttext 56,151,guipostvidmsg2,220-15 + GUIOuttext 55,150,guipostvidmsg2,220 + call vidpastecopyscr + ; Wait for all mouse and input data to be 0 + + call JoyRead + xor ebx,ebx + mov ecx,256+128+64 +.b2 + cmp byte[pressed+ebx],0 + jne near .pressedfail + inc ebx + loop .b2 + cmp byte[MouseDis],1 + je .mousedis3 + call Get_MouseData + test bx,01h + jnz near .pressedfail +.mousedis3 + +.again + call JoyRead + xor ebx,ebx + mov ecx,256+128+64 +.b + cmp byte[pressed+ebx],0 + jne .pressedokay + inc ebx + loop .b + cmp byte[MouseDis],1 + je .mousedis + call Get_MouseData + test bx,01h + jnz .pressedokay +.mousedis + cmp dword[GUIkeydelay],0 + je .pressedokay + jmp .again +.pressedokay +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey + cmp byte[MouseDis],1 + je .mousedis2 + push ebx +; mov eax,0Bh +; int 33h + pop ebx +.mousedis2 + mov byte[GUIpclicked],1 + ret + +guipostvidmsg1 db 'VIDEO MODE CHANGED.',0 +guipostvidmsg2 db 'PRESS ANY KEY',0 + + +guipostvideofail: + mov dword[guipostvidptr],guipostvidmsg3b + mov byte[guipostvidmsg3b],0 + mov byte[guipostvidmsg4b],0 + mov byte[guipostvidmsg5b],0 + mov eax,[ErrorPointer] + mov ebx,eax +.loop + cmp byte[ebx],0 + je .found + cmp byte[ebx],'$' + je .found + inc ebx + jmp .loop +.found + mov edx,ebx + sub edx,eax +.detnext + or edx,edx + jz .notext + cmp edx,25 + jbe .copytext +.nospace + dec edx + cmp byte[eax+edx],32 + jne .nospace + jmp .detnext +.copytext + push ebx + mov ecx,[guipostvidptr] +.copytextloop + mov bl,[eax] + cmp bl,'$' + jne .notdol + mov bl,0 +.notdol + mov [ecx],bl + inc eax + inc ecx + dec edx + jnz .copytextloop + mov byte[ecx],0 + pop ebx + add dword[guipostvidptr],26 + cmp byte[eax],0 + je .notext + cmp byte[eax],'$' + je .notext + inc eax + jmp .found +.notext + + xor ebx,ebx + mov ecx,256 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 43,90,213,163,160 + GUIBox 43,90,213,90,162 + GUIBox 43,90,43,163,161 + GUIBox 213,90,213,163,159 + GUIBox 43,163,213,163,158 + GUIOuttext 56,96,guipostvidmsg1b,220-15 + GUIOuttext 55,95,guipostvidmsg1b,220 + GUIOuttext 56,108,guipostvidmsg2b,220-15 + GUIOuttext 55,107,guipostvidmsg2b,220 + GUIOuttext 56,119,guipostvidmsg3b,220-15 + GUIOuttext 55,118,guipostvidmsg3b,220 + GUIOuttext 56,129,guipostvidmsg4b,220-15 + GUIOuttext 55,128,guipostvidmsg4b,220 + GUIOuttext 56,139,guipostvidmsg5b,220-15 + GUIOuttext 55,138,guipostvidmsg5b,220 + GUIOuttext 56,152,guipostvidmsg8b,220-15 + GUIOuttext 55,151,guipostvidmsg8b,220 + call vidpastecopyscr + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + mov dword[GUIkeydelay],0FFFFFFFFh + jmp guipostvideo.pressedfail + +guipostvidmsg1b db 'VIDEO MODE CHANGE FAILED.',0 +guipostvidmsg2b db 'UNABLE TO INIT VESA2:',0 +guipostvidmsg3b db 'AAAAAAAAAAAAAAAAAAAAAAAAA',0 +guipostvidmsg4b db 'AAAAAAAAAAAAAAAAAAAAAAAAA',0 +guipostvidmsg5b db 'AAAAAAAAAAAAAAAAAAAAAAAAA',0 +guipostvidmsg8b db 'PRESS ANY KEY',0 +guipostvidptr dd 0 + +GUILoadManualDir + mov ebx,GUILoadTextA + mov [ManualCPtr],ebx + cmp byte[ebx],0 + je near .nofindfile + xor eax,eax +.next + cmp byte[ebx],':' + jne .nocolon + mov eax,ebx +.nocolon + inc ebx + cmp byte[ebx],0 + jne .next + or eax,eax + jz .nomorecolon + cmp eax,GUILoadTextA + je .invalidcolon + mov bl,[eax-1] + cmp bl,'a' + jb .nolower + cmp bl,'z' + ja .nolower + sub bl,'a'-'A' +.nolower + cmp bl,'A' + jb .invalidcolon + cmp bl,'Z' + ja .invalidcolon + sub bl,'A' + mov dl,bl + push eax + call Change_Drive + pop eax + mov byte[ManualStatus],1 +.invalidcolon + inc eax + mov [ManualCPtr],eax +.nomorecolon + mov ebx,[ManualCPtr] + cmp byte[ebx],0 + je near .finish + xor eax,eax +.next2 + cmp byte[ebx],'\' + jne .nobackslash + mov eax,ebx +.nobackslash + inc ebx + cmp byte[ebx],0 + jne .next2 + or eax,eax + jz .finish + inc eax + mov cl,[eax] + mov byte[eax],0 + push ecx + push eax + mov edx,[ManualCPtr] + call Change_Single_Dir + jc .nosuchdir + mov byte[ManualStatus],1 +.nosuchdir + pop eax + pop ecx + mov [eax],cl + mov [ManualCPtr],eax +.finish + mov edx,[ManualCPtr] + call Change_Single_Dir + jc .notdir + mov byte[ManualStatus],1 + jmp .nomoredir +.notdir + call .nomoredir + mov edx,[ManualCPtr] + cmp byte[edx],0 + je .nofindfile + ; otherwise set ManualStatus to 2 + mov byte[ManualStatus],2 + mov dword[GUIcurrentfilewin],0 +.nofindfile + ret +.nomoredir + ; refresh dir if necessary + cmp byte[ManualStatus],1 + jne .norefresh + call GetLoadData.a +.norefresh + ret + +ManualCPtr dd 0 +ManualStatus db 0 + + +NEWSYM MovieCounter, dd 0 + +UnableMovie2 db 'MUST PLAY WITH SOUND OFF',0 +UnableMovie3 db 'MUST PLAY WITH SOUND ON',0 + +MoviePlay: + cmp byte[CNetType],20 + je near .dontplay + mov byte[GUICBHold],0 + mov dword[MovieCounter],0 + cmp byte[MovieProcessing],0 + jne near .dontplay + mov byte[GUIQuit],2 + mov ebx,[statefileloc] + mov eax,[fnamest+ebx-3] + push eax + mov dword[fnamest+ebx-3],'.ZMV' + mov al,[CMovieExt] + mov byte[fnamest+ebx],al + call ChangetoSRAMdir + mov dword[Totalbyteloaded],0 + call loadstate2 + mov edx,fnamest+1 + call Open_File + jc near .notexist + mov bx,ax + mov [MovieFileHand],bx + mov cx,[Totalbyteloaded+2] + mov dx,[Totalbyteloaded] + call File_Seek + mov edx,RecData + mov ecx,16 + call Read_File + cmp byte[RecData+2],1 + jne .noextra + mov eax,[RecData+3] + mov [timer2upd],eax + mov eax,[RecData+7] + mov [curexecstate],eax + mov dword[nmiprevaddrl],0 + mov dword[nmiprevaddrh],0 + mov dword[nmirept],0 + mov dword[nmiprevline],224 + mov dword[nmistatus],0 + mov byte[spcnumread],0 + mov byte[NextLineCache],0 +.noextra + mov al,[RecData] + cmp al,[soundon] + jne near .soundisoff + cmp dword[ramsize],0 + je .noram + mov edx,[sram] + mov ecx,[ramsize] + call Read_File +.noram + mov byte[MovieProcessing],1 +.skip + mov dword[PJoyAOrig],0 + mov dword[PJoyBOrig],0 + mov dword[PJoyCOrig],0 + mov dword[PJoyDOrig],0 + mov dword[PJoyEOrig],0 + mov byte[sramsavedis],1 + mov byte[UseRemoteSRAMData],0 + mov byte[DSPMem+08h],0 + mov byte[DSPMem+18h],0 + mov byte[DSPMem+28h],0 + mov byte[DSPMem+38h],0 + mov byte[DSPMem+48h],0 + mov byte[DSPMem+58h],0 + mov byte[DSPMem+68h],0 + mov byte[DSPMem+78h],0 +.notexist + call ChangetoLOADdir + pop eax + mov ebx,[statefileloc] + mov [fnamest+ebx-3],eax +.dontplay + ret +.soundisoff + mov dword[Msgptr],UnableMovie2 + cmp byte[soundon],0 + jne .soundon + mov dword[Msgptr],UnableMovie3 +.soundon + mov eax,[MsgCount] + mov [MessageOn],eax + call Close_File + pop eax + ret + +NEWSYM Totalbyteloaded, dd 0 +NEWSYM sramsavedis, db 0 + + +DevicePtr dd pl1selk,pl2selk,pl3selk,pl4selk,pl5selk + +CheckMenuItemHelp: + mov al,[GUIcmenupos] + mov [GUIpmenupos],al + mov byte[GUIcmenupos],0 + cmp byte[GUIwinactiv+edx],1 + je .menuontop + xor eax,eax + mov al,[GUIwinptr] + inc byte[GUIwinptr] + mov byte[GUIwinorder+eax],dl + mov byte[GUIwinactiv+edx],1 + cmp byte[resetposn],1 + jne .nomenuitem + mov eax,[GUIwinposxo+edx*4] + mov [GUIwinposx+edx*4],eax + mov eax,[GUIwinposyo+edx*4] + mov [GUIwinposy+edx*4],eax + jmp .nomenuitem +.menuontop + xor eax,eax + ; look for match +.notfoundyet + mov bl,byte[GUIwinorder+eax] + cmp bl,dl + je .nextfind + inc eax + jmp .notfoundyet +.nextfind + inc eax + cmp al,[GUIwinptr] + je .foundend + mov cl,[GUIwinorder+eax] + mov [GUIwinorder+eax-1],cl + jmp .nextfind +.foundend + mov byte[GUIpclicked],0 + mov [GUIwinorder+eax-1],bl +.nomenuitem + ret + +%macro GUICheckMenuItem 2 + mov edx,%1 + cmp byte[GUIcrowpos],%2 + jne near %%nomenuitem + call CheckMenuItemHelp +%%nomenuitem +%endmacro + +%macro checkqloadvalue 1 + cmp byte[GUIcrowpos],%1 + jne %%skip + mov esi,prevloaddnamel+%1*512 + cmp byte[esi+1],0 + je %%notvalid + mov edi,prevloadfnamel+%1*512 + mov ebx,prevloadnames+%1*16 + mov ecx,%1 + call loadquickfname +%%notvalid + ret +%%skip +%endmacro + +GUITryMenuItem: + cmp byte[GUIcmenupos],1 + jne near .noquickload + checkqloadvalue 0 + checkqloadvalue 1 + checkqloadvalue 2 + checkqloadvalue 3 + checkqloadvalue 4 + checkqloadvalue 5 + checkqloadvalue 6 + checkqloadvalue 7 + checkqloadvalue 8 + checkqloadvalue 9 + cmp byte[GUIcrowpos],11 + jne .skipswitch + xor byte[prevlfreeze],1 + cmp byte[prevlfreeze],0 + je .off + mov byte[GUIPrevMenuData.onoff+15],'O' + mov byte[GUIPrevMenuData.onoff+15],'N' + mov byte[GUIPrevMenuData.onoff+16],' ' + jmp .on +.off + mov byte[GUIPrevMenuData.onoff+14],'O' + mov byte[GUIPrevMenuData.onoff+15],'F' + mov byte[GUIPrevMenuData.onoff+16],'F' +.on +.skipswitch + cmp byte[GUIcrowpos],12 + jne .skipclear + cmp byte[prevlfreeze],0 + jne .skipclear + mov edi,prevloadnames + mov eax,20202020h + mov ecx,4*10 + rep stosd + mov edi,prevloaddnamel + xor eax,eax + mov ecx,128*10 + rep stosd + mov edi,prevloadfnamel + mov eax,0 ;20202020h + mov ecx,128*10 + rep stosd + call GUIQuickLoadUpdate + ret +.skipclear +.noquickload + cmp byte[GUIcmenupos],2 + jne near .nomain + GUICheckMenuItem 1, 0 ; Load + cmp byte[GUIcrowpos],0 + jne .noloadrefresh + jmp GetLoadData +.noloadrefresh + cmp byte[romloadskip],0 + jne near .noromloaded + cmp byte[GUIcrowpos],1 ; Run + jne .norun + cmp byte[romloadskip],0 + jne .dontquit + mov byte[GUIQuit],2 +.dontquit + ret +.norun + cmp byte[CNetType],21 + je near .noreset + cmp byte[CNetType],22 + je near .noreset + GUICheckMenuItem 12, 2 ; Reset + cmp byte[GUIcrowpos],2 + jne .noreset + mov byte[GUICResetPos],1 +.noreset + cmp byte[OSPort],3 + je .win32state +; cmp byte[CNetType],20 +; je near .noromloaded +.win32state + cmp byte[CNetType],21 + je near .noromloaded + cmp byte[CNetType],22 + je near .noromloaded + cmp byte[GUIcrowpos],4 + jne .nosavestate + mov byte[GUIStatesText5],0 + mov byte[GUICStatePos],1 +.nosavestate + cmp byte[GUIcrowpos],5 + jne .noloadstate + mov byte[GUIStatesText5],1 + mov byte[GUICStatePos],1 +.noloadstate + GUICheckMenuItem 14, 4 ; Save State + GUICheckMenuItem 14, 5 ; Load State + GUICheckMenuItem 2, 6 ; Select State +.noromloaded + cmp byte[GUIcrowpos],8 + jne .noquit + mov byte[GUIQuit],1 +.noquit +.nomain + cmp byte[GUIcmenupos],3 + jne near .noconfig + GUICheckMenuItem 3, 0 + GUICheckMenuItem 3, 1 + GUICheckMenuItem 3, 2 + GUICheckMenuItem 3, 3 + GUICheckMenuItem 3, 4 + cmp byte[GUIcrowpos],0 + jne .noplay1 + mov byte[cplayernum],0 +.noplay1 + cmp byte[GUIcrowpos],1 + jne .noplay2 + mov byte[cplayernum],1 +.noplay2 + cmp byte[GUIcrowpos],2 + jne .noplay3 + mov byte[cplayernum],2 +.noplay3 + cmp byte[GUIcrowpos],3 + jne .noplay4 + mov byte[cplayernum],3 +.noplay4 + cmp byte[GUIcrowpos],4 + jne .noplay5 + mov byte[cplayernum],4 +.noplay5 + GUICheckMenuItem 17, 6 + GUICheckMenuItem 4, 8 + GUICheckMenuItem 5, 9 + GUICheckMenuItem 6, 10 +.noconfig + cmp byte[romloadskip],0 + jne near .nocheat + cmp byte[CNetType],20 + je near .nocheat + cmp byte[CNetType],21 + je near .nocheat + cmp byte[CNetType],22 + je near .nocheat + cmp byte[GUIcmenupos],4 + jne near .nocheat + GUICheckMenuItem 7, 0 + GUICheckMenuItem 7, 1 + GUICheckMenuItem 13, 2 + cmp byte[GUIcrowpos],0 + jne .noaddc + mov dword[GUIcurrentcheatwin],1 +.noaddc + cmp byte[GUIcrowpos],1 + jne .nobrowsec + mov dword[GUIcurrentcheatwin],0 +.nobrowsec +.nocheat + cmp byte[GUIcmenupos],5 + jne near .nonet + cmp byte[GOSPort],3 + je near .win32 + cmp byte[CNetType],10 + jae .nomod + mov byte[CNetType],0 +.nomod + GUICheckMenuItem 8, 0 + GUICheckMenuItem 8, 1 + cmp byte[CNetType],10 + jae near .nonet + cmp byte[GUIcrowpos],1 + jne .noipx + mov byte[CNetType],7 +.noipx + cmp byte[GUIcrowpos],0 + jne near .nonet + mov byte[CNetType],1 + jmp .nonet +.win32 + GUICheckMenuItem 8, 0 + cmp byte[CNetType],10 + jae near .nonet + cmp byte[GUIcrowpos],0 + jne near .nonet + mov byte[CNetType],4 + call GetHostName +.nonet + cmp byte[GUIcmenupos],6 + jne near .nomisc + GUICheckMenuItem 9, 0 + GUICheckMenuItem 10, 1 + cmp byte[romloadskip],0 + jne near .nomovie + GUICheckMenuItem 15, 2 + cmp byte[GUIcrowpos],2 + jne .nomovie + mov byte[MovieRecordWinVal],0 +.nomovie + GUICheckMenuItem 16, 3 + cmp byte[GUIcrowpos],4 + jne .nosavestuff + + ; change dir to InitDrive/InitDir + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + call createnewcfg + call GUISaveVars + + call Makemode7Table + mov dword[GUICMessage],.message1 + mov dword[GUICTimer],50 + ; change dir to LoadDrive/LoadDir + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir +.nosavestuff + GUICheckMenuItem 11, 6 +.nomisc + ret + +.message1 db 'CONFIGURATION FILES SAVED.',0 + +DisplayBoxes: + xor esi,esi + mov byte[cwindrawn],0 +.next2 + mov al,[GUIwinorder+esi] + cmp al,0 + je .done + inc byte[cwindrawn] + inc esi + jmp .next2 +.done + dec byte[cwindrawn] + xor eax,eax + xor esi,esi +.next + mov al,[GUIwinorder+esi] + cmp al,0 + je near .nomore + push esi + cmp al,1 + jne .noguiconfirm + call DisplayGUILoad + jmp .finstuff +.noguiconfirm + cmp al,2 + jne .noguichosesave + call DisplayGUIChoseSave + jmp .finstuff +.noguichosesave + cmp al,3 + jne .noguiinput + call DisplayGUIInput + jmp .finstuff +.noguiinput + cmp al,4 + jne .noguioption + call DisplayGUIOption + jmp .finstuff +.noguioption + cmp al,5 + jne .noguivideo + call DisplayGUIVideo + jmp .finstuff +.noguivideo + cmp al,6 + jne .noguisound + call DisplayGUISound + jmp .finstuff +.noguisound + cmp al,7 + jne .noguicheat + call DisplayGUICheat + jmp .finstuff +.noguicheat + cmp al,8 + jne .noguinet + call DisplayNetOptns + jmp .finstuff +.noguinet + cmp al,9 + jne .noguigameop + call DisplayGameOptns + jmp .finstuff +.noguigameop + cmp al,10 + jne .noguiconf + call DisplayGUIOptns + jmp .finstuff +.noguiconf + cmp al,11 + jne .noguiconf2 + call DisplayGUIAbout + jmp .finstuff +.noguiconf2 + cmp al,12 + jne .noguireset + call DisplayGUIReset + jmp .finstuff +.noguireset + cmp al,13 + jne .noguisearch + call DisplayGUISearch + jmp .finstuff +.noguisearch + cmp al,14 + jne .noguistates + call DisplayGUIStates + jmp .finstuff +.noguistates + cmp al,15 + jne .noguimovies + call DisplayGUIMovies + jmp .finstuff +.noguimovies + cmp al,16 + jne .noguicombo + call DisplayGUICombo + jmp .finstuff +.noguicombo + cmp al,17 + jne .noaddon + call DisplayGUIAddOns + jmp .finstuff +.noaddon +.finstuff + pop esi + inc esi + dec byte[cwindrawn] + jmp .next +.nomore + ret + + + +ChangetoSRAMdir: + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + ret + +ChangetoLOADdir: + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir + ret + +GUIProcStates: + xor eax,eax + mov al,[GUIwinptr] + dec eax + mov byte[GUIwinactiv+14],0 + mov byte[GUIwinorder+eax],0 + dec byte[GUIwinptr] + cmp byte[GUICBHold],10 + je .yesstate + mov byte[GUICBHold],0 + ret +.yesstate + mov byte[GUICBHold],0 + ; change dir to SRAMDrive/SRAMDir + call ChangetoSRAMdir + cmp byte[GUIStatesText5],1 + je .loadstate + call statesaver + jmp .changedir +.loadstate + cmp byte[CNetType],20 + jne .notnet + call NetLoadStuff + jmp .changedir +.notnet + call loadstate2 +.changedir + ; change dir to LoadDrive/LoadDir + call ChangetoLOADdir + ret + +SaveSecondState: + ; change dir to SRAMDrive/SRAMDir + call ChangetoSRAMdir + mov ebx,[statefileloc] + mov al,[fnamest+ebx] + mov byte[fnamest+ebx],'S' + push eax + call statesaver + pop eax + mov ebx,[statefileloc] + mov [fnamest+ebx],al + call ChangetoLOADdir + ret + +LoadSecondState: + call ChangetoSRAMdir + mov ebx,[statefileloc] + mov al,[fnamest+ebx] + mov byte[fnamest+ebx],'S' + push eax + call loadstate2 + pop eax + mov ebx,[statefileloc] + mov [fnamest+ebx],al + call ChangetoLOADdir + ret + +GUIProcReset: + cmp byte[GUICBHold],2 + jne .noreset + call GUIDoReset + cmp byte[CNetType],20 + jne .noreset + call PreparePacket + mov al,40 + call RemoteSendChar + call SendPacket + mov byte[GUIQuit],0 +.noreset + mov byte[GUICBHold],0 + xor eax,eax + mov al,[GUIwinptr] + dec eax + mov byte[GUIwinactiv+12],0 + mov byte[GUIwinorder+eax],0 + dec byte[GUIwinptr] + ret + +LoadDuplicFound db 0 + + +%macro GUIDMHelp 4 + mov byte[GUItextcolor],46 + mov byte[GUItextcolor+1],42 + mov byte[GUItextcolor+2],38 + mov byte[GUItextcolor+3],44 + mov byte[GUItextcolor+4],40 + cmp byte[GUIcmenupos],%4 + jne %%nohighlight + mov byte[GUItextcolor],38 + mov byte[GUItextcolor+1],40 + mov byte[GUItextcolor+2],46 + mov byte[GUItextcolor+3],40 + mov byte[GUItextcolor+4],44 +%%nohighlight + GUIBox %1,3,%2,3,[GUItextcolor] + GUIBox %1,4,%2,12,[GUItextcolor+1] + GUIBox %1,13,%2,13,[GUItextcolor+2] + GUIBox %1,3,%1,12,[GUItextcolor+3] + GUIBox %2,4,%2,13,[GUItextcolor+4] + GUIOuttext %1+5,7,%3,44 + GUIOuttext %1+4,6,%3,62 +%endmacro + +%macro GUIDMHelpB 4 + mov byte[GUItextcolor],46 + mov byte[GUItextcolor+1],42 + mov byte[GUItextcolor+2],38 + mov byte[GUItextcolor+3],44 + mov byte[GUItextcolor+4],40 + cmp byte[GUIcwinpress],%4 + jne %%nohighlight + mov byte[GUItextcolor],38 + mov byte[GUItextcolor+1],40 + mov byte[GUItextcolor+2],46 + mov byte[GUItextcolor+3],40 + mov byte[GUItextcolor+4],44 +%%nohighlight + GUIBox %1,3,%2,3,[GUItextcolor] + GUIBox %1,4,%2,12,[GUItextcolor+1] + GUIBox %1,13,%2,13,[GUItextcolor+2] + GUIBox %1,3,%1,12,[GUItextcolor+3] + GUIBox %2,4,%2,13,[GUItextcolor+4] + GUIOuttext %1+3,7,%3,44 + GUIOuttext %1+2,6,%3,62 +%endmacro + +%macro GUIDrawMenuM 10 + GUIShadow %7,%8,%7+4+%3*6,%8+3+%4*10 + GUIBox %1,%2,%1+4+%3*6,%2+3+%4*10,43 + + mov edi,[GUIcrowpos] + mov ecx,edi + shl edi,8 + shl ecx,5 + add edi,ecx + lea edi,[edi*5] + shl edi,1 + add edi,[vidbuffer] + add edi,%1+17+18*288 + mov ecx,6*%3+3 + mov edx,1 + mov al,73 + push edi + call GUIDrawBox + pop edi + add edi,288 + mov ecx,6*%3+3 + mov edx,7 + mov al,72 + push edi + call GUIDrawBox + pop edi + add edi,288*7 + mov ecx,6*%3+3 + mov edx,1 + mov al,73 + call GUIDrawBox + + GUIBox %1+%10,%2,%1+4+%3*6,%2,47 + GUIBox %1,%2,%1,%9,45 + GUIBox %1,%9,%1+4+%3*6,%9,39 + GUIBox %1+4+%3*6,1+%2,%1+4+%3*6,%9,41 + mov edi,%5 + mov esi,[vidbuffer] + add esi,16+%6+20*288 + mov ecx,%4 + mov edx,6*%3 + call GUIMenuDisplay + + mov dword[GUIMenuL],%1+1 + mov dword[GUIMenuR],%1+6*%3+3 + mov dword[GUIMenuD],18+%4*10 +%endmacro + +DisplayMenu: + ; Draw Shadow + GUIShadow 5,7,235,21 + ; Display Top Border + GUIBox 0,1,229,1,71 + GUIBox 0,2,229,2,70 + GUIBox 0,3,229,3,69 + GUIBox 0,4,229,4,68 + GUIBox 0,5,229,5,67 + GUIBox 0,6,229,6,66 + GUIBox 0,7,229,7,65 + GUIBox 0,8,229,8,64 + GUIBox 0,9,229,9,65 + GUIBox 0,10,229,10,66 + GUIBox 0,11,229,11,67 + GUIBox 0,12,229,12,68 + GUIBox 0,13,229,13,69 + GUIBox 0,14,229,14,70 + GUIBox 0,15,229,15,71 + + cmp byte[OSPort],3 + jne near .notwinpressa + GUIShadow 238,9,247,19 + GUIShadow 249,9,256,19 +.notwinpressa + + cmp byte[OSPort],3 + jne near .notwinpressb + mov byte[GUIMenuItem+36],249 + GUIDMHelpB 233,242,GUIMenuItem+36,1 + mov byte[GUIMenuItem+36],'x' + GUIDMHelpB 244,253,GUIMenuItem+36,2 +.notwinpressb + ; Display upper-left box + mov byte[GUIMenuItem+36],25 + GUIDMHelp 4,12,GUIMenuItem+6,1 + GUIOuttext 4+3,7,GUIMenuItem+36,44 + GUIOuttext 4+2,6,GUIMenuItem+36,62 + ; Display boxes + GUIDMHelp 17,47,GUIMenuItem,2 + GUIDMHelp 52,94,GUIMenuItem+7,3 + GUIDMHelp 99,135,GUIMenuItem+14,4 + GUIDMHelp 140,188,GUIMenuItem+21,5 + GUIDMHelp 193,223,GUIMenuItem+29,6 + + mov dword[GUIMenuL],0 + mov dword[GUIMenuR],0 + mov dword[GUIMenuD],0 + + ; format : x pos, y pos, #charx, #chary, name, xpos+2, xpos+5,22, + ; 19+#chary*10, length of top menu box + cmp byte[GUIcmenupos],1 + jne near .nomenu1 + GUIDrawMenuM 4,16,30,13,GUIPrevMenuData,6,9,22,149,8 ;19+13*10 + mov dword[GUICYLocPtr],MenuDat1 +.nomenu1 + cmp byte[GUIcmenupos],2 + jne near .nomenu2 + GUIDrawMenuM 17,16,10,9,GUIGameMenuData,19,22,22,109,30 ;19+9*10 + mov dword[GUICYLocPtr],MenuDat2 +.nomenu2 + cmp byte[GUIcmenupos],3 + jne near .nomenu3 + GUIDrawMenuM 52,16,9,11,GUIConfigMenuData,54,57,22,129,42 ;19+11*10 + mov dword[GUICYLocPtr],MenuDat3 +.nomenu3 + cmp byte[GUIcmenupos],4 + jne near .nomenu4 + GUIDrawMenuM 99,16,11,3,GUICheatMenuData,101,104,22,49,36 ;19+3*10 + mov dword[GUICYLocPtr],MenuDat4 +.nomenu4 + cmp byte[GUIcmenupos],5 + jne near .nomenu5 + cmp byte[GOSPort],3 + je near .menu5b + GUIDrawMenuM 140,16,10,2,GUINetPlayMenuData,142,145,22,39,48 ;19+2*10 + mov dword[GUICYLocPtr],MenuDat5 + jmp .nomenu5 +.menu5b + GUIDrawMenuM 140,16,10,1,GUINetPlayMenuData,142,145,22,29,48 ;19+2*10 + mov dword[GUICYLocPtr],MenuDat5 +.nomenu5 + cmp byte[GUIcmenupos],6 + jne near .nomenu6 + GUIDrawMenuM 193,16,9,7,GUIMiscMenuData,195,198,22,89,30 ;19+5*10 + mov dword[GUICYLocPtr],MenuDat6 +.nomenu6 + ret + +GUIMenuDisplay: + xor ebx,ebx +.next + mov al,[edi] + push ebx + push ecx + push esi + cmp al,0 + je near .notext + cmp al,2 + je .darktext + inc edi + mov byte[GUItextcolor],44 + cmp byte[GUIcrowpos],bl + je .nodrawshadow + push edi + push esi + add esi,289 + call GUIOutputString + pop esi + pop edi +.nodrawshadow + mov byte[GUItextcolor],63 + call GUIOutputString + inc edi + jmp .text +.darktext + inc edi + mov byte[GUItextcolor],42 + cmp byte[GUIcrowpos],bl + je .nodrawshadow2 + push edi + push esi + add esi,289 + call GUIOutputString + pop esi + pop edi +.nodrawshadow2 + mov byte[GUItextcolor],57 + call GUIOutputString + inc edi + jmp .text +.notext + add esi,4*288 + mov ecx,edx +.loop + mov byte[esi],45 + mov byte[esi-289],40 + mov byte[esi+289],42 + inc esi + dec ecx + jnz .loop + add edi,14 +.text + pop esi + pop ecx + pop ebx + add esi,10*288 + inc ebx + dec ecx + jnz near .next + ret + + + +InitGUI: + cmp byte[newengen],0 + je .nong16b + cmp byte[cbitmode],0 + je .nong16b + call GetScreen +.nong16b + call ClearScreen + call GUISetPal + call GUIBufferData + ret + +GUISetPal: + cmp byte[cbitmode],1 + je near GUISetPal16 + ; set palette + ; Fixed Color Scale = 0 .. 31 + mov dx,03C8h + mov al,0 + out dx,al + inc dx + out dx,al + out dx,al + out dx,al + + inc al + mov dx,03C8h + mov bl,1 + out dx,al + inc dx +.loopd + mov al,bl + add al,[GUIRAdd] + out dx,al + mov al,bl + add al,[GUIGAdd] + out dx,al + mov al,bl + add al,[GUIBAdd] + out dx,al + inc bl + cmp bl,32 + jne .loopd + ; gray scale = 32 .. 63 + mov dx,03C8h + mov bl,32 + mov al,32 + out dx,al + inc dx +.loopc + mov al,bl + add al,al + out dx,al + out dx,al + out dx,al + inc bl + cmp bl,64 + jne .loopc + ; shadow = 96 .. 127 + inc al + mov al,96 + mov dx,03C8h + mov bl,0 + out dx,al + inc dx +.loope + mov al,bl + add al,[GUIRAdd] + mov ah,al + add al,al + add al,ah + shr al,2 + out dx,al + mov al,bl + add al,[GUIGAdd] + mov ah,al + add al,al + add al,ah + shr al,2 + out dx,al + mov al,bl + add al,[GUIBAdd] + mov ah,al + add al,al + add al,ah + shr al,2 + out dx,al + inc bl + cmp bl,32 + jne .loope + + GUIPal 64,0,21,57 + GUIPal 65,0,21,54 + GUIPal 66,0,20,51 + GUIPal 67,0,18,48 + GUIPal 68,0,16,44 + GUIPal 69,0,14,40 + GUIPal 70,0,12,36 + GUIPal 71,0,10,31 + GUIPal 72,40,0,20 + GUIPal 73,34,0,21 + + GUIPal 80,0,10,28 + GUIPal 81,0,10,27 + GUIPal 82,0,10,25 + GUIPal 83,0,09,24 + GUIPal 84,0,08,22 + GUIPal 85,0,07,20 + GUIPal 86,0,06,18 + GUIPal 87,0,05,15 + GUIPal 88,20,0,10 + GUIPal 89,17,0,10 + + ; Orange Scale + mov dx,03C8h + mov al,128 + mov cl,20 + out dx,al + mov bh,0 + mov ah,0 + inc dx +.loopf + add bh,2 + add ah,1 + mov al,63 + out dx,al + mov al,bh + out dx,al + mov al,ah + out dx,al + dec cl + jnz .loopf + + ; Blue scale = 148 .. 167 + GUIPal 148,00,00,34 + GUIPal 149,04,04,38 + GUIPal 150,08,08,42 + GUIPal 151,12,12,46 + GUIPal 152,16,16,50 + + GUIPal 153,05,00,24 + GUIPal 154,09,04,28 + GUIPal 155,13,08,32 + GUIPal 156,18,12,36 + GUIPal 157,23,16,40 + + GUIPal 158,10,00,14 + GUIPal 159,14,04,18 + GUIPal 160,18,08,22 + GUIPal 161,22,12,26 + GUIPal 162,26,16,30 + + GUIPal 163,40,40,00 + GUIPal 164,30,30,00 + GUIPal 165,50,00,00 + GUIPal 166,35,00,00 + GUIPal 167,00,00,00 + + ; Blue scale shadow + GUIPal 168,00,00,17 + GUIPal 169,02,02,19 + GUIPal 170,04,04,21 + GUIPal 171,06,06,23 + GUIPal 172,08,08,25 + + GUIPal 173,02,00,12 + GUIPal 174,04,02,14 + GUIPal 175,06,04,16 + GUIPal 176,09,06,18 + GUIPal 177,11,08,20 + + GUIPal 178,05,00,07 + GUIPal 179,07,02,09 + GUIPal 180,09,04,11 + GUIPal 181,11,06,13 + GUIPal 182,13,08,15 + + GUIPal 183,20,20,00 + GUIPal 184,15,15,00 + GUIPal 185,25,00,00 + GUIPal 186,17,00,00 + GUIPal 187,00,00,00 + + ; gray scale2 = 189 .. 220 + mov dx,03C8h + mov al,189 + mov bl,0 + out dx,al + inc dx +.loopi + mov al,bl + add al,al + mov ah,bl + shr ah,1 + sub al,ah + out dx,al + out dx,al + add al,ah + out dx,al + inc bl + cmp bl,64 + jne .loopi + + GUIPal 221,00,55,00 + GUIPal 222,00,45,00 + GUIPal 223,00,25,00 + + GUIPal 224,40,0,20 + GUIPal 225,32,0,15 + + GUIPal 226,20,0,10 + GUIPal 227,16,0,07 + + GUIPal 228,45,45,50 + GUIPal 229,40,40,45 + GUIPal 230,35,35,40 + GUIPal 231,30,30,35 + + GUIPal 232,35,15,15 + + GUIPal 233,50,12,60 + GUIPal 234,30,14,60 + + cmp byte[GUIPalConv],0 + je .convert + ret +.convert + mov byte[GUIPalConv],1 + + ; Convert Image data to Gray Scale + ; Create Palette Table + call GUIconvpal + ; Convert Current Image in Buffer + mov esi,[vidbuffer] + mov ecx,288*240 + xor eax,eax +.next + mov al,[esi] + mov bl,[SubPalTable+eax] + mov [esi],bl + inc esi + dec ecx + jnz .next + ret + +NEWSYM GUICPC, times 256 dw 0 + +%macro GUIPal16b 4 + mov ax,%2 >> 1 + shl ax,11 + or ax,%3 << 5 + or ax,%4 >> 1 + mov word[GUICPC+%1*2],ax +%endmacro + +GUISetPal16: + ; set palette + ; Fixed Color Scale = 0 .. 31 + mov word[GUICPC],0 + inc al + xor ebx,ebx + mov bl,1 +.loopd + xor ecx,ecx + mov cl,bl + add cl,[GUIRAdd] + shr cl,1 + shl ecx,11 + xor eax,eax + mov al,bl + add al,[GUIGAdd] + shl eax,5 + or ecx,eax + xor eax,eax + mov al,bl + add al,[GUIBAdd] + shr eax,1 + or ecx,eax + mov [GUICPC+ebx*2],cx + inc bl + cmp bl,32 + jne .loopd + + ; gray scale = 32 .. 63 + mov bl,32 + mov al,32 +.loopc + mov al,bl + add al,al + xor ecx,ecx + mov cl,al + shr ecx,1 + shl ecx,11 + xor edx,edx + mov dl,al + shl edx,5 + or ecx,edx + xor edx,edx + mov dl,al + shr edx,1 + or ecx,edx + mov [GUICPC+ebx*2],cx + inc bl + cmp bl,64 + jne .loopc + + ; shadow = 96 .. 127 + xor ebx,ebx +.loope + xor ecx,ecx + mov al,bl + add al,[GUIRAdd] + mov ah,al + add al,al + add al,ah + shr al,2 + shr al,1 + or cl,al + shl ecx,6 + mov al,bl + add al,[GUIGAdd] + mov ah,al + add al,al + add al,ah + shr al,2 + or cl,al + shl ecx,5 + mov al,bl + add al,[GUIBAdd] + mov ah,al + add al,al + add al,ah + shr al,2 + shr al,1 + or cl,al + mov [GUICPC+ebx*2+96*2],cx + inc bl + cmp bl,32 + jne .loope + + GUIPal16b 64,0,21,57 + GUIPal16b 65,0,21,54 + GUIPal16b 66,0,20,51 + GUIPal16b 67,0,18,48 + GUIPal16b 68,0,16,44 + GUIPal16b 69,0,14,40 + GUIPal16b 70,0,12,36 + GUIPal16b 71,0,10,31 + GUIPal16b 72,40,0,20 + GUIPal16b 73,34,0,21 + + GUIPal16b 80,0,10,28 + GUIPal16b 81,0,10,27 + GUIPal16b 82,0,10,25 + GUIPal16b 83,0,09,24 + GUIPal16b 84,0,08,22 + GUIPal16b 85,0,07,20 + GUIPal16b 86,0,06,18 + GUIPal16b 87,0,05,15 + GUIPal16b 88,20,0,10 + GUIPal16b 89,17,0,10 + + ; Orange Scale + mov cl,20 + mov bh,0 + mov ah,0 + inc dx + mov esi,128 +.loopf + add bh,2 + add ah,1 + mov edx,1Fh << 6 + or dl,bh + shl edx,5 + mov al,ah + shr al,1 + or dl,al + mov [GUICPC+esi*2],dx + inc esi + dec cl + jnz .loopf + + ; Blue scale = 148 .. 167 + GUIPal16b 148,00,00,34 + GUIPal16b 149,04,04,38 + GUIPal16b 150,08,08,42 + GUIPal16b 151,12,12,46 + GUIPal16b 152,16,16,50 + + GUIPal16b 153,05,00,24 + GUIPal16b 154,09,04,28 + GUIPal16b 155,13,08,32 + GUIPal16b 156,18,12,36 + GUIPal16b 157,23,16,40 + + GUIPal16b 158,10,00,14 + GUIPal16b 159,14,04,18 + GUIPal16b 160,18,08,22 + GUIPal16b 161,22,12,26 + GUIPal16b 162,26,16,30 + + GUIPal16b 163,40,40,00 + GUIPal16b 164,30,30,00 + GUIPal16b 165,50,00,00 + GUIPal16b 166,35,00,00 + GUIPal16b 167,00,00,00 + + ; Blue scale shadow + GUIPal16b 168,00,00,17 + GUIPal16b 169,02,02,19 + GUIPal16b 170,04,04,21 + GUIPal16b 171,06,06,23 + GUIPal16b 172,08,08,25 + + GUIPal16b 173,02,00,12 + GUIPal16b 174,04,02,14 + GUIPal16b 175,06,04,16 + GUIPal16b 176,09,06,18 + GUIPal16b 177,11,08,20 + + GUIPal16b 178,05,00,07 + GUIPal16b 179,07,02,09 + GUIPal16b 180,09,04,11 + GUIPal16b 181,11,06,13 + GUIPal16b 182,13,08,15 + + GUIPal16b 183,20,20,00 + GUIPal16b 184,15,15,00 + GUIPal16b 185,25,00,00 + GUIPal16b 186,17,00,00 + GUIPal16b 187,00,00,00 + + ; gray scale2 = 189 .. 220 + mov bl,0 + mov esi,189 +.loopi + xor edx,edx + mov al,bl + add al,al + mov ah,bl + shr ah,1 + sub al,ah + mov dl,al + shr dl,1 + shl edx,6 + or dl,al + shl edx,5 + add al,ah + shr al,1 + or dl,al + mov [GUICPC+esi*2],dx + inc esi + inc bl + cmp bl,64 + jne .loopi + + GUIPal16b 221,00,55,00 + GUIPal16b 222,00,45,00 + GUIPal16b 223,00,25,00 + + GUIPal16b 224,40,0,20 + GUIPal16b 225,32,0,15 + + GUIPal16b 226,20,0,10 + GUIPal16b 227,16,0,07 + + GUIPal16b 228,45,45,50 + GUIPal16b 229,40,40,45 + GUIPal16b 230,35,35,40 + GUIPal16b 231,30,30,35 + + GUIPal16b 232,35,15,15 + + GUIPal16b 233,50,12,60 + GUIPal16b 234,30,14,60 + GUIPal16b 235,12,60,25 + GUIPal16b 236,14,42,25 + GUIPal16b 237,60,20,25 + GUIPal16b 238,42,20,25 + + cmp byte[vesa2red10],1 + jne .nored10 + jmp .nored10 + mov esi,GUICPC + mov ecx,256 +.next2 + mov ax,[esi] + mov bx,ax + and bx,0000000000011111b + and ax,1111111111000000b + shr ax,1 + or ax,bx + mov [esi],ax + add esi,2 + dec ecx + jnz .next2 +.nored10 + cmp byte[GUIPalConv],0 + je .convert + ret +.convert + mov byte[GUIPalConv],1 + mov esi,[vidbuffer] + mov edi,288*240 + xor ebx,ebx +.next + mov ax,[esi+ebx*2] + mov ecx,eax + shr ecx,11 + and ecx,1Fh + mov edx,eax + shr edx,6 + and edx,1Fh + add ecx,edx + mov edx,eax + and edx,1Fh + add ecx,edx + shr ecx,1 + mov al,[.multab+ecx] + mov [esi+ebx],al + inc ebx + dec edi + jnz .next + ret + +.multab db 1,1,1,2,2,3,4,4,5,6,6,7,8,8,9,10,10,11,12,12,13,14,14,15,16,16, + db 17,18,18,19,20,20,21,22,22,23,24,24,25,26,26,27,28,28,29,30,30, + db 31 + +GUIBufferData: + mov ecx,16384 + cmp byte[cbitmode],1 + jne near .16b + add ecx,16384 + cmp word[PrevResoln],224 + je .nobufb + add esi,288*8 +.nobufb +.16b + ; copy to spritetable + mov esi,[vidbuffer] + cmp word[PrevResoln],224 + je .nobufa + add esi,288*8 +.nobufa + mov edi,[spritetablea] + add edi,8*288 +.loop + mov eax,[esi] + mov [edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .loop + mov edi,sprlefttot + mov ecx,64*5 +.a + mov dword[edi],0 + add edi,4 + dec ecx + jnz .a + ret + +GUIUnBuffer: + mov ecx,16384 + ; copy from spritetable + mov edi,[vidbuffer] + mov esi,[spritetablea] + add esi,8*288 + rep movsd + mov eax,01010101h + mov ecx,2*288 + rep stosd + ret + +GUIconvpal: + mov ax,[cgram] + mov [tempco0],ax + test byte[scaddtype],00100000b + jz near .noaddition + test byte[scaddtype],10000000b + jnz near .noaddition + mov cx,[cgram] + mov ax,cx + and ax,001Fh + add al,[coladdr] + cmp al,01Fh + jb .noadd + mov al,01Fh +.noadd + mov bx,ax + mov ax,cx + shr ax,5 + and ax,001Fh + add al,[coladdg] + cmp al,01Fh + jb .noaddb + mov al,01Fh +.noaddb + shl ax,5 + add bx,ax + mov ax,cx + shr ax,10 + and ax,001Fh + add al,[coladdb] + cmp al,01Fh + jb .noaddc + mov al,01Fh +.noaddc + shl ax,10 + add bx,ax + mov [cgram],bx +.noaddition + mov edi,cgram + mov ebx,prevpal + xor ah,ah +.loopa + mov cx,[edi] + push eax + push ebx + mov [ebx],cx + mov al,ah + mov ax,cx + and al,01Fh + mov bh,[maxbr] + mov bl,bh + mul bl + mov bl,15 + div bl + mov [curgsval],al + mov ax,cx + shr ax,5 + and al,01Fh + mov bl,bh + mul bl + mov bl,15 + div bl + add [curgsval],al + mov ax,cx + shr ax,10 + and al,01Fh + mov bl,bh + mul bl + mov bl,15 + div bl + add [curgsval],al + pop ebx + pop eax + add edi,2 + add ebx,2 + push eax + push ebx + mov al,ah + and eax,0FFh + mov bl,[curgsval] + push eax + push ebx + mov al,bl + mov bl,3 + xor ah,ah + div bl + pop ebx + mov bl,al + pop eax + cmp byte[MessageOn],0 + je .nochange128 + cmp al,128 + jne .nochange128 + mov bl,31 +.nochange128 + or bl,bl + jnz .noadder + inc bl +.noadder + mov [SubPalTable+eax],bl + pop ebx + pop eax + inc ah + jnz near .loopa + mov al,[maxbr] + mov [prevbright],al + mov ax,[tempco0] + mov [cgram],ax + ret + +GUIMousePtr db 50+88,47+88,45+88,43+88,42+88,00,00,00 + db 53+88,52+88,46+88,42+88,00,00,00,00 + db 55+88,54+88,54+88,44+88,00,00,00,00 + db 57+88,57+88,56+88,52+88,45+88,00,00,00 + db 59+88,00,00,55+88,50+88,45+88,00,00 + db 00,00,00,00,55+88,50+88,45+88,00 + db 00,00,00,00,00,55+88,50+88,47+88 + db 00,00,00,00,00,00,52+88,00 + + db 50,47,45,43,40,00,00,00 + db 53,52,46,42,00,00,00,00 + db 55,54,54,44,00,00,00,00 + db 57,57,56,52,45,00,00,00 + db 59,00,00,55,50,45,00,00 + db 00,00,00,00,55,50,45,00 + db 00,00,00,00,00,55,50,47 + db 00,00,00,00,00,00,52,00 + +NEWSYM GUIFontData + db 0,0,0,0,0 + db 01110000b + db 10011000b + db 10101000b + db 11001000b + db 01110000b; 0 + db 00100000b + db 01100000b + db 00100000b + db 00100000b + db 01110000b; 1 + db 01110000b + db 10001000b + db 00110000b + db 01000000b + db 11111000b; 2 + db 01110000b + db 10001000b + db 00110000b + db 10001000b + db 01110000b; 3 + db 01010000b + db 10010000b + db 11111000b + db 00010000b + db 00010000b; 4 + db 11111000b + db 10000000b + db 11110000b + db 00001000b + db 11110000b; 5 + db 01110000b + db 10000000b + db 11110000b + db 10001000b + db 01110000b; 6 + db 11111000b + db 00001000b + db 00010000b + db 00010000b + db 00010000b; 7 + db 01110000b + db 10001000b + db 01110000b + db 10001000b + db 01110000b; 8 + db 01110000b + db 10001000b + db 01111000b + db 00001000b + db 01110000b; 9 + db 01110000b + db 10001000b + db 11111000b + db 10001000b + db 10001000b; A + db 11110000b + db 10001000b + db 11110000b + db 10001000b + db 11110000b; B + db 01110000b + db 10001000b + db 10000000b + db 10001000b + db 01110000b; C + db 11110000b + db 10001000b + db 10001000b + db 10001000b + db 11110000b; D + db 11111000b + db 10000000b + db 11110000b + db 10000000b + db 11111000b; E + db 11111000b + db 10000000b + db 11110000b + db 10000000b + db 10000000b; F + db 01111000b + db 10000000b + db 10011000b + db 10001000b + db 01110000b; G + db 10001000b + db 10001000b + db 11111000b + db 10001000b + db 10001000b; H + db 11111000b + db 00100000b + db 00100000b + db 00100000b + db 11111000b; I + db 01111000b + db 00010000b + db 00010000b + db 10010000b + db 01100000b; J + db 10010000b + db 10100000b + db 11100000b + db 10010000b + db 10001000b; K + db 10000000b + db 10000000b + db 10000000b + db 10000000b + db 11111000b; L + db 11011000b + db 10101000b + db 10101000b + db 10101000b + db 10001000b; M + db 11001000b + db 10101000b + db 10101000b + db 10101000b + db 10011000b; N + db 01110000b + db 10001000b + db 10001000b + db 10001000b + db 01110000b; O + db 11110000b + db 10001000b + db 11110000b + db 10000000b + db 10000000b; P + db 01110000b + db 10001000b + db 10101000b + db 10010000b + db 01101000b; Q + db 11110000b + db 10001000b + db 11110000b + db 10010000b + db 10001000b; R + db 01111000b + db 10000000b + db 01110000b + db 00001000b + db 11110000b; S + db 11111000b + db 00100000b + db 00100000b + db 00100000b + db 00100000b; T + db 10001000b + db 10001000b + db 10001000b + db 10001000b + db 01110000b; U + db 10001000b + db 10001000b + db 01010000b + db 01010000b + db 00100000b; V + db 10001000b + db 10101000b + db 10101000b + db 10101000b + db 01010000b; W + db 10001000b + db 01010000b + db 00100000b + db 01010000b + db 10001000b; X + db 10001000b + db 01010000b + db 00100000b + db 00100000b + db 00100000b; Y + db 11111000b + db 00010000b + db 00100000b + db 01000000b + db 11111000b; Z + db 00000000b + db 00000000b + db 11111000b + db 00000000b + db 00000000b; - + db 00000000b + db 00000000b + db 00000000b + db 00000000b + db 11111000b; _ + db 01101000b + db 10010000b + db 00000000b + db 00000000b + db 00000000b; ~ + db 00000000b + db 00000000b + db 00000000b + db 00000000b + db 00100000b; . + db 00001000b + db 00010000b + db 00100000b + db 01000000b + db 10000000b; / + db 00010000b + db 00100000b + db 01000000b + db 00100000b + db 00010000b; < + db 01000000b + db 00100000b + db 00010000b + db 00100000b + db 01000000b; > + db 01110000b + db 01000000b + db 01000000b + db 01000000b + db 01110000b; [ + db 01110000b + db 00010000b + db 00010000b + db 00010000b + db 01110000b; ] + db 00000000b + db 00100000b + db 00000000b + db 00100000b + db 00000000b; : + db 01100000b + db 10011000b + db 01110000b + db 10011000b + db 01101000b; & + db 00100000b + db 00100000b + db 10101000b + db 01110000b + db 00100000b; arrow + db 01010000b + db 11111000b + db 01010000b + db 11111000b + db 01010000b; # + db 00000000b + db 11111000b + db 00000000b + db 11111000b + db 00000000b; = + db 01001000b + db 10010000b + db 00000000b + db 00000000b + db 00000000b; " + db 10000000b + db 01000000b + db 00100000b + db 00010000b + db 00001000b; \ + db 10101000b + db 01110000b + db 11111000b + db 01110000b + db 10101000b; * + db 01110000b + db 10001000b + db 00110000b + db 00000000b + db 00100000b; ? + db 10001000b + db 00010000b + db 00100000b + db 01000000b + db 10001000b; % + db 00100000b + db 00100000b + db 11111000b + db 00100000b + db 00100000b; + + db 00000000b + db 00000000b + db 00000000b + db 00100000b + db 01000000b; , + db 00110000b + db 01000000b + db 01000000b + db 01000000b + db 00110000b; ( + db 01100000b + db 00010000b + db 00010000b + db 00010000b + db 01100000b; ) + db 01110000b + db 10011000b + db 10111000b + db 10000000b + db 01110000b; @ + db 00100000b + db 01000000b + db 00000000b + db 00000000b + db 00000000b; ' + db 00100000b + db 00100000b + db 00100000b + db 00000000b + db 00100000b; ! + db 01111000b + db 10100000b + db 01110000b + db 00101000b + db 11110000b; $ + db 00000000b + db 00100000b + db 00000000b + db 00100000b + db 01000000b; ; + db 01000000b + db 00100000b + db 00000000b + db 00000000b + db 00000000b; ` + db 00100000b + db 01010000b + db 00000000b + db 00000000b + db 00000000b; ^ + db 00110000b + db 01000000b + db 11000000b + db 01000000b + db 00110000b; { + db 01100000b + db 00010000b + db 00011000b + db 00010000b + db 01100000b; } + db 00100000b + db 00100000b + db 01110000b + db 01110000b + db 11111000b; Up + db 11111000b + db 01110000b + db 01110000b + db 00100000b + db 00100000b; Down + db 00001000b + db 00111000b + db 11111000b + db 00111000b + db 00001000b; Left + db 10000000b + db 11100000b + db 11111000b + db 11100000b + db 10000000b; Right + db 00100000b + db 01100000b + db 11111000b + db 01100000b + db 00100000b; Arrow Left + db 00111000b + db 00100000b + db 00110000b + db 00001000b + db 10110000b; .5 + db 11111000b + db 10001000b + db 10001000b + db 10001000b + db 11111000b; Maximize + +; 189 .. 220 +GUIIconDataClose: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,216,216,216,216,216,216,216,0 ,0 + db 214,212,202,212,212,212,202,212,210,0 + db 214,212,212,200,212,200,212,212,210,202 + db 214,212,212,212,198,212,212,212,210,202 + db 214,212,212,196,212,196,212,212,210,200 + db 214,212,194,212,212,212,194,212,210,200 + db 0 ,208,208,208,208,208,208,208,198,198 + db 0 ,0 ,198,198,198,198,198,198,198,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + +GUIIconDataButtonHole: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,207,205,207,0 ,0 ,0 ,0 + db 0 ,0 ,207,203,202,203,207,0 ,0 ,0 + db 0 ,207,203,200,198,200,203,207,0 ,0 + db 0 ,207,202,198,197,198,202,207,0 ,0 + db 0 ,207,203,200,198,200,203,207,0 ,0 + db 0 ,0 ,207,203,202,203,207,0 ,0 ,0 + db 0 ,0 ,0 ,207,205,207,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + +GUIIconDataButtonFill: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,207,209,207,0 ,0 ,0 ,0 + db 0 ,0 ,207,211,212,211,207,0 ,0 ,0 + db 0 ,207,211,214,216,214,211,207,0 ,0 + db 0 ,207,212,216,217,216,212,207,0 ,0 + db 0 ,207,211,214,216,214,211,207,0 ,0 + db 0 ,0 ,207,211,212,211,207,0 ,0 ,0 + db 0 ,0 ,0 ,207,209,207,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + +GUIIconDataSlideBar: + db 0 ,0 ,0 ,0 ,216,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,212,216,220,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,212,216,220,202,0 ,0 ,0 + db 0 ,0 ,212,212,216,218,220,0 ,0 ,0 + db 0 ,0 ,212,214,216,218,220,202,0 ,0 + db 0 ,0 ,212,214,216,218,220,202,0 ,0 + db 0 ,0 ,0 ,212,216,220,202,202,0 ,0 + db 0 ,0 ,0 ,212,216,220,202,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,216,202,202,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,202,0 ,0 ,0 ,0 + +GUIIconDataCheckBoxUC: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,220,219,218,217,216,215,0 ,0 ,0 + db 0 ,219,218,217,216,215,214,202,0 ,0 + db 0 ,218,217,216,215,214,213,202,0 ,0 + db 0 ,217,216,215,214,213,212,202,0 ,0 + db 0 ,216,215,214,213,212,211,202,0 ,0 + db 0 ,215,214,213,212,211,210,202,0 ,0 + db 0 ,0 ,202,202,202,202,202,202,0 ,0 + +GUIIconDataCheckBoxC: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,165,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,165,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,165,0 ,0 ,0 + db 0 ,220,219,218,217,165,215,0 ,0 ,0 + db 0 ,165,165,217,165,165,214,202,0 ,0 + db 0 ,218,165,216,165,214,213,202,0 ,0 + db 0 ,217,165,165,165,213,212,202,0 ,0 + db 0 ,216,215,165,213,212,211,202,0 ,0 + db 0 ,215,214,165,212,211,210,202,0 ,0 + db 0 ,0 ,202,202,202,202,202,202,0 ,0 + +GUIIconDataCheckBoxX: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,165,0 ,0 ,0 ,0 ,0 ,165,0 ,0 + db 0 ,220,165,218,217,216,165,0 ,0 ,0 + db 0 ,219,218,165,216,165,214,202,0 ,0 + db 0 ,218,217,216,165,214,213,202,0 ,0 + db 0 ,217,216,165,214,165,212,202,0 ,0 + db 0 ,216,165,214,213,212,165,202,0 ,0 + db 0 ,165,214,213,212,211,210,165,0 ,0 + db 0 ,0 ,202,202,202,202,202,202,0 ,0 + +GUIIconDataUpArrow: + db 201,209,209,209,209,209,209,200,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 207,205,201,202,203,202,205,203,0 ,0 + db 207,200,205,202,203,205,201,203,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 199,201,201,201,201,201,201,198,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + +GUIIconDataDownArrow: + db 201,209,209,209,209,209,209,200,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 207,200,205,202,203,205,201,203,0 ,0 + db 207,205,201,202,203,202,205,203,0 ,0 + db 207,205,205,202,203,205,205,203,0 ,0 + db 199,201,201,201,201,201,201,198,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + +NEWSYM SnowData +dw 161,251,115,211,249,87,128,101,232,176,51,180,108,193,224,112,254,159,102,238 +dw 223,123,218,42,173,160,143,170,64,1,174,29,34,187,194,199,40,89,232,32 +dw 7,195,141,67,216,48,234,1,243,116,164,182,146,136,66,70,36,43,98,208 +dw 63,240,216,253,147,36,33,253,98,80,228,156,73,82,85,1,97,72,187,239 +dw 18,196,127,182,22,22,101,25,124,145,240,213,186,22,7,161,30,98,90,197 +dw 22,205,32,150,59,133,49,140,10,128,142,185,176,142,220,195,100,102,105,194 +dw 43,139,184,153,1,95,176,169,192,201,233,243,73,65,188,14,194,39,251,140 +dw 239,181,142,160,242,248,82,49,9,157,233,162,254,121,112,6,118,24,56,121 +dw 74,209,1,223,145,6,75,73,18,168,194,168,58,39,222,170,214,75,45,218 +dw 39,197,242,98,22,90,255,5,144,244,252,55,98,18,135,101,27,85,215,207 +dw 183,28,201,142,45,122,145,159,41,243,109,29,117,203,7,234,231,214,131,133 +dw 217,8,74,207,130,77,21,229,167,78,218,109,142,58,134,238,29,182,178,14 +dw 144,129,196,219,60,128,30,105,57,53,76,122,242,208,101,241,246,99,248,67 +dw 137,244,70,51,202,94,164,125,115,72,61,72,129,169,155,122,91,154,160,83 +dw 41,102,223,218,140,40,132,16,223,92,50,230,168,47,126,117,242,136,1,245 +dw 171,0,36,98,73,69,14,229,66,177,108,92,39,250,243,161,111,85,211,99 +dw 52,98,121,188,128,201,90,205,223,92,177,19,87,18,75,54,6,81,235,137 +dw 247,66,211,129,247,39,119,206,116,250,113,231,190,196,53,51,34,114,39,22 +dw 192,33,249,151,26,22,139,97,171,238,182,88,22,176,157,255,178,199,138,98 +dw 140,36,112,90,25,245,134,64,48,190,165,113,24,195,84,70,175,9,179,69 +dw 13,26,167,237,163,159,185,128,109,114,86,74,188,103,141,48,188,203,205,191 +dw 215,193,224,4,153,36,108,3,172,235,56,251,211,115,173,216,240,33,78,150 +dw 133,64,51,103,56,26,165,222,70,148,115,119,246,229,181,63,109,49,228,108 +dw 126,10,170,48,87,42,193,24,28,255,176,176,209,181,97,93,61,241,201,137 +dw 129,97,24,159,168,215,61,113,104,143,168,7,196,216,149,239,110,65,75,143 +dw 238,0,37,19,8,56,65,234,228,72,42,5,226,95,243,51,55,231,114,90 +dw 160,141,171,108,218,252,154,64,175,142,214,211,180,129,217,118,33,130,213,2 +dw 73,145,93,21,162,141,97,225,112,253,49,43,113,208,131,104,31,51,192,37 +dw 117,186,16,45,61,114,220,6,89,163,197,203,142,80,89,115,190,190,228,15 +dw 166,145,59,139,120,79,104,252,246,73,113,144,224,65,204,155,221,85,31,99 +dw 48,253,94,159,215,31,123,204,248,153,31,210,174,178,54,146,152,88,56,92 +dw 197,35,124,104,211,118,1,207,108,68,123,161,107,69,143,13,79,170,130,193 +dw 214,153,219,247,227,2,170,208,248,139,118,241,247,183,18,135,246,126,201,46 +dw 70,234,171,72,18,135,236,216,32,178,148,231,161,15,6,254,34,181,5,71 +dw 2,219,71,87,252,16,202,190,180,83,99,209,75,134,78,84,114,32,171,246 +dw 125,11,57,200,102,29,176,26,205,151,152,108,100,146,117,95,71,77,158,207 +dw 60,192,50,135,223,237,231,53,27,195,170,146,155,160,92,224,247,187,14,50 +dw 203,5,153,42,17,75,109,14,78,160,236,114,131,105,189,209,233,135,221,207 +dw 226,119,104,10,178,107,77,160,233,179,120,227,133,241,32,223,63,247,66,157 +dw 140,81,118,81,63,193,173,228,214,78,124,123,222,149,9,242,0,128,194,110 + +NEWSYM SnowVelDist +db 57,92,100,19,100,184,238,225,55,240,255,221,215,105,226,153,164,41,22,93 +db 176,203,155,199,244,52,233,219,110,227,229,227,152,240,83,248,226,31,163,22 +db 28,156,18,10,248,67,123,167,25,138,90,10,79,107,208,229,248,233,185,10 +db 167,21,19,178,132,154,81,70,20,71,95,147,72,27,91,189,13,189,102,84 +db 195,123,251,93,68,36,178,59,107,99,104,191,76,110,44,206,123,46,98,112 +db 26,50,1,35,150,17,242,208,69,23,202,197,59,80,136,124,40,89,11,40 +db 1,136,90,72,198,83,2,174,174,4,28,205,135,35,194,54,22,40,4,132 +db 191,88,163,66,204,230,35,111,9,177,254,174,163,68,5,88,111,235,58,236 +db 4,248,172,154,101,164,43,223,10,13,210,125,146,73,192,57,117,152,128,36 +db 106,21,253,113,110,133,244,4,150,32,76,71,22,106,210,244,46,128,27,215 +db 231,112,177,196,198,120,196,57,234,74,235,108,64,181,209,188,177,63,197,200 +db 126,164,136,163,48,62,225,223,212,201,195,121,90,7,10,196,88,53,39,249 +db 147,98,65,253,246,3,152,125,242,105,44,129,94,232,13,4,86,220,194,67 +db 186,210,171,197,64,138,89,78,58,150,52,79,138,201,244,111,106,181,192,69 +db 234,253,239,113,98,37,209,151,60,47,241,235,185,52,173,94,172,182,47,150 +db 80,118,10,58,161,237,10,64,238,198,14,74,132,250,234,63,169,86,158,170 +db 76,168,124,133,28,203,246,140,228,77,50,53,115,113,157,218,90,192,28,209 +db 72,117,156,101,226,99,11,245,69,59,17,175,164,59,8,166,163,185,10,60 +db 100,19,26,38,114,232,180,115,238,184,88,103,178,67,212,21,87,64,85,1 +db 62,87,155,62,21,96,205,195,131,97,191,252,218,209,179,201,12,2,234,110 +db 162,14,145,170,156,105,85,132,132,60,239,14,80,129,225,144,149,244,188,8 +db 13,168,181,168,30,142,24,110,26,172,231,182,50,214,66,193,100,45,132,144 +db 205,190,16,133,45,250,83,183,140,229,117,226,68,59,163,96,235,227,25,155 +db 209,105,41,214,30,107,2,85,180,23,241,39,113,63,75,44,107,142,93,29 +db 62,240,235,152,147,52,54,146,109,112,139,162,238,198,201,8,141,115,112,106 +db 4,99,25,155,111,161,114,253,75,100,28,59,101,150,2,122,228,6,12,59 +db 249,181,67,136,227,227,199,46,75,203,50,25,50,61,62,22,238,124,218,134 +db 243,21,243,222,94,138,161,234,133,23,138,45,4,226,154,227,8,84,105,126 +db 200,127,240,144,124,197,102,144,53,29,94,231,108,175,136,37,44,183,178,95 +db 41,196,214,12,42,221,106,225,151,32,53,130,24,211,88,14,135,18,90,219 +db 177,129,90,217,162,181,199,133,116,56,36,100,230,91,220,83,41,65,20,64 +db 177,197,249,24,242,62,26,234,92,44,167,153,243,94,179,163,103,29,220,199 +db 128,94,236,152,53,32,77,78,228,89,124,85,87,50,197,116,179,105,236,139 +db 102,17,159,66,176,27,205,36,113,80,60,6,61,174,254,174,246,72,154,31 +db 97,40,10,8,114,203,238,26,89,51,134,110,118,176,87,32,192,210,146,207 +db 88,45,156,179,61,224,87,107,107,1,252,187,203,100,169,211,205,105,12,231 +db 137,176,166,37,192,241,169,84,32,85,112,168,154,7,247,146,183,225,246,173 +db 57,103,110,236,113,118,203,200,22,87,251,7,138,37,12,84,221,171,51,209 +db 242,37,89,73,151,162,139,189,131,209,221,96,107,144,175,79,199,123,98,138 +db 226,86,221,254,72,14,126,180,200,171,85,94,120,124,196,225,150,57,219,158 + + + +  \ No newline at end of file diff --git a/zsnes/src/gui/guicheat.inc b/zsnes/src/gui/guicheat.inc new file mode 100644 index 00000000..27685695 --- /dev/null +++ b/zsnes/src/gui/guicheat.inc @@ -0,0 +1,1340 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + +; GUI Cheat Code Routines + +AddCSCheatCode: + cmp byte[CSInputDisplay],'_' + je .nodisplay + jmp .okay +.nodisplay + ret +.okay + mov eax,[curentryval] + mov [curaddrvalcs],eax + mov eax,[CSCurValue] + mov [curvaluecs],eax + xor ecx,ecx + mov cl,[CheatSrcByteSize] + inc cl + cmp byte[CheatUpperByteOnly],0 + je .cspardisploop + mov cl,1 +.cspardispagain + cmp dword[curvaluecs],0FFh + jbe .cspardisploop + shr dword[curvaluecs],8 + inc dword[curaddrvalcs] + jmp .cspardispagain +.cspardisploop + push ecx + mov esi,GUICSrcTextQ + mov ecx,3 + mov eax,[curaddrvalcs] + add eax,7E0000h + mov bl,[curvaluecs] + ; write bl at address eax + call AddCheatCode + + shr dword[curvaluecs],8 + mov byte[GUItextcolor],223 + + add dword[CheatSearchYPos],10 + inc dword[curaddrvalcs] + pop ecx + dec ecx + jnz near .cspardisploop + mov byte[CheatWinMode],2 + ret + +%macro SearchCMPByte 0 + mov bl,[edi] + cmp bl,[esi] +%endmacro + +%macro SearchCMP2Bytes 0 + mov bx,[edi] + cmp bx,[esi] +%endmacro + +%macro SearchCMP3Bytes 0 + push ecx + mov ebx,[edi] + mov ecx,[esi] + and ebx,0FFFFFFh + and ecx,0FFFFFFh + cmp ebx,ecx + pop ecx +%endmacro + +%macro SearchCMP4Bytes 0 + mov ebx,[edi] + cmp ebx,[esi] +%endmacro + +%macro SearchMacro 2 + mov dl,0FEh +%%searchloop + %2 + %1 %%nofail + and [eax],dl +%%nofail + inc edi + inc esi + cmp dl,7Fh + jne %%noinceax + inc eax +%%noinceax + rol dl,1 + loop %%searchloop +%endmacro + +%macro SearchMacroB 1 + cmp byte[CheatCompareValue],0 + je near %%greater + cmp byte[CheatCompareValue],1 + je near %%lessthan + cmp byte[CheatCompareValue],3 + je near %%notequalthan + SearchMacro je, %1 + jmp .end +%%greater + SearchMacro ja, %1 + jmp .end +%%lessthan + SearchMacro jb, %1 + jmp .end +%%notequalthan + SearchMacro jne, %1 + jmp .end +%endmacro + +CheatCodeSearchProcess: + cmp byte[CheatSrcSearchType],1 + je near .comparative + cmp byte[CSInputDisplay],0 + je near .nodisplay + cmp byte[CSInputDisplay],'_' + je near .nodisplay + cmp byte[CSOverValue],1 + je near .nodisplay + mov byte[CSInputDisplay],'_' + mov byte[CSInputDisplay+1],0 + ; Process Cheat Search + mov ecx,65536*2 + xor ebx,ebx + mov bl,byte[CheatSrcByteSize] + sub ecx,ebx + mov edx,[SrcMask+ebx*4] + mov edi,dword[vidbuffer] + add edi,129600+65536*2 + mov esi,[wramdata] + mov bl,0FEh + mov bh,01h +.exactloop + mov eax,[esi] + and eax,edx + cmp eax,[CSCurValue] + je .found + inc eax + and eax,edx + cmp eax,[CSCurValue] + je .foundb +.failedfind + and [edi],bl + jmp .foundc +.found + test byte[edi+16384],bh + jz .failedfind + jmp .foundc +.foundb + cmp byte[FirstSearch],1 + je .clear + test byte[edi+16384],bh + jnz .failedfind + jmp .foundc +.clear + and byte[edi+16384],bl +.foundc + cmp bl,7Fh + jne .noincedi + inc edi +.noincedi + rol bl,1 + rol bh,1 + inc esi + loop .exactloop +; CSCurValue dd 0 + mov byte[CopyRamToggle],1 + mov byte[CheatSearchStatus],1 +.nodisplay + ret +.comparative + mov byte[CSInputDisplay],'_' + mov byte[CSInputDisplay+1],0 + mov byte[CheatSearchStatus],1 + mov eax,dword[vidbuffer] + add eax,129600+65536*2 + mov esi,dword[vidbuffer] + add esi,129600 + mov edi,[wramdata] + mov ecx,65536*2 + cmp byte[CheatSrcByteSize],1 + je near .bytesize2 + cmp byte[CheatSrcByteSize],2 + je near .bytesize3 + cmp byte[CheatSrcByteSize],3 + je near .bytesize4 + SearchMacroB SearchCMPByte +.bytesize2 + dec ecx + SearchMacroB SearchCMP2Bytes +.bytesize3 + sub ecx,2 + SearchMacroB SearchCMP3Bytes +.bytesize4 + sub ecx,3 + SearchMacroB SearchCMP4Bytes +.end + mov byte[CopyRamToggle],1 + ret + +CopyRamToggle db 0 +FirstSearch db 0 + +CheatCodeSearchInit: + mov byte[CSInputDisplay],'_' + mov byte[CSInputDisplay+1],0 + mov byte[CheatWinMode],1 + mov byte[CheatSearchStatus],0 + cmp byte[CopyRamToggle],0 + mov byte[FirstSearch],1 + mov eax,dword[vidbuffer] + add eax,129600 + ; copy 128k ram + mov ebx,[wramdata] + mov ecx,32768 +.loop + mov edx,[ebx] + mov [eax],edx + add ebx,4 + add eax,4 + loop .loop + ; fill searched buffer with 0xFF + mov eax,dword[vidbuffer] + add eax,129600+65536*2 + mov ecx,8192 +.loop2 + mov dword[eax],0FFFFFFFFh + add eax,4 + loop .loop2 + cmp byte[CheatSrcSearchType],1 + jne .nottype1 + mov byte[CheatSearchStatus],1 +.nottype1 + mov dword[CheatCompareValue],0 + mov eax,dword[vidbuffer] + add eax,129600+65536*2 + cmp byte[CheatSrcByteSize],1 + je near .bytesize2 + cmp byte[CheatSrcByteSize],2 + je near .bytesize3 + cmp byte[CheatSrcByteSize],3 + je near .bytesize4 + ret +.bytesize2 + and byte[eax+16383],07Fh + ret +.bytesize3 + and byte[eax+16383],03Fh + ret +.bytesize4 + and byte[eax+16383],01Fh + ret + +CheatCodeSave: + cmp byte[NumCheats],0 + jne .okay + mov byte[GUICBHold],0 + ret +.okay + mov byte[cheatdata+6],254 + mov byte[cheatdata+7],252 + + call SRAMDirc + mov byte[GUICBHold],0 + mov ebx,[statefileloc] + sub ebx,2 + mov eax,[fnamest+ebx] + mov dword[fnamest+ebx],'CHT' + push eax + push ebx + mov edx,fnamest+1 + call Create_File + jc .cheatsavefail + mov bx,ax + mov ecx,[NumCheats] + mov edx,ecx + shl ecx,4 + shl edx,2 + add ecx,edx + add ecx,edx + add ecx,edx + mov edx,cheatdata + call Write_File + call Close_File +.cheatsavefail + pop ebx + pop eax + mov [fnamest+ebx],eax + call LOADDir + ret + +CheatCodeLoad: + call SRAMDirc + mov byte[GUICBHold],0 + mov ebx,[statefileloc] + sub ebx,2 + mov eax,[fnamest+ebx] + mov dword[fnamest+ebx],'CHT' + push eax + push ebx + mov edx,fnamest+1 + call Open_File + jc near .fail + mov bx,ax + ; Disable all codes + push ebx + mov esi,cheatdata + mov ecx,[NumCheats] + cmp ecx,0 + je .skip +.loop2 + test byte[esi],4 + jnz .disabled2 + push esi + push ecx + call DisableCheatCode + pop ecx + pop esi +.disabled2 + add esi,28 + dec ecx + jnz .loop2 +.skip + pop ebx + mov ecx,255*28 + mov edx,cheatdata + call Read_File + push eax + call Close_File + pop eax + cmp byte[cheatdata+6],254 + jne .notnewformat + cmp byte[cheatdata+7],252 + jne .notnewformat + jmp .newformat +.notnewformat + ; Convert format + mov esi,cheatdata + mov ebx,18 + push eax + xor edx,edx + div ebx + push edx + mov [NumCheats],eax + mov ebx,28 + mul ebx + mov ecx,eax + pop edx + pop eax + sub eax,edx +.convloop + sub ecx,28 + sub eax,18 + mov ebx,6 +.convloopb + mov dl,[cheatdata+eax+ebx-1] + mov [cheatdata+ecx+ebx-1],dl + dec ebx + jnz .convloopb + mov ebx,12 +.convloopd + mov dl,[cheatdata+eax+ebx+5] + mov [cheatdata+ecx+ebx+7],dl + dec ebx + jnz .convloopd + mov ebx,8 +.convloopc + mov byte[cheatdata+ecx+ebx+19],0 + dec ebx + jnz .convloopc + or ecx,ecx + jnz .convloop + jmp .fin +.newformat + mov ebx,28 + xor edx,edx + div ebx + mov [NumCheats],eax +.fin + pop ebx + pop eax + mov [fnamest+ebx],eax + ; Enable all ON toggled cheat codes + mov esi,cheatdata + mov ecx,[NumCheats] + cmp ecx,0 + je .skip2 +.loop + test byte[esi],4 + jnz .disabled + push esi + push ecx + call EnableCheatCode + pop ecx + pop esi +.disabled + add esi,28 + dec ecx + jnz .loop +.skip2 + mov eax,[NumCheats] + cmp eax,[GUIcurrentcheatcursloc] + ja .noconf + dec eax + mov dword[GUIcurrentcheatcursloc],eax +.noconf + cmp dword[NumCheats],0 + jne .nozero + mov dword[GUIcurrentcheatcursloc],0 + mov byte[CheatOn],0 + call LOADDir + ret +.nozero + mov byte[CheatOn],1 + call LOADDir + ret +.fail + pop ebx + pop eax + mov [fnamest+ebx],eax + call LOADDir + ret + +CheatCodeRemove: + cmp dword[NumCheats],0 + jne .nonone + mov byte[GUICBHold],0 + ret +.nonone + mov byte[GUICBHold],0 + mov esi,[GUIcurrentcheatcursloc] + shl esi,5 + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + add esi,cheatdata + push esi + call DisableCheatCode + pop esi + mov eax,255 + sub eax,[GUIcurrentcheatcursloc] + mov ebx,eax + shl eax,4 + add eax,ebx + add eax,ebx +.loop + mov bl,[esi+28] + mov [esi],bl + inc esi + dec eax + jnz .loop + dec dword[NumCheats] + mov eax,[GUIcurrentcheatcursloc] + cmp dword[NumCheats],0 + je .okay + cmp eax,[NumCheats] + jne .okay + dec dword[GUIcurrentcheatcursloc] +.okay + cmp byte[NumCheats],0 + jne .cheatexists + mov byte[CheatOn],0 +.cheatexists + ret + +CheatCodeFix: + cmp dword[NumCheats],0 + jne .nonone + mov byte[GUICBHold],0 + ret +.nonone + mov byte[GUICBHold],0 + call DisableCheatCode + mov esi,[GUIcurrentcheatcursloc] + shl esi,5 + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + add esi,cheatdata + xor byte[esi+3],80h + call EnableCheatCodeNoPrevMod + ret + +CheatCodeToggle: + cmp dword[NumCheats],0 + jne .nonone + mov byte[GUICBHold],0 + ret +.nonone + mov byte[GUICBHold],0 + mov esi,[GUIcurrentcheatcursloc] + shl esi,5 + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + add esi,cheatdata + test byte[esi],4 + jz DisableCheatCode + jmp EnableCheatCodeNoPrevMod + +DisableCheatCode: + ; code is at esi + xor ecx,ecx + xor ebx,ebx + or byte[esi],4 + test byte[esi],1 + jnz .gfrom + mov al,[esi+5] + mov cx,[esi+2] + mov bl,[esi+4] + mov byte[writeon],1 + test byte[esi],80h + jnz .nowrite + test byte[esi-28],80h + jnz .nowrite + call dword near [memtablew8+ebx*4] +.nowrite + mov byte[writeon],0 + ret +.gfrom + mov al,[esi+5] + mov ecx,[esi+2] + and ecx,0FFFFFFh + mov esi,[romdata] + mov [esi+ecx],al + ret +.gfram + mov al,[esi+5] + mov ecx,[esi+2] + and ecx,0FFFFFFh + mov esi,[sram] + mov [esi+ecx],al + ret + +EnableCheatCode: + ; code is at esi + xor ecx,ecx + xor ebx,ebx + and byte[esi],0FBh + test byte[esi],1 + jnz .gfrom + mov al,[esi+1] + mov cx,[esi+2] + mov bl,[esi+4] + push ecx + push eax + push ebx + push edx + call dword near [memtabler8+ebx*4] + pop edx + mov byte[esi+5],al + pop ebx + pop eax + pop ecx + mov byte[writeon],1 + test byte[esi],80h + jnz .nowrite + test byte[esi-28],80h + jnz .nowrite + call dword near [memtablew8+ebx*4] +.nowrite + mov byte[writeon],0 + ret +.gfrom + mov al,[esi+1] + mov ecx,[esi+2] + and ecx,0FFFFFFh + mov esi,[romdata] + mov bl,[esi+ecx] + mov [esi+ecx],al + mov [esi+5],bl + ret +.gfram + mov al,[esi+1] + mov ecx,[esi+2] + and ecx,0FFFFFFh + mov esi,[sram] + mov bl,[esi+ecx] + mov [esi+ecx],al + mov [esi+5],bl + ret + +EnableCheatCodeNoPrevMod: + ; code is at esi + xor ecx,ecx + xor ebx,ebx + and byte[esi],0FBh + test byte[esi],1 + jnz .gfrom + mov al,[esi+1] + mov cx,[esi+2] + mov bl,[esi+4] + mov byte[writeon],1 + test byte[esi],80h + jnz .nowrite + test byte[esi-28],80h + jnz .nowrite + call dword near [memtablew8+ebx*4] +.nowrite + mov byte[writeon],0 + ret +.gfrom + mov al,[esi+1] + mov ecx,[esi+2] + and ecx,0FFFFFFh + mov esi,[romdata] + mov bl,[esi+ecx] + mov [esi+ecx],al + mov [esi+5],bl + ret +.gfram + mov al,[esi+1] + mov ecx,[esi+2] + and ecx,0FFFFFFh + mov esi,[sram] + mov bl,[esi+ecx] + mov [esi+ecx],al + mov [esi+5],bl + ret + +AddCheatCode: + mov byte[GUICBHold],0 + cmp dword[NumCheats],255 + jne .okay + ret +.okay + push eax + push ebx + ; transfer description + mov eax,[NumCheats] + shl eax,5 + sub eax,[NumCheats] + sub eax,[NumCheats] + sub eax,[NumCheats] + sub eax,[NumCheats] + add eax,cheatdata + mov edx,eax + push edx + add eax,6 + mov ebx,CSDescDisplay + mov ecx,20 +.dloop + mov dl,[ebx] + mov [eax+2],dl + mov [eax+18+2],dl + mov [eax+18*2+2],dl + inc ebx + inc eax + loop .dloop + pop edx + pop ebx + pop eax + ; toggle, value, address, pvalue, name(12) + mov byte[edx],0 + mov [edx+1],bl + push eax + sub eax,7E0000h + add eax,[wramdata] + mov bh,[eax] + mov [eax],bl + pop eax + mov [edx+2],eax + mov [edx+5],bh + inc dword[NumCheats] + mov edx,7 + mov al,[GUIpmenupos] + push eax + call CheckMenuItemHelp + pop eax + mov [GUIpmenupos],al + mov byte[CheatOn],1 + ret + +ProcessCheatCode: + mov byte[GUICBHold],0 + cmp dword[NumCheats],255 + je .fail + cmp byte[GUICheatPosA],0 + je .fail + jmp .okay +.fail + ret +.okay + ; make sure flashing cursor doesn't exist + xor ebx,ebx + mov bl,[GUICheatPosB] + mov byte[GUICheatTextA+ebx],0 + ; transfer description + mov eax,[NumCheats] + shl eax,5 + sub eax,[NumCheats] + sub eax,[NumCheats] + sub eax,[NumCheats] + sub eax,[NumCheats] + add eax,cheatdata + add eax,6 + mov ebx,GUICheatTextA + mov ecx,20 +.dloop + mov dl,[ebx] + mov [eax+2],dl + mov [eax+18+2],dl + mov [eax+18*2+2],dl + inc ebx + inc eax + loop .dloop + ; determine whether it is gamegenie, par, or GF + ; uppercase all codes if necessary + mov eax,GUICheatText9 + mov ecx,14 +.loop + mov bl,[eax] + cmp bl,'a' + jb .nolower + cmp bl,'z' + ja .nolower + sub bl,'a'-'A' + mov [eax],bl +.nolower + inc eax + loop .loop + mov byte[guicheatvalrep],0 + xor eax,eax + mov al,[GUICheatPosA] + dec al + cmp byte[GUICheatText9+eax],'R' + jne .notrep + mov byte[guicheatvalrep],80h + dec byte[GUICheatPosA] +.notrep + cmp byte[GUICheatPosA],8 + je near .par + cmp byte[GUICheatPosA],9 + je near .gg + cmp byte[GUICheatPosA],14 + je near .gf +.invalidpar + jmp guicheaterror +.par + ; check if code is valid + mov eax,GUICheatText9 + mov ecx,8 +.looppar + mov bl,[eax] + cmp bl,'0' + jb .invalidpar + cmp bl,'9' + jbe .okaypar + cmp bl,'A' + jb .invalidpar + cmp bl,'F' + ja .invalidpar +.okaypar + inc eax + loop .looppar + jmp decodepar +.invalidgg + jmp guicheaterror +.gg + ; check if code is valid + mov eax,GUICheatText9 + mov ecx,9 +.loopgg + cmp ecx,5 + jne .nomid + cmp byte[eax],'-' + jne .invalidgg + inc eax + dec ecx +.nomid + mov bl,[eax] + cmp bl,'0' + jb .invalidgg + cmp bl,'9' + jbe .okaygg + cmp bl,'A' + jb .invalidgg + cmp bl,'F' + ja .invalidgg +.okaygg + inc eax + loop .loopgg + jmp decodegg + ret +.invalidgf + jmp guicheaterror +.gf + ; check if code is valid + mov eax,GUICheatText9 + mov ecx,5 +.loopgf + mov bl,[eax] + cmp bl,'0' + jb .invalidgf + cmp bl,'9' + jbe .okaygf + cmp bl,'A' + jb .invalidgf + cmp bl,'F' + ja .invalidgf +.okaygf + inc eax + loop .loopgf + mov eax,GUICheatText9+5 + mov ecx,6 +.loopgf2 + mov bl,[eax] + cmp bl,'X' + je .okaygf2 + cmp bl,'0' + jb .invalidgf + cmp bl,'9' + jbe .okaygf2 + cmp bl,'A' + jb near .invalidgf + cmp bl,'F' + ja near .invalidgf +.okaygf2 + inc eax + loop .loopgf2 + mov bl,[GUICheatText9+13] + cmp bl,'0' + je .okaygf3 + cmp bl,'1' + jne near .invalidgf +.okaygf3 + jmp decodegf + +decodegf: + ; convert code to number format + mov ecx,14 + mov esi,GUICheatText9 +.loopb2 + mov al,[esi] + cmp al,'X' + je .let2 + cmp al,'A' + jb .num2 + sub al,'A' + add al,10 + jmp .let2 +.num2 + sub al,'0' +.let2 + mov [esi],al + inc esi + dec ecx + jnz .loopb2 + + ; get address + xor ebx,ebx + xor ecx,ecx + mov cl,[GUICheatText9] + shl ecx,4 + add cl,[GUICheatText9+1] + shl ecx,4 + add cl,[GUICheatText9+2] + shl ecx,4 + add cl,[GUICheatText9+3] + shl ecx,4 + add cl,[GUICheatText9+4] + + mov edx,[NumCheats] + shl edx,5 + sub edx,[NumCheats] + sub edx,[NumCheats] + sub edx,[NumCheats] + sub edx,[NumCheats] + + ; Write data to memory + cmp byte[GUICheatText9+13],1 + je near .modifysram + + ; get data + cmp byte[GUICheatText9+5],'X' + je near .nocode + cmp byte[GUICheatText9+6],'X' + je near .nocode + mov bl,[GUICheatText9+5] + shl bl,4 + add bl,[GUICheatText9+6] + mov esi,[romdata] + mov al,[esi+ecx] + mov [esi+ecx],bl + mov byte[cheatdata+edx],1 + mov [cheatdata+edx+2],ecx + mov [cheatdata+edx+1],bl + mov [cheatdata+edx+5],al + push eax + mov al,[guicheatvalrep] + or [cheatdata+edx],al + pop eax + inc byte[NumCheats] + add edx,28 +.nocode + inc ecx + cmp byte[GUICheatText9+7],'X' + je near .nocode1 + cmp byte[GUICheatText9+8],'X' + je near .nocode1 + cmp byte[NumCheats],255 + je near .nocode1 + mov bl,[GUICheatText9+7] + shl bl,4 + add bl,[GUICheatText9+8] + mov esi,[romdata] + mov al,[esi+ecx] + mov [esi+ecx],bl + mov byte[cheatdata+edx],1 + mov [cheatdata+edx+2],ecx + mov [cheatdata+edx+1],bl + mov [cheatdata+edx+5],al + inc byte[NumCheats] + add edx,28 +.nocode1 + inc ecx + cmp byte[GUICheatText9+9],'X' + je near .nocode2 + cmp byte[GUICheatText9+10],'X' + je near .nocode2 + cmp byte[NumCheats],255 + je near .nocode2 + mov bl,[GUICheatText9+9] + shl bl,4 + add bl,[GUICheatText9+10] + mov esi,[romdata] + mov al,[esi+ecx] + mov [esi+ecx],bl + mov byte[cheatdata+edx],1 + mov [cheatdata+edx+2],ecx + mov [cheatdata+edx+1],bl + mov [cheatdata+edx+5],al + inc byte[NumCheats] +.nocode2 + jmp .quit + +.modifysram + cmp ecx,65535 + ja near .quit + mov esi,[sram] + ; get data + cmp byte[GUICheatText9+5],'X' + je .nocodeb + cmp byte[GUICheatText9+6],'X' + je .nocodeb + mov bl,[GUICheatText9+5] + shl bl,4 + add bl,[GUICheatText9+6] + mov al,[esi+ecx] + mov [esi+ecx],bl + mov byte[cheatdata+edx],2 + mov [cheatdata+edx+2],ecx + mov [cheatdata+edx+1],bl + mov [cheatdata+edx+5],al + inc byte[NumCheats] + add edx,28 +.nocodeb + inc ecx + cmp byte[GUICheatText9+7],'X' + je .nocode1b + cmp byte[GUICheatText9+8],'X' + je .nocode1b + cmp byte[NumCheats],255 + je .nocode1b + cmp ecx,65535 + ja .nocode1b + mov bl,[GUICheatText9+7] + shl bl,4 + add bl,[GUICheatText9+8] + mov al,[esi+ecx+1] + mov [esi+ecx+1],bl + mov byte[cheatdata+edx],2 + mov [cheatdata+edx+2],ecx + mov [cheatdata+edx+1],bl + mov [cheatdata+edx+5],al + inc byte[NumCheats] + add edx,28 +.nocode1b + inc ecx + cmp byte[GUICheatText9+9],'X' + je .nocode2c + cmp byte[GUICheatText9+10],'X' + je .nocode2c + cmp byte[NumCheats],255 + je .nocode2c + cmp ecx,65535 + ja .nocode2c + mov bl,[GUICheatText9+9] + shl bl,4 + add bl,[GUICheatText9+10] + mov al,[esi+ecx+2] + mov [esi+ecx+2],bl + mov byte[cheatdata+edx],2 + mov [cheatdata+edx+2],ecx + mov [cheatdata+edx+1],bl + mov [cheatdata+edx+5],al + inc byte[NumCheats] +.nocode2c + +.quit + cmp byte[NumCheats],0 + je .nocheat + mov byte[CheatOn],1 + mov dword[GUIcurrentcheatwin],1 + mov eax,[NumCheats] + dec eax + mov [GUIcurrentcheatcursloc],eax + sub eax,11 + mov [GUIcurrentcheatviewloc],eax + test dword[GUIcurrentcheatviewloc],80000000h + jz .noview + mov dword[GUIcurrentcheatviewloc],0 +.noview +.nocheat + mov dword[GUICheatText9],0 + mov dword[GUICheatTextA],0 + mov byte[GUICheatPosA],0 + mov byte[GUICheatPosB],0 + ret + +decodegg: +;Genie Hex: D F 4 7 0 9 1 5 6 B C 8 A 2 3 E +;Normal Hex: 0 1 2 3 4 5 6 7 8 9 A B C D E F +; 4 6 D E 2 7 8 3 B 5 C 9 A 0 F 1 + ; Convert code + mov esi,GUICheatText9 + mov eax,[esi+5] + mov [esi+4],eax + ; convert code to number format + mov ecx,8 + xor eax,eax +.loopb3 + mov al,[esi] + cmp al,'A' + jb .num3 + sub al,'A' + add al,10 + jmp .let3 +.num3 + sub al,'0' +.let3 + mov al,[.GG2Norm+eax] + mov [esi],al + inc esi + dec ecx + jnz .loopb3 + + mov esi,GUICheatText9 + xor ecx,ecx + mov cl,[esi+2] + shl ecx,4 + add cl,[esi+3] + shl ecx,4 + add cl,[esi+4] + shl ecx,4 + add cl,[esi+5] + shl ecx,4 + add cl,[esi+6] + shl ecx,4 + add cl,[esi+7] +; 0123456789ABCDEF01234567 +; 24bit encoded address: ijklqrstopabcduvwxefghmn +; abcdefghijklmnopqrstuvwx +; >8 >12 >6<10 >6 <14 <10 + mov ebx,ecx + and ebx,000000000011110000000000b ;abcd + shl ebx,10 + mov eax,ecx + and eax,000000000000000000111100b ;efgh + shl eax,14 + add ebx,eax + mov eax,ecx + and eax,111100000000000000000000b ;ijkl + shr eax,8 + add ebx,eax + mov eax,ecx + and eax,000000000000000000000011b ;mn + shl eax,10 + add ebx,eax + mov eax,ecx + and eax,000000001100000000000000b ;op + shr eax,6 + add ebx,eax + mov eax,ecx + and eax,000011110000000000000000b ;qrst + shr eax,12 + add ebx,eax + mov eax,ecx + and eax,000000000000001111000000b ;uvwx + shr eax,6 + add ebx,eax + xor ecx,ecx + mov cx,bx + shr ebx,16 + test bl,40h + jz .noover +; xor cx,8000h +.noover + mov al,[esi] + shl al,4 + add al,[esi+1] + + ; store into cheatdata + mov edx,[NumCheats] + shl edx,5 + sub edx,[NumCheats] + sub edx,[NumCheats] + sub edx,[NumCheats] + sub edx,[NumCheats] + mov byte[cheatdata+edx],0 + mov [cheatdata+edx+1],al + mov [cheatdata+edx+2],cx + mov [cheatdata+edx+4],bl + push eax + mov al,[guicheatvalrep] + or [cheatdata+edx],al + pop eax + push ecx + push eax + push ebx + push edx + call dword near [memtabler8+ebx*4] + pop edx + mov byte[cheatdata+edx+5],al + pop ebx + pop eax + pop ecx + + mov byte[writeon],1 + + test byte[cheatdata+edx],80h + jnz .nowrite + test byte[cheatdata+edx-28],80h + jnz .nowrite + call dword near [memtablew8+ebx*4] +.nowrite + + mov byte[writeon],0 + mov byte[CheatOn],1 + inc byte[NumCheats] + mov dword[GUICheatText9],0 + mov dword[GUICheatTextA],0 + mov byte[GUICheatPosA],0 + mov byte[GUICheatPosB],0 + mov dword[GUIcurrentcheatwin],1 + mov eax,[NumCheats] + dec eax + mov [GUIcurrentcheatcursloc],eax + sub eax,11 + mov [GUIcurrentcheatviewloc],eax + test dword[GUIcurrentcheatviewloc],80000000h + jz .noview + mov dword[GUIcurrentcheatviewloc],0 +.noview + ret +.GG2Norm db 04h,06h,0Dh,0Eh,02h,07h,08h,03h,0Bh,05h,0Ch,09h,0Ah,00h,0Fh,01h + +decodepar: + ; convert code to number format + mov ecx,8 + mov esi,GUICheatText9 +.loopb + mov al,[esi] + cmp al,'A' + jb .num + sub al,'A' + add al,10 + jmp .let +.num + sub al,'0' +.let + mov [esi],al + inc esi + dec ecx + jnz .loopb + ; get address + xor ebx,ebx + xor ecx,ecx + mov bl,[GUICheatText9] + shl bl,4 + add bl,[GUICheatText9+1] + mov cl,[GUICheatText9+2] + shl cx,4 + add cl,[GUICheatText9+3] + shl cx,4 + add cl,[GUICheatText9+4] + shl cx,4 + add cl,[GUICheatText9+5] + mov al,[GUICheatText9+6] + shl al,4 + add al,[GUICheatText9+7] + + ; store into cheatdata + xor edx,edx + mov dl,[NumCheats] + push ebx + mov ebx,edx + shl edx,5 + sub edx,ebx + sub edx,ebx + sub edx,ebx + sub edx,ebx + pop ebx + mov byte[cheatdata+edx],0 + mov [cheatdata+edx+1],al + mov [cheatdata+edx+2],cx + mov [cheatdata+edx+4],bl + push eax + mov al,[guicheatvalrep] + or [cheatdata+edx],al + pop eax + push ecx + push eax + push ebx + push edx + call dword near [memtabler8+ebx*4] + pop edx + mov byte[cheatdata+edx+5],al + pop ebx + pop eax + pop ecx + + mov byte[writeon],1 + test byte[cheatdata+edx],80h + jnz .nowrite + test byte[cheatdata+edx-28],80h + jnz .nowrite + call dword near [memtablew8+ebx*4] +.nowrite + mov byte[writeon],0 + mov byte[CheatOn],1 + inc dword[NumCheats] + mov dword[GUICheatText9],0 + mov dword[GUICheatTextA],0 + mov byte[GUICheatPosA],0 + mov byte[GUICheatPosB],0 + mov dword[GUIcurrentcheatwin],1 + mov eax,[NumCheats] + dec eax + mov [GUIcurrentcheatcursloc],eax + sub eax,11 + mov [GUIcurrentcheatviewloc],eax + test dword[GUIcurrentcheatviewloc],80000000h + jz .noview + mov dword[GUIcurrentcheatviewloc],0 +.noview + ret + +guicheaterror: + xor ebx,ebx + mov ecx,256+128+64 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a +.again + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 75,95,192,143,160 + GUIBox 75,95,192,95,162 + GUIBox 75,95,75,143,161 + GUIBox 192,95,192,143,159 + GUIBox 75,143,192,143,158 + GUIOuttext 81,101,guicheaterror1,220-15 + GUIOuttext 80,100,guicheaterror1,220 + GUIOuttext 81,109,guicheaterror2,220-15 + GUIOuttext 80,108,guicheaterror2,220 + GUIOuttext 81,117,guicheaterror3,220-15 + GUIOuttext 80,116,guicheaterror3,220 + GUIOuttext 81,125,guicheaterror4,220-15 + GUIOuttext 80,124,guicheaterror4,220 + GUIOuttext 81,135,guicheaterror5,220-15 + GUIOuttext 80,134,guicheaterror5,220 + call vidpastecopyscr + call JoyRead + xor ebx,ebx + mov ecx,256+128+64 +.b + cmp byte[pressed+ebx],0 + jne .pressedokay + inc ebx + loop .b + cmp byte[MouseDis],1 + je .mousedis + call Get_MouseData + test bx,01h + jnz .pressedokay +.mousedis + jmp .again +.pressedokay +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey + cmp byte[MouseDis],1 + je .mousedis2 + push ebx +; mov eax,0Bh +; int 33h + pop ebx +.mousedis2 + mov dword[GUIcurrentcheatwin],1 + mov byte[GUIpclicked],1 + ret +guicheaterror1 db 'INVALID CODE! YOU',0 +guicheaterror2 db 'MUST ENTER A VALID',0 +guicheaterror3 db 'GAME GENIE,PAR, OR',0 +guicheaterror4 db 'GOLD FINGER CODE.',0 +guicheaterror5 db 'PRESS ANY KEY.',0 +guicheatvalrep db 0 + + \ No newline at end of file diff --git a/zsnes/src/gui/guicombo.inc b/zsnes/src/gui/guicombo.inc new file mode 100644 index 00000000..b6ebd103 --- /dev/null +++ b/zsnes/src/gui/guicombo.inc @@ -0,0 +1,190 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + +ComboClip: + xor eax,eax + mov al,[GUINumCombo] +.next + cmp al,42 + jae .excess + mov byte[GUIComboData+eax],0 + inc eax + jmp .next +.excess + ret + +ComboAdder: + cmp byte[romloadskip],0 + je .romloaded + cmp byte[GUIComboGameSpec],0 + jne near .skipall +.romloaded + pushad + call ComboClip + mov eax,[NumCombo] + shl eax,6 + add eax,[NumCombo] + add eax,[NumCombo] + add eax,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespec + sub eax,CombinDataGlob + add eax,CombinDataLocl +.nogamespec + ; copy data to eax + mov ecx,20 ; copy name + mov ebx,GUIComboTextH +.loop + mov dl,[ebx] + mov [eax],dl + inc ebx + inc eax + loop .loop + mov ecx,42 ; copy combination code + mov ebx,GUIComboData +.loop2 + mov dl,[ebx] + mov [eax],dl + inc ebx + inc eax + loop .loop2 + mov dx,[GUIComboKey] + mov [eax],dx + mov dl,[GUIComboPNum] + mov [eax+2],dl + mov dl,[GUIComboLHorz] + mov [eax+3],dl + mov eax,[NumCombo] + mov [GUIccombcursloc],eax + sub eax,7 + cmp [GUIccombviewloc],eax + jge .rangeokay + mov [GUIccombviewloc],eax +.rangeokay + inc dword[NumCombo] + mov eax,[NumCombo] + cmp byte[GUIComboGameSpec],0 + jne .local + mov [NumComboGlob],eax + jmp .global +.local + mov [NumComboLocl],eax +.global + popad + mov byte[GUIComboTextH],0 + mov byte[GUINumCombo],0 + mov dword[GUIComboKey],0 +.skipall + ret + +ComboReplace: + pushad + call ComboClip + mov eax,[GUIccombcursloc] + shl eax,6 + add eax,[GUIccombcursloc] + add eax,[GUIccombcursloc] + add eax,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespec + sub eax,CombinDataGlob + add eax,CombinDataLocl +.nogamespec + ; copy data to eax + mov ecx,20 ; copy name + mov ebx,GUIComboTextH +.loop + mov dl,[ebx] + mov [eax],dl + inc ebx + inc eax + loop .loop + mov ecx,42 ; copy combination code + mov ebx,GUIComboData +.loop2 + mov dl,[ebx] + mov [eax],dl + inc ebx + inc eax + loop .loop2 + mov dx,[GUIComboKey] + mov [eax],dx + mov dl,[GUIComboPNum] + mov [eax+2],dl + mov dl,[GUIComboLHorz] + mov [eax+3],dl + popad + ret + +ComboRemoval: + pushad + mov eax,[GUIccombcursloc] + shl eax,6 + add eax,[GUIccombcursloc] + add eax,[GUIccombcursloc] + add eax,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespec + sub eax,CombinDataGlob + add eax,CombinDataLocl +.nogamespec + mov ecx,[NumCombo] + sub ecx,[GUIccombcursloc] + dec ecx + cmp ecx,0 + jle .nomove +.loop2 + mov ebx,66 +.loop + mov dl,[eax+66] + mov [eax],dl + inc eax + dec ebx + jnz .loop + loop .loop2 +.nomove + dec dword[NumCombo] + mov eax,[NumCombo] + or eax,eax + jz .yeszero + dec eax +.yeszero + cmp [GUIccombviewloc],eax + jbe .notequal + mov [GUIccombviewloc],eax +.notequal + cmp [GUIccombcursloc],eax + jbe .notequal2 + mov [GUIccombcursloc],eax +.notequal2 + mov eax,[NumCombo] + cmp byte[GUIComboGameSpec],0 + jne .local + mov [NumComboGlob],eax + jmp .global +.local + mov [NumComboLocl],eax +.global + popad + ret + \ No newline at end of file diff --git a/zsnes/src/gui/guikeys.inc b/zsnes/src/gui/guikeys.inc new file mode 100644 index 00000000..dacbba0b --- /dev/null +++ b/zsnes/src/gui/guikeys.inc @@ -0,0 +1,2186 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + +; GUI Keyboard Routines + +%macro GUIqcheckkeys 1 + cmp byte[pressed+%1],1 + jne %%skip + mov dword[GUIfirstkey],1 +%%skip +%endmacro + +%macro GUIqcheckkeys2 2 + mov eax,%1 + cmp byte[pressed+eax],1 + jne %%skip + cmp byte[GUIJoyPadnk+%2],2 + je %%skip + mov dword[GUIfirstkey],1 +%%skip +%endmacro + +%macro GUIgetprkeys 2 + cmp byte[pressed+%1],1 + je %%okay + cmp byte[pressed+%1],2 + jne %%nopr + cmp dword[GUIfirstkey],1 + je %%nopr + cmp dword[GUIlastkey],%1 + jne %%nopr + jmp %%skipnext +%%okay + mov dword[GUInextkeydelay],10 +%%skipnext + mov dword[GUIlastkey],%1 + mov byte[pressed+%1],2 + cmp dword[GUIkeydelay],0 + jne near .done + mov eax,[GUInextkeydelay] + mov [GUIkeydelay],eax + mov dword[GUInextkeydelay],2 + mov eax,%2 + jmp .done +%%nopr +%endmacro + +%macro GUIgetprkeysb 2 + cmp byte[pressed+%1],1 + jne %%nopr + cmp byte[GUIescpress],1 + je %%nopr2 + mov byte[pressed+%1],2 + mov eax,%2 + jmp .done +%%nopr + cmp byte[pressed+%1],0 + jne %%nopr2 + mov byte[GUIescpress],0 +%%nopr2 +%endmacro + +%macro GUIgetprkeys2 3 + mov ebx,%1 + cmp byte[pressed+ebx],0 + jne %%pressed + mov byte[GUIJoyPadnk+%3],0 + jmp %%nopr +%%pressed + cmp byte[GUIJoyPadnk+%3],2 + je %%secondpress + cmp byte[pressed+ebx],1 + je %%okay +%%secondpress + cmp dword[GUIfirstkey],1 + je %%nopr + cmp dword[GUIlastkey],ebx + jne %%nopr + jmp %%skipnext +%%okay + mov dword[GUInextkeydelay],10 +%%skipnext + mov [GUIlastkey],ebx + mov byte[GUIJoyPadnk+%3],2 + cmp dword[GUIkeydelay],0 + jne near .done + mov eax,[GUInextkeydelay] + mov [GUIkeydelay],eax + mov byte[GUIDelayB],5 + mov dword[GUInextkeydelay],2 + mov eax,%2 + jmp .done +%%nopr +%endmacro + +GUIfirstkey dd 0 +GUIlastkey dd 0 +NEWSYM GUIkeydelay, dd 0 +NEWSYM GUIkeydelay2, dd 0 +GUInextkeydelay dd 0 +GUIJoyPadnk db 0,0,0,0,0,0,0,0 +NEWSYM GUIDelayB, db 0 +UseExtKey db 0 + +GUIgetcurrentinput: + cmp byte[HoldCommand],2 + jne .nohold + ret +.nohold + mov byte[UseExtKey],0 + xor ch,ch + xor cl,cl +.getnextkey + call Check_Key + or al,al + jz .nokeyd + call Get_Key + cmp cl,0 + jne .nostorekey + mov ch,al +.nostorekey + xor cl,cl + cmp al,0 + jne .noextkey + call Get_Key + mov [UseExtKey],al + xor al,al + mov ch,al + mov cl,1 +.noextkey +; jmp .getnextkey +.nokeyd + mov dh,ch + mov byte[GUIDelayB],0 + ; Convert pressed to keys + mov dword[GUIfirstkey],0 +; GUIqcheckkeys 72 +; GUIqcheckkeys 80 + GUIqcheckkeys 75 + GUIqcheckkeys 77 + GUIqcheckkeys 73 + GUIqcheckkeys 81 + GUIqcheckkeys 71 + GUIqcheckkeys 79 + GUIqcheckkeys 1 + GUIqcheckkeys 1Ch + + cmp byte[OSPort],3 + jne near .notwinport + GUIqcheckkeys 0C8h + GUIqcheckkeys 0D0h + GUIqcheckkeys 0CBh + GUIqcheckkeys 0CDh + GUIqcheckkeys 0C9h + GUIqcheckkeys 0D1h + GUIqcheckkeys 0C7h + GUIqcheckkeys 0CFh + GUIqcheckkeys 09Ch +.notwinport + + cmp byte[JoyPad1Move],0 + je near .nopad1 + push edx + call JoyRead + pop edx + GUIqcheckkeys2 [pl1upk],0 + GUIqcheckkeys2 [pl1downk],1 + GUIqcheckkeys2 [pl1leftk],2 + GUIqcheckkeys2 [pl1rightk],3 + GUIqcheckkeys2 [pl1Lk],4 + GUIqcheckkeys2 [pl1Rk],5 + GUIqcheckkeys2 [pl1Bk],6 + GUIqcheckkeys2 [pl1Ak],7 +.nopad1 + xor al,al +; GUIgetprkeys 72,72 +; GUIgetprkeys 80,80 + GUIgetprkeys 75,75 + GUIgetprkeys 77,77 + GUIgetprkeys 71,71 + GUIgetprkeys 79,79 + GUIgetprkeys 81,81 + GUIgetprkeys 73,73 + GUIgetprkeysb 1,27 + GUIgetprkeys 1Ch,13 + + mov cl,[UseExtKey] + cmp cl,72 + je .okayextk + cmp cl,80 + jne .notextkb +.okayextk + mov al,cl +.notextkb + + cmp byte[OSPort],3 + jne near .notwinport2 +; GUIgetprkeys 0C8h,72 +; GUIgetprkeys 0D0h,80 + GUIgetprkeys 0CBh,75 + GUIgetprkeys 0CDh,77 + GUIgetprkeys 0C9h,73 + GUIgetprkeys 0D1h,81 + GUIgetprkeys 0C7h,71 + GUIgetprkeys 0CFh,79 + GUIgetprkeys 09Ch,13 +.notwinport2 + + cmp byte[JoyPad1Move],0 + je near .nopad1b + GUIgetprkeys2 [pl1upk],72,0 + GUIgetprkeys2 [pl1downk],80,1 + GUIgetprkeys2 [pl1leftk],75,2 + GUIgetprkeys2 [pl1rightk],77,3 + GUIgetprkeys2 [pl1Lk],73,4 + GUIgetprkeys2 [pl1Rk],81,5 + GUIgetprkeys2 [pl1Bk],27,6 + GUIgetprkeys2 [pl1Ak],13,7 +.nopad1b + cmp dh,' ' + jne .notspace + mov al,' ' +.notspace + mov dword[GUInextkeydelay],10 + mov dword[GUIkeydelay],0 +.done + cmp byte[GUIcmenupos],0 + jne near .processmenu + mov dl,al + xor eax,eax + mov al,[GUIwinptr] + cmp dl,27 + jne .noclosewin + or eax,eax + jz near .runprog +.noclosewin + dec eax + xor ebx,ebx + mov bl,[GUIwinorder+eax] + cmp ebx,8 + jne near .nonetwin + cmp byte[CNetType],12 + jne .noprocess7 + cmp byte[ModemProcess],7 + jne .noprocess7 + cmp dh,13 + je .ret + cmp dh,32 + jb .noprocess7 +.ret + mov al,dh + call ModemSendChar + ret +.noprocess7 + cmp dl,27 + jne .nonetwin + cmp byte[CNetType],2 + je .yesnetwin + cmp byte[CNetType],3 + je .yesnetwin + cmp byte[CNetType],10 + je .yesnetwin + cmp byte[CNetType],11 + je .yesnetwin + cmp byte[CNetType],12 + je .yesnetwin + cmp byte[CNetType],15 + je .yesnet15 + jmp .nonetwin +.yesnet15 + mov byte[CNetType],0 + cmp byte[OSPort],1 + je .nodeinitipx + call deinitipx +.nodeinitipx + jmp .closewin +.yesnetwin + cmp byte[ModemInitStat],0 + je .nodeinitmodem + call DeInitModemC + mov byte[ModemInitStat],0 +.nodeinitmodem + mov byte[CNetType],1 + ret +.nonetwin + cmp ebx,13 + jne .notcskeys + cmp byte[CheatWinMode],1 + ja .avoidesc +.notcskeys + cmp dl,27 + je near .closewin +.avoidesc + mov al,dl + cmp ebx,1 + je near GUILoadKeys + cmp ebx,2 + je near GUIStateSelKeys + cmp ebx,4 + je near GUIOptionKeys + cmp ebx,6 + je near GUISoundKeys + cmp ebx,7 + je near GUICheatKeys + cmp ebx,10 + je near GUIGUIOptnsKeys + cmp ebx,12 + je near GUIResetKeys + cmp ebx,13 + je near GUICheatSearchKeys + cmp ebx,14 + je near GUIStateKeys + cmp ebx,16 + je near GUIComboKeys + cmp ebx,8 + jne .notstartmenu + cmp byte[CNetType],4 + jne .notcpip + jmp GUITCPIPKeys +.notcpip + cmp byte[CNetType],1 + jne .notstartmenu + jmp GUINetMenuKeys1 +.notstartmenu + cmp ebx,8 + je near GUIGetInputLine + ret +.runprog + cmp byte[romloadskip],0 + jne .noquit + mov byte[GUIQuit],2 +.noquit + ret +.closewin + ; close window + mov byte[GUIwinorder+eax],0 + mov byte[GUIwinactiv+ebx],0 + dec byte[GUIwinptr] + cmp byte[GUIwinptr],0 + jne .nowinopen + mov al,[GUIpmenupos] + mov [GUIcmenupos],al +.nowinopen + ret +.processmenu + cmp dh,'a' + jb .nolower + cmp dh,'z' + ja .nolower + sub dh,'a'-'A' +.nolower + cmp byte[GUIcmenupos],1 + jne near .noquickmenu + cmp dh,'1' + jne .no1 + mov byte[GUIcrowpos],0 +.no1 + cmp dh,'2' + jne .no2 + mov byte[GUIcrowpos],1 +.no2 + cmp dh,'3' + jne .no3 + mov byte[GUIcrowpos],2 +.no3 + cmp dh,'4' + jne .no4 + mov byte[GUIcrowpos],3 +.no4 + cmp dh,'5' + jne .no5 + mov byte[GUIcrowpos],4 +.no5 + cmp dh,'6' + jne .no6 + mov byte[GUIcrowpos],5 +.no6 + cmp dh,'7' + jne .no7 + mov byte[GUIcrowpos],6 +.no7 + cmp dh,'8' + jne .no8 + mov byte[GUIcrowpos],7 +.no8 + cmp dh,'9' + jne .no9 + mov byte[GUIcrowpos],8 +.no9 + cmp dh,'0' + jne .no0 + mov byte[GUIcrowpos],9 +.no0 + cmp dh,'F' + jne .nof + mov byte[GUIcrowpos],11 +.nof + cmp dh,'C' + jne .noc + mov byte[GUIcrowpos],12 +.noc +.noquickmenu + cmp byte[GUIcmenupos],2 + jne near .noloadmenu + cmp dh,'L' + jne .nol + mov byte[GUIcrowpos],0 +.nol + cmp dh,'R' + jne .nor + mov byte[GUIcrowpos],2 +.nor + cmp dh,'S' + jne .nos + mov byte[GUIcrowpos],4 +.nos + cmp dh,'O' + jne .noo + mov byte[GUIcrowpos],5 +.noo + cmp dh,'P' + jne .nop + mov byte[GUIcrowpos],6 +.nop + cmp dh,'Q' + jne .noq + mov byte[GUIcrowpos],8 +.noq +.noloadmenu + cmp byte[GUIcmenupos],4 + jne near .nocheatmenu + cmp dh,'A' + jne .noa + mov byte[GUIcrowpos],0 +.noa + cmp dh,'B' + jne .nob + mov byte[GUIcrowpos],1 +.nob + cmp dh,'S' + jne .nos2 + mov byte[GUIcrowpos],2 +.nos2 +.nocheatmenu + cmp byte[romloadskip],0 + jne .dontquit + cmp al,27 + jne .noexit + mov byte[GUIQuit],2 +.noexit +.dontquit + cmp al,13 + jne .noenter + call GUITryMenuItem +.noenter + cmp al,75 + jne .noleft + mov byte[GUIcrowpos],0 + cmp byte[GUIcmenupos],1 + jbe .left + dec byte[GUIcmenupos] + jmp .noleft +.left + mov byte[GUIcmenupos],6 +.noleft + cmp al,77 + jne .noright + mov byte[GUIcrowpos],0 + inc byte[GUIcmenupos] + cmp byte[GUIcmenupos],7 + jne .noright + mov byte[GUIcmenupos],1 +.noright + cmp byte[GUIcmenupos],0 + je near .noupdown + cmp al,80 + jne .nodown + xor eax,eax + mov al,[GUIcrowpos] + mov ebx,[GUICYLocPtr] + cmp byte[eax+ebx+1],2 + jne .nobottom + mov byte[GUIcrowpos],0 + jmp .nokey +.nobottom + inc eax + cmp byte[eax+ebx+1],0 + je .nobottom + mov [GUIcrowpos],al + jmp .nokey +.nodown + cmp al,72 + jne .noup + xor eax,eax + mov al,[GUIcrowpos] + mov ebx,[GUICYLocPtr] + or al,al + jz .top + cmp byte[eax+ebx+1],3 + jne .notop +.top + mov al,[ebx] + mov byte[GUIcrowpos],al + jmp .nokey +.notop + dec eax + cmp byte[eax+ebx+1],0 + je .notop + mov [GUIcrowpos],al + jmp .nokey +.noup +.noupdown +.nokey + ret + +GUITCPIPKeys: +;GUINetTextk2 db ' 0. 0. 0. 0',0 +;GUINetTextl2 db '7845',0 +;GUINetTextm2 db 0,0,0 + cmp byte[GUINetTextm2],1 + je near .section2 + mov edi,GUINetTextk2 + mov esi,26 + cmp byte[GUINetTextm2],2 + jne .notsecondstring + mov edi,ChatNick + mov esi,9 +.notsecondstring + mov ebx,edi +.next + cmp byte[ebx],0 + je .done2 + inc ebx + jmp .next +.done2 + sub ebx,edi + mov [GUINetTextm2+1],bl + xor eax,eax + mov al,[GUINetTextm2+1] + shl al,2 + add al,2 + cmp dh,32 + jbe .notnum2 + cmp byte[GUINetTextm2],0 + je .notsecondstringb + cmp dh,'_' + je .notsecondstringb + cmp dh,'-' + je .notsecondstringb + cmp dh,'^' + je .notsecondstringb + cmp dh,'=' + je .notsecondstringb + cmp dh,'+' + je .notsecondstringb + cmp dh,'[' + je .notsecondstringb + cmp dh,']' + je .notsecondstringb + cmp dh,'0' + jb .notnum2 + cmp dh,'9' + jbe .notsecondstringb + cmp dh,'A' + jb .notnum2 + cmp dh,'Z' + jbe .notsecondstringb + cmp dh,'a' + jb .notnum2 + cmp dh,'z' + jbe .notsecondstringb +.notsecondstringb + cmp ebx,esi + jae near .donesection1 + add ebx,edi + mov byte[ebx],dh + jmp .donesection1 +.notnum2 + cmp dh,8 + jne .notbacksp + or ebx,ebx + jz near .donesection1 + add ebx,edi + mov byte[ebx-1],0 + jmp .donesection1 +.notbacksp + cmp dh,'c' + je .yesc + cmp dh,'C' + jne .noc +.yesc +; mov byte[CNetType],15 +; mov byte[ModemProcess],41 +; mov byte[WhichRemote],4 +.noc + cmp dh,'s' + je .yess + cmp dh,'S' + jne .nos +.yess +; mov byte[CNetType],15 +; mov byte[ModemProcess],40 +; mov byte[WhichRemote],4 +.nos +.donesection1 + ret + +.section2 + mov ebx,GUINetTextl2 +.loopz + cmp byte[ebx],0 + je .donez + inc ebx + jmp .loopz +.donez + cmp byte[GUINetTextl2],'0' + jne .notzerob + cmp byte[GUINetTextl2+1],0 + jne .notzerob + dec ebx +.notzerob + cmp dh,'0' + jb .notnum + cmp dh,'9' + ja .notnum + mov byte[ebx],dh + mov byte[ebx+1],0 + push ebx + call .convert + pop ebx + cmp ecx,65536 + jb .donenumb + mov byte[ebx],0 +.donenumb + jmp .donenum +.notnum + cmp dh,8 + jne .donenum + cmp byte[GUINetTextl2],0 + je .donenum + mov byte[ebx-1],0 +.donenum + call .convert + cmp ecx,0 + jne .notzero + mov byte[GUINetTextl2],'0' + mov byte[GUINetTextl2+1],0 +.notzero + mov [TCPIPPortNum],ecx + ret +.convert + mov ebx,GUINetTextl2 + xor ecx,ecx +.loop + cmp byte[ebx],0 + je .done + mov eax,ecx + push ebx + mov ebx,10 + mul ebx + pop ebx + mov ecx,eax + xor eax,eax + mov al,[ebx] + sub eax,48 + add ecx,eax + inc ebx + jmp .loop +.done + ret + + +NEWSYM TCPIPPortNum, dd 7845 + +GUIOptionKeys: + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp dh,'A' + jne .noautofr + mov byte[FPSOn],0 + cmp byte[frameskip],0 + je .zero + mov byte[frameskip],0 + jmp .notzero +.zero + mov byte[frameskip],2 +.notzero +.noautofr + cmp dh,'N' + jne .nonewgfx + xor eax,eax + mov al,[cvidmode] + cmp byte[GUINGVID+eax],1 + jne near .invalidng + xor byte[newengen],1 + mov al,[newengen] + mov [cfgnewgfx],al +.invalidng +.nonewgfx + cmp dh,'V' + jne .novsync + xor byte[vsyncon],1 + mov al,[vsyncon] + mov [cfgvsync],al +.novsync + cmp dh,'M' + jne .nommxcopy + xor byte[FPUCopy],2 + mov al,[FPUCopy] + mov [cfgcopymethod],al +.nommxcopy + cmp dh,'U' + jne .nousepl34 + xor byte[pl12s34],1 + mov byte[MultiTap],1 + cmp byte[pl12s34],1 + je .nomtap + cmp byte[pl3contrl],0 + jne .mtap + cmp byte[pl4contrl],0 + jne .mtap + cmp byte[pl5contrl],0 + jne .mtap +.nomtap + mov byte[MultiTap],0 +.mtap +.nousepl34 + cmp dh,'S' + jne .noswfix + xor byte[SidewinderFix],1 +.noswfix + cmp dh,'P' + jne .nofpsatstart + xor byte[FPSAtStart],1 +.nofpsatstart + cmp dh,'E' + jne .nouse30hz + xor byte[Turbo30hz],1 +.nouse30hz + ret + +GUIGUIOptnsKeys: + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp dh,'M' + jne .guioptn1 + xor byte[mousewrap],1 +.guioptn1 + cmp dh,'S' + jne .guioptn2 + xor byte[mouseshad],1 +.guioptn2 + cmp dh,'K' + jne .guioptn3 + xor byte[lastcursres],1 +.guioptn3 + cmp dh,'W' + jne .guioptn4 + xor byte[resetposn],1 +.guioptn4 + cmp dh,'C' + jne .guioptn5 + xor byte[GUIClick],1 +.guioptn5 + cmp dh,'U' + jne .guioptn6 + xor byte[JoyPad1Move],1 +.guioptn6 + ret + +GUISoundKeys: + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp dh,'E' + jne .notenablesound + xor byte[cfgsoundon],1 +.notenablesound + cmp dh,'S' + jne .notstereo + xor byte[cfgStereoSound],1 +.notstereo + cmp dh,'N' + jne .notnoise + xor byte[SoundNoiseDis],1 +.notnoise + cmp dh,'R' + jne .notsrate + xor eax,eax + mov al,[cfgSoundQuality] + mov al,[.sampratenext+eax] + mov [cfgSoundQuality],al +.notsrate + cmp dh,'V' + jne .notrevst + xor byte[RevStereo],1 +.notrevst + ret + +.sampratenext db 1,4,5,6,2,3,0,0,0,0 + +GUINetMenuKeys1: + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp dh,'C' + jne .notconfig + mov byte[CNetType],2 +.notconfig + cmp dh,'D' + jne .notdial + mov byte[CNetType],3 +.notdial + cmp dh,'M' + jne .notmanual + mov byte[CNetType],12 + mov byte[ModemProcess],0 + cmp byte[ModemInitStat],1 + je .noinit + call InitModem + mov byte[ModemInitStat],1 +.noinit + ret +.notmanual + cmp dh,'W' + jne .notwait + mov byte[CNetType],10 + mov byte[ModemProcess],0 + cmp byte[ModemInitStat],1 + je .noinit2 + call InitModem + mov byte[ModemInitStat],1 +.noinit2 + ret +.notwait + ret + +GUIGetInputLine: + cmp ebx,8 + jne .nodial + cmp byte[CNetType],20 + jne .nochat + cmp dh,13 + jne .nochat + mov byte[RemoteCommand],2 + ret +.nochat + cmp byte[CNetType],3 + jne .nodial + cmp dh,13 + jne .nodial + mov byte[CNetType],11 + mov byte[ModemProcess],0 + cmp byte[ModemInitStat],1 + je .noinit + call InitModem + mov byte[ModemInitStat],1 +.noedit + ret +.noinit +.nodial + ; search string for 0, record length of string + cmp dword[GUIEditString],0 + je .noedit + mov eax,[GUIEditString] + xor ecx,ecx + dec ecx +.next + mov bl,[eax] + inc eax + inc ecx + cmp bl,0 + jne .next + cmp byte[GUIEditStringcWin],0 + je near .blinkstuff + cmp ecx,0 + je .nodel + cmp dh,8 + jne .nodel + mov byte[eax-2],0 + dec eax + jmp .blinkstuff +.nodel + cmp ecx,[GUIEditStringmLen] + jne .notend + jmp .blinkstuff +.notend + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp dh,32 + jb .noinsert + mov [eax-1],dh + mov byte[eax],0 + inc eax +.noinsert + jmp .blinkstuff +.blinkstuff + dec eax + mov [GUIEditStringcLen],eax + ret + +GUIEditString dd 0 ; Pointer to string +GUIEditStringcLen dd 0 ; Pointer to end of string (done in function) +GUIEditStringmLen dd 0 ; Max length of string +GUIEditStringLTxt dd 0 ; blink value, should be set to 0 when box selected +GUIEditStringLstb dd 0 ; if cursor is placed (set in main function) +GUIEditStringcWin dd 0 ; 0 = no text window selected + +GUIComboKeys: + ; Calculate Position + xor eax,eax +.nozero + cmp byte[GUIComboTextH+eax],0 + je .zero + inc eax + jmp .nozero +.zero + mov [GUIComboPos],al + cmp dh,8 + jne .nobacksp + cmp byte[GUIComboPos],0 + je .nochar + mov byte[GUICCFlash],0 + xor eax,eax + mov al,[GUIComboPos] + dec eax + mov byte[GUIComboTextH+eax],0 + ret +.nobacksp + cmp dh,0 + je .nochar + cmp dh,13 + je .nochar + cmp byte[GUIComboPos],19 + je .nochar + xor eax,eax + mov byte[GUICCFlash],0 + mov al,[GUIComboPos] + mov byte[GUIComboTextH+eax],dh +.nochar + ret + +GUICheatKeys: + cmp dword[GUIcurrentcheatwin],1 + je near .textboxa + cmp dword[GUIcurrentcheatwin],2 + je near .textboxb + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp dh,'R' + jne .noremocheat + jmp CheatCodeRemove +.noremocheat + cmp dh,'T' + jne .notoggcheat + jmp CheatCodeToggle +.notoggcheat + cmp dh,'S' + jne .nosavecheat + jmp CheatCodeSave +.nosavecheat + cmp dh,'L' + jne .noloadcheat + jmp CheatCodeLoad +.noloadcheat + cmp dword[NumCheats],0 + jne .nozero + ret +.nozero + cmp al,71 + jne .nohome + mov dword[GUIcurrentcheatcursloc],0 + mov dword[GUIcurrentcheatviewloc],0 + ret +.nohome + cmp al,79 + jne .noendp + mov eax,[NumCheats] + dec eax + mov dword[GUIcurrentcheatcursloc],eax + sub eax,11 + mov dword[GUIcurrentcheatviewloc],eax + test dword[GUIcurrentcheatviewloc],8000000h + jz .posve + mov dword[GUIcurrentcheatviewloc],0 +.posve + ret +.noendp + cmp al,72 + jne .noup +.up + cmp dword[GUIcurrentcheatcursloc],0 + je .noup + mov ebx,[GUIcurrentcheatcursloc] + cmp [GUIcurrentcheatviewloc],ebx + jne .noviewdec + dec dword[GUIcurrentcheatviewloc] +.noviewdec + dec dword[GUIcurrentcheatcursloc] +.noup + cmp al,80 + jne .nodown + mov ebx,[GUIcurrentcheatcursloc] + inc ebx + cmp ebx,[NumCheats] + jae .noviewinc + inc dword[GUIcurrentcheatcursloc] + sub ebx,12 + cmp ebx,[GUIcurrentcheatviewloc] + jne .noviewinc + inc dword[GUIcurrentcheatviewloc] +.noviewinc +.nodown + cmp al,73 + jne .nopageup + sub dword[GUIcurrentcheatviewloc],12 + sub dword[GUIcurrentcheatcursloc],12 + test dword[GUIcurrentcheatviewloc],8000000h + jz .posv + mov dword[GUIcurrentcheatviewloc],0 +.posv + test dword[GUIcurrentcheatcursloc],8000000h + jz .posc + mov dword[GUIcurrentcheatcursloc],0 +.posc +.nopageup + cmp al,81 + jne .nopagedown + add dword[GUIcurrentcheatviewloc],12 + add dword[GUIcurrentcheatcursloc],12 + mov ebx,[NumCheats] + dec ebx + cmp dword[GUIcurrentcheatcursloc],ebx + jb .poscd + mov dword[GUIcurrentcheatcursloc],ebx +.poscd + sub ebx,11 + cmp dword[GUIcurrentcheatviewloc],ebx + jl .posvd + test ebx,8000000h + jz .noneg + mov ebx,0 +.noneg + mov dword[GUIcurrentcheatviewloc],ebx +.posvd +.nopagedown + ret + +.textboxa + cmp byte[GUICheatPosA],0 + je near .nobacksp + cmp dh,9 + je .yesret + cmp dh,13 + jne near .noret +.yesret + cmp byte[GUICheatPosA],2 + jne near .nocodemod + mov byte[GUICheatPosA],0 + mov esi,[GUIcurrentcheatcursloc] + shl esi,5 + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + sub esi,[GUIcurrentcheatcursloc] + add esi,cheatdata + mov al,[GUICheatText9] + cmp al,'a' + jae .lowletter + cmp al,'A' + jae .letter + sub al,'0' + jmp .num +.lowletter + sub al,'a'-10 + jmp .num +.letter + sub al,'A'-10 +.num + mov ah,[GUICheatText9+1] + cmp ah,'a' + jae .lowletter2 + cmp ah,'A' + jae .letter2 + sub ah,'0' + jmp .num2 +.lowletter2 + sub ah,'a'-10 + jmp .num2 +.letter2 + sub ah,'A'-10 +.num2 + shl al,4 + and ah,0Fh + or al,ah + mov [esi+1],al + mov word[GUICheatText9],0 + pushad + call EnableCheatCodeNoPrevMod + popad + jmp .noret +.nocodemod + inc dword[GUIcurrentcheatwin] + mov byte[GUICCFlash],0 +.noret + cmp dh,8 + jne .nobacksp + mov byte[GUICCFlash],0 + dec byte[GUICheatPosA] + xor eax,eax + mov al,[GUICheatPosA] + mov byte[GUICheatText9+eax],'_' + mov byte[GUICheatText9+eax+1],0 + ret +.nobacksp + cmp dh,0 + je .nochar + cmp dh,13 + je .nochar + cmp dh,8 + je .nochar + cmp dh,9 + je .nochar + cmp byte[GUICheatPosA],14 + je .nochar + mov byte[GUICCFlash],0 + xor eax,eax + mov al,[GUICheatPosA] + mov byte[GUICheatText9+eax],dh + mov byte[GUICheatText9+eax+1],'_' + mov byte[GUICheatText9+eax+2],0 + inc byte[GUICheatPosA] +.nochar + ret + +.textboxb + cmp dh,13 + jne .noretb + mov byte[GUICCFlash],0 + jmp ProcessCheatCode +.noretb + cmp byte[GUICheatPosB],0 + je .nobackspb + cmp dh,8 + jne .nobackspb + mov byte[GUICCFlash],0 + dec byte[GUICheatPosB] + xor eax,eax + mov al,[GUICheatPosB] + mov byte[GUICheatTextA+eax],'_' + mov byte[GUICheatTextA+eax+1],0 + ret +.nobackspb + cmp dh,0 + je .nocharb + cmp dh,13 + je .nocharb + cmp dh,8 + je .nocharb + cmp byte[GUICheatPosB],18 + je .nocharb + xor eax,eax + mov byte[GUICCFlash],0 + mov al,[GUICheatPosB] + mov byte[GUICheatTextA+eax],dh + mov byte[GUICheatTextA+eax+1],'_' + mov byte[GUICheatTextA+eax+2],0 + inc byte[GUICheatPosB] +.nocharb + ret + +%macro CompareKeyMacro 3 + cmp dh,%1 + jne %%skip + mov byte[%2],%3 +%%skip +%endmacro + +InsertSearchCharacter: + push edx + push eax + ; Send character into CSInputDisplay + ; Find location + mov ecx,CSInputDisplay +.next + cmp byte[ecx],0 + je .found + cmp byte[ecx],'_' + je .found + inc ecx + jmp .next +.found + ; Delete if necessary + cmp dh,8 + jne .notdelete + cmp ecx,CSInputDisplay + je near .done + dec ecx + jmp .placecursor +.notdelete + cmp ecx,CSInputDisplay+10 + je near .done + ; Add character if necessary + cmp dh,'0' + jb near .done + cmp dh,'9' + jbe .okay + cmp byte[CheatSrcByteBase],0 + je near .done + cmp dh,'F' + ja near .done + cmp dh,'A' + jb near .done +.okay + mov byte[ecx],dh + inc ecx + ; Process cursor if over the window +.placecursor + mov byte[ecx],'_' + mov byte[ecx+1],0 + + mov byte[CSOverValue],0 + ; Find overall value and delete if over + mov ecx,CSInputDisplay + mov ebx,10 + cmp byte[CheatSrcByteBase],0 + je .dec + mov ebx,16 +.dec + xor eax,eax +.next2 + cmp byte[ecx],0 + je .found2 + cmp byte[ecx],'_' + je .found2 + mul ebx + or edx,edx + jz .notoverflow + mov byte[CSOverValue],1 +.notoverflow + xor edx,edx + mov dl,[ecx] + cmp dl,'A' + jb .below + sub dl,'A'-10-'0' +.below + sub dl,'0' + add eax,edx + jnc .notoverflowb + mov byte[CSOverValue],1 +.notoverflowb + inc ecx + jmp .next2 +.found2 + xor ebx,ebx + mov bl,[CheatSrcByteSize] + mov ebx,[SrcMask+ebx*4] + mov [CSCurValue],eax + cmp eax,ebx + jbe .done + mov byte[CSOverValue],1 +.done + pop eax + pop edx + ret + +CSOverValue db 0 +CSCurValue dd 0 + +InsertSearchDescription: + mov eax,CSDescDisplay + xor dl,dl +.next + cmp byte[eax],0 + je .fin + inc eax + inc dl + jmp .next +.fin + or dl,dl + jz .nobackspb + cmp dh,8 + jne .nobackspb + mov byte[eax-1],0 + ret +.nobackspb + cmp dh,0 + je .nocharb + cmp dh,13 + je .nocharb + cmp dh,8 + je .nocharb + cmp dl,18 + je .nocharb + mov byte[eax],dh + mov byte[eax+1],0 +.nocharb + ret + +GUICheatSearchKeys: + cmp dh,'a' + jb .nocap + cmp dh,'z' + ja .nocap + sub dh,'z'-'Z' +.nocap + cmp byte[CheatWinMode],3 + je near .add + cmp byte[CheatWinMode],2 + je near .view + cmp byte[CheatWinMode],1 + je near .search + CompareKeyMacro '1',CheatSrcByteSize,0 + CompareKeyMacro '2',CheatSrcByteSize,1 + CompareKeyMacro '3',CheatSrcByteSize,2 + CompareKeyMacro '4',CheatSrcByteSize,3 + CompareKeyMacro 'D',CheatSrcByteBase,0 + CompareKeyMacro 'H',CheatSrcByteBase,1 + CompareKeyMacro 'E',CheatSrcSearchType,0 + CompareKeyMacro 'C',CheatSrcSearchType,1 + cmp dh,13 + je .start + cmp dh,'S' + jne .notstart +.start + call CheatCodeSearchInit + ret +.notstart + ret +.search + cmp byte[CheatSrcSearchType],1 + je .compare + call InsertSearchCharacter + jmp .nomovedown +.compare + cmp dh,',' + je .lessthan + cmp dh,'<' + jne .notlessthan +.lessthan + mov byte[CheatCompareValue],0 +.notlessthan + cmp dh,'.' + je .greaterthan + cmp dh,'>' + jne .notgreaterthan +.greaterthan + mov byte[CheatCompareValue],1 +.notgreaterthan + cmp dh,'=' + je .equalthan + cmp dh,'+' + jne .notequalthan +.equalthan + mov byte[CheatCompareValue],2 +.notequalthan + cmp dh,'N' + jne .notnotequalthan + mov byte[CheatCompareValue],3 +.notnotequalthan + cmp al,72 + jne .nomoveup + cmp byte[CheatCompareValue],0 + je .nomoveup + dec byte[CheatCompareValue] +.nomoveup + cmp al,80 + jne .nomovedown + cmp byte[CheatCompareValue],3 + je .nomovedown + inc byte[CheatCompareValue] +.nomovedown + cmp dh,'R' + jne .notrestart + mov byte[CheatWinMode],0 + mov byte[CheatSearchStatus],0 +.notrestart + cmp dh,'V' + jne .notview + mov byte[CheatWinMode],2 +.notview + cmp dh,13 + je .searchprocess + cmp dh,'S' + jne .nosearchprocess +.searchprocess + cmp byte[CheatSearchStatus],1 + je .nosearchprocess + call CheatCodeSearchProcess +.nosearchprocess + ret +.view + cmp dword[NumCheatSrc],0 + jne .nozero + cmp dh,27 + je .yesret + cmp dh,'R' + jne .notreturnb +.yesret + mov byte[CheatWinMode],1 +.notreturnb + ret +.nozero + cmp al,71 + jne .nohome + mov dword[GUIcurrentchtsrccursloc],0 + mov dword[GUIcurrentchtsrcviewloc],0 + ret +.nohome + cmp al,79 + jne .noendp + mov eax,[NumCheatSrc] + dec eax + mov dword[GUIcurrentchtsrccursloc],eax + sub eax,11 + mov dword[GUIcurrentchtsrcviewloc],eax + test dword[GUIcurrentchtsrcviewloc],8000000h + jz .posve + mov dword[GUIcurrentchtsrcviewloc],0 +.posve + ret +.noendp + cmp al,72 + jne .noup +.up + cmp dword[GUIcurrentchtsrccursloc],0 + je .noup + mov ebx,[GUIcurrentchtsrccursloc] + cmp [GUIcurrentchtsrcviewloc],ebx + jne .noviewdec + dec dword[GUIcurrentchtsrcviewloc] +.noviewdec + dec dword[GUIcurrentchtsrccursloc] +.noup + cmp al,80 + jne .nodown + mov ebx,[GUIcurrentchtsrccursloc] + inc ebx + cmp ebx,[NumCheatSrc] + jae .noviewinc + inc dword[GUIcurrentchtsrccursloc] + sub ebx,12 + cmp ebx,[GUIcurrentchtsrcviewloc] + jne .noviewinc + inc dword[GUIcurrentchtsrcviewloc] +.noviewinc +.nodown + cmp al,73 + jne .nopageup + sub dword[GUIcurrentchtsrcviewloc],12 + sub dword[GUIcurrentchtsrccursloc],12 + test dword[GUIcurrentchtsrcviewloc],8000000h + jz .posv + mov dword[GUIcurrentchtsrcviewloc],0 +.posv + test dword[GUIcurrentchtsrccursloc],8000000h + jz .posc + mov dword[GUIcurrentchtsrccursloc],0 +.posc +.nopageup + cmp al,81 + jne .nopagedown + add dword[GUIcurrentchtsrcviewloc],12 + add dword[GUIcurrentchtsrccursloc],12 + mov ebx,[NumCheatSrc] + dec ebx + cmp dword[GUIcurrentchtsrccursloc],ebx + jb .poscd + mov dword[GUIcurrentchtsrccursloc],ebx +.poscd + sub ebx,11 + cmp dword[GUIcurrentchtsrcviewloc],ebx + jl .posvd + test ebx,8000000h + jz .noneg + mov ebx,0 +.noneg + mov dword[GUIcurrentchtsrcviewloc],ebx +.posvd +.nopagedown + cmp dh,27 + je .yesretb + cmp dh,'R' + jne .notreturn +.yesretb + mov byte[CheatWinMode],1 +.notreturn + cmp dh,13 + je .yesadd + cmp dh,'A' + jne .notadd +.yesadd + mov byte[CheatWinMode],3 + mov byte[CurCStextpos],0 + mov byte[CSInputDisplay],'_' + mov byte[CSInputDisplay+1],0 + mov byte[CSDescDisplay],0 +.notadd + ret + +.add + cmp dh,27 + je .yesretc + cmp byte[CurCStextpos],1 + je .notreturnc + cmp dh,'R' + jne .notreturnc +.yesretc + mov byte[CheatWinMode],2 +.notreturnc + cmp byte[CurCStextpos],0 + jne near .nofirstbox + cmp dh,9 + je .yestab + cmp byte[CSOverValue],1 + je .noret + cmp dh,13 + jne .noret +.yestab + mov byte[CurCStextpos],1 +.noret + call InsertSearchCharacter + ret +.nofirstbox + cmp byte[CurCStextpos],1 + jne near .nosecondbox + cmp dh,9 + jne .notab + mov byte[CurCStextpos],0 +.notab + cmp dh,13 + jne .noenter + jmp AddCSCheatCode +.noenter + call InsertSearchDescription + ret +.nosecondbox + ret + +GUIStateSelKeys: + cmp al,13 + jne .noenter + xor eax,eax + mov al,[GUIwinptr] + dec eax + mov byte[GUIwinactiv+2],0 + mov byte[GUIwinorder+eax],0 + dec byte[GUIwinptr] + mov al,[GUIpmenupos] + mov [GUIcmenupos],al + ret +.noenter + cmp al,75 + jne .noleft + mov ebx,[statefileloc] + mov cl,[fnamest+ebx] + cmp cl,'T' + jne .no1st + mov cl,'4' + jmp .done +.no1st + cmp cl,'1' + jne .no2nd + mov cl,'T' + jmp .done +.no2nd + cmp cl,'5' + jne .no5th + mov cl,'9' + jmp .done +.no5th + dec cl + jmp .done +.noleft + cmp al,77 + jne .noright + mov ebx,[statefileloc] + mov cl,[fnamest+ebx] + cmp cl,'T' + jne .noT + mov cl,'1' + jmp .done +.noT + cmp cl,'4' + jne .no4th + mov cl,'T' + jmp .done +.no4th + cmp cl,'9' + jne .no9th + mov cl,'5' + jmp .done +.no9th + inc cl + jmp .done +.noright + cmp al,72 + je .vert + cmp al,80 + jne .novert +.vert + mov ebx,[statefileloc] + mov cl,[fnamest+ebx] + cmp cl,'T' + jne .noTv + mov cl,'5' + jmp .done +.noTv + cmp cl,'5' + jne .no5v + mov cl,'T' + jmp .done +.no5v + cmp cl,'5' + jb .noabove + sub cl,5 + jmp .done +.noabove + add cl,5 + jmp .done +.novert + ret +.done + mov [fnamest+ebx],cl + ret + +GUIResetKeys: + cmp al,75 + jne .noleft + mov byte[GUICResetPos],0 +.noleft + cmp al,77 + jne .noright + mov byte[GUICResetPos],1 +.noright + cmp al,13 + jne .noconf + cmp byte[GUICResetPos],0 + je .yesreset + jmp .noreset +.noconf + cmp dh,'Y' + je .yesreset + cmp dh,'y' + jne .notyesreset +.yesreset + mov byte[GUICBHold],2 + jmp GUIProcReset +.notyesreset + cmp dh,'N' + je .noreset + cmp dh,'n' + jne .notnoreset +.noreset + xor eax,eax + mov al,[GUIwinptr] + dec eax + mov byte[GUIwinactiv+12],0 + mov byte[GUIwinorder+eax],0 + dec byte[GUIwinptr] + mov al,[GUIpmenupos] + mov [GUIcmenupos],al +.notnoreset + ret + +GUIStateKeys: + cmp al,75 + jne .noleft + mov byte[GUICStatePos],0 +.noleft + cmp al,77 + jne .noright + mov byte[GUICStatePos],1 +.noright + cmp al,13 + jne .noconf + cmp byte[GUICStatePos],0 + je .yesreset + jmp .noreset +.noconf + cmp dh,'Y' + je .yesreset + cmp dh,'y' + jne .notyesreset +.yesreset + mov byte[GUICBHold],10 + jmp GUIProcStates +.notyesreset + cmp dh,'N' + je .noreset + cmp dh,'n' + jne .notnoreset +.noreset + xor eax,eax + mov al,[GUIwinptr] + dec eax + mov byte[GUIwinactiv+14],0 + mov byte[GUIwinorder+eax],0 + dec byte[GUIwinptr] + mov al,[GUIpmenupos] + mov [GUIcmenupos],al +.notnoreset + ret + +GUILoadKeys: + mov byte[ManualStatus],0 + mov dword[ManualCPtr],GUILoadTextA + cmp dword[GUIfileentries],0 + je .noright + cmp dword[GUIdirentries],0 + je .noright + cmp al,75 + jne .noleft + mov byte[GUILoadPos],0 + xor dword[GUIcurrentfilewin],1 +.noleft + cmp al,77 + jne .noright + mov byte[GUILoadPos],0 + xor dword[GUIcurrentfilewin],1 +.noright + cmp al,13 + jne .noenter + mov byte[GUILoadPos],0 + + mov ebx,GUILoadTextA +.nextl + cmp byte[ebx],':' + je .donel + cmp byte[ebx],'\' + je .donel + inc ebx + cmp byte[ebx],0 + je .nofnamel + jmp .nextl +.donel + call GUILoadManualDir + cmp byte[ManualStatus],2 + je near .done + ret +.nofnamel + mov ebx,GUILoadTextA + cmp byte[ebx],0 + je .nodirtry + mov edx,ebx + call Change_Single_Dir + jc .nodirtry + call GetLoadData.a + ret +.nodirtry + call GUILoadData + ret +.noenter + cmp dword[GUIcurrentfilewin],1 + je near .dirwin + + cmp al,71 + jne .nohome + mov byte[GUILoadPos],0 + mov dword[GUIcurrentcursloc],0 + mov dword[GUIcurrentviewloc],0 + ret +.nohome + cmp al,79 + jne .noendp + mov byte[GUILoadPos],0 + mov eax,[GUIfileentries] + dec eax + mov dword[GUIcurrentcursloc],eax + sub eax,14 + mov dword[GUIcurrentviewloc],eax + test dword[GUIcurrentviewloc],8000000h + jz .posve + mov dword[GUIcurrentviewloc],0 +.posve + ret +.noendp + cmp al,72 + jne .noup +.up + mov byte[GUILoadPos],0 + cmp dword[GUIcurrentcursloc],0 + je .noup + mov ebx,[GUIcurrentcursloc] + cmp [GUIcurrentviewloc],ebx + jne .noviewdec + dec dword[GUIcurrentviewloc] +.noviewdec + dec dword[GUIcurrentcursloc] +.noup + cmp al,80 + jne .nodown + mov byte[GUILoadPos],0 + mov ebx,[GUIcurrentcursloc] + inc ebx + cmp ebx,[GUIfileentries] + je .noviewinc + inc dword[GUIcurrentcursloc] + sub ebx,15 + cmp ebx,[GUIcurrentviewloc] + jne .noviewinc + inc dword[GUIcurrentviewloc] +.noviewinc +.nodown + cmp al,73 + jne .nopageup + mov byte[GUILoadPos],0 + sub dword[GUIcurrentviewloc],15 + sub dword[GUIcurrentcursloc],15 + test dword[GUIcurrentviewloc],8000000h + jz .posv + mov dword[GUIcurrentviewloc],0 +.posv + test dword[GUIcurrentcursloc],8000000h + jz .posc + mov dword[GUIcurrentcursloc],0 +.posc +.nopageup + cmp al,81 + jne .nopagedown + mov byte[GUILoadPos],0 + add dword[GUIcurrentviewloc],15 + add dword[GUIcurrentcursloc],15 + mov ebx,[GUIfileentries] + dec ebx + cmp dword[GUIcurrentcursloc],ebx + jb .poscd + mov dword[GUIcurrentcursloc],ebx +.poscd + sub ebx,14 + cmp dword[GUIcurrentviewloc],ebx + jl .posvd + test ebx,8000000h + jz .noneg + mov ebx,0 +.noneg + mov dword[GUIcurrentviewloc],ebx +.posvd +.nopagedown + +.textboxa + cmp byte[GUILoadPos],0 + je near .nobacksp + cmp dh,8 + jne .nobacksp + mov byte[GUILDFlash],0 + dec byte[GUILoadPos] + xor eax,eax + mov al,[GUILoadPos] + ret +.nobacksp + cmp dh,0 + je near .posvl2 + cmp dh,13 + je near .posvl2 + cmp dh,8 + je near .posvl2 + cmp dh,9 + je near .posvl2 + cmp byte[GUILoadPos],36 + je near .posvl2 + mov byte[GUILDFlash],0 + xor eax,eax + mov al,[GUILoadPos] + mov byte[GUILoadTextA+eax],dh + inc byte[GUILoadPos] + ; Go to closest matching filename if there are no :, /, or \ in the filename + mov ebx,[ManualCPtr] + cmp byte[ebx],0 + je near .posvl2 +.next + cmp byte[ebx],':' + je near .posvl2 + cmp byte[ebx],'/' + je near .posvl2 + cmp byte[ebx],'\' + je near .posvl2 + inc ebx + cmp byte[ebx],0 + je .done + jmp .next +.done + + mov ebx,[GUIfileentries] + xor esi,esi + cmp dword[GUIcurrentfilewin],1 + jne near .notdir + mov esi,[GUIfileentries] + mov ebx,[GUIfileentries] + add ebx,[GUIdirentries] +.notdir + mov ecx,esi + mov dword[.foundval],esi + mov dword[.maxfound],0 +.loop2 + mov dword[.numfound],0 + cmp byte[GUIloadfntype],0 + jne .nottype02 + mov eax,[spcRamcmp+esi*4] + jmp .type02 +.nottype02 + mov eax,esi + shl eax,5 + add eax,[spcBuffera] +.type02 + inc eax + mov edi,[ManualCPtr] + cmp byte[eax],'[' + jne .nodrive + inc eax +.nodrive +.loop3 + mov dl,[eax] + cmp dl,'a' + jb .nolowerb2 + cmp dl,'z' + ja .nolowerb2 + sub dl,'a'-'A' +.nolowerb2 + mov dh,[edi] + cmp dh,'a' + jb .nolowerb3 + cmp dh,'z' + ja .nolowerb3 + sub dh,'a'-'A' +.nolowerb3 + cmp dl,dh + jne .notfound + cmp byte[ManualStatus],2 + jne .notfullload + or dh,dh + jnz .notfullload + or dl,dl + jnz .notfullload + mov byte[ManualStatus],3 +.notfullload + or dh,dh + jz .notfound + or dl,dl + jz .notfound + inc dword[.numfound] + inc eax + inc edi + jmp .loop3 +.notfound + mov edx,[.numfound] + cmp edx,[.maxfound] + jbe .nfound + mov [.maxfound],edx + mov [.foundval],esi +.nfound + inc esi + cmp esi,ebx + jne .noend2 + mov esi,[GUIfileentries] + cmp dword[GUIcurrentfilewin],1 + je .noend2 + xor esi,esi +.noend2 + cmp esi,ecx + jne near .loop2 +.skipall + mov esi,[.foundval] + cmp dword[GUIcurrentfilewin],1 + jne .notdir2 + sub esi,[GUIfileentries] + mov [GUIcurrentdircursloc],esi + mov [GUIcurrentdirviewloc],esi + mov ebx,[GUIdirentries] + sub ebx,15 + cmp dword[GUIcurrentdirviewloc],ebx + jb .posvl2 + mov dword[GUIcurrentdirviewloc],ebx + jmp .posvl2 +.notdir2 + mov [GUIcurrentcursloc],esi + mov [GUIcurrentviewloc],esi + mov ebx,[GUIfileentries] + sub ebx,15 + cmp dword[GUIcurrentviewloc],ebx + jb .posvl2 + mov dword[GUIcurrentviewloc],ebx +.posvl2 + cmp byte[ManualStatus],3 + jne .notdirectload + call GUILoadData +.notdirectload + ret +.foundval dd 0 +.numfound dd 0 +.maxfound dd 0 + +.dirwin + cmp al,71 + jne .nohome2 + mov byte[GUILoadPos],0 + mov dword[GUIcurrentdircursloc],0 + mov dword[GUIcurrentdirviewloc],0 + ret +.nohome2 + cmp al,79 + jne .noendp2 + mov byte[GUILoadPos],0 + mov eax,[GUIdirentries] + dec eax + mov dword[GUIcurrentdircursloc],eax + sub eax,14 + mov dword[GUIcurrentdirviewloc],eax + test dword[GUIcurrentdirviewloc],8000000h + jz .posve2 + mov dword[GUIcurrentdirviewloc],0 +.posve2 + ret +.noendp2 + cmp al,72 + jne .noup2 + mov byte[GUILoadPos],0 + cmp dword[GUIcurrentdircursloc],0 + je .noup2 + mov ebx,[GUIcurrentdircursloc] + cmp [GUIcurrentdirviewloc],ebx + jne .noviewdec2 + dec dword[GUIcurrentdirviewloc] +.noviewdec2 + dec dword[GUIcurrentdircursloc] +.noup2 + cmp al,80 + jne .nodown2 + mov byte[GUILoadPos],0 + mov ebx,[GUIcurrentdircursloc] + inc ebx + cmp ebx,[GUIdirentries] + je .noviewinc2 + inc dword[GUIcurrentdircursloc] + sub ebx,15 + cmp ebx,[GUIcurrentdirviewloc] + jne .noviewinc2 + inc dword[GUIcurrentdirviewloc] +.noviewinc2 +.nodown2 + cmp al,73 + jne .nopageup2 + mov byte[GUILoadPos],0 + sub dword[GUIcurrentdirviewloc],15 + sub dword[GUIcurrentdircursloc],15 + test dword[GUIcurrentdirviewloc],8000000h + jz .posv2 + mov dword[GUIcurrentdirviewloc],0 +.posv2 + test dword[GUIcurrentdircursloc],8000000h + jz .posc2 + mov dword[GUIcurrentdircursloc],0 +.posc2 +.nopageup2 + cmp al,81 + jne .nopagedown2 + mov byte[GUILoadPos],0 + add dword[GUIcurrentdirviewloc],15 + add dword[GUIcurrentdircursloc],15 + mov ebx,[GUIdirentries] + dec ebx + cmp dword[GUIcurrentdircursloc],ebx + jb .poscd2 + mov dword[GUIcurrentdircursloc],ebx +.poscd2 + sub ebx,14 + cmp dword[GUIcurrentdirviewloc],ebx + jb .posvd2 + test ebx,8000000h + jz .noneg2 + mov ebx,0 +.noneg2 + mov dword[GUIcurrentdirviewloc],ebx +.posvd2 +.nopagedown2 + jmp .textboxa + +WaitForKey: +.again3 + mov edx,10 +.again4 + mov cx,1000 + push edx + call delay + call JoyRead +; mov dword[pressed+0CCh],0 ; Up,Down,Left,Right, pl1 +; mov dword[pressed+0E8h],0 ; Up,Down,Left,Right, pl2 +; mov dword[pressed+14Ch],0 ; Up,Down,Left,Right, pl1 +; mov dword[pressed+168h],0 ; Up,Down,Left,Right, pl2 +; mov dword[pressed+080h],0 ; Button 7 +; mov dword[pressed+081h],0 ; Button 8 +; mov dword[pressed+086h],0 ; Button 5 +; mov dword[pressed+087h],0 ; Button 6 +; mov dword[pressed+100h],0 ; Button 7 +; mov dword[pressed+101h],0 ; Button 8 +; mov dword[pressed+106h],0 ; Button 5 +; mov dword[pressed+107h],0 ; Button 6 + pop edx + xor ebx,ebx + mov ecx,256+128+64 +.b2 + cmp byte[pressed+ebx],0 + jne near .again3 + inc ebx + loop .b2 + dec edx + jnz near .again4 +.again + call JoyRead +; mov dword[pressed+0CCh],0 ; Up,Down,Left,Right, pl1 +; mov dword[pressed+0E8h],0 ; Up,Down,Left,Right, pl2 +; mov dword[pressed+14Ch],0 ; Up,Down,Left,Right, pl1 +; mov dword[pressed+168h],0 ; Up,Down,Left,Right, pl2 +; mov dword[pressed+080h],0 ; Button 7 +; mov dword[pressed+081h],0 ; Button 8 +; mov dword[pressed+086h],0 ; Button 5 +; mov dword[pressed+087h],0 ; Button 6 +; mov dword[pressed+100h],0 ; Button 7 +; mov dword[pressed+101h],0 ; Button 8 +; mov dword[pressed+106h],0 ; Button 5 +; mov dword[pressed+107h],0 ; Button 6 + xor ebx,ebx + mov ecx,256+128+64 +.b + cmp byte[pressed+ebx],0 + jne .pressedokay + inc ebx + loop .b + jmp .again +.pressedokay +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey + cmp byte[MouseDis],1 + je .mousedis2 + push ebx +; mov eax,0Bh +; int 33h + pop ebx +.mousedis2 + mov byte[GUIpclicked],1 + ret + \ No newline at end of file diff --git a/zsnes/src/gui/guiload.inc b/zsnes/src/gui/guiload.inc new file mode 100644 index 00000000..c73ee72a --- /dev/null +++ b/zsnes/src/gui/guiload.inc @@ -0,0 +1,1555 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + +; GUI File (Game) Loader + +%macro GUIGetEntry 1 + mov edx,%1 + mov cx,20h + call Get_First_Entry + jc %%nomore +%%moreentries + test byte[DTALoc+15h],10h + jnz %%nofile + inc dword[GUInumentries] + mov esi,DTALoc+1Eh + mov byte[edi],0 + inc edi + mov ecx,13 +%%nextchar + mov al,[esi] + mov [edi],al + inc esi + inc edi + dec ecx + jnz %%nextchar +%%nofile + call Get_Next_Entry + jnc %%moreentries +%%nomore +%endmacro + +%macro GUIGetEntry2 1 + mov edx,%1 + mov cx,20h + call Get_First_Entry + jc %%nomore +%%moreentries + test byte[DTALoc+15h],10h + jnz %%nofile + mov eax,[GUInumentries] + shl eax,2 + add eax,spcRamcmp + mov [eax],edi + inc dword[GUInumentries] + mov esi,DTALoc+1Eh + mov byte[edi],0 + inc edi +%%nextchar + mov al,[esi] + mov [edi],al + inc esi + inc edi + or al,al + jnz %%nextchar +%%nofile + call Get_Next_Entry + jnc %%moreentries +%%nomore +%endmacro + +%macro GUIGetDir2 0 + mov edx,GUIfindDIR + mov cx,10h + call Get_First_Entry + jc .nomore +.moreentries + test byte[DTALoc+15h],10h + jz .nodir + mov eax,[GUInumentries] + shl eax,2 + add eax,spcRamcmp + mov [eax],edi + inc dword[GUInumentries] + inc dword[GUIdirentries] + mov esi,DTALoc+1Eh + mov byte[edi],1 + inc edi +.nextchar + mov al,[esi] + mov [edi],al + inc esi + inc edi + or al,al + jnz .nextchar +.nodir + call Get_Next_Entry + jnc .moreentries +.nomore +%endmacro + +%macro GUIGetDir 0 + mov edx,GUIfindDIR + mov cx,10h + call Get_First_Entry + jc .nomore +.moreentries + test byte[DTALoc+15h],10h + jz .nodir + inc dword[GUInumentries] + inc dword[GUIdirentries] + mov esi,DTALoc+1Eh + mov byte[edi],1 + inc edi + mov ecx,13 +.nextchar + mov al,[esi] + mov [edi],al + inc esi + inc edi + dec ecx + jnz .nextchar +.nodir + call Get_Next_Entry + jnc .moreentries +.nomore +%endmacro + +%macro GUIPutDrive 0 + mov byte[edi],2 + inc edi + mov byte[edi],'[' + mov [edi+1],al + mov byte[edi+2],':' + mov byte[edi+3],']' + mov byte[edi+4],0 + add edi,13 + mov byte[esi],2 + inc esi + mov byte[esi],'[' + mov [esi+1],al + mov byte[esi+2],':' + mov byte[esi+3],']' + mov byte[esi+4],0 + add esi,31 + inc dword[GUInumentries] + inc dword[GUIdirentries] +%endmacro + +%macro GUIPutDrive2 0 + mov byte[edi],2 + inc edi + mov byte[edi],'[' + mov [edi+1],al + mov byte[edi+2],':' + mov byte[edi+3],']' + mov byte[edi+4],0 + add edi,5 + inc dword[GUInumentries] + inc dword[GUIdirentries] +%endmacro + +;LGUI + +netlastloaded db 0 + +GUIloadfilename: + cmp byte[CNetType],15 + je .noload + cmp byte[CNetType],12 + je .noload + cmp byte[CNetType],11 + je .noload + cmp byte[CNetType],10 + je .noload + cmp byte[CNetType],21 + je .noload + cmp byte[CNetType],22 + jne .yesload +.noload + ret +.yesload + cmp byte[CNetType],20 + jne near .nocnettype + mov byte[netlastloaded],1 +; FileNameMod times 29 db 0 + cmp byte[GUIcmenupos],1 + jne .nomenuout + mov byte[GUIcmenupos],0 +.nomenuout + mov esi,FileNameMod +.nextfnc + mov cl,[eax] + mov [esi],cl + inc eax + inc esi + cmp cl,0 + jne .nextfnc + mov byte[RemoteCommand],10 + pushad + call GUIQuickLoadUpdate + popad + ret +.nocnettype + cmp byte[CNetType],20 + je .okay20 +; ret +.okay20 + mov esi,eax + ; find length of string & copy filename + xor cl,cl +.findnext + mov ch,[esi] + cmp byte[esi],0 + je .foundend + inc esi + inc cl + jmp .findnext +.foundend + mov [fname],cl + ; copy filename + mov esi,eax + mov edi,fname+1 +.continuecopy + mov al,[esi] + mov [edi],al + cmp al,0 + je .foundzero + inc esi + inc edi + jmp .continuecopy +.foundzero + + ; get LoadDrive/LoadDir & SRAMDrive/SRAMDir + mov ebx,LoadDir + mov edx,LoadDrive + call Get_Dir + cmp byte[cfgloadsdir],0 + jne .nosdrive + mov ebx,SRAMDir + mov edx,SRAMDrive + call Get_Dir +.nosdrive + + ; create .srm header + call makeextension + ; clear memory + mov edi,[sram] + mov eax,0FFFFFFFFh + mov ecx,8192 +.n + mov [edi],eax + add edi,4 + dec ecx + jnz .n + call clearmem2 + + mov dword[nmiprevaddrl],0 + mov dword[nmiprevaddrh],0 + mov dword[nmirept],0 + mov dword[nmiprevline],224 + mov dword[nmistatus],0 + mov byte[spcnumread],0 + mov byte[NextLineCache],0 + mov byte[curexecstate],1 + + ; load file + call loadfileGUI + cmp byte[ZipSupport],2 + je near .noloader + cmp byte[GUIloadfailed],1 + je near .noloader + + mov byte[CheatOn],0 + mov byte[NumCheats],0 +; mov byte[CheatSrcByteSize],0 +; mov byte[CheatSrcByteBase],0 +; mov byte[CheatSrcSearchType],0 + mov byte[CheatWinMode],0 + mov byte[CheatSearchStatus],0 + + call CheckROMType + cmp byte[ROMTypeNOTFound],0 + je .foundromtype + mov byte[romtype],1 +.foundromtype + call SetIRQVectors + call ClearScreen + cmp byte[cbitmode],0 + jne .nomakepal + call makepal +.nomakepal + ; get sram size + mov esi,[romdata] + add esi,7FD8h + cmp byte[romtype],2 + jne .nohirom2 + add esi,8000h +.nohirom2 + mov cl,[esi-1] + mov [curromsize],cl + + mov cl,[esi] + inc esi + xor eax,eax + mov al,1 + shl al,cl + cmp al,1 + jne .yessram + mov al,0 +.yessram + shl eax,10 + cmp eax,65536 + jbe .nosramc + mov eax,65536 +.nosramc + mov [ramsize],eax + dec eax + mov [ramsizeand],eax + + ; get pal/ntsc + mov al,[esi] + cmp byte[ForcePal],1 + jne .nontsc + mov al,0 +.nontsc + cmp byte[ForcePal],2 + jne .nopal2 + mov al,2 +.nopal2 + mov byte[romispal],0 + mov word[totlines],262 + mov dword[MsgCount],120 + cmp al,1 + jbe .nopal + mov byte[romispal],1 + mov word[totlines],314 + mov dword[MsgCount],100 +.nopal + call initsnes + mov byte[snesmouse],0 + mov byte[sramsavedis],0 + mov eax,regsbackup + mov ebx,sndrot + mov ecx,3019 +.rbackupl + mov dl,[eax] + mov [ebx],dl + inc ebx + inc eax + loop .rbackupl + cmp byte[yesoutofmemory],1 + jne .noout + call outofmemfix +.noout + call GUIDoReset + call GUIQuickLoadUpdate + cmp byte[AutoLoadCht],0 + je .nocheatload + cmp byte[CNetType],20 + je .nocheatload + ; change dir to LoadDrive/LoadDir + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir + + call CheatCodeLoad +.nocheatload + cmp byte[AutoState],0 + je .noloader + call LoadSecondState +.noloader + cmp byte[GUIwinptr],1 + jne .nowinopen + mov al,[GUIpmenupos] + mov [GUIcmenupos],al +.nowinopen + ; change dir to LoadDrive/LoadDir + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir + ret + +GUILoadData: + mov byte[GUICBHold],0 + cmp byte[GUIcurrentfilewin],0 + je near .loadfiles + ; Change directory + cmp byte[GUIloadfntype],0 + jne .nottype0c + mov eax,[GUIcurrentdircursloc] + add eax,[GUIfileentries] + mov eax,[spcRamcmp+eax*4] + jmp .donetype0 +.nottype0c + mov eax,[GUIcurrentdircursloc] + mov ebx,eax + lea eax,[eax*8] + add ebx,ebx + add eax,ebx + add ebx,ebx + add eax,ebx + add eax,[GUIdirStartLoc] +.donetype0 + inc eax + cmp byte[eax+2],':' + je .drive + mov edx,eax + call Change_Single_Dir + jc .error + call GetLoadData.a +.error + ret +.drive + ; Change Drive + mov dl,[eax+1] + sub dl,65 + call Change_Drive + call GetLoadData.a + ret +.unableload + pop eax + ret +.loadfiles + mov byte[LoadDuplicFound],0 + cmp byte[prevlfreeze],0 + jne near .frozen +; cmp byte[GUIloadfntype],0 +; je near .frozen + + ; check if a duplicate exists + mov esi,prevloadnames +.checkanother + push esi + mov edx,[GUIcurrentcursloc] + shl edx,5 + add edx,[spcBuffera] + cmp byte[GUIloadfntype],0 + jne .nottype0 + mov edx,[GUIcurrentcursloc] + mov edx,[spcRamcmp+edx*4] +.nottype0 + inc edx + mov cl,16 +.dloop + mov al,[edx] + cmp [esi],al + jne .nomatch + inc edx + inc esi + dec cl + jz .matchfound + cmp al,0 + jne .dloop +.matchfound + pop esi + mov byte[LoadDuplicFound],1 + jmp .frozen +.nomatch + pop esi + add esi,16 + cmp esi,prevloadnames+10*16 + jne near .checkanother + + ; copy game name + ; shift names down + mov esi,prevloadnames+16*9-1 + mov ecx,16*9 +.loop + mov al,[esi] + mov [esi+16],al + dec esi + dec edi + dec ecx + jnz .loop + mov esi,prevloadfnamel+512*9-1 + mov edi,prevloaddnamel+512*9-1 + mov ecx,512*9 +.loop2 + mov al,[esi] + mov [esi+512],al + mov al,[edi] + mov [edi+512],al + dec esi + dec edi + dec ecx + jnz .loop2 +.skip + ; copy game name + mov edx,[GUIcurrentcursloc] + shl edx,5 + add edx,[spcBuffera] + cmp byte[GUIloadfntype],0 + jne .nottype0b + mov edx,[GUIcurrentcursloc] + mov edx,[spcRamcmp+edx*4] +.nottype0b + inc edx + mov ebx,prevloadnames + mov ecx,16 +.loopfnc + mov al,[edx] + mov [ebx],al + inc edx + inc ebx + loop .loopfnc + + ; get Drive/Dir + mov ebx,prevloaddnamel+1 + mov edx,prevloaddnamel + call Get_Dir +.frozen + + cmp byte[GUIloadfntype],0 + jne .nottype0b2 + mov eax,[GUIcurrentcursloc] + mov eax,[spcRamcmp+eax*4] + jmp .donetype0b +.nottype0b2 + mov eax,[GUIcurrentcursloc] + mov ebx,eax + lea eax,[eax*8] + add ebx,ebx + add eax,ebx + add ebx,ebx + add eax,ebx + add eax,spcRamcmp +.donetype0b + inc eax + cmp byte[prevlfreeze],0 + jne .foundend + cmp byte[LoadDuplicFound],0 + jne .foundend + mov esi,eax + mov edi,prevloadfnamel + ; copy filename +.findnext + mov ch,[esi] + mov [edi],ch + cmp ch,0 + je .foundend + inc esi + inc edi + jmp .findnext +.foundend + call GUIloadfilename + xor eax,eax + mov al,[GUIwinptr] + dec eax + mov byte[GUIwinactiv+1],0 + mov byte[GUIwinorder+eax],0 + dec byte[GUIwinptr] + ret +.drivefn db 'A:\temp.tmp',0 + +GetNormalEntries2: + cmp byte[showallext],1 + je near .guishowall + GUIGetEntry2 GUIsmcfind + GUIGetEntry2 GUIsfcfind + GUIGetEntry2 GUIswcfind + GUIGetEntry2 GUIfigfind + GUIGetEntry2 GUIfind058 + GUIGetEntry2 GUIfind078 + GUIGetEntry2 GUIfindUSA + GUIGetEntry2 GUIfindJAP + GUIGetEntry2 GUIfindBIN + cmp byte[OSPort],1 + je near .noasm + GUIGetEntry2 GUIfindZIP +.noasm + GUIGetEntry2 GUIfind1 + jmp .guiNext +.guishowall + GUIGetEntry2 GUIfindall +.guiNext + ret + +GetNormalEntries: + cmp byte[showallext],1 + je near .guishowall + GUIGetEntry GUIsmcfind + GUIGetEntry GUIsfcfind + GUIGetEntry GUIswcfind + GUIGetEntry GUIfigfind + GUIGetEntry GUIfind058 + GUIGetEntry GUIfind078 + GUIGetEntry GUIfindUSA + GUIGetEntry GUIfindJAP + GUIGetEntry GUIfindBIN + cmp byte[OSPort],1 + je near .noasm + GUIGetEntry GUIfindZIP +.noasm + GUIGetEntry GUIfind1 + jmp .guiNext +.guishowall + GUIGetEntry GUIfindall +.guiNext + ret + +GUIGetEntryLFNfunc: + push es + push edi + mov eax,714Eh ; Findfirst + mov cx,ds + mov es,cx + mov ch,0 + mov cl,0 + mov edi,LFNData + mov si,0 + int 21h + mov [LFNHandle],ax + pop edi + pop es + jc near .done +.next + mov esi,LFNData+44 + mov ecx,23 +.loop + mov al,[esi] + cmp al,'a' + jb .nocap + cmp al,'z' + ja .nocap + sub al,'a'-'A' +.nocap + cmp al,'%' + jne .noperc + cmp byte[esi+1],'0' + jb .noperc + cmp byte[esi+1],'F' + ja .noperc + cmp byte[esi+2],'0' + jb .noperc + cmp byte[esi+2],'F' + ja .noperc + mov al,[esi+2] + sub al,'0' + cmp al,9 + jbe .nodec + sub al,'A'-'0'-10 +.nodec + mov ah,[esi+1] + sub ah,'0' + cmp ah,9 + jbe .nodecb + sub ah,'A'-'0'-10 +.nodecb + shl ah,4 + or al,ah + add esi,2 +.noperc + mov [edi],al + inc edi + inc esi + dec ecx + jnz near .loop + mov byte[edi],0 + add edi,9 + push es + push edi + mov bx,[LFNHandle] + mov eax, 714Fh ; Findnext + mov dx,ds + mov es,dx + mov edi,LFNData + mov si,0 + int 21h + pop edi + pop es + jnc near .next +.done + mov eax,71A1h ;Filefind Close + mov bx,[LFNHandle] + int 21h + ret + +GUIGetEntryLFNfuncdir: + mov edx,GUIfindall + push es + push edi + mov eax,714Eh ; Findfirst + mov cx,ds + mov es,cx + mov ch,10h + mov cl,10h + mov edi,LFNData + mov si,0 + int 21h + mov [LFNHandle],ax + pop edi + pop es + jc near .done +.next + mov esi,LFNData+44 + mov ecx,11 +.loop + mov al,[esi] + cmp al,'a' + jb .nocap + cmp al,'z' + ja .nocap + sub al,'a'-'A' +.nocap + mov [edi],al + inc edi + inc esi + dec ecx + jnz .loop + mov byte[edi],0 + add edi,21 + push es + push edi + mov bx,[LFNHandle] + mov eax, 714Fh ; Findnext + mov dx,ds + mov es,dx + mov edi,LFNData + mov si,0 + int 21h + pop edi + pop es + jnc near .next +.done + mov eax,71A1h ;Filefind Close + mov bx,[LFNHandle] + int 21h + ret + +%macro GUIGetEntryLFN 1 + mov edx,%1 + call GUIGetEntryLFNfunc +%endmacro + +GetLoadLfn: + call GetNormalEntries + push edi + mov edi,[spcBuffera] + inc edi + cmp byte[showallext],1 + je near .guishowall + GUIGetEntryLFN GUIsmcfind + GUIGetEntryLFN GUIsfcfind + GUIGetEntryLFN GUIswcfind + GUIGetEntryLFN GUIfigfind + GUIGetEntryLFN GUIfind058 + GUIGetEntryLFN GUIfind078 + GUIGetEntryLFN GUIfindUSA + GUIGetEntryLFN GUIfindJAP + GUIGetEntryLFN GUIfindBIN + GUIGetEntryLFN GUIfindZIP + GUIGetEntryLFN GUIfind1 + jmp .guiNext +.guishowall + GUIGetEntryLFN GUIfindall +.guiNext + pop edi + ret + +LFNData times 400 db 0 +LFNHandle dw 0 + +GetLoadNormal: + call GetNormalEntries2 + ret + +GetLoadHeader: + call GetNormalEntries + push edi + ; Copy every 14 bytes of spcRamcmp into every 32 bytes of spcBuffer + mov ecx,[GUInumentries] + mov esi,spcRamcmp+1 + mov edi,[spcBuffera] + inc edi + cmp ecx,0 + je near .none +.loop + ; open file at esi and store in edi + push esi + push ecx + push edi + ; check if .zip file + mov eax,esi +.zipdet + cmp byte[eax],0 + je near .skipcheck + cmp byte[eax],'.' + je .dotdetected + inc eax + jmp .zipdet +.dotdetected + cmp byte[eax+1],'z' + je near .yeszipa + cmp byte[eax+1],'Z' + jne near .skipcheck +.yeszipa + cmp byte[eax+2],'i' + je near .yeszipb + cmp byte[eax+2],'I' + jne near .skipcheck +.yeszipb + cmp byte[eax+3],'p' + je near .yeszipc + cmp byte[eax+3],'P' + jne near .skipcheck +.yeszipc + ; move esi to edi +.ziploop + mov al,[esi] + mov [edi],al + inc esi + inc edi + or al,al + jnz .ziploop + jmp .doneall +.skipcheck + ; open file + mov edx,esi + call Open_File + jc near .fileerror + mov bx,ax + ; Check filesize + mov cx,0 + mov dx,0 + call File_Seek_End + jc near .fileerror + cmp dx,0 + jne .locokay + cmp ax,32768 + jae .locokay + jmp .fileerror +.locokay + ; Look for 512 byte header + mov cx,0 + mov dx,250 + call File_Seek + jc near .fileerror + mov ecx,20 + mov edx,fnameheadtemp + call Read_File + jc near .fileerror + ; if 10 or more 0's, then header + mov ecx,20 + mov esi,fnameheadtemp + xor eax,eax +.loop2 + cmp byte[esi],0 + jne .notzero2 + inc eax +.notzero2 + inc esi + dec ecx + jnz .loop2 + cmp eax,10 + ja near .yes512header + mov cx,0 + mov dx,32704 + call File_Seek + jc near .fileerror + mov ecx,20 + mov edx,edi + call Read_File + jc near .fileerror + mov cx,0 + mov dx,32704+32768 + call File_Seek + jc near .fileerror + mov ecx,20 + mov edx,fnameheadtemp + call Read_File + jc near .fileerror + jmp .noheaderdone +.yes512header + mov cx,0 + mov dx,32704+512 + call File_Seek + jc near .fileerror + mov ecx,20 + mov edx,edi + call Read_File + jc near .fileerror + mov cx,1 + mov dx,448 + call File_Seek + jc near .fileerror + mov ecx,20 + mov edx,fnameheadtemp + call Read_File + jc near .fileerror +.noheaderdone + mov ecx,20 +.loops + cmp byte[edi],0 + jne .notzero + mov byte[edi],32 +.notzero + inc edi + dec ecx + jnz .loops + ; Check which header has more alphabets, then move + sub edi,20 + call .checkalpha + push eax + push edi + mov edi,fnameheadtemp + call .checkalpha + pop edi + mov ecx,eax + pop eax + cmp ecx,eax + jb .noswaps + mov ecx,20 + sub edi,20 + mov esi,fnameheadtemp +.loops2 + mov al,[esi] + mov [edi],al + inc edi + inc esi + dec ecx + jnz .loops2 +.noswaps + jmp .fileokay +.fileerror + mov eax,[.invfile] + mov [edi],eax + mov eax,[.invfile+4] + mov [edi+4],eax + mov eax,[.invfile+8] + mov [edi+8],eax + mov eax,[.invfile+12] + mov [edi+12],eax + mov eax,[.invfile+16] + mov [edi+16],eax +.fileokay + call Close_File +.doneall + pop edi + pop ecx + pop esi + mov byte[edi+20],0 + push edi + push esi + push ecx + ; check if first 20 bytes are all equal or not + mov al,[edi+1] + mov ecx,19 +.loopchk + cmp byte[edi+1],al + jne .notequal + inc edi + dec ecx + jnz .loopchk + sub edi,19 + mov ecx,14 +.loopcpy + mov al,[esi] + mov [edi],al + inc esi + inc edi + dec ecx + jnz .loopcpy +.notequal + pop ecx + pop esi + pop edi + ; Capitalize + push edi + push ecx + mov ecx,20 +.loop4 + mov al,[edi] + cmp al,'a' + jb .nocap + cmp al,'z' + ja .nocap + sub al,'a'-'A' +.nocap + mov [edi],al + loop .loop4 + pop ecx + pop edi + add esi,14 + add edi,32 + dec ecx + jnz near .loop +.none + pop edi + ret + +.checkalpha + mov ecx,20 + xor eax,eax +.loop3 + cmp byte[edi],32 + je .alpha + cmp byte[edi],'A' + jb .noalpha + cmp byte[edi],'Z' + jbe .alpha + cmp byte[edi],'a' + jb .noalpha + cmp byte[edi],'z' + ja .noalpha +.alpha + inc eax +.noalpha + inc edi + dec ecx + jnz .loop3 + ret + +.invfile db 255,'** INVALID FILE **',0 +fnameheadtemp times 22 db 0 + +GetNormalDirEntries2: + GUIGetDir2 + ret + +GetNormalDirEntries: + GUIGetDir + ret + +GetLoadDirNormal2: + call GetNormalDirEntries2 + ret + +GetLoadDirNormal: + call GetNormalDirEntries + push edi + ; Copy every 14 bytes of spcRamcmp into every 32 bytes of spcBuffer + mov ecx,[GUIdirentries] + mov esi,[GUIdirStartLoc] + mov edi,dword[GUIfileentries] + shl edi,5 + add edi,[spcBuffera] + cmp ecx,0 + je .none +.loop + mov eax,[esi] + mov [edi],eax + mov eax,[esi+4] + mov [edi+4],eax + mov eax,[esi+8] + mov [edi+8],eax + xor ax,ax + mov [edi+12],ax + add esi,14 + add edi,32 + dec ecx + jnz .loop +.none + pop edi + ret + +GetLoadDirNormallfn: + call GetNormalDirEntries + push edi + ; Copy every 14 bytes of spcRamcmp into every 32 bytes of spcBuffer + mov edi,dword[GUIfileentries] + shl edi,5 + add edi,[spcBuffera] + inc edi + call GUIGetEntryLFNfuncdir + pop edi + ret + +Win95Failed db 0 + +NEWSYM GetCurDir + ; get Drive/Dir + mov ebx,GUIcurrentdir+3 + mov edx,GUIcurrentdir + call Get_Dir + add byte[GUIcurrentdir],65 + + mov byte[GUIcurrentdir+1],':' + mov byte[GUIcurrentdir+2],'\' + cmp byte[GUIcurrentdir+35],0 + je .nodotend + mov byte[GUIcurrentdir+35],'.' + mov byte[GUIcurrentdir+36],'.' + mov byte[GUIcurrentdir+37],'.' + mov byte[GUIcurrentdir+38],0 +.nodotend + ; Set DTA address + call Set_DTA_Address + ret + +GetLoadData: + mov dword[GUIcurrentfilewin],0 +.a + call GetCurDir + mov dword[GUInumentries],0 + mov dword[GUIcurrentviewloc],0 + mov dword[GUIcurrentcursloc],0 + mov dword[GUIcurrentdirviewloc],0 + mov dword[GUIcurrentdircursloc],0 + mov edi,spcRamcmp + mov byte[Win95Failed],0 + cmp byte[OSPort],1 + ja .notdos + cmp byte[GUIloadfntype],2 + jne .nowin95lfn + clc + mov ax,7100h + int 21h + jc .nowin95lfn +.notdos + mov byte[GUIloadfntype],0 +.nowin95lfn + cmp byte[GUIloadfntype],2 + je .win95lfn + cmp byte[GUIloadfntype],1 + je .snesheader + mov edi,[spcBuffera] + call GetLoadNormal + jmp .doneheader +.snesheader + mov byte[showallext],0 + call GetLoadHeader + jmp .doneheader +.win95lfn + call GetLoadLfn +.doneheader + cmp byte[Win95Failed],1 + jne .notfailed + mov byte[GUIloadfntype],0 + jmp GetLoadData +.notfailed + mov eax,dword[GUInumentries] + mov dword[GUIfileentries],eax + cmp dword[GUIfileentries],0 + jne .nonoentry + mov dword[GUIcurrentfilewin],1 +.nonoentry + + ; Sort List + push edi + ; compares string at esi to edi and returns 1 to al if esi is >, else 0 +.sortagain + mov byte[BubbleSorted],0 + mov esi,[spcBuffera] + inc esi + mov edi,spcRamcmp+1 + cmp dword[GUInumentries],1 + jbe near .nosort + cmp byte[GUIloadfntype],0 + je near .sort2 + mov ecx,[GUInumentries] + dec ecx +.nextentry + push ecx + ; check if esi > esi+32 + call GUIStringGreater + ; if it is, swap! + cmp al,0 + je near .noswap + mov ecx,31 +.nextswap + mov al,[esi] + mov bl,[esi+32] + mov [esi],bl + mov [esi+32],al + inc esi + dec ecx + jnz .nextswap + mov ecx,13 +.nextswap2 + mov al,[edi] + mov bl,[edi+14] + mov [edi],bl + mov [edi+14],al + inc edi + dec ecx + jnz .nextswap2 + mov byte[BubbleSorted],1 + sub esi,31 + sub edi,13 +.noswap + add esi,32 + add edi,14 + pop ecx + dec ecx + jnz near .nextentry +.nosort + cmp byte[BubbleSorted],1 + je near .sortagain + jmp .donesort + +.sort2 + mov esi,spcRamcmp + mov ecx,[GUInumentries] + dec ecx +.nextentryb + push ecx + mov ebx,[esi] + mov edx,[esi+4] + inc ebx + inc edx + ; check if ebx > edx + call GUIStringGreater2 + ; if it is, swap! + cmp al,0 + je near .noswapb + mov eax,[esi] + mov ebx,[esi+4] + mov [esi],ebx + mov [esi+4],eax + mov byte[BubbleSorted],1 +.noswapb + add esi,4 + pop ecx + dec ecx + jnz near .nextentryb +.nosortb + cmp byte[BubbleSorted],1 + je near .sortagain +.donesort + pop edi +GUIGetDirs: + mov dword[GUIdirentries],0 + mov [GUIdirStartLoc],edi + cmp byte[GUIloadfntype],0 + jne near .loadtype0 + mov eax,[GUInumentries] + mov [GUIdirStartLoc],eax +.loadtype0 + + cmp byte[GUIloadfntype],2 + je .win95lfn + cmp byte[GUIloadfntype],0 + je .normaldir + call GetLoadDirNormal + jmp .nowin95 +.normaldir + call GetLoadDirNormal2 + jmp .nowin95 +.win95lfn + call GetLoadDirNormallfn +.nowin95 + cmp dword[GUInumentries],0 + je near .nodirs + cmp dword[GUIdirentries],0 + je near .nodirs + + ; Sort List + ; copy from GUIdirStartLoc to spcBuffer+GUIdirentries*32 + ; compares string at esi to edi and returns 1 to al if esi is >, else 0 + + push edi + ; compares string at esi to edi and returns 1 to al if esi is >, else 0 +.sortagain + mov byte[BubbleSorted],0 + mov esi,dword[GUIfileentries] + shl esi,5 + add esi,[spcBuffera] + mov edi,[GUIdirStartLoc] + inc esi + inc edi + + cmp dword[GUIdirentries],1 + jbe near .nosort + mov ecx,[GUIdirentries] + dec ecx + cmp byte[GUIloadfntype],0 + je near .sort2 +.nextentry + push ecx + ; check if esi > esi+32 + call GUIStringGreater + ; if it is, swap! + cmp al,0 + je near .noswap + mov ecx,31 +.nextswap + mov al,[esi] + mov bl,[esi+32] + mov [esi],bl + mov [esi+32],al + inc esi + dec ecx + jnz .nextswap + mov ecx,13 +.nextswap2 + mov al,[edi] + mov bl,[edi+14] + mov [edi],bl + mov [edi+14],al + inc edi + dec ecx + jnz .nextswap2 + mov byte[BubbleSorted],1 + sub esi,31 + sub edi,13 +.noswap + add esi,32 + add edi,14 + pop ecx + dec ecx + jnz near .nextentry +.nosort + cmp byte[BubbleSorted],1 + je near .sortagain + pop edi + jmp .nodirs +.sort2 + mov esi,dword[GUIfileentries] + shl esi,2 + add esi,spcRamcmp +.nextentryb + push ecx + mov ebx,[esi] + mov edx,[esi+4] + inc ebx + inc edx + ; check if ebx > edx + call GUIStringGreater2 + ; if it is, swap! + cmp al,0 + je near .noswapb + mov eax,[esi] + mov ebx,[esi+4] + mov [esi],ebx + mov [esi+4],eax + mov byte[BubbleSorted],1 +.noswapb + add esi,4 + pop ecx + dec ecx + jnz near .nextentryb +.nosortb + cmp byte[BubbleSorted],1 + je near .sortagain + pop edi +.nodirs + cmp byte[GUIloadfntype],0 + je near .drive2 + mov esi,[GUInumentries] + shl esi,5 + add esi,[spcBuffera] + mov al,65 + mov ecx,[numdrives] +.nextdrive + GUIPutDrive + inc al + dec ecx + jnz .nextdrive + jmp .nodrive +.drive2 + mov esi,[GUInumentries] + shl esi,2 + add esi,spcRamcmp + mov al,65 + mov ecx,[numdrives] +.nextdriveb + mov [esi],edi + GUIPutDrive2 + add esi,4 + inc al + dec ecx + jnz .nextdriveb +.nodrive + ret + +BubbleSorted db 0 +GUIcurrentfilewin dd 0 +GUIcurrentviewloc dd 0 +GUIcurrentcursloc dd 0 +GUIcurrentdirviewloc dd 0 +GUIcurrentdircursloc dd 0 +GUIdirStartLoc dd 0 +GUInumentries dd 0 +GUIdirentries dd 0 +GUIfileentries dd 0 +NEWSYM GUIsmcfind, db '*.SMC',0 +NEWSYM GUIsfcfind, db '*.SFC',0 +NEWSYM GUIswcfind, db '*.SWC',0 +NEWSYM GUIfigfind, db '*.FIG',0 +NEWSYM GUIfind058, db '*.058',0 +NEWSYM GUIfind078, db '*.078',0 +NEWSYM GUIfindUSA, db '*.USA',0 +NEWSYM GUIfindJAP, db '*.JAP',0 +NEWSYM GUIfindBIN, db '*.BIN',0 +NEWSYM GUIfindZIP, db '*.ZIP',0 +NEWSYM GUIfindGZIP, db '*.GZ',0 +NEWSYM GUIfind1, db '*.1',0 +GUIfindDIR db '*.*',0 +NEWSYM GUIfindall, db '*.*',0 +NEWSYM DTALoc, times 2048+32 db 0 + +; Routines to load from the Quick Menu +loadquickfname: + ; move menuitem to top + cmp ecx,0 + je near .nomove + cmp byte[prevlfreeze],0 + jne near .nomove + + ; copy 16 bytes of ebx to pressed + mov eax,[ebx] + mov [pressed],eax + mov eax,[ebx+4] + mov [pressed+4],eax + mov eax,[ebx+8] + mov [pressed+8],eax + mov eax,[ebx+12] + mov [pressed+12],eax + ; move each entry above ebx down +.next2 + mov eax,[ebx-16] + mov [ebx],eax + mov eax,[ebx+4-16] + mov [ebx+4],eax + mov eax,[ebx+8-16] + mov [ebx+8],eax + mov eax,[ebx+12-16] + mov [ebx+12],eax + sub ebx,16 + cmp ebx,prevloadnames + jne .next2 + ; copy 16 bytes of pressed to top + mov eax,[pressed] + mov [ebx],eax + mov eax,[pressed+4] + mov [ebx+4],eax + mov eax,[pressed+8] + mov [ebx+8],eax + mov eax,[pressed+12] + mov [ebx+12],eax + + ; copy 512 bytes of edi to pressed + mov ecx,128 + xor ebx,ebx +.loopb + mov eax,[edi+ebx*4] + mov [pressed+ebx*4],eax + inc ebx + dec ecx + jnz .loopb + ; move each entry above ebx down +.next3b + mov ecx,128 + xor ebx,ebx +.loop2b + mov eax,[edi-512+ebx*4] + mov [edi+ebx*4],eax + inc ebx + dec ecx + jnz .loop2b + sub edi,512 + cmp edi,prevloadfnamel + jne .next3b + ; copy 512 bytes of pressed to top + mov ecx,128 + xor ebx,ebx +.loop3b + mov eax,[pressed+ebx*4] + mov [edi+ebx*4],eax + inc ebx + dec ecx + jnz .loop3b + + ; copy 512 bytes of esi to pressed + mov ecx,128 + xor ebx,ebx +.loop + mov eax,[esi+ebx*4] + mov [pressed+ebx*4],eax + inc ebx + dec ecx + jnz .loop + ; move each entry above ebx down +.next3 + mov ecx,128 + xor ebx,ebx +.loop2 + mov eax,[esi-512+ebx*4] + mov [esi+ebx*4],eax + inc ebx + dec ecx + jnz .loop2 + sub esi,512 + cmp esi,prevloaddnamel + jne .next3 + ; copy 512 bytes of pressed to top + mov ecx,128 + xor ebx,ebx +.loop3 + mov eax,[pressed+ebx*4] + mov [esi+ebx*4],eax + inc ebx + dec ecx + jnz .loop3 + +; pushad +; mov ax,03h +; int 10h +; popad +; push edi +; mov edx,esi+1 +; call PrintStr +; pop edi +; mov edx,edi+1 +; call PrintStr +; jmp DosExit + + ; clear pressed + mov eax,pressed + mov ecx,128 +.loop4 + mov dword[eax],0 + add eax,4 + dec ecx + jnz .loop4 +.nomove + ; change dir + mov dl,[esi] + mov ebx,esi + inc ebx + call Change_Dir + call GetCurDir + mov eax,edi + push eax + mov edx,edi + call Open_File + jc near .failed + mov bx,ax + mov edx,.temp + mov ecx,1 + call Read_File + jc near .failed2 + call Close_File + jc near .failed + pop eax + pushad + call GUIQuickLoadUpdate + popad + + call GUIloadfilename + ret +.failed2 + call Close_File +.failed + pop eax + ret +.temp times 256 dd 0 + \ No newline at end of file diff --git a/zsnes/src/gui/guimisc.inc b/zsnes/src/gui/guimisc.inc new file mode 100644 index 00000000..ac0e1793 --- /dev/null +++ b/zsnes/src/gui/guimisc.inc @@ -0,0 +1,499 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + +; Movie, Joystick setting (display) routines, SNES Reset Function + +MovieRecord: + mov byte[GUICBHold],0 + mov dword[MovieCounter],0 + cmp byte[MovieProcessing],0 + jne near .dontrecord + ; check if movie exists already + mov ebx,[statefileloc] + mov eax,[fnamest+ebx-3] + push eax + mov dword[fnamest+ebx-3],'.ZMV' + mov al,[CMovieExt] + mov byte[fnamest+ebx],al + + ; check if file exists + cmp byte[MovieRecordWinVal],1 + je .nocheck + mov edx,fnamest+1 + call Open_File + jc .nocheck + mov bx,ax + call Close_File + mov byte[MovieRecordWinVal],1 + jmp .skipstate +.nocheck + mov dword[CFWriteHead],0 + mov dword[CReadHead],0 + mov dword[ReadHead],0 + mov dword[CFWriteStart],64 + mov byte[MovieRecordWinVal],0 + call ChangetoSRAMdir + mov byte[NoPictureSave],1 + call statesaver + mov byte[NoPictureSave],0 + mov edx,fnamest+1 + call Open_File_Write + mov bx,ax + mov [MovieFileHand],bx + mov cx,0 + mov dx,0 + call File_Seek_End + mov al,[soundon] + mov [RecData],al + mov eax,[welcome+8] + mov [RecData+1],eax + mov byte[RecData+2],1 + mov eax,[timer2upd] + mov [RecData+3],eax + mov eax,[curexecstate] + mov [RecData+7],eax + mov edx,RecData + mov ecx,16 + call Write_File + cmp dword[ramsize],0 + je .noram + mov edx,[sram] + mov ecx,[ramsize] + call Write_File +.noram + mov byte[MovieProcessing],2 + mov dword[MovieBuffSize],0 + mov dword[MovieBuffFrame],0 + mov byte[RepeatFrame],0 + cmp byte[CNetType],20 + je near .netstuff + cmp byte[CNetType],21 + je near .netstuff + mov dword[nmiprevaddrl],0 + mov dword[nmiprevaddrh],0 + mov dword[nmirept],0 + mov dword[nmiprevline],224 + mov dword[nmistatus],0 + mov byte[spcnumread],0 + mov byte[NextLineCache],0 + mov dword[PJoyAOrig],0 + mov dword[PJoyBOrig],0 + mov dword[PJoyCOrig],0 + mov dword[PJoyDOrig],0 + mov dword[PJoyEOrig],0 + mov byte[DSPMem+08h],0 + mov byte[DSPMem+18h],0 + mov byte[DSPMem+28h],0 + mov byte[DSPMem+38h],0 + mov byte[DSPMem+48h],0 + mov byte[DSPMem+58h],0 + mov byte[DSPMem+68h],0 + mov byte[DSPMem+78h],0 +.netstuff + call ChangetoLOADdir +.skipstate + pop eax + mov ebx,[statefileloc] + mov [fnamest+ebx-3],eax +.dontrecord + ret + +MovieRecordWinVal db 0 +NEWSYM MovieProcessing, db 0 +NEWSYM MovieFileHand, dw 0 +NEWSYM RepeatFrame, db 0 +NEWSYM RecData, times 16 db 0 +NEWSYM NoPictureSave, db 0 + +SkipMovie: + mov byte[MovieRecordWinVal],0 + mov byte[GUICBHold],0 + ret + +MovieStop: + mov byte[GUICBHold],0 + cmp byte[MovieProcessing],0 + je .skipfileend + mov bx,[MovieFileHand] + mov byte[MovieProcessing],0 + call Close_File +.skipfileend + ret + +CalibrateDispA: + xor ebx,ebx + mov ecx,256 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 75,103,192,135,160 + GUIBox 75,103,192,103,162 + GUIBox 75,103,75,135,161 + GUIBox 192,103,192,135,159 + GUIBox 75,135,192,135,158 + GUIOuttext 81,109,guicalberror1,220-15 + GUIOuttext 80,108,guicalberror1,220 + GUIOuttext 81,117,guicalberror2,220-15 + GUIOuttext 80,116,guicalberror2,220 + GUIOuttext 81,125,guicalberror3,220-15 + GUIOuttext 80,124,guicalberror3,220 + call vidpastecopyscr + call WaitForKey + ret + +CalibrateDispB: + xor ebx,ebx + mov ecx,256 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 75,103,192,143,160 + GUIBox 75,103,192,103,162 + GUIBox 75,103,75,143,161 + GUIBox 192,103,192,143,159 + GUIBox 75,143,192,143,158 + GUIOuttext 81,109,guicalberror4,220-15 + GUIOuttext 80,108,guicalberror4,220 + GUIOuttext 81,117,guicalberror5,220-15 + GUIOuttext 80,116,guicalberror5,220 + GUIOuttext 81,125,guicalberror6,220-15 + GUIOuttext 80,124,guicalberror6,220 + GUIOuttext 81,133,guicalberror7,220-15 + GUIOuttext 80,132,guicalberror7,220 + call vidpastecopyscr + call WaitForKey + ret + +guicalberror1 db 'PRESS THE TOP LEFT',0 +guicalberror2 db 'CORNER AND PRESS A',0 +guicalberror3 db 'BUTTON OR KEY',0 +guicalberror4 db 'PRESS THE BOTTOM',0 +guicalberror5 db 'RIGHT CORNER AND',0 +guicalberror6 db 'PRESS A BUTTON OR',0 +guicalberror7 db 'KEY',0 + + +SetAllKeys: + xor ebx,ebx + mov ecx,256+128+64 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + + mov byte[GUICBHold],0 + mov edi,pl1selk + cmp byte[cplayernum],1 + jne .nopl2 + mov edi,pl2selk +.nopl2 + cmp byte[cplayernum],2 + jne .nopl3 + mov edi,pl3selk +.nopl3 + cmp byte[cplayernum],3 + jne .nopl4 + mov edi,pl4selk +.nopl4 + cmp byte[cplayernum],4 + jne .nopl5 + mov edi,pl5selk +.nopl5 + mov dword[guicpressptr],edi + xor ebx,ebx + mov ecx,12 + mov dword[guipressptr],guipresstext4b +.loop + mov eax,[.ordercalb+ebx*4] + shl eax,2 + add dword[guicpressptr],eax + push ebx + push ecx + call guipresstestb + pop ecx + pop ebx + add dword[guipressptr],21 + mov eax,[.ordercalb+ebx*4] + shl eax,2 + sub dword[guicpressptr],eax + inc ebx + dec ecx + jnz .loop + ret +.ordercalb dd 2,3,4,5,1,0,7,10,6,9,8,11 + +CalibrateDev1: + xor eax,eax + mov al,[cplayernum] + mov ebx,[GUIInputRefP+eax*4] + mov bl,[ebx] + mov byte[GUICBHold],0 + cmp byte[pl1p209+eax],0 + jne near .port209 + cmp bl,1 + jbe .nojoy + cmp bl,18 + je near .6button + cmp bl,5 + je near .6button + cmp bl,6 + jae .nojoy + mov dx,201h + call GetCoords + mov eax,[JoyX] + mov [.joybcx],eax + mov eax,[JoyY] + mov [.joybcy],eax + call CalibrateDispA + mov dx,201h + call GetCoords + mov eax,[JoyX] + mov [.joyblx],eax + mov eax,[JoyY] + mov [.joybly],eax + call CalibrateDispB + mov dx,201h + call GetCoords + jmp .procdir +.nojoy + ret +.6button + mov dx,201h + call GetCoords3 + mov eax,[JoyX] + mov [.joybcx],eax + mov eax,[JoyY] + mov [.joybcy],eax + call CalibrateDispA + mov dx,201h + call GetCoords3 + mov eax,[JoyX] + mov [.joyblx],eax + mov eax,[JoyY] + mov [.joybly],eax + call CalibrateDispB + mov dx,201h + call GetCoords3 +.procdir + mov eax,[.joybcx] + add eax,[.joyblx] + shr eax,1 + mov [JoyMinX],eax + mov [CalibXmin],eax + mov eax,[.joybcy] + add eax,[.joybly] + shr eax,1 + mov [JoyMinY],eax + mov [CalibYmin],eax + mov eax,[.joybcx] + add eax,[JoyX] + shr eax,1 + mov [JoyMaxX],eax + mov [CalibXmax],eax + mov eax,[.joybcy] + add eax,[JoyY] + shr eax,1 + mov [JoyMaxY],eax + mov [CalibYmax],eax + ret +.port209 + cmp bl,1 + jbe .nojoy209 + cmp bl,18 + je near .6button209 + cmp bl,5 + je near .6button209 + cmp bl,6 + jae .nojoy209 + mov dx,209h + call GetCoords + mov eax,[JoyX] + mov [.joybcx],eax + mov eax,[JoyY] + mov [.joybcy],eax + call CalibrateDispA + mov dx,209h + call GetCoords + mov eax,[JoyX] + mov [.joyblx],eax + mov eax,[JoyY] + mov [.joybly],eax + call CalibrateDispB + mov dx,209h + call GetCoords + jmp .procdir209 +.nojoy209 + ret +.6button209 + mov dx,209h + call GetCoords3 + mov eax,[JoyX] + mov [.joybcx],eax + mov eax,[JoyY] + mov [.joybcy],eax + call CalibrateDispA + mov dx,209h + call GetCoords3 + mov eax,[JoyX] + mov [.joyblx],eax + mov eax,[JoyY] + mov [.joybly],eax + call CalibrateDispB + mov dx,209h + call GetCoords3 +.procdir209 + mov eax,[.joybcx] + add eax,[.joyblx] + shr eax,1 + mov [JoyMinX209],eax + mov [CalibXmin209],eax + mov eax,[.joybcy] + add eax,[.joybly] + shr eax,1 + mov [JoyMinY209],eax + mov [CalibYmin209],eax + mov eax,[.joybcx] + add eax,[JoyX] + shr eax,1 + mov [JoyMaxX209],eax + mov [CalibXmax209],eax + mov eax,[.joybcy] + add eax,[JoyY] + shr eax,1 + mov [JoyMaxY209],eax + mov [CalibYmax209],eax + ret +.joyblx dd 0 +.joybly dd 0 +.joybcx dd 0 +.joybcy dd 0 + + +SetDevice: + mov byte[GUICBHold],0 + xor eax,eax + mov al,[cplayernum] + cmp byte[OSPort],1 + ja .notdos + cmp byte[pl1p209+eax],0 + jne .port209 +.notdos + mov dword[CalibXmin],0 + mov ecx,[DevicePtr+eax*4] + mov eax,[GUIInputRefP+eax*4] + mov ebx,[GUIcurrentinputcursloc] + mov bl,[GUIInputRefF+ebx] + mov [eax],bl + mov eax,ecx + mov bh,[cplayernum] + call SetInputDevice + call UpdateDevices + jmp .procmtap +.port209 + mov dword[CalibXmin209],0 + mov ecx,[DevicePtr+eax*4] + mov eax,[GUIInputRefP+eax*4] + mov ebx,[GUIcurrentinputcursloc] + mov bl,[GUIInputRefF+ebx] + mov [eax],bl + mov eax,ecx + mov bh,[cplayernum] + call SetInputDevice209 + call UpdateDevices +.procmtap + mov byte[MultiTap],1 + cmp byte[SFXEnable],1 + je .dismtap + cmp byte[pl3contrl],0 + jne .mtap + cmp byte[pl4contrl],0 + jne .mtap + cmp byte[pl5contrl],0 + jne .mtap +.dismtap + mov byte[MultiTap],0 +.mtap + ret + +NEWSYM GUIDoReset + call ClearScreen +; mov byte[NetPlayNoMore],1 + mov byte[RestoreValues],0 + + cmp byte[MovieProcessing],0 + je .skipfileend + mov bx,[MovieFileHand] + mov byte[MovieProcessing],0 + call Close_File +.skipfileend + call RestoreSystemVars + ; clear spc700 ram + mov al,0FFh + mov edi,spcRam + mov ecx,65472 + rep stosb + ; clear dsp ram + xor al,al + mov edi,DSPMem + mov ecx,256 + rep stosb + + ; reset the snes + call init65816 + call procexecloop + + mov eax,spcRam + mov edx,0EFh +.loop + mov byte[eax],0 + inc eax + dec edx + jnz .loop + + xor eax,eax + mov edx,spcRam + mov ax,0FFC9h + add edx,eax + mov [spcPCRam],edx + mov dword [spcS],1EFh + mov dword [spcRamDP],spcRam + mov byte[spcA],0 + mov byte[spcX],0 + mov byte[spcY],0 + mov byte[spcP],0 + mov byte[spcNZ],0 + mov byte[Voice0Status],0 + mov byte[Voice1Status],0 + mov byte[Voice2Status],0 + mov byte[Voice3Status],0 + mov byte[Voice4Status],0 + mov byte[Voice5Status],0 + mov byte[Voice6Status],0 + mov byte[Voice7Status],0 + mov byte[GUIQuit],2 + ret + \ No newline at end of file diff --git a/zsnes/src/gui/guimouse.inc b/zsnes/src/gui/guimouse.inc new file mode 100644 index 00000000..8a9ce077 --- /dev/null +++ b/zsnes/src/gui/guimouse.inc @@ -0,0 +1,2861 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + +lastmouseholded db 0 +mousebuttonstat dw 0 +MouseMoveOkay db 0 +LastHoldEnable db 0 + +ProcessMouse: + ; Process holds + mov al,[GUIHold] + cmp al,[LastHoldEnable] + je near .noholdnecessary + cmp byte[GUIHold],0 + jne .noholda + mov ecx,0 + mov edx,255 + call Set_MouseXMax + mov ecx,0 + mov edx,223 + call Set_MouseYMax +.noholda + cmp byte[GUIHold],1 + jne .nohold1 + mov ecx,0 + mov edx,255 + call Set_MouseXMax + mov ecx,16 + mov edx,223 + call Set_MouseYMax +.nohold1 + cmp byte[GUIHold],5 + je .dohold5 + cmp byte[GUIHold],2 + jne .nohold2m +.dohold5 + mov ecx,[GUIHoldXlimL] + mov edx,[GUIHoldXlimR] + call Set_MouseXMax + mov ecx,[GUIHoldYlim] + mov edx,[GUIHoldYlim] + call Set_MouseYMax +.nohold2m + cmp byte[GUIHold],3 + jne .nohold3m + mov ecx,[GUIHoldXlimL] + mov edx,[GUIHoldXlimR] + call Set_MouseXMax + mov ecx,[GUIHoldYlim] + mov edx,[GUIHoldYlimR] + call Set_MouseYMax +.nohold3m + mov al,[GUIHold] + mov [LastHoldEnable],al +.noholdnecessary + mov byte[MouseMoveOkay],0 + call Get_MouseData + mov [mousebuttonstat],bx + cmp byte[lastmouseholded],0 + je .noprevhold + test bx,01h + jnz .noprevhold + mov byte[lastmouseholded],0 + mov cx,[GUImouseposx] + mov dx,[GUImouseposy] + call Set_MousePosition +.noprevhold + cmp byte[mousewrap],1 + je near ProcessMouseWrap + call Get_MouseData + cmp word[GUImouseposx],cx + je .zero2 + mov byte[MouseMoveOkay],1 +.zero2 + cmp word[GUImouseposy],dx + je .zero3 + mov byte[MouseMoveOkay],1 +.zero3 + mov word[GUImouseposx],cx + test word[GUImouseposx],8000h + jz .nowrapleft + mov word[GUImouseposx],0 +.nowrapleft + cmp word[GUImouseposx],255 + jbe .nowrapright + mov word[GUImouseposx],255 +.nowrapright + mov word[GUImouseposy],dx + test word[GUImouseposy],8000h + jz .nowrapup + mov word[GUImouseposy],0 +.nowrapup + cmp word[GUImouseposy],223 + jbe .nowrapdown + mov word[GUImouseposy],100 +.nowrapdown + jmp ProcessMouseButtons +ProcessMouseWrap: + call Get_MousePositionDisplacement + add word[GUImouseposx],cx +.again + test word[GUImouseposx],8000h + jz .nowrapleft + add word[GUImouseposx],256 + jmp .again +.nowrapleft + cmp word[GUImouseposx],255 + jbe .nowrapright + sub word[GUImouseposx],256 + jmp .again +.nowrapright + add word[GUImouseposy],dx +.again2 + test word[GUImouseposy],8000h + jz .nowrapup + add word[GUImouseposy],224 + jmp .again2 +.nowrapup + cmp word[GUImouseposy],223 + jbe .nowrapdown + cmp byte[GUIHold],1 + jne .nohold + sub word[GUImouseposy],224-16 + jmp .again2 +.nohold + sub word[GUImouseposy],224 + jmp .again2 +.nowrapdown + cmp dx,0 + jne .nozero + cmp cx,0 + je .zero +.nozero + mov byte[MouseMoveOkay],1 +.zero +ProcessMouseButtons: + cmp byte[MouseMoveOkay],1 + jne .zero + mov byte[GUIOnMenuItm],0 + mov ax,[GUImouseposx] + cmp ax,[GUIMenuL] + jbe .zero + cmp ax,[GUIMenuR] + jae .zero + mov ax,[GUImouseposy] + cmp ax,18 + jbe .zero + cmp ax,[GUIMenuD] + jae .zero + ; Mouse Menu + xor dx,dx + sub ax,18 + mov bx,10 + div bx + and eax,0FFh + mov ebx,[GUICYLocPtr] + mov byte[GUIOnMenuItm],2 + cmp byte[eax+ebx+1],0 + je .zero + mov byte[GUIcrowpos],al + mov byte[GUIOnMenuItm],1 +.zero + ; Check if mouse is clicked on menu + mov bx,[mousebuttonstat] + cmp byte[GUIClick],1 + jne .norclick2 + test bx,02h + jz .norclick + cmp byte[romloadskip],0 + jne .norclick2 + cmp byte[MousePRClick],0 + jne .norclick2 + mov byte[GUIQuit],2 +.norclick + mov byte[MousePRClick],0 +.norclick2 + test bx,01h + jz near .notclicked + cmp byte[GUIpclicked],1 + je near .noclick + cmp byte[GUIOnMenuItm],2 + je near .noclick + cmp byte[GUIOnMenuItm],1 + jne .nomenuitem + call GUITryMenuItem + jmp .noclick +.nomenuitem + cmp word[GUImouseposy],15 + ja near .nomenu + cmp word[GUImouseposy],3 + jb near .noclicked + cmp word[GUImouseposy],13 + ja near .noclicked +; GUIDMHelp 4,12,GUIMenuItem+6,1 + cmp word[GUImouseposx],4 + jb near .noclicked + cmp word[GUImouseposx],12 + ja .notfound + mov byte[GUIcmenupos],1 + mov byte[GUIcrowpos],0 + jmp .noclick +.notfound +; GUIDMHelp 17,47,GUIMenuItem,2 + cmp word[GUImouseposx],17 + jb near .noclicked + cmp word[GUImouseposx],47 + ja .notfound2 + mov byte[GUIcmenupos],2 + mov byte[GUIcrowpos],0 + jmp .noclick +.notfound2 +; GUIDMHelp 52,94,GUIMenuItem+7,3 + cmp word[GUImouseposx],52 + jb near .noclicked + cmp word[GUImouseposx],94 + ja .notfound3 + mov byte[GUIcmenupos],3 + mov byte[GUIcrowpos],0 + jmp .noclick +.notfound3 +; GUIDMHelp 99,135,GUIMenuItem+14,4 + cmp word[GUImouseposx],99 + jb near .noclicked + cmp word[GUImouseposx],135 + ja .notfound4 + mov byte[GUIcmenupos],4 + mov byte[GUIcrowpos],0 + jmp .noclick +.notfound4 +; GUIDMHelp 140,188,GUIMenuItem+21,5 + cmp word[GUImouseposx],140 + jb near .noclicked + cmp word[GUImouseposx],188 + ja .notfound5 + mov byte[GUIcmenupos],5 + mov byte[GUIcrowpos],0 + jmp .noclick +.notfound5 +; GUIDMHelp 193,223,GUIMenuItem+29,6 + cmp word[GUImouseposx],193 + jb near .noclicked + cmp word[GUImouseposx],223 + ja .notfound6 + mov byte[GUIcmenupos],6 + mov byte[GUIcrowpos],0 + jmp .noclick +.notfound6 + cmp word[GUImouseposx],230 + jb near .noclicked + cmp word[GUImouseposx],233 + jb near .noclick + cmp word[GUImouseposx],242 + ja .notfound7 + mov byte[GUIcwinpress],1 + jmp .noclick +.notfound7 + cmp word[GUImouseposx],244 + jb near .noclick + cmp word[GUImouseposx],253 + ja .notfound8 + mov byte[GUIcwinpress],2 + jmp .noclick +.notfound8 + jmp .noclick +.noclicked + cmp byte[OSPort],3 + jne .noclick + mov byte[GUIpclicked],1 + mov byte[GUIHold],255 + mov eax,[GUImouseposy] + mov [GUIHoldYlim],eax + mov eax,[GUImouseposx] + mov [GUIHoldXlimL],eax + call MouseWindow + jmp .noclick +.nomenu + cmp byte[GUIcmenupos],0 + je near .checkmenuboxclick + mov al,[GUIcmenupos] + mov [GUIpmenupos],al + mov byte[GUIcmenupos],0 +.noclick + mov byte[GUIpclicked],1 + xor eax,eax + mov al,[GUIwinptr] + dec eax + xor ebx,ebx + mov bl,[GUIwinorder+eax] + cmp byte[GUIHold],2 + je .hold2 + cmp byte[GUIHold],3 + je near .hold3 + cmp byte[GUIHold],4 + je near .hold4 + cmp byte[GUIHold],5 + je near .hold5 + cmp byte[GUIHold],1 + je near .hold + cmp byte[GUIHold],255 + je .holded + mov byte[GUICHold],0 + ret +.holded + mov eax,[GUIHoldYlim] + mov [GUImouseposy],eax + mov eax,[GUIHoldXlimL] + mov [GUImouseposx],eax + mov cx,[GUIHoldXlimL] + mov dx,[GUIHoldYlim] + call Set_MousePosition + ret +.hold2 + ; Slide Bar Hold + mov eax,[GUIHoldYlim] + mov [GUImouseposy],eax + mov ebx,[GUImouseposx] + mov eax,[GUIHoldXlimL] + cmp ebx,eax + jnl .noless + mov [GUImouseposx],eax +.noless + mov eax,[GUIHoldXlimR] + cmp ebx,eax + jng .nogreat + mov [GUImouseposx],eax +.nogreat + mov byte[lastmouseholded],1 + jmp DisplayGUIOptnsClick +.hold3 + ; Box Hold + mov ebx,[GUIHoldYlim] + cmp ebx,[GUImouseposy] + jl .boxhold1 + mov [GUImouseposy],ebx +.boxhold1 + mov ebx,[GUIHoldXlimL] + cmp ebx,[GUImouseposx] + jl .boxhold2 + mov [GUImouseposx],ebx +.boxhold2 + mov ebx,[GUIHoldYlimR] + cmp ebx,[GUImouseposy] + jg .boxhold3 + mov [GUImouseposy],ebx +.boxhold3 + mov ebx,[GUIHoldXlimR] + cmp ebx,[GUImouseposx] + jg .boxhold4 + mov [GUImouseposx],ebx +.boxhold4 + mov byte[lastmouseholded],1 + jmp GUIWindowMove +.hold4 + mov eax,[GUImouseposx] + sub eax,[GUIwinposx+ebx*4] + mov edx,[GUImouseposy] + sub edx,[GUIwinposy+ebx*4] + cmp eax,[GUIHoldXlimL] + jl near .nobhold + cmp edx,[GUIHoldYlim] + jl near .nobhold + cmp eax,[GUIHoldXlimR] + jg near .nobhold + cmp edx,[GUIHoldYlimR] + jg near .nobhold + mov al,[GUICBHold2] + mov [GUICBHold],al + ret +.nobhold + mov byte[GUICBHold],0 + ret +.hold5 + ; Slide Bar Hold + mov eax,[GUIHoldYlim] + mov [GUImouseposy],eax + mov ebx,[GUImouseposx] + mov eax,[GUIHoldXlimL] + cmp ebx,eax + jnl .nolessa + mov [GUImouseposx],eax +.nolessa + mov eax,[GUIHoldXlimR] + cmp ebx,eax + jng .nogreata + mov [GUImouseposx],eax +.nogreata + mov byte[lastmouseholded],1 + jmp DisplayGUISoundClick +.hold + cmp word[GUImouseposy],16 + jge .noover + test byte[mousewrap],1 + jz .nomwrap + add word[GUImouseposy],224-16 + jmp .hold +.nomwrap + mov word[GUImouseposy],16 +.noover + mov cx,word[GUImouseposy] + sub cx,[GUIHoldy] + add cx,[GUIHoldym] + movsx ecx,cx + xor eax,eax + mov al,[GUIwinptr] + dec eax + xor ebx,ebx + mov bl,[GUIwinorder+eax] + mov [GUIwinposy+ebx*4],ecx + mov cx,word[GUImouseposx] + sub cx,[GUIHoldx] + add cx,[GUIHoldxm] + movsx ecx,cx + mov [GUIwinposx+ebx*4],ecx + ret +.notclicked + mov byte[GUICHold],0 + mov byte[GUIpclicked],0 + mov byte[GUIHold],0 + + cmp byte[OSPort],3 + jne .notwinpressa + cmp byte[GUIcwinpress],1 + jne .notwinpressa + mov byte[GUIcwinpress],0 + cmp word[GUImouseposy],3 + jb .notwinpressa + cmp word[GUImouseposy],13 + ja .notwinpressa + cmp word[GUImouseposx],233 + jb .notwinpressa + cmp word[GUImouseposx],242 + ja .notwinpressa + call SwitchFullScreen + ret +.notwinpressa + + cmp byte[OSPort],3 + jne .notwinpressb + cmp byte[GUIcwinpress],2 + jne .notwinpressb + mov byte[GUIcwinpress],0 + cmp word[GUImouseposy],3 + jb .notwinpressb + cmp word[GUImouseposy],13 + ja .notwinpressb + cmp word[GUImouseposx],244 + jb .notwinpressb + cmp word[GUImouseposx],253 + ja .notwinpressb + mov byte[GUIQuit],1 + ret +.notwinpressb + + ; ButtonProcess + cmp byte[GUICBHold],1 + je near GUILoadData + cmp byte[GUICBHold],2 + je near GUIProcReset + cmp byte[GUICBHold],3 + je near GUIProcReset + cmp byte[GUICBHold],4 + je near GUIProcVideo + cmp byte[GUICBHold],10 + je near GUIProcStates + cmp byte[GUICBHold],11 + je near GUIProcStates + cmp byte[GUICBHold],5 + je near CheatCodeRemove + cmp byte[GUICBHold],6 + je near CheatCodeToggle + cmp byte[GUICBHold],7 + je near CheatCodeSave + cmp byte[GUICBHold],8 + je near CheatCodeLoad + cmp byte[GUICBHold],9 + je near ProcessCheatCode + cmp byte[GUICBHold],33 + je near CheatCodeFix + cmp byte[GUICBHold],14 + je near SetDevice + cmp byte[GUICBHold],15 + je near CalibrateDev1 + cmp byte[GUICBHold],16 + je near MoviePlay + cmp byte[GUICBHold],17 + je near MovieRecord + cmp byte[GUICBHold],18 + je near MovieStop + cmp byte[GUICBHold],19 + je near MovieRecord + cmp byte[GUICBHold],20 + je near SkipMovie + cmp byte[GUICBHold],40 + je near SetAllKeys + cmp byte[GUICBHold],50 + jne .notstartcheat + call CheatCodeSearchInit +.notstartcheat + cmp byte[GUICBHold],60 + jne .nocombclear + mov byte[GUIComboTextH],0 + mov byte[GUINumCombo],0 + mov dword[GUIComboKey],0 +.nocombclear + cmp byte[GUICBHold],61 + jne .nocomboadd + cmp byte[NumCombo],50 + je .nocomboadd + call ComboAdder +.nocomboadd + cmp byte[GUICBHold],62 + jne .nocomboreplace + cmp byte[NumCombo],0 + je .nocomboreplace + call ComboReplace +.nocomboreplace + cmp byte[GUICBHold],63 + jne .nocomboremove + cmp byte[NumCombo],0 + je .nocomboremove + call ComboRemoval +.nocomboremove + cmp byte[GUICBHold],51 + jne .notrestartcheat + mov byte[CheatWinMode],0 + mov byte[CheatSearchStatus],0 +.notrestartcheat + cmp byte[GUICBHold],52 + jne .notviewcheat + mov byte[CheatWinMode],2 +.notviewcheat + cmp byte[GUICBHold],53 + jne .notsearchprocess + call CheatCodeSearchProcess +.notsearchprocess + cmp byte[GUICBHold],54 + jne .notreturnview + mov byte[CheatWinMode],1 +.notreturnview + cmp byte[GUICBHold],55 + jne .notadd + cmp dword[NumCheatSrc],0 + je .notadd + mov byte[CheatWinMode],3 + mov byte[CurCStextpos],0 + mov byte[CSInputDisplay],'_' + mov byte[CSInputDisplay+1],0 + mov byte[CSDescDisplay],0 +.notadd + cmp byte[GUICBHold],56 + jne .notreturnadd + mov byte[CheatWinMode],2 +.notreturnadd + cmp byte[GUICBHold],57 + jne .noinsertscc + call AddCSCheatCode +; call InsertSearchDescription +.noinsertscc + cmp byte[GUICBHold],21 + jne .nomodem1 + mov byte[CNetType],3 +.nomodem1 + cmp byte[GUICBHold],22 + jne .nomodem2 + mov byte[CNetType],10 + mov byte[ModemProcess],0 +.nomodem2 + cmp byte[GUICBHold],23 + jne .nomodem3 + mov byte[CNetType],2 +.nomodem3 + cmp byte[GUICBHold],24 + jne .nomodem4 + mov byte[CNetType],12 + mov byte[ModemProcess],0 +.nomodem4 + cmp byte[GUICBHold],25 + jne .nomodem4b + mov byte[CNetType],15 + mov byte[ModemProcess],40 + mov byte[WhichRemote],4 +.nomodem4b + cmp byte[GUICBHold],26 + jne .nomodem4c + mov byte[CNetType],15 + mov byte[ModemProcess],41 + mov byte[WhichRemote],4 +.nomodem4c + cmp byte[GUICBHold],27 + jne .noinit + cmp byte[CNetType],20 + jne near .nostat20b2 + call PreparePacket + mov al,255 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,255 + call RemoteSendChar + call SendPacket + call PreparePacket + mov al,255 + call RemoteSendChar + call SendPacket + cmp byte[NetQuitAfter],0 + je .nostat20b2 + mov byte[GUIQuit],1 +.nostat20b2 + call RemoteDeInit +.noinit + cmp byte[GUICBHold],28 + jne .nomodem5 + mov byte[CNetType],11 + mov byte[ModemProcess],0 +.nomodem5 + cmp byte[GUICBHold],34 + jne .noipx1 + mov byte[WhichRemote],2 + mov byte[ModemProcess],30 + mov byte[CNetType],15 +.noipx1 + cmp byte[GUICBHold],64 + jne .nostatecancel + mov byte[NetStateQuit],1 +.nostatecancel + cmp byte[GUICBHold],65 + jne .nohomepage + call GotoHomepage +.nohomepage + mov byte[GUICBHold],0 + ret +.checkmenuboxclick + mov byte[GUIpclicked],1 + xor eax,eax + mov al,[GUIwinptr] + or eax,eax + jz near .nomore + dec eax + xor ebx,ebx + mov bl,[GUIwinorder+eax] + mov ecx,[GUIwinposx+ebx*4] + cmp ecx,[GUImouseposx] + jge .noinsdwin + mov ecx,[GUIwinposy+ebx*4] + cmp ecx,[GUImouseposy] + jge .noinsdwin + mov ecx,[GUIwinposx+ebx*4] + add ecx,[GUIwinsizex+ebx*4] + cmp ecx,[GUImouseposx] + jle .noinsdwin + mov ecx,[GUIwinposy+ebx*4] + add ecx,[GUIwinsizey+ebx*4] + add ecx,10 + cmp ecx,[GUImouseposy] + jle .noinsdwin + jmp GUIWinClicked +.noinsdwin +.nextwindowfind + or eax,eax + jz near .nomore + dec eax + mov bl,[GUIwinorder+eax] + mov ecx,[GUIwinposx+ebx*4] + cmp ecx,[GUImouseposx] + jge .nextwindowfind + mov ecx,[GUIwinposy+ebx*4] + cmp ecx,[GUImouseposy] + jge .nextwindowfind + mov ecx,[GUIwinposx+ebx*4] + add ecx,[GUIwinsizex+ebx*4] + cmp ecx,[GUImouseposx] + jle .nextwindowfind + mov ecx,[GUIwinposy+ebx*4] + add ecx,[GUIwinsizey+ebx*4] + add ecx,10 + cmp ecx,[GUImouseposy] + jle .nextwindowfind + ; Shift all following windows downwards by 1 +.nextfind + inc eax + cmp al,[GUIwinptr] + je .foundend + mov cl,[GUIwinorder+eax] + mov [GUIwinorder+eax-1],cl + jmp .nextfind +.foundend + mov byte[GUIpclicked],0 + mov [GUIwinorder+eax-1],bl + ret +.nomore + cmp dword[SantaPos],272 + je .nosanta + cmp byte[ShowTimer],0 + jne .nosanta + mov dword[MsgGiftLeft],36*4 + mov byte[ShowTimer],1 +.nosanta + ret + + +GUIProcVideo: + mov al,[GUIcurrentvideocursloc] + cmp byte[OSPort],2 + jae .yes16b + cmp al,3 + je .yes16b + cmp al,5 + je .yes16b + cmp al,7 + je .yes16b + cmp al,10 + je .yes16b + cmp al,8 + jne .no16b +.yes16b +; mov byte[newengen],0 +; mov byte[cfgnewgfx],0 +; jmp .skipno16b +.no16b + mov byte[newengen],1 + mov byte[cfgnewgfx],1 +.skipno16b + mov byte[GUICBHold],0 + call guiprevideo + mov al,[cvidmode] + mov [.prevvid],al + mov al,[GUIcurrentvideocursloc] + mov [cvidmode],al + mov byte[ExitFromGUI],1 + call initvideo + cmp byte[videotroub],1 + je .failed + call GUISetPal + mov al,[cvidmode] + mov [cfgcvidmode],al + call guipostvideo + cmp dword[GUIkeydelay],0 + je .failed2 + mov dword[GUIkeydelay],0 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIWFVID+eax],1 + je .fullsc + mov [PrevWinMode],al + ret +.fullsc + mov [PrevFSMode],al + ret +.failed + mov byte[videotroub],0 + mov al,[.prevvid] + mov [cvidmode],al + mov [cfgcvidmode],al + call initvideo + call GUISetPal + call guipostvideofail + mov dword[GUIkeydelay],0 + ret +.failed2 + mov byte[videotroub],0 + mov al,[.prevvid] + mov [cvidmode],al + mov [cfgcvidmode],al + call initvideo + call GUISetPal + mov dword[GUIkeydelay],0 + ret +.prevvid db 0 + +NEWSYM SwitchFullScreen + pushad + mov ecx,255*296 + mov eax,[vidbufferofsb] +.loop + mov dword[eax],0FEFEFEFEh + add eax,4 + loop .loop + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIWFVID+eax],0 + je .fullsc + mov al,[PrevWinMode] + mov [cvidmode],al + mov [cfgcvidmode],al + call initvideo + popad + ret +.fullsc + mov al,[PrevFSMode] + mov [cvidmode],al + mov [cfgcvidmode],al + call initvideo + popad + ret + +GUIWindowMove: + xor eax,eax + mov al,[GUIwinptr] + dec eax + xor ebx,ebx + mov bl,[GUIwinorder+eax] + mov eax,[GUImouseposx] + sub eax,[GUIwinposx+ebx*4] + mov edx,[GUImouseposy] + sub edx,[GUIwinposy+ebx*4] + cmp ebx,13 + je near DisplayGUICheatSearchClick2 + cmp ebx,7 + je near DisplayGUICheatClick2 + cmp ebx,5 + je near DisplayGUIVideoClick2 + cmp ebx,3 + je near DisplayGUIInputClick2 + cmp ebx,16 + je near DisplayGUIComboClick2 + jmp DisplayGUIConfirmClick2 + +GUIWinClicked: + mov ecx,[GUImouseposx] + sub ecx,[GUIwinposx+ebx*4] + mov edx,[GUImouseposy] + sub edx,[GUIwinposy+ebx*4] + mov esi,ecx + sub esi,[GUIwinsizex+ebx*4] + add esi,10 + cmp esi,-1 + jle .noclose + cmp esi,10 + jge .noclose + cmp edx,0 + jle .noclose + cmp edx,10 + jge .noclose + mov byte[GUIwinorder+eax],0 + mov byte[GUIwinactiv+ebx],0 + dec byte[GUIwinptr] + ret +.noclose + cmp edx,10 + jge .nomove + mov byte[GUIHold],1 + mov ax,[GUIwinposx+ebx*4] + movsx eax,ax + mov [GUIHoldxm],eax + mov ax,[GUIwinposy+ebx*4] + movsx eax,ax + mov [GUIHoldym],eax + xor eax,eax + mov ax,[GUImouseposx] + mov [GUIHoldx],eax + mov ax,[GUImouseposy] + mov [GUIHoldy],eax + ret +.nomove + mov eax,[GUImouseposx] + sub eax,[GUIwinposx+ebx*4] + mov edx,[GUImouseposy] + sub edx,[GUIwinposy+ebx*4] + cmp ebx,1 + je near DisplayGUIConfirmClick + cmp ebx,2 + je near DisplayGUIChoseSaveClick + cmp ebx,3 + je near DisplayGUIInputClick + cmp ebx,4 + je near DisplayGUIOptionClick + cmp ebx,5 + je near DisplayGUIVideoClick + cmp ebx,6 + je near DisplayGUISoundClick + cmp ebx,7 + je near DisplayGUICheatClick + cmp ebx,8 + je near DisplayNetOptnsClick + cmp ebx,9 + je near DisplayGameOptnsClick + cmp ebx,10 + je near DisplayGUIOptnsClick + cmp ebx,11 + je near DisplayGUIAboutClick + cmp ebx,12 + je near DisplayGUIResetClick + cmp ebx,13 + je near DisplayGUICheatSearchClick + cmp ebx,14 + je near DisplayGUIStatesClick + cmp ebx,15 + je near DisplayGUIMovieClick + cmp ebx,16 + je near DisplayGUIComboClick + cmp ebx,17 + je near DisplayGUIAddOnClick + ret + +%macro GUIClickCButton 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor %3,1 +%%noclick +%endmacro + +%macro GUIClickCButtonC 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor %3,1 + mov dword[GUIccombviewloc],0 + mov dword[GUIccombcursloc],0 + mov dword[GUIccomblcursloc],0 +%%noclick +%endmacro + +%macro GUIClickCButtonN 4 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + mov %3,%4 +%%noclick +%endmacro + +%macro GUIClickCButtonO 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + push eax + xor %3,1 + mov al,%3 + mov [bgfixer],al + pop eax +%%noclick +%endmacro + +%macro GUIClickCButtonS 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + push eax + xor %3,1 + call initrevst + mov al,[DSPMem+0Ch] + call WDSPReg0C + mov al,[DSPMem+1Ch] + call WDSPReg1C + mov al,[DSPMem+2Ch] + call WDSPReg2C + mov al,[DSPMem+3Ch] + call WDSPReg3C + pop eax +%%noclick +%endmacro + +%macro GUIClickCButtonM 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor %3,1 + mov byte[MultiTap],1 + cmp byte[pl12s34],1 + je .nomtap + cmp byte[pl3contrl],0 + jne .mtap + cmp byte[pl4contrl],0 + jne .mtap + cmp byte[pl5contrl],0 + jne .mtap +.nomtap + mov byte[MultiTap],0 +.mtap +%%noclick +%endmacro + +%macro GUIClickCButtonID 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor %3,1 + call SetDevice +%%noclick +%endmacro + +%macro GUIClickCButton2 5 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor %3,%5 + mov al,%3 + mov %4,al + ret +%%noclick +%endmacro + +%macro GUIClickCButton3 5 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor %3,%5 + mov al,%3 + mov %4,al + call ClearScreen + push eax + push ecx + mov eax,[vidbufferofsb] + mov ecx,288*128 +%%loop + mov dword[eax],0 + add eax,4 + loop %%loop + pop ecx + pop eax + ret +%%noclick +%endmacro + +%macro GUIClickCButton5 4 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + cmp %3,%4 + jne %%set + xor %3,%4 + jmp %%clear +%%set + mov %3,%4 +%%clear + ret +%%noclick +%endmacro + +%macro GUIClickCButton6 4 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + cmp %3,%4 + jne %%set + xor %3,%4 + jmp %%clear +%%set + mov %3,%4 + push eax + push ecx + mov eax,[vidbufferofsb] + mov ecx,288*128 +%%loop + mov dword[eax],0 + add eax,4 + loop %%loop + pop ecx + pop eax +%%clear + ret +%%noclick +%endmacro + +%macro GUIClickCButton4 5 + cmp eax,%1+1 + jl near %%noclick + cmp edx,%2+3 + jl near %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + cmp %3,%5 + jne %%set + xor %3,%5 + jmp %%done +%%set + mov %3,%5 +%%done + mov al,%3 + mov %4,al + cmp byte[En2xSaI],0 + jne %%nomodeq + call ClearScreen + cmp byte[OSPort],2 + jae %%nomodeq + cmp byte[cvidmode],1 + jne %%nomodeq + mov byte[cbitmode],1 + call initvideo2 + mov byte[cbitmode],0 + call GUISetPal +%%nomodeq + ret +%%noclick +%endmacro + +%macro GUIClickCButtonfr 3 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + mov byte[FPSOn],0 + cmp %3,0 + je %%zero + mov %3,0 + jmp %%notzero +%%zero + mov %3,2 +%%notzero +%%noclick +%endmacro + +%macro GUIClickCButtonL 2 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+3 + jl %%noclick + cmp eax,%1+6 + jg %%noclick + cmp edx,%2+8 + jg %%noclick + xor byte[showallext],1 + xor byte[GUIshowallext],1 + call GetLoadData + ret +%%noclick +%endmacro + +%macro GUISlidebarPostImpl 13 ; x1,y1,x2,y2,upjump,downjump,holdpos,scsize,view,cur,listsize + cmp dword[%11],0 + je near %%nolower + cmp dword[GUIdispmode],1 + je near %%slidebar + cmp eax,%1 + jl near %%noupper + cmp edx,%2-7 + jl near %%noupper + cmp eax,%3 + jg near %%noupper + cmp edx,%2-1 + jg near %%noupper + mov byte[%12],%13 + mov byte[GUICHold],%7 + jmp %5 +%%noupper + cmp eax,%1 + jl near %%nolower + cmp edx,%4+1 + jl near %%nolower + cmp eax,%3 + jg near %%nolower + cmp edx,%4+7 + jg near %%nolower + mov byte[%12],%13 + mov byte[GUICHold],%7+1 + jmp %6 +%%slidebar + cmp eax,%1 + jl near %%nolower + cmp edx,%2 + jl near %%nolower + cmp eax,%3 + jg near %%nolower + cmp edx,%4 + jg near %%nolower + mov byte[%12],%13 + ; displacement = (GUIdispmode * pixeldisp. / (listsize-scsize)) + mov eax,[%11] + sub eax,%8 + mov ebx,edx + sub ebx,[GUIlastypos] + imul ebx + mov ebx,[GUIlastdispval] + or ebx,ebx + jz near %%zerodiv + test ebx,80000000h + jnz near %%zerodiv + idiv ebx + mov ebx,[GUIlastvpos] + add ebx,eax + mov [%9],ebx + mov ebx,[GUIlastcpos] + add ebx,eax + mov [%10],ebx + test dword[%9],8000000h + jz %%noneg + mov dword[%9],0 +%%noneg + test dword[%10],8000000h + jz %%noneg2 + mov dword[%10],0 +%%noneg2 + mov eax,[%11] + dec eax + cmp [%10],eax + jb %%notover + mov [%10],eax +%%notover + sub eax,%8-1 + cmp [%9],eax + jb %%notover2 + mov [%9],eax +%%notover2 +%%zerodiv + ret +%%nolower +%endmacro + +GUIlastdispval dd 0 +GUIdispmode dd 0 +GUIlastypos dd 0 +GUIlastcpos dd 0 +GUIlastvpos dd 0 + +%macro GUISlidebarImpl 10 ; x1,y1,x2,y2,GUI?StA,ScrnSize,ViewLoc,CursLoc,Entries,win# + mov dword[GUIdispmode],0 + cmp eax,%1 + jl near %%nobar + cmp edx,%2 + jl near %%nobar + cmp eax,%3 + jg near %%nobar + cmp edx,%4 + jg near %%nobar + sub edx,%2 + cmp [%5+4],edx + ja near %%above + cmp [%5+8],edx + jb near %%below + add edx,%2 + mov [GUIlastypos],edx + mov dword[GUIdispmode],1 + mov eax,[GUIwinposy+%10*4] + add eax,%2 + mov [GUIHoldYlim],eax + mov eax,[GUIwinposy+%10*4] + add eax,%4 + mov [GUIHoldYlimR],eax + mov eax,[GUIwinposx+%10*4] + add eax,%1 + mov [GUIHoldXlimL],eax + mov eax,[GUIwinposx+%10*4] + add eax,%3 + mov [GUIHoldXlimR],eax + mov eax,[%5] + mov [GUIlastdispval],eax + mov eax,dword[%8] + mov [GUIlastcpos],eax + mov eax,dword[%7] + mov [GUIlastvpos],eax + mov byte[GUIHold],3 + ret +%%above + sub dword[%7],%6 + sub dword[%8],%6 + test dword[%7],8000000h + jz %%noneg + mov dword[%7],0 + mov dword[%8],0 +%%noneg + ret +%%below + add dword[%7],%6 + add dword[%8],%6 + mov ebx,[%9] + dec ebx + cmp [%8],ebx + jb %%notoverflow + mov [%8],ebx + sub ebx,%6-1 + mov [%7],ebx +%%notoverflow + mov ebx,[%9] + sub ebx,%6 + cmp [%7],ebx + jb %%notoverflow2 + mov [%7],ebx +%%notoverflow2 + ret +%%nobar + ; upper arrow + cmp eax,%1 + jl near %%noupper + cmp edx,%2-7 + jl near %%noupper + cmp eax,%3 + jg near %%noupper + cmp edx,%2-1 + jg near %%noupper + mov eax,[GUIwinposy+%10*4] + add eax,%2-7 + mov [GUIHoldYlim],eax + mov eax,[GUIwinposy+%10*4] + add eax,%2-1 + mov [GUIHoldYlimR],eax + mov eax,[GUIwinposx+%10*4] + add eax,%1 + mov [GUIHoldXlimL],eax + mov eax,[GUIwinposx+%10*4] + add eax,%3 + mov [GUIHoldXlimR],eax + mov byte[GUIHold],3 + ret +%%noupper + ; lower arrow + cmp eax,%1 + jl near %%nolower + cmp edx,%4+1 + jl near %%nolower + cmp eax,%3 + jg near %%nolower + cmp edx,%4+7 + jg near %%nolower + mov eax,[GUIwinposy+%10*4] + add eax,%4+1 + mov [GUIHoldYlim],eax + mov eax,[GUIwinposy+%10*4] + add eax,%4+7 + mov [GUIHoldYlimR],eax + mov eax,[GUIwinposx+%10*4] + add eax,%1 + mov [GUIHoldXlimL],eax + mov eax,[GUIwinposx+%10*4] + add eax,%3 + mov [GUIHoldXlimR],eax + mov byte[GUIHold],3 + ret +%%nolower +%endmacro + +%macro GUIPostWinBoxMove 11 ;x1,y1,x2,y2,view,curs,num,.scru,.scrd,jumpto,sizeofscreen + cmp eax,%1 + jl near %%noload + cmp eax,%3 + jg near %%noload + cmp edx,%2 + je near %%scrollup + cmp edx,%4 + jne near %%noload + ; Scroll Down + cmp dword[%7],%11 + jbe %9 + mov ebx,[%5] + add ebx,%11-1 + mov [%6],ebx +%9 + cmp dword[GUIScrolTim1],0 + jne near %%donescrol + mov ebx,[%7] + dec ebx + cmp ebx,[%6] + jbe %%donescrolldown + inc dword[%6] + cmp dword[%7],%11 + jbe near %%donescrol + inc dword[%5] + mov ebx,[%7] + sub ebx,%11 + cmp ebx,[%5] + ja near %%donescrolldown + mov [%5],ebx + jmp %%donescrolldown +%%scrollup + mov ebx,[%5] + mov [%6],ebx +%8 + cmp dword[GUIScrolTim1],0 + jne near %%donescrol + cmp dword[%6],0 + je %%donescrolldown + dec dword[%6] + cmp dword[%5],0 + je %%donescrolldown + dec dword[%5] +%%donescrolldown + mov dword[GUIScrolTim1],1 + cmp dword[GUIScrolTim2],4 + jb %%noscrol1 + inc dword[GUIScrolTim1] +%%noscrol1 + cmp dword[GUIScrolTim2],0 + je %%noscrol2 + inc dword[GUIScrolTim1] + dec dword[GUIScrolTim2] +%%noscrol2 +%%donescrol + jmp %10 +%%noload +%endmacro + +%macro GUIPHoldbutton 5 + cmp eax,%1 + jl near %%nohold + cmp edx,%2 + jl near %%nohold + cmp eax,%3 + jg near %%nohold + cmp edx,%4 + jg near %%nohold + mov dword[GUIHoldXlimL],%1 + mov dword[GUIHoldXlimR],%3 + mov dword[GUIHoldYlim],%2 + mov dword[GUIHoldYlimR],%4 + mov byte[GUICBHold2],%5 + mov byte[GUIHold],4 +%%nohold +%endmacro + +%macro GUIPHoldbutton2 8 + cmp eax,%1 + jl near %%nohold + cmp edx,%2 + jl near %%nohold + cmp eax,%3 + jg near %%nohold + cmp edx,%4 + jg near %%nohold + cmp byte[GUIHold],0 + jne %%nohold + mov dword[GUIHoldXlimL],%1 + mov dword[GUIHoldXlimR],%3 + mov dword[GUIHoldYlim],%2 + mov dword[GUIHoldYlimR],%4 + mov byte[GUICBHold2],%5 + mov byte[GUIHold],4 + cmp %6,%8 + je %%nohold + add %6,%7 +%%nohold +%endmacro + +%macro GUITextBoxInput 6 + cmp eax,%1 + jl %%noclick + cmp edx,%2 + jl %%noclick + cmp eax,%3 + jg %%noclick + cmp edx,%4 + jg %%noclick + mov dword[GUIEditString],%5 + mov dword[GUIEditStringmLen],%6 + mov dword[GUIEditStringLTxt],0 + mov dword[GUIEditStringcWin],1 +%%noclick +%endmacro + +%macro GUITextBoxInputB 5 + cmp eax,%1 + jl %%noclick + cmp edx,%2 + jl %%noclick + cmp eax,%3 + jg %%noclick + cmp edx,%4 + jg %%noclick + mov byte[GUINetTextm2],%5 +%%noclick +%endmacro + +%macro GUIPButtonHole 4 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+1 + jl %%noclick + cmp eax,%1+7 + jg %%noclick + cmp edx,%2+7 + jg %%noclick + mov %3,%4 +%%noclick +%endmacro + +%macro GUIPButtonHole2 6 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+1 + jl %%noclick + cmp eax,%1+7 + jg %%noclick + cmp edx,%2+7 + jg %%noclick + mov %3,%4 + mov %5,%6 +%%noclick +%endmacro + +%macro GUIPButtonHoleLoad 4 + cmp eax,%1+1 + jl %%noclick + cmp edx,%2+1 + jl %%noclick + cmp eax,%1+7 + jg %%noclick + cmp edx,%2+7 + jg %%noclick + mov %3,%4 + call GetLoadData + ret +%%noclick +%endmacro + +%macro GUIWinControl 13 ;x,y,x2,y2,currentwin,vpos,#entries,starty,y/entry,cpos,winval,win#,dclicktick# + cmp eax,%1 + jl near %%noload + cmp edx,%2 + jl near %%noload + cmp eax,%3 + jg near %%noload + cmp edx,%4 + jg near %%noload + cmp dword[%7],0 + je near %%noload + mov dword[%5],%11 + mov eax,edx + sub eax,%8 + xor edx,edx + mov ebx,%9 + div ebx + add eax,[%6] + mov ebx,[%7] + dec ebx + cmp eax,ebx + jg %%nomod + mov [%10],eax +%%nomod + cmp byte[GUIHold],0 + jne %%held + cmp dword[GUIDClickTL],0 + je %%noprevhold + cmp byte[GUIDClCWin],%11 + jne %%noprevhold + cmp [GUIDClCEntry],eax + jne %%noprevhold + mov dword[GUIDClickTL],0 + mov eax,%12 + cmp eax,1 + jne %%cheat + call GUILoadData + ret +%%cheat + call CheatCodeToggle + ret +%%noprevhold + mov dword[GUIDClickTL],%13 + mov byte[GUIDClCWin],%11 + mov [GUIDClCEntry],eax +%%held + mov eax,[GUIwinposy+%12*4] + add eax,%2-1 + mov [GUIHoldYlim],eax + mov eax,[GUIwinposy+%12*4] + add eax,%4+1 + mov [GUIHoldYlimR],eax + mov eax,[GUIwinposx+%12*4] + add eax,%1 + mov [GUIHoldXlimL],eax + mov eax,[GUIwinposx+%12*4] + add eax,%3 + mov [GUIHoldXlimR],eax + mov byte[GUIHold],3 + ret +%%noload +%endmacro + +%macro GUIWinControl2 13 ;Key Combination Editor Exclusive + cmp eax,%1 + jl near %%noload + cmp edx,%2 + jl near %%noload + cmp eax,%3 + jg near %%noload + cmp edx,%4 + jg near %%noload + cmp dword[%7],0 + je near %%noload + mov dword[GUIccomblcursloc],0FFFFFFFFh + mov dword[%5],%11 + mov eax,edx + sub eax,%8 + xor edx,edx + mov ebx,%9 + div ebx + add eax,[%6] + mov ebx,[%7] + dec ebx + cmp eax,ebx + jg %%nomod + mov [%10],eax +%%nomod + cmp byte[GUIHold],0 + jne %%held + cmp dword[GUIDClickTL],0 + je %%noprevhold + cmp byte[GUIDClCWin],%11 + jne %%noprevhold + cmp [GUIDClCEntry],eax + jne %%noprevhold + mov dword[GUIDClickTL],0 + mov eax,%12 + cmp eax,1 + jne %%cheat + call GUILoadData + ret +%%cheat + call CheatCodeToggle + ret +%%noprevhold + mov dword[GUIDClickTL],%13 + mov byte[GUIDClCWin],%11 + mov [GUIDClCEntry],eax +%%held + mov eax,[GUIwinposy+%12*4] + add eax,%2-1 + mov [GUIHoldYlim],eax + mov eax,[GUIwinposy+%12*4] + add eax,%4+1 + mov [GUIHoldYlimR],eax + mov eax,[GUIwinposx+%12*4] + add eax,%1 + mov [GUIHoldXlimL],eax + mov eax,[GUIwinposx+%12*4] + add eax,%3 + mov [GUIHoldXlimR],eax + mov byte[GUIHold],3 + ret +%%noload +%endmacro + +; Mouseimplementation + +DisplayGUIConfirmClick2: + cmp dword[GUIfileentries],1 + jbe near .noload2 + GUISlidebarPostImpl 146,33,153,33+93,.scrollupsl,.scrolldownsl,1,15,GUIcurrentviewloc,GUIcurrentcursloc,GUIfileentries,GUIcurrentfilewin,0 + GUIPostWinBoxMove 5,26,144,27+15*7,GUIcurrentviewloc,GUIcurrentcursloc,GUIfileentries,.scrollupsl,.scrolldownsl,DisplayGUIConfirmClick.skipscrol,15 +.noload2 + cmp dword[GUIdirentries],1 + jbe near .noload3 + GUISlidebarPostImpl 230,33,237,33+93,.scrollupsld,.scrolldownsld,3,15,GUIcurrentdirviewloc,GUIcurrentdircursloc,GUIdirentries,GUIcurrentfilewin,1 + GUIPostWinBoxMove 160,26,228,27+15*7,GUIcurrentdirviewloc,GUIcurrentdircursloc,GUIdirentries,.scrollupsld,.scrolldownsld,DisplayGUIConfirmClick.skipscrol,15 +.noload3 +DisplayGUIConfirmClick: +;DrawSlideBarWin 1,133,43,[GUIcurrentviewloc],[GUIfileentries],15,94,[GUILStA] + ; offset 0 = (ysize-(yend-ystart+1)), offset 1 = starty, offset 2 = endy + ; SlideBar Implementation + GUISlidebarImpl 146,33,153,33+93,GUILStA,15,GUIcurrentviewloc,GUIcurrentcursloc,GUIfileentries,1 + GUISlidebarImpl 230,33,237,33+93,GUILStB,15,GUIcurrentdirviewloc,GUIcurrentdircursloc,GUIdirentries,1 + mov dword[GUIScrolTim1],0 + mov dword[GUIScrolTim2],6 +.skipscrol + GUIClickCButtonL 10,187 + GUIWinControl 5,27,144,26+15*7,GUIcurrentfilewin,GUIcurrentviewloc,GUIfileentries,27,7,GUIcurrentcursloc,0,1,30 + GUIWinControl 160,27,228,26+15*7,GUIcurrentfilewin,GUIcurrentdirviewloc,GUIdirentries,27,7,GUIcurrentdircursloc,1,1,30 + GUIPHoldbutton 186,167,228,178,1 + GUIPButtonHoleLoad 9,163,byte[GUIloadfntype],0 + GUIPButtonHoleLoad 9,171,byte[GUIloadfntype],1 + GUIPButtonHoleLoad 9,179,byte[GUIloadfntype],2 + ret + +DisplayGUIChoseSaveClick: + GUIPButtonHole 10,28,byte[GUIChoseSaveText2],'T' + GUIPButtonHole 30,28,byte[GUIChoseSaveText2],'1' + GUIPButtonHole 50,28,byte[GUIChoseSaveText2],'2' + GUIPButtonHole 70,28,byte[GUIChoseSaveText2],'3' + GUIPButtonHole 90,28,byte[GUIChoseSaveText2],'4' + GUIPButtonHole 10,43,byte[GUIChoseSaveText2],'5' + GUIPButtonHole 30,43,byte[GUIChoseSaveText2],'6' + GUIPButtonHole 50,43,byte[GUIChoseSaveText2],'7' + GUIPButtonHole 70,43,byte[GUIChoseSaveText2],'8' + GUIPButtonHole 90,43,byte[GUIChoseSaveText2],'9' + mov ebx,[statefileloc] + mov al,[GUIChoseSaveText2] + mov [fnamest+ebx],al + ret + +DisplayGUIMovieClick: + cmp byte[MovieRecordWinVal],0 + je near .displayboxa + GUIPHoldbutton 17,55,59,66,19 + GUIPHoldbutton 70,55,112,66,20 + ret +.displayboxa + GUIPHoldbutton 7,17,49,28,16 + GUIPHoldbutton 7,33,49,44,17 + GUIPHoldbutton 7,49,49,60,18 + GUIPButtonHole 60,25,byte[CMovieExt],'V' + GUIPButtonHole 80,25,byte[CMovieExt],'1' + GUIPButtonHole 100,25,byte[CMovieExt],'2' + GUIPButtonHole 120,25,byte[CMovieExt],'3' + GUIPButtonHole 60,40,byte[CMovieExt],'4' + GUIPButtonHole 80,40,byte[CMovieExt],'5' + GUIPButtonHole 100,40,byte[CMovieExt],'6' + GUIPButtonHole 120,40,byte[CMovieExt],'7' + GUIPButtonHole 60,55,byte[CMovieExt],'8' + GUIPButtonHole 80,55,byte[CMovieExt],'9' + ret + +%macro DGOptnsProcBox 3 + cmp eax,%1 + jl %%skip + cmp edx,%2 + jl %%skip + cmp eax,%1+19 + jg %%skip + cmp edx,%2+6 + jg %%skip + push edi + call guipresstest + pop edi + cmp ebx,1 + je %%cancelkey + cmp ebx,3Bh + je %%cancelkey + mov %3,ebx + cmp byte[OSPort],3 + jne %%notwin32 + cmp dword[keycontrolval],0 + je %%notwin32 + push ebx + mov ebx,[keycontrolval] + mov byte[ebx],1 + pop ebx +%%notwin32 + ret +%%cancelkey + xor ebx,ebx + mov %3,ebx + ret +%%skip +%endmacro + +%macro DGOptnsProcBoxc 5 + cmp eax,%1 + jl %%skip + cmp edx,%2 + jl %%skip + cmp eax,%3 + jg %%skip + cmp edx,%4 + jg %%skip + push edi + call guipresstest + pop edi + cmp ebx,1 + je %%cancelkey + cmp ebx,3Bh + je %%cancelkey + mov %5,ebx + ret +%%cancelkey + cmp ebx,1 + jne %%noesc + mov byte[pressed+1],2 +%%noesc + xor ebx,ebx + mov %5,ebx + ret +%%skip +%endmacro + +%macro DGOptnsProcBoxb 3 + cmp eax,%1 + jl near %%skip + cmp edx,%2 + jl near %%skip + cmp eax,%1+19 + jg near %%skip + cmp edx,%2+6 + jg near %%skip + push edi + call guipresstest + pop edi + cmp ebx,1 + je %%cancelkey + cmp ebx,3Bh + je %%cancelkey + mov %3,ebx + jmp %%donekey +%%cancelkey + cmp ebx,1 + jne %%noesc + mov byte[pressed+1],2 +%%noesc + xor ebx,ebx + mov %3,ebx +%%donekey + xor ecx,ecx +%%joysloop + cmp dword[pl1ULk+ecx*4],80h + jbe %%nojoystick + mov dword[pl1ULk+ecx*4],0 +%%nojoystick + inc ecx + cmp ecx,16 + jne %%joysloop + ret +%%skip +%endmacro + +DisplayGUIInputClick2: + push eax + mov eax,[NumInputDevices] + mov dword[GUINumValue],eax + pop eax + GUISlidebarPostImpl 109,42,116,69,.scrollup,.scrolldown,9,5,GUIcurrentinputviewloc,GUIcurrentinputcursloc,GUINumValue,GUIBlankVar,1 + GUIPostWinBoxMove 5,35,107,35+5*8,GUIcurrentinputviewloc,GUIcurrentinputcursloc,GUINumValue,.scrollup,.scrolldown,DisplayGUIInputClick.skipscrol,5 +DisplayGUIInputClick: + ; SlideBar Implementation + push eax + mov eax,[NumInputDevices] + mov dword[GUINumValue],eax + pop eax + GUISlidebarImpl 109,42,116,69,GUIIStA,5,GUIcurrentinputviewloc,GUIcurrentinputcursloc,GUINumValue,3 +.skipscrol + ;x,y,x2,y2,currentwin,vpos,#entries,starty,y/entry,cpos,winval,win#,dclicktick# + GUIWinControl 5,36,107,34+5*8,GUIBlankVar,GUIcurrentinputviewloc,GUINumValue,35,8,GUIcurrentinputcursloc,4,3,0 + GUIPHoldbutton 125,34,155,45,14 + cmp byte[OSPort],3 + je near .win32 + GUIPHoldbutton 125,50,185,61,15 +.win32 + GUIPHoldbutton 125,66,185,77,40 + mov edi,pl1selk + mov dword[keycontrolval],pl1contrl + cmp byte[cplayernum],1 + jne .nopl2 + mov edi,pl2selk + mov dword[keycontrolval],pl2contrl +.nopl2 + cmp byte[cplayernum],2 + jne .nopl3 + mov edi,pl3selk + mov dword[keycontrolval],pl3contrl +.nopl3 + cmp byte[cplayernum],3 + jne .nopl4 + mov edi,pl4selk + mov dword[keycontrolval],pl4contrl +.nopl4 + cmp byte[cplayernum],4 + jne .nopl5 + mov edi,pl5selk + mov dword[keycontrolval],pl5contrl +.nopl5 + DGOptnsProcBox 45,150,[edi] + DGOptnsProcBox 45,140,[edi+4] + DGOptnsProcBox 45,100,[edi+8] + DGOptnsProcBox 45,110,[edi+12] + DGOptnsProcBox 45,120,[edi+16] + DGOptnsProcBox 45,130,[edi+20] + DGOptnsProcBox 85,120,[edi+24] + DGOptnsProcBox 85,100,[edi+28] + DGOptnsProcBox 85,140,[edi+32] + DGOptnsProcBox 85,130,[edi+36] + DGOptnsProcBox 85,110,[edi+40] + DGOptnsProcBox 85,150,[edi+44] + + mov edi,pl1Atk + cmp byte[cplayernum],1 + jne .nopl2t + mov edi,pl2Atk +.nopl2t + cmp byte[cplayernum],2 + jne .nopl3t + mov edi,pl3Atk +.nopl3t + cmp byte[cplayernum],3 + jne .nopl4t + mov edi,pl4Atk +.nopl4t + cmp byte[cplayernum],4 + jne .nopl5t + mov edi,pl5Atk +.nopl5t + DGOptnsProcBox 165,100,[edi] ; A Turbo + DGOptnsProcBox 165,110,[edi+4] ; B Turbo + DGOptnsProcBox 125,100,[edi+8] ; X Turbo + DGOptnsProcBox 125,110,[edi+12] ; Y Turbo + + mov edi,pl1ULk + cmp byte[cplayernum],1 + jne .nopl2tb + mov edi,pl2ULk +.nopl2tb + cmp byte[cplayernum],2 + jne .nopl3tb + mov edi,pl3ULk +.nopl3tb + cmp byte[cplayernum],3 + jne .nopl4tb + mov edi,pl4ULk +.nopl4tb + cmp byte[cplayernum],4 + jne .nopl5tb + mov edi,pl5ULk +.nopl5tb + DGOptnsProcBoxb 165,135,[edi] + DGOptnsProcBoxb 165,145,[edi+4] + DGOptnsProcBoxb 125,135,[edi+8] + DGOptnsProcBoxb 125,145,[edi+12] + + xor ebx,ebx + mov bl,[cplayernum] + GUIClickCButtonID 5,162,byte[pl1p209+ebx] + ret + + +DisplayGUIOptionClick: + GUIClickCButtonfr 11,26,byte[frameskip] + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUINGVID+ebx],1 + jne near .invalidng + GUIClickCButton2 11,36,byte[newengen],byte[cfgnewgfx],1 +.invalidng + GUIClickCButton2 11,46,byte[vsyncon],byte[cfgvsync],1 + GUIClickCButton2 11,56,byte[FPUCopy],byte[cfgcopymethod],2 + GUIClickCButtonM 11,66,byte[pl12s34] + GUIClickCButton 11,76,byte[SidewinderFix] + GUIClickCButton 11,86,byte[FPSAtStart] + GUIClickCButton 11,96,byte[Turbo30hz] + GUIClickCButton 11,106,byte[TimerEnable] + GUIClickCButton 11,116,byte[FastFwdToggle] + GUIClickCButton 11,126,byte[SRAMSave5Sec] + GUIClickCButtonO 11,136,byte[OldGfxMode2] + GUIClickCButton 11,146,byte[LatestSave] + GUIClickCButton 11,156,byte[AutoState] + GUIClickCButton 11,166,byte[DontSavePath] + GUIClickCButton 11,176,byte[SPCDisable] + GUIClickCButton 11,186,byte[GUIEnableTransp] + ; Frameskip = 0 + cmp byte[frameskip],0 + je near .autopress + GUIPHoldbutton2 97,12,105,22,12,byte[frameskip],1,10 + GUIPHoldbutton2 108,12,116,22,13,byte[frameskip],-1,1 + ret +.autopress + GUIPHoldbutton2 118,12,126,22,12,byte[maxskip],1,9 + GUIPHoldbutton2 129,12,137,22,13,byte[maxskip],-1,0 + ret + + +DisplayGUIVideoClick2: + push eax + mov eax,[NumVideoModes] + mov dword[GUINumValue],eax + pop eax + GUISlidebarPostImpl 117,33,124,62,.scrollup,.scrolldown,5,5,GUIcurrentvideoviewloc,GUIcurrentvideocursloc,GUINumValue,GUIBlankVar,1 + GUIPostWinBoxMove 5,27,115,27+5*8,GUIcurrentvideoviewloc,GUIcurrentvideocursloc,GUINumValue,.scrollup,.scrolldown,DisplayGUIVideoClick.skipscrol,5 +DisplayGUIVideoClick: + ; SlideBar Implementation + push eax + mov eax,[NumVideoModes] + mov dword[GUINumValue],eax + pop eax + GUISlidebarImpl 117,33,124,62,GUIVStA,5,GUIcurrentvideoviewloc,GUIcurrentvideocursloc,GUINumValue,5 +.skipscrol + GUIWinControl 5,28,115,26+5*8,GUIBlankVar,GUIcurrentvideoviewloc,GUINumValue,27,8,GUIcurrentvideocursloc,2,5,0 + + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUISLVID+ebx],0 + je near .nocheckboxb + GUIClickCButton4 11,103,byte[scanlines],byte[cfgscanline],1 +.nocheckboxb + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUITBVID+ebx],0 + je .nocheckboxttb + GUIClickCButton5 11,163,byte[Triplebufen],1 +.nocheckboxttb + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUIM7VID+ebx],0 + je .nocheckboxtm7 + GUIClickCButton5 11,173,byte[Mode7HiRes16b],1 +.nocheckboxtm7 + + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUIHSVID+ebx],0 + je near .nohsline + GUIClickCButton4 11,113,byte[scanlines],byte[cfgscanline],3 + GUIClickCButton4 11,123,byte[scanlines],byte[cfgscanline],2 +.nohsline + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUI2xVID+ebx],0 + je near .no2xSaI + GUIClickCButton6 11,133,byte[En2xSaI],1 + GUIClickCButton6 11,143,byte[En2xSaI],2 + GUIClickCButton6 11,153,byte[En2xSaI],3 +.no2xSaI + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUIIEVID+ebx],0 + je .nocheckbox1b + GUIClickCButton3 11,73,byte[antienab],byte[cfginterp],1 +.nocheckbox1b + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUIFSVID+ebx],0 + je .nocheckbox2b + GUIClickCButton3 11,83,byte[ScreenScale],byte[GUIScreenScale],1 +.nocheckbox2b + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUISSVID+ebx],0 + je .nocheckbox3b + GUIClickCButton3 11,93,byte[smallscreenon],byte[GUIsmallscreenon],1 +.nocheckbox3b + xor ebx,ebx + mov bl,[cvidmode] + cmp byte[GUII2VID+ebx],0 + je .nocheckboxi2 + GUIClickCButton3 11,163,byte[antienab],byte[cfginterp],1 +.nocheckboxi2 + + GUIPHoldbutton 128,60,164,71,4 + ret + +GUINumValue dd 0 +GUIBlankVar dd 0 + +DisplayGUISoundClick: + mov eax,[GUImouseposx] + sub eax,[GUIwinposx+6*4] + mov edx,[GUImouseposy] + sub edx,[GUIwinposy+6*4] + GUIClickCButton 11,21,byte[cfgsoundon] + GUIClickCButton 11,30,byte[cfgStereoSound] + GUIClickCButton 11,39,byte[RaisePitch] + GUIClickCButton 11,101,byte[SoundNoiseDis] + GUIClickCButtonS 11,111,byte[RevStereo] + GUIClickCButton 11,121,byte[Surround] + GUIClickCButton 11,131,byte[InterSound] + GUIClickCButton 11,141,byte[LowPassFilter] + GUIClickCButton 11,151,byte[SoundBufEn] + cmp eax,15 + jl near .nosrate + cmp edx,61 + jl near .nosrate + cmp eax,69 + jg near .nosrate + cmp edx,69 + jg near .nosrate + xor eax,eax + mov al,[cfgSoundQuality] + mov al,[sampratenext+eax] + mov [cfgSoundQuality],al +.nosrate + cmp eax,15 + jl near .nomovebar + cmp eax,15+100 + jg near .nomovebar + cmp edx,89 + jl near .nomovebar + cmp edx,93 + jg near .nomovebar + sub eax,15 + mov [MusicRelVol],al + mov [cfgvolume],al + mov byte[GUIHold],5 + mov eax,[GUIwinposy+6*4] + add eax,91 + mov [GUIHoldYlim],eax + xor eax,eax + xor edx,edx + mov al,[MusicRelVol] + shl eax,7 + mov ebx,100 + div ebx + cmp al,127 + jb .noof + mov al,127 +.noof + mov [MusicVol],al + mov al,[DSPMem+0Ch] + call WDSPReg0C + mov al,[DSPMem+1Ch] + call WDSPReg1C + + mov eax,[GUIwinposx+6*4] + add eax,15 + mov [GUIHoldXlimL],eax + add eax,100 + mov [GUIHoldXlimR],eax +.nomovebar + ret + +sampratenext db 1,4,5,6,2,3,0,0,0,0 + +%macro GUIBoxVar 6 + cmp eax,%1 + jl %%nope + cmp edx,%2 + jl %%nope + cmp eax,%3 + jg %%nope + cmp edx,%4 + jg %%nope + mov dword[%5],%6 +%%nope +%endmacro + +DisplayGUICheatClick2: + GUISlidebarPostImpl 231,28,238,100,.scrollup,.scrolldown,7,12,GUIcurrentcheatviewloc,GUIcurrentcheatcursloc,NumCheats,GUIBlankVar,1 + GUIPostWinBoxMove 5,22,229,22+12*7,GUIcurrentcheatviewloc,GUIcurrentcheatcursloc,NumCheats,.scrollup,.scrolldown,DisplayGUICheatClick.skipscrol,12 +DisplayGUICheatClick: + GUIBoxVar 5,20,181,110,GUIcurrentcheatwin,0 + GUIBoxVar 82,129,173,136,GUIcurrentcheatwin,1 + GUIBoxVar 82,140,196,147,GUIcurrentcheatwin,2 + ; SlideBar Implementation + GUISlidebarImpl 231,28,238,100,GUICStA,12,GUIcurrentcheatviewloc,GUIcurrentcheatcursloc,NumCheats,7 +.skipscrol + cmp byte[GUIcurrentcheatwin],0 + jne near .nowin + GUIWinControl 5,23,229,21+12*7,GUIBlankVar,GUIcurrentcheatviewloc,NumCheats,22,7,GUIcurrentcheatcursloc,3,7,30 +.nowin + GUIPHoldbutton 5,113,47,124,5 + GUIPHoldbutton 52,113,94,124,6 + GUIPHoldbutton 99,113,141,124,7 + GUIPHoldbutton 146,113,188,124,8 + GUIPHoldbutton 212,134,236,145,9 + GUIPHoldbutton 193,113,235,124,33 + + GUIClickCButton5 11,186,byte[AutoLoadCht],1 + ret + +DisplayNetOptnsClick: + cmp byte[CNetType],1 + jne near .nomodem + GUIPHoldbutton 5,15,89,26,21 + GUIPHoldbutton 5,30,89,41,22 + GUIPHoldbutton 5,45,89,56,23 + GUIPHoldbutton 5,60,89,71,24 +.nomodem + cmp byte[CNetType],2 + jne near .nomodemc + GUIPButtonHole2 9,25,byte[ComNum],1,byte[ComIRQ],4 + GUIPButtonHole2 9,35,byte[ComNum],2,byte[ComIRQ],3 + GUIPButtonHole2 9,45,byte[ComNum],3,byte[ComIRQ],4 + GUIPButtonHole2 9,55,byte[ComNum],4,byte[ComIRQ],3 + GUIPButtonHole 94,25,byte[BaudRate],0 + GUIPButtonHole 94,35,byte[BaudRate],1 + GUIPButtonHole 94,45,byte[BaudRate],2 + GUIPButtonHole 94,55,byte[BaudRate],3 + GUIPButtonHole 94,65,byte[BaudRate],4 + GUIPButtonHole 94,75,byte[BaudRate],5 + GUIPButtonHole 94,85,byte[BaudRate],6 + GUIPButtonHole 9,85,byte[GUIDialSt+3],'T' + GUIPButtonHole 9,95,byte[GUIDialSt+3],'P' + GUIPHoldbutton2 55,69,63,79,25,byte[ComIRQ],1,15 + GUIPHoldbutton2 66,69,74,79,26,byte[ComIRQ],-1,2 + GUITextBoxInput 21,125,175,133,GUIInitSt1,24 + GUITextBoxInput 21,136,175,144,GUIInitSt2,24 + GUIClickCButton 12,147,byte[FossilUse] +.nomodemc + cmp byte[CNetType],3 + jne near .nomodemd + GUIPHoldbutton 141,38,175,49,28 +.nomodemd + cmp byte[CNetType],4 + jne near .notcpip + cmp byte[NetPlayNoMore],1 + je near .notcpip + GUIPHoldbutton 5,35,129,46,25 + GUIPHoldbutton 5,70,129,81,26 + GUITextBoxInputB 55,13,95,21,1 + GUITextBoxInputB 26,58,191,66,0 + GUITextBoxInputB 55,23,119,31,2 + + GUIClickCButton 5,93,byte[UDPConfig] +.notcpip + cmp byte[CNetType],10 + je .init + cmp byte[CNetType],11 + je .init + cmp byte[CNetType],15 + je .init + cmp byte[CNetType],12 + jne near .noinit +.init + GUIPHoldbutton 120,135,181,146,27 +.noinit + cmp byte[CNetType],7 + jne near .noipx + GUIPHoldbutton 53,48,87,59,34 +.noipx + cmp byte[CNetType],20 + jne near .nochat + GUIPHoldbutton 111,169,181,180,27 + GUIClickCButtonN 7,135,byte[RemoteCommand],3 + GUIClickCButtonN 32,135,byte[RemoteCommand],4 + GUIClickCButtonN 57,135,byte[RemoteCommand],5 + GUIClickCButtonN 7,145,byte[RemoteCommand],6 + GUIClickCButtonN 32,145,byte[RemoteCommand],7 + GUIClickCButtonN 7,175,byte[RemoteCommand],8 + + GUIClickCButtonN 111,135,byte[RemoteCommand],50 + GUIClickCButtonN 111,145,byte[RemoteCommand],41 + GUIClickCButtonN 111,155,byte[RemoteCommand],42 + GUIPHoldbutton2 79,156,87,166,29,byte[Latencytochange],1,19 + GUIPHoldbutton2 90,156,98,166,30,byte[Latencytochange],-1,1 +; DrawSlideBarWin 8,181,15,[GUIcurrentvideoviewloc],[TViewLoc],12,97,GUINCStA +; GUISlidebarImpl 181,15,188,112,GUINCStA,12,GUIcurrentcheatviewloc,TViewCLoc,TViewLoc,12 + + mov al,[Latency] + cmp byte[Latencytochange],al + je .nochat + mov byte[RemoteCommand],20 +.nochat + + cmp byte[CNetType],22 + je .yesstate + cmp byte[CNetType],21 + jne near .nostate +.yesstate + GUIPHoldbutton 73,48,127,59,64 +.nostate + ret + +guipresstest: + xor ebx,ebx + mov ecx,256+128+64 +.a + mov byte[pressed+ebx],0 + inc ebx + loop .a + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 75,95,180,131,160 + GUIBox 75,95,180,95,162 + GUIBox 75,95,75,131,161 + GUIBox 180,95,180,131,159 + GUIBox 75,131,180,131,158 + GUIOuttext 81,101,guipresstext1,220-15 + GUIOuttext 80,100,guipresstext1,220 + GUIOuttext 81,111,guipresstext2,220-15 + GUIOuttext 80,110,guipresstext2,220 + GUIOuttext 81,121,guipresstext3,220-15 + GUIOuttext 80,120,guipresstext3,220 + call vidpastecopyscr +.again + call JoyRead +; mov dword[pressed+0CCh],0 +; mov dword[pressed+0CCh+80h],0 +; mov dword[pressed+0E8h],0 +; mov dword[pressed+0E8h+80h],0 + xor ebx,ebx + mov ecx,256+128+64 +.b + cmp byte[pressed+ebx],0 + jne .pressedokay + inc ebx + loop .b + jmp .again +.pressedokay + push ebx + xor ebx,ebx + mov ecx,256+128+64 +.a2 + cmp byte[pressed+ebx],0 + je .pressedokayb + mov byte[pressed+ebx],2 +.pressedokayb + inc ebx + loop .a2 + pop ebx +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey +; push ebx +; mov eax,0Bh +; int 33h +; pop ebx + ret + +guipresstext1 db 'ENTER THE KEY',0 +guipresstext2 db 'OR BUTTON TO USE',0 +guipresstext3 db '(ESC TO CLEAR)',0 + +guipresstestb: + call GUIUnBuffer + call DisplayBoxes + call DisplayMenu + GUIBox 65,80,194,126,160 + GUIBox 65,80,194,80,162 + GUIBox 65,80,65,126,161 + GUIBox 194,80,194,126,159 + GUIBox 65,126,194,126,158 + GUIOuttext 71,86,guipresstext1,220-15 + GUIOuttext 70,85,guipresstext1,220 + GUIOuttext 71,96,guipresstext2,220-15 + GUIOuttext 70,95,guipresstext2,220 + GUIOuttext 71,116,guipresstext3b,220-15 + GUIOuttext 70,115,guipresstext3b,220 + mov eax,[guipressptr] + GUIOuttext 71,106,eax,220-15 + mov eax,[guipressptr] + GUIOuttext 70,105,eax,220 + call vidpastecopyscr + mov ecx,8192 + call delay +.tryagain + call JoyRead + xor ebx,ebx + mov ecx,256+128+64 +.b2 + cmp byte[pressed+ebx],0 + jne .tryagain + inc ebx + loop .b2 + +.again + call JoyRead +; mov dword[pressed+0CCh],0 +; mov dword[pressed+0CCh+80h],0 +; mov dword[pressed+0E8h],0 +; mov dword[pressed+0E8h+80h],0 + + xor ebx,ebx + mov ecx,256+128+64 +.b + cmp byte[pressed+ebx],0 + jne .pressedokay + inc ebx + loop .b + jmp .again +.pressedokay +.again2 + call Check_Key + or al,al + jz .nokey + call Get_Key + jmp .again2 +.nokey + cmp ebx,1 + je .skip + cmp ebx,3Bh + je .skip + mov eax,[guicpressptr] + mov [eax],ebx +.skip +; push ebx +; mov eax,0Bh +; int 33h +; pop ebx + ret + +guipresstext3b db '(ESC TO SKIP)',0 +guipresstext4b db 'FOR UP ',0 +db 'FOR DOWN ',0 +db 'FOR LEFT ',0 +db 'FOR RIGHT ',0 +db 'FOR START ',0 +db 'FOR SELECT ',0 +db 'FOR A (RIGHT BUTTON)',0 +db 'FOR B (DOWN BUTTON) ',0 +db 'FOR X (TOP BUTTON) ',0 +db 'FOR Y (LEFT BUTTON) ',0 +db 'FOR THE L BUTTON ',0 +db 'FOR THE R BUTTON ',0 +guipressptr dd 0 +guicpressptr dd 0 + +DisplayGameOptnsClick: + ; Process boxes + mov dword[keycontrolval],0 + DGOptnsProcBox 27,24,[KeyBGDisble0] + DGOptnsProcBox 27+45,24,[KeyBGDisble1] + DGOptnsProcBox 27+45*2,24,[KeyBGDisble2] + DGOptnsProcBox 27+45*3,24,[KeyBGDisble3] + DGOptnsProcBox 27,32,[KeySprDisble] + DGOptnsProcBox 78,52,[KeyResetAll] + DGOptnsProcBox 78,60,[KeyExtraEnab] + DGOptnsProcBox 78,68,[KeyNewGfxSwt] + DGOptnsProcBox 78,76,[KeyWinDisble] + DGOptnsProcBox 78,84,[KeyOffsetMSw] + DGOptnsProcBox 78,92,[KeySlowDown] + DGOptnsProcBox 178,60,[KeyVolUp] + DGOptnsProcBox 178,68,[KeyVolDown] + DGOptnsProcBox 178,76,[KeyFRateUp] + DGOptnsProcBox 178,84,[KeyFRateDown] + cmp byte[OSPort],3 + jne near .notwin32 + DGOptnsProcBox 178,44,[KeyRewind] +.notwin32 + DGOptnsProcBox 178,52,[KeyFastFrwrd] + DGOptnsProcBox 27,112,[KeyDisableSC0] + DGOptnsProcBox 27+45,112,[KeyDisableSC1] + DGOptnsProcBox 27+45*2,112,[KeyDisableSC2] + DGOptnsProcBox 27+45*3,112,[KeyDisableSC3] + DGOptnsProcBox 27,120,[KeyDisableSC4] + DGOptnsProcBox 27+45,120,[KeyDisableSC5] + DGOptnsProcBox 27+45*2,120,[KeyDisableSC6] + DGOptnsProcBox 27+45*3,120,[KeyDisableSC7] + DGOptnsProcBox 27+45*2,132,[KeyStateSlc0] + DGOptnsProcBox 27+45*3,132,[KeyStateSlc1] + DGOptnsProcBox 27,140,[KeyStateSlc2] + DGOptnsProcBox 27+45,140,[KeyStateSlc3] + DGOptnsProcBox 27+45*2,140,[KeyStateSlc4] + DGOptnsProcBox 27+45*3,140,[KeyStateSlc5] + DGOptnsProcBox 27,148,[KeyStateSlc6] + DGOptnsProcBox 27+45,148,[KeyStateSlc7] + DGOptnsProcBox 27+45*2,148,[KeyStateSlc8] + DGOptnsProcBox 27+45*3,148,[KeyStateSlc9] + DGOptnsProcBox 8+25,158,[KeySaveState] + DGOptnsProcBox 8+57+25,158,[KeyLoadState] + DGOptnsProcBox 8+114+25,158,[KeyStateSelct] + DGOptnsProcBox 8+25,178,[KeyQuickLoad] + DGOptnsProcBox 8+57+31,178,[KeyQuickRst] + DGOptnsProcBox 8+114+25,178,[KeyQuickExit] + DGOptnsProcBox 8+25,188,[KeyQuickChat] + DGOptnsProcBox 8+57+49,188,[KeyQuickSnapShot] + ret + +DisplayGUIOptnsClick: + mov eax,[GUImouseposx] + sub eax,[GUIwinposx+10*4] + mov edx,[GUImouseposy] + sub edx,[GUIwinposy+10*4] + GUIClickCButton 12,23,byte[mousewrap] + GUIClickCButton 12,33,byte[mouseshad] + GUIClickCButton 12,43,byte[lastcursres] + GUIClickCButton 12,53,byte[resetposn] + GUIClickCButton 12,63,byte[GUIClick] + GUIClickCButton 12,73,byte[JoyPad1Move] + GUIClickCButton6 12,83,byte[GUIEffect],1 + GUIClickCButton6 12,93,byte[GUIEffect],2 + cmp eax,25 + jl near .nomovebar + cmp eax,25+32*4-1 + jg near .nomovebar + sub eax,25 + shr eax,2 + cmp edx,122 + jl .nomovebar1 + cmp edx,126 + jg .nomovebar1 + cmp byte[GUIRAdd],al + je .nomovebar1b + mov byte[GUIRAdd],al + call GUISetPal +.nomovebar1b + mov byte[GUIHold],2 + mov eax,[GUIwinposy+10*4] + add eax,124 + mov [GUIHoldYlim],eax + jmp .nomovebar +.nomovebar1 + cmp edx,134 + jl .nomovebar2 + cmp edx,138 + jg .nomovebar2 + cmp byte[GUIGAdd],al + je .nomovebar2b + mov byte[GUIGAdd],al + call GUISetPal +.nomovebar2b + mov byte[GUIHold],2 + mov eax,[GUIwinposy+10*4] + add eax,136 + mov [GUIHoldYlim],eax + jmp .nomovebar +.nomovebar2 + cmp edx,146 + jl .nomovebar3 + cmp edx,150 + jg .nomovebar3 + cmp byte[GUIBAdd],al + je .nomovebar3b + mov byte[GUIBAdd],al + call GUISetPal +.nomovebar3b + mov byte[GUIHold],2 + mov eax,[GUIwinposy+10*4] + add eax,148 + mov [GUIHoldYlim],eax +.nomovebar3 +.nomovebar + cmp byte[GUIHold],2 + jne .nohold + mov eax,[GUIwinposx+10*4] + add eax,25 + mov [GUIHoldXlimL],eax + mov eax,[GUIwinposx+10*4] + add eax,25+32*4-1 + mov [GUIHoldXlimR],eax +.nohold + ret + +DisplayGUIAboutClick: + cmp byte[OSPort],3 + jne near .nowin32 + GUIPHoldbutton 5,87,74,98,65 +.nowin32 + ret + +%macro ComboBoxProc 5 + cmp eax,%1 + jl %%nope + cmp edx,%2 + jl %%nope + cmp eax,%3 + jg %%nope + cmp edx,%4 + jg %%nope + cmp byte[GUINumCombo],42 + je %%nope + xor ebx,ebx + mov bl,[GUINumCombo] + mov byte[GUIComboData+ebx],%5 + inc byte[GUINumCombo] +%%nope +%endmacro + +%macro ComboBoxProcD 4 + cmp eax,%1 + jl %%nope + cmp edx,%2 + jl %%nope + cmp eax,%3 + jg %%nope + cmp edx,%4 + jg %%nope + cmp byte[GUINumCombo],0 + je %%nope + dec byte[GUINumCombo] +%%nope +%endmacro + +; DrawSlideBar 16,192,20,[GUIccombviewloc],[NumCombo],8,61,GUICSStC,13,14 +; DrawBorderedBox 16,10,20,190,80,19 + +; DrawGUIWinBox 3,5,34,107,77,167 +; DrawSlideBarWin 3,109,42,[GUIcurrentinputviewloc],16,5,28,GUIIStA + +DisplayGUIComboClick2: + mov dword[keycontrolval],0 + ; x1,y1,x2,y2,upjump,downjump,holdpos,scsize,view,cur,listsize + GUISlidebarPostImpl 192,28,199,72,.scrollup,.scrolldown,13,8,GUIccombviewloc,GUIccombcursloc,NumCombo,GUIBlankVar,1 + ;x1,y1,x2,y2,view,curs,num,.scru,.scrd,jumpto,sizeofscreen + GUIPostWinBoxMove 10,22,190,23+8*7,GUIccombviewloc,GUIccombcursloc,NumCombo,.scrollup,.scrolldown,DisplayGUIComboClick.skipscrol,8 +DisplayGUIComboClick: + ; SlideBar Implementation + ; x1,y1,x2,y2,GUI?StA,ScrnSize,ViewLoc,CursLoc,Entries,win# + GUISlidebarImpl 192,28,199,72,GUICSStC,8,GUIccombviewloc,GUIccombviewloc,NumCombo,16 +.skipscrol + ;x,y,x2,y2,currentwin,vpos,#entries,starty,y/entry,cpos,winval,win#,dclicktick# + GUIWinControl2 10,23,190,22+8*7,GUIBlankVar,GUIccombviewloc,NumCombo,23,7,GUIccombcursloc,6,16,0 + + GUIPButtonHole 178,82,byte[GUIComboPNum],0 + GUIPButtonHole 196,82,byte[GUIComboPNum],1 + GUIPButtonHole 214,82,byte[GUIComboPNum],2 + GUIPButtonHole 232,82,byte[GUIComboPNum],3 + GUIClickCButton 163,88,byte[GUIComboLHorz] + GUIClickCButtonC 163,96,byte[GUIComboGameSpec] + GUIPHoldbutton 202,20,246,31,60 + GUIPHoldbutton 202,35,246,46,61 + GUIPHoldbutton 202,50,246,61,62 + GUIPHoldbutton 202,65,246,76,63 + DGOptnsProcBoxc 135,91,157,99,[GUIComboKey] + + ComboBoxProc 75,150,85,157,1 + ComboBoxProc 89,150,99,157,2 + ComboBoxProc 103,150,113,157,3 + ComboBoxProc 117,150,127,157,4 + ComboBoxProc 131,150,141,157,5 + ComboBoxProc 145,150,155,157,6 + ComboBoxProc 159,150,169,157,7 + ComboBoxProc 173,150,183,157,8 + ComboBoxProc 187,150,197,157,9 + ComboBoxProc 201,150,211,157,10 + ComboBoxProc 215,150,227,157,11 + ComboBoxProc 231,150,243,157,12 + ComboBoxProc 75,160,85,167,13 + ComboBoxProc 89,160,99,167,14 + ComboBoxProc 103,160,113,167,15 + ComboBoxProc 117,160,127,167,16 + ComboBoxProc 131,160,141,167,17 + ComboBoxProc 145,160,155,167,18 + ComboBoxProc 159,160,169,167,19 + ComboBoxProc 173,160,183,167,20 + ComboBoxProc 187,160,197,167,21 + ComboBoxProc 201,160,211,167,22 + ComboBoxProc 215,160,227,167,23 + ComboBoxProc 231,160,243,167,24 + ComboBoxProc 75,170,85,177,25 + ComboBoxProc 89,170,99,177,26 + ComboBoxProc 103,170,113,177,27 + ComboBoxProc 117,170,127,177,28 + ComboBoxProc 131,170,141,177,29 + ComboBoxProc 145,170,155,177,30 + ComboBoxProc 159,170,169,177,31 + ComboBoxProc 173,170,183,177,32 + ComboBoxProc 187,170,197,177,33 + ComboBoxProc 201,170,211,177,34 + ComboBoxProc 215,170,227,177,35 + ComboBoxProc 231,170,243,177,36 + + ComboBoxProc 10,189,20,196,37 + ComboBoxProc 24,189,34,196,38 + ComboBoxProc 38,189,48,196,39 + ComboBoxProc 52,189,62,196,40 + ComboBoxProc 66,189,76,196,41 + ComboBoxProc 80,189,90,196,42 + ComboBoxProc 107,189,117,196,43 + ComboBoxProc 121,189,131,196,44 + ComboBoxProc 135,189,145,196,45 + ComboBoxProc 149,189,159,196,46 + ComboBoxProc 163,189,173,196,47 + ComboBoxProc 177,189,187,196,48 + ComboBoxProcD 204,189,218,196 + mov ebx,[NumComboLocl] + cmp byte[GUIComboGameSpec],0 + jne .local + mov ebx,[NumComboGlob] +.local + mov [NumCombo],ebx + xor ebx,ebx + ret + +DisplayGUIResetClick: + GUIPHoldbutton 20,30,56,41,2 + GUIPHoldbutton 80,30,116,41,3 + ret + +DisplayGUIStatesClick: + GUIPHoldbutton 20,30,56,41,10 + GUIPHoldbutton 80,30,116,41,11 + ret + +DisplayGUICheatSearchClick2: + cmp byte[CheatWinMode],2 + je near DisplayGUICheatSearchClick.preview +DisplayGUICheatSearchClick: + cmp byte[CheatWinMode],1 + je near .incheatmode + cmp byte[CheatWinMode],2 + je near .view + cmp byte[CheatWinMode],3 + je near .add + GUIPHoldbutton 95,140,140,152,50 + GUIPButtonHole 11,28,byte[CheatSrcByteSize],0 + GUIPButtonHole 11,38,byte[CheatSrcByteSize],1 + GUIPButtonHole 11,48,byte[CheatSrcByteSize],2 + GUIPButtonHole 11,58,byte[CheatSrcByteSize],3 + GUIPButtonHole 11,73,byte[CheatSrcByteBase],0 + GUIPButtonHole 11,83,byte[CheatSrcByteBase],1 + GUIPButtonHole 11,113,byte[CheatSrcSearchType],0 + GUIPButtonHole 11,123,byte[CheatSrcSearchType],1 + ret +.incheatmode + GUIPHoldbutton 30,140,80,152,51 + cmp byte[CheatSearchStatus],1 + jne near .cheatsearching + jmp .nosearch +.cheatsearching + cmp byte[CheatSrcSearchType],1 + je near .cheatsearchingcomp + jmp .searched +.cheatsearchingcomp + GUIPButtonHole 11,33,byte[CheatCompareValue],0 + GUIPButtonHole 11,43,byte[CheatCompareValue],1 + GUIPButtonHole 11,53,byte[CheatCompareValue],2 + GUIPButtonHole 11,63,byte[CheatCompareValue],3 + +.searched + GUIPHoldbutton 120,140,170,152,53 +.nosearch + GUIPHoldbutton 10,140,60,152,51 + GUIPHoldbutton 70,140,110,152,52 + ret + +.preview + ; x1,y1,x2,y2,upjump,downjump,holdpos,scsize,view,cur,listsize + GUISlidebarPostImpl 173,28,180,100,.scrollup,.scrolldown,11,12,GUIcurrentchtsrcviewloc,GUIcurrentchtsrccursloc,NumCheatSrc,GUIBlankVar,1 + ;x1,y1,x2,y2,view,curs,num,.scru,.scrd,jumpto,sizeofscreen + GUIPostWinBoxMove 5,22,171,22+12*7,GUIcurrentchtsrcviewloc,GUIcurrentchtsrccursloc,NumCheatSrc,.scrollup,.scrolldown,DisplayGUICheatSearchClick.skipscrol,12 +.view + ; x1,y1,x2,y2,GUI?StA,ScrnSize,ViewLoc,CursLoc,Entries,win# + GUISlidebarImpl 173,28,180,100,GUICSStA,12,GUIcurrentchtsrcviewloc,GUIcurrentchtsrccursloc,NumCheatSrc,13 +.skipscrol + ; x,y,x2,y2,currentwin,vpos,#entries,starty,y/entry,cpos,winval,win#,dclicktick# + GUIWinControl 5,23,171,21+12*7,GUIBlankVar,GUIcurrentchtsrcviewloc,NumCheatSrc,22,7,GUIcurrentchtsrccursloc,5,13,30 + GUIPHoldbutton 70,140,130,152,54 + GUIPHoldbutton 140,140,180,152,55 + ret +; DrawSlideBarWin 13,173,28,[GUIcurrentchtsrcviewloc],[NumCheatSrc],12,73,GUICSStA +; DrawGUIWinBox 13,5,20,171,108,167 +.add + GUIPHoldbutton 60,155,120,167,56 + GUIPHoldbutton 130,155,160,167,57 + GUIClickCButton 8,139,byte[CheatUpperByteOnly] + GUIBoxVar 10,30,80,37,CurCStextpos,0 + GUIBoxVar 10,55,126,62,CurCStextpos,1 + ret + +DisplayGUIAddOnClick: + GUIPButtonHole 9,15,byte[snesmouse],0 + GUIPButtonHole 9,25,byte[snesmouse],1 + GUIPButtonHole 9,35,byte[snesmouse],2 + GUIPButtonHole 9,45,byte[snesmouse],3 + GUIPButtonHole 9,55,byte[snesmouse],4 + ret + +DrawMouse: + mov edi,[vidbuffer] + add edi,16 + add edi,[GUImouseposx] + mov eax,[GUImouseposy] + shl eax,8 + mov ebx,[GUImouseposy] + shl ebx,5 + add eax,ebx + add edi,eax + mov esi,GUIMousePtr + mov edx,8 +.next2 + mov ecx,8 +.next + mov al,[esi] + or al,al + jz near .nodraw + test byte[mouseshad],1 + jz near .finishadow + + mov bl,[edi+288*10+8] + cmp bl,32 + jae .noprimshad + add byte[edi+288*10+8],96 + jmp .finishadow +.noprimshad + + mov bl,[edi+288*4+3] + cmp bl,32 + jb .nogray + cmp bl,63 + ja .nogray + sub bl,32 + shr bl,1 + add bl,32 + mov [edi+288*4+3],bl + jmp .finishadow +.nogray + and bl,11110000b + cmp bl,64 + jne .nomidshad2 + add byte[edi+288*4+3],16 + jmp .finishadow +.nomidshad2 + + mov bl,[edi+288*7+5] + cmp bl,148 + jb .nomidshad + cmp bl,167 + ja .mid2 + add byte[edi+288*7+5],20 + jmp .finishadow +.mid2 + cmp bl,189 + jb .nomidshad + cmp bl,220 + ja .nomidshad + sub bl,189 +; test bl,01h +; jnz .nomidshad + shr bl,1 + add bl,189 + mov byte[edi+288*7+5],bl + jmp .finishadow +.nomidshad + +.finishadow + mov [edi],al +.nodraw + inc esi + inc edi + dec ecx + jnz near .next + add edi,288-8 + dec edx + jnz near .next2 + ret + + \ No newline at end of file diff --git a/zsnes/src/gui/guinetpl.inc b/zsnes/src/gui/guinetpl.inc new file mode 100644 index 00000000..901c6e8f --- /dev/null +++ b/zsnes/src/gui/guinetpl.inc @@ -0,0 +1,1780 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +; GUI NetPlay Routines (Modem,IPX,UDP+TCP/IP) + +ProcessModem: + cmp byte[ModemProcess],40 + jne near .noprocess40 + cmp byte[maxskip],3 + jae .okaymf + mov byte[maxskip],3 +.okaymf + mov byte[frameskip],0 + mov byte[Latencytochange],3 + mov byte[Latency],3 + mov byte[IPXSearchval],0 + mov byte[RemoteDisconnect],0 + mov byte[HoldCommand],1 + mov byte[RemoteCommand],1 + ; Clear Screen Buffer + mov eax,ViewBuffer + mov ecx,50*32 +.clooptcpip + mov byte[eax],0 + inc eax + loop .clooptcpip + mov dword[CCursLoc],0 + mov dword[CViewLoc],0 + mov dword[NViewLoc],0 + mov esi,.tcpipinit + call .writestr + mov esi,.tcpipport + call .writestr + mov esi,GUINetTextl2 + call .writestr + mov esi,.tcpipret + call .writestr + mov esi,.tcpipportt + cmp byte[UDPConfig],0 + je .notudp + mov esi,.tcpipportu +.notudp + call .writestr + mov esi,.tcpipret + call .writestr + mov esi,.tcpipserv + call .writestr + mov byte[ModemProcess],42 + ret +.tcpipdones db 'DONE',13,10,13,10,'WAITING FOR CLIENT...',0 +.tcpipdonec db 'DONE',13,10,13,10,'CONNECTING TO SERVER...',0 +.tcpipdones2 db 13,10,13,10,'FOUND CLIENT.',0 +.tcpipdonec2 db 13,10,13,10,'CONNECTION SUCCESSFUL.',0 +.tcpiperror db 'FAILED',13,10,13,10,'ERROR: ',0 +.tcpipip db 'IP : ',0 +.tcpipip2 db 'SIP : ',0 +.tcpipport db 'PORT : ',0 +.tcpipportu db 'PROTOCOL: UDP',13,10,0 +.tcpipportt db 'PROTOCOL: TCP/IP',13,10,0 +.tcpipret db 13,10,0 +.errorinit db 'FAILED NET INIT',0 +.errorinit2 db 'CANNOT START SERVER',0 +.errorinit3 db 'CANNOT CONNECT',0 +.noprocess40 + cmp byte[ModemProcess],41 + jne near .noprocess41 + cmp byte[maxskip],3 + jae .okaymf2 + mov byte[maxskip],3 +.okaymf2 + mov byte[frameskip],0 + mov byte[Latencytochange],3 + mov byte[Latency],3 + mov byte[IPXSearchval],0 + mov byte[RemoteDisconnect],0 + mov byte[HoldCommand],1 + mov byte[RemoteCommand],1 + ; Clear Screen Buffer + mov eax,ViewBuffer + mov ecx,50*32 +.clooptcpip2 + mov byte[eax],0 + inc eax + loop .clooptcpip2 + mov dword[CCursLoc],0 + mov dword[CViewLoc],0 + mov dword[NViewLoc],0 + mov esi,.tcpipinit + call .writestr + mov esi,.tcpipport + call .writestr + mov esi,GUINetTextl2 + call .writestr + mov esi,.tcpipret + call .writestr + mov esi,.tcpipportt + cmp byte[UDPConfig],0 + je .notudp2 + mov esi,.tcpipportu +.notudp2 + call .writestr + mov esi,.tcpipip2 + call .writestr + mov esi,GUINetTextk2 + call .writestr + mov esi,.tcpipret + call .writestr + mov esi,.tcpipret + call .writestr + mov esi,.tcpipclie + call .writestr + mov byte[ModemProcess],43 + ret +.noprocess41 + cmp byte[ModemProcess],42 + jne near .noprocess42 + call TCPIPStartServer + or eax,eax + jnz .tcpfailed + mov esi,.tcpipdones + call .writestr + mov byte[ModemProcess],44 + ret +.tcpfailed + mov esi,.tcpiperror + call .writestr + mov esi,.errorinit + call .writestr + mov byte[ModemProcess],255 + ret +.noprocess42 + cmp byte[ModemProcess],43 + jne near .noprocess43 + call TCPIPInitConnectToServer + or eax,eax + jnz .tcpfailed2 + mov esi,.tcpipdonec + call .writestr + mov byte[ModemProcess],45 + ret +.tcpfailed2 + mov esi,.tcpiperror + call .writestr + mov esi,.errorinit + call .writestr + mov byte[ModemProcess],255 + ret +.noprocess43 + cmp byte[ModemProcess],44 + jne near .noprocess44 + call TCPIPWaitForConnection + cmp eax,1 + je .successb + or eax,eax + jnz .tcpfailed3 + ret +.successb + mov esi,.tcpipdones2 + call .writestr + mov byte[ModemProcess],46 + ret +.tcpfailed3 +; add al,'Z' +; mov byte[.tcpiperror],al + mov esi,.tcpiperror + call .writestr + mov esi,.errorinit2 + call .writestr + mov byte[ModemProcess],255 + ret +.noprocess44 + cmp byte[ModemProcess],45 + jne near .noprocess45 + call TCPIPConnectToServer + or eax,eax + jnz .tcpfailed4 + mov byte[ModemProcess],47 + ret +.tcpfailed4 +; add al,'Z' +; mov [.errorinit3],al + mov esi,.tcpiperror + call .writestr + mov esi,.errorinit3 + call .writestr + mov byte[ModemProcess],255 + ret +.noprocess45 + cmp byte[ModemProcess],46 + jne near .noprocess46 + mov byte[pl2neten],2 + mov byte[pl1neten],1 + mov byte[UseRemoteSRAMData],1 + mov byte[ModemProcess],66 + ret +.noprocess46 + cmp byte[ModemProcess],47 + jne near .noprocess47 + call TCPIPConnectToServerW + or eax,eax + jnz .connected + ret +.connected + mov esi,.tcpipdonec2 + call .writestr + mov byte[pl2neten],1 + mov byte[pl1neten],2 + mov byte[UseRemoteSRAMData],2 + mov byte[ModemProcess],66 + ret +.noprocess47 + cmp byte[ModemProcess],30 + jne near .noprocess30 + mov byte[Latencytochange],2 + mov byte[Latency],2 + mov byte[IPXSearchval],0 + ; Clear Screen Buffer + mov eax,ViewBuffer + mov ecx,50*32 +.cloopipx + mov byte[eax],0 + inc eax + loop .cloopipx + mov dword[CCursLoc],0 + mov dword[CViewLoc],0 + mov dword[NViewLoc],0 + mov esi,.initc + call .writestr + mov esi,.localid + call .writestr + push es + mov es,[selc0040] + mov ax,[es:108] + mov [IPXInfoStr],ax + pop es + call .writehex + ; ipx + cmp byte[OSPort],1 + je .noinitipx + call initipx +.noinitipx + cmp ax,0 + je .success + mov byte[ModemProcess],255 + mov esi,.noipx + call .writestr + ret +.success + mov byte[ModemProcess],31 + mov dword[ModemPTimer],36 + mov esi,.yesipx + call .writestr + ret +.noprocess30 + cmp byte[ModemProcess],31 + jne .noprocess31 + ; Wait for remote + cmp dword[ModemPTimer],0 + jne .nolookforconnect + mov dword[ModemPTimer],36 + cmp byte[OSPort],1 + je .noipxlook + call ipxlookforconnect +.noipxlook + cmp byte[IPXSearchval],0 + je .nolookforconnect + mov esi,.connectest + call .writestr + mov esi,.remoteid + call .writestr + mov ax,[IPXInfoStrR] + call .writehex + mov byte[ModemProcess],64 + mov byte[Connected],1 + mov byte[WhichRemote],2 +.nolookforconnect + ret +.noprocess31 + cmp byte[ModemProcess],0 + jne near .noprocess0 + mov byte[Latencytochange],2 + mov byte[Latency],2 + cmp byte[ModemInitStat],1 + je .nomodeminit + call InitModem + mov byte[ModemInitStat],1 +.nomodeminit + mov byte[Connected],0 + ; Clear Screen Buffer + mov eax,ViewBuffer + mov ecx,50*32 +.cloop + mov byte[eax],0 + inc eax + loop .cloop + mov dword[CCursLoc],0 + mov dword[CViewLoc],0 + mov dword[NViewLoc],0 + mov esi,.init + call .writestr + mov esi,.uart0 + cmp byte[UartType],0 + je .nouart0 + mov esi,.uart1 + cmp byte[UartType],1 + je .nouart0 + mov esi,.uart2 +.nouart0 + call .writestr + mov esi,.initb + call .writestr + mov byte[ModemProcess],8 + mov dword[ModemPTimer],36 + mov byte[InitStr1Done],0 + mov byte[ModemOKStat],0 + cmp byte[cantinitmodem],0 + je .okayinit + mov esi,.unableinit + call .writestr + mov byte[ModemProcess],255 +.okayinit + ret +.noprocess0 + cmp byte[ModemProcess],8 + jne .noprocess8 + cmp dword[ModemPTimer],0 + jne .skipnext8 + mov dword[ModemPTimer],18 + mov byte[ModemProcess],1 + cmp byte[CNetType],12 + jne .nomanual + mov byte[ModemProcess],7 + mov dword[ModemPTimer],0 +.nomanual + mov al,13 + call ModemSendChar + mov al,13 + call ModemSendChar +.skipnext8 + ret +.noprocess8 + cmp byte[ModemProcess],1 + jne .noprocess1 + cmp dword[ModemPTimer],0 + jne .skipnext + mov byte[ModemProcess],2 + call ModemClearBuffer +.skipnext + ret +.noprocess1 + cmp byte[ModemProcess],2 + jne .noprocess2 + mov byte[ModemProcess],3 + mov dword[ModemPTimer],36*5 + mov esi,GUIInitSt1 + cmp byte[InitStr1Done],0 + je .notinit2 + mov esi,GUIInitSt2 +.notinit2 + call ModemSendStr + mov al,13 + call ModemSendChar + ret +.noprocess2 + cmp byte[ModemProcess],3 + jne .noprocess3 + cmp byte[ModemOKStat],0 + je .norecv + mov byte[ModemProcess],9 +.norecv + cmp dword[ModemPTimer],0 + jne .notimeout + mov esi,.tout + call .writestr + mov byte[ModemProcess],255 +.notimeout + ret +.noprocess3 + cmp byte[ModemProcess],9 + jne .noprocess9 + cmp dword[ModemPTimer],0 + je .timeout + cmp byte[ModemOKStat],4 + jne .notcomplete +.timeout + mov byte[ModemProcess],4 +.notcomplete + ret +.noprocess9 + cmp byte[ModemProcess],4 + jne .noprocess4 + inc byte[InitStr1Done] + cmp byte[InitStr1Done],2 + je .noinit2 + cmp byte[GUIInitSt2],0 + je .noinit2 + mov byte[ModemProcess],1 + mov dword[ModemPTimer],18 + mov byte[ModemOKStat],0 + ret +.noinit2 + mov byte[ModemProcess],5 + mov dword[ModemPTimer],18 + ret +.noprocess4 + cmp byte[ModemProcess],5 + jne .noprocess5 + cmp dword[ModemPTimer],0 + jne .finishtimer + + ; ***** - Comment the following 4 lines +; mov byte[ModemProcess],64 +; mov byte[Connected],1 +; mov byte[WhichRemote],1 +; ret + + ; dial, wait for ring, etc. + cmp byte[CNetType],11 ; dial + jne .nodial + mov esi,GUIDialSt + call ModemSendStr + mov esi,DialNumber + call ModemSendStr + mov al,13 + call ModemSendChar + mov byte[ModemProcess],7 + ret +.nodial + cmp byte[CNetType],10 ; wait for ring + jne .noanswer + mov esi,.rdet + call .writestr + mov byte[ModemProcess],6 + ret +.noanswer + mov byte[ModemProcess],7 + ret +.finishtimer +.noprocess5 + cmp byte[ModemProcess],6 + jne .noprocess6 + call ModemCheckRing + cmp al,1 + jne .noprocess6 + mov esi,.ata + call ModemSendStr + mov byte[ModemProcess],7 +.noprocess6 + cmp byte[ModemProcess],7 + jne .noprocess7 + call ModemCheckDCD + cmp al,1 + jne .nocdc7 + mov esi,.cdet + call .writestr + mov byte[ModemProcess],64 + mov byte[WhichRemote],1 +.nocdc7 + ret +.noprocess7 + + ; Connect initialization + cmp byte[ModemProcess],64 + jne .noprocess64 + mov dword[ModemPTimer],72 ;36 + mov byte[ModemProcess],65 + mov byte[Connected],1 + ret +.noprocess64 + cmp byte[ModemProcess],65 + jne .noprocess65 + cmp dword[ModemPTimer],0 + je .okay65 + ret +.okay65 + mov byte[ModemProcess],66 + ret +.noprocess65 + cmp byte[ModemProcess],69 + jne .noprocess69 + cmp dword[ModemPTimer],0 + jne .notimer69 + mov dword[ModemPTimer],90 ; 2.5s + call PreparePacket + mov al,228 + call RemoteSendChar + call SendPacket +.notimer69 + call RemoteGetChar + cmp dh,0 + je .doneprocess69 + cmp dl,228 + jne .doneprocess69 + mov byte[ModemProcess],66 +.doneprocess69 + ret +.noprocess69 + cmp byte[ModemProcess],66 + jne .noprocess66 + ; Send ID and version # + call PreparePacket + mov al,'I' + call RemoteSendChar + mov al,'D' + call RemoteSendChar + mov al,222 + call RemoteSendChar + mov al,[welcome+7] + call RemoteSendChar + mov al,[welcome+9] + call RemoteSendChar + mov al,[welcome+10] + call RemoteSendChar + mov al,[welcome+11] + call RemoteSendChar + mov al,[soundon] + call RemoteSendChar + cmp al,byte[CNetType] + call RemoteSendChar + call SendPacket + mov byte[ModemProcess],67 + mov byte[IDCheckPos],0 + ret + ; Check if versions are the same +.noprocess66 + cmp byte[ModemProcess],67 + jne near .noprocess67 + call RemoteGetChar + cmp dh,0 + je near .doneprocess + cmp dl,'I' + jne .noI + mov byte[IDCheckPos],1 + ret +.noI + cmp byte[IDCheckPos],1 + jne .nocheck2 + cmp dl,'D' + jne .noD + mov byte[IDCheckPos],2 + ret +.noD + mov byte[IDCheckPos],0 + ret +.nocheck2 + cmp byte[IDCheckPos],2 + jne .nocheck3 + cmp dl,222 + jne .no222 + mov byte[IDCheckPos],3 + ret +.no222 + mov byte[IDCheckPos],0 + ret +.nocheck3 + cmp byte[IDCheckPos],3 + jne .nocheck4 + cmp dl,[welcome+7] + jne near .invversion + mov byte[IDCheckPos],4 + ret +.nocheck4 + cmp byte[IDCheckPos],4 + jne .nocheck5 + cmp dl,[welcome+9] + jne near .invversion + mov byte[IDCheckPos],5 + ret +.nocheck5 + cmp byte[IDCheckPos],5 + jne .nocheck6 + cmp dl,[welcome+10] + jne .invversion + mov byte[IDCheckPos],6 + ret +.nocheck6 + cmp byte[IDCheckPos],6 + jne .nocheck7 + cmp dl,[welcome+11] + jne .invversion + mov byte[IDCheckPos],9 + ret +.nocheck7 + cmp byte[IDCheckPos],9 + jne .nocheck10 + cmp dl,[soundon] + jne .invsound + mov byte[IDCheckPos],7 + ret +.nocheck10 + cmp byte[IDCheckPos],7 + jne .nocheck8 + mov [RemCNetType],dl + mov byte[IDCheckPos],0 + mov byte[ModemProcess],80 + cmp byte[WhichRemote],4 + jne .nocheck8 + mov byte[ModemProcess],81 +.nocheck8 + ret +.invversion + mov esi,.invver + call .writestr + mov byte[IDCheckPos],8 + ret +.invsound + mov esi,.invsnd + call .writestr + mov byte[IDCheckPos],8 + ret +.doneprocess + ret +.noprocess67 + cmp byte[ModemProcess],81 + je near .nonetpl + cmp byte[ModemProcess],80 + jne near .noprocess80 + mov dword[pl1neten],0 + mov byte[pl5neten],0 + mov byte[UseRemoteSRAMData],0 + cmp byte[CNetType],10 + jne .noans + mov byte[pl2neten],2 + mov byte[pl1neten],1 +.noans + cmp byte[RemCNetType],10 + jne .noans2 + mov byte[pl2neten],1 + mov byte[pl1neten],2 +.noans2 + cmp byte[CNetType],11 + jne .noans3 + mov byte[pl2neten],1 + mov byte[pl1neten],2 +.noans3 + cmp byte[RemCNetType],11 + jne .noans4 + mov byte[pl2neten],2 + mov byte[pl1neten],1 +.noans4 + cmp byte[CNetType],15 + jne near .nonetpl + mov bx,[IPXInfoStr] + mov ax,[IPXInfoStrR] +.nextpldet + push eax + push ebx + xor ax,bx + test ax,1 + jz .nochipx + test bx,1 + jz .pl2 + mov byte[pl2neten],2 + mov byte[pl1neten],1 + jmp .skipipxpl +.pl2 + mov byte[pl2neten],1 + mov byte[pl1neten],2 + jmp .skipipxpl +.nochipx + pop ebx + pop eax + shr eax,1 + shr ebx,1 + jmp .nextpldet +.skipipxpl + pop ebx + pop eax + mov byte[UseRemoteSRAMData],0 +.nonetpl + mov eax,ViewBuffer + mov ecx,50*32 +.cloop2 + mov byte[eax],0 + inc eax + loop .cloop2 + mov dword[CCursLoc],0 + mov dword[CViewLoc],0 + mov dword[NViewLoc],0 + mov byte[CNetType],20 + mov dword[ChatString],0 + mov byte[RemoteCommand],1 + mov byte[romloadskip],1 + call LoadDetermine + call PreparePacket + mov al,1 + call RemoteSendChar + call SendPacket +.noprocess80 + ret +.writestr + mov dh,1 +.loop + mov dl,[esi] + or dl,dl + jz .nomore + call NetAddChar + inc esi + jmp .loop +.nomore + ret +.writehex + mov dx,ax + shr dx,12 + and edx,0Fh + mov dl,[.hexval+edx] + push eax + call NetAddChar + pop eax + mov dx,ax + shr dx,8 + and edx,0Fh + mov dl,[.hexval+edx] + push eax + call NetAddChar + pop eax + mov dx,ax + shr dx,4 + and edx,0Fh + mov dl,[.hexval+edx] + push eax + call NetAddChar + pop eax + mov dx,ax + and edx,0Fh + mov dl,[.hexval+edx] + call NetAddChar + ret +.hexval db '0123456789ABCDEF' +.unableinit db 'CANNOT INIT DRIVER!',13,10,0 +.init db 'ZSNES MODEM TERMINAL',13,10,0 +.initb db 13,10,'INITIALIZING MODEM :',13,10,13,10,0 +.initc db 'ZSNES IPX TERMINAL',13,10,13,10,0 +.uart0 db 'USING 8250 UART',13,10,0 +.uart1 db 'USING 16550A UART',13,10,0 +.uart2 db 'USING FOSSIL DRIVER',13,10,0 +.tout db 'MODEM RESPONSE TIMEOUT',13,10,0 +.ata db 'ATA',13,0 +.cdet db 'CARRIER DETECTED',13,10,0 +.invver db 13,10,'INCOMPATIBLE VERSION!',13,10,0 +.rdet db 'WAITING FOR RING...',13,10,0 +.invsnd db 'INVALID SOUND SETTING!',13,10,0 +.noipx db 13,10,13,10,'UNABLE TO INIT IPX!',13,10,0 +.yesipx db 13,10,13,10,'IPX INITIALIZED.',13,10,13,10,'WAITING FOR REMOTE',13,10,0 +.localid db 'LOCAL ID : ',0 +.remoteid db 'REMOTE ID : ',0 +.connectest db 'CONNECTION ESTABLISHED',13,10,0 +.tcpipinit db 'ZSNES NET INTERFACE',13,10,13,10,0 +.tcpipserv db 'INIT SERVER ... ',0 +.tcpipclie db 'INIT CLIENT ... ',0 +InitStr1Done db 0 + +NEWSYM PreparePacket + call PreparePacketIPX + cmp byte[WhichRemote],4 + jne .nottcpip + call TCPIPPreparePacket +.nottcpip + ret + +NEWSYM SendPacket + call SendPacketIPX + cmp byte[WhichRemote],4 + jne .nottcpip + call TCPIPSendPacket +.nottcpip + ret + +NEWSYM SendPacketUDP + call SendPacketIPX + cmp byte[WhichRemote],4 + jne .nottcpip + call TCPIPSendPacketUDP +.nottcpip + ret + +NEWSYM WritetochatBuffer + ; 28 characters + mov dh,1 +.loop + mov dl,[esi] + or dl,dl + jz .nomore + call NetAddChar + inc esi + jmp .loop +.nomore + ret + +NEWSYM RemoteCommand, db 0 +HoldCommand db 0 + +RemoteDeInit: + cmp byte[ModemInitStat],0 + je .nodeinitmodem + call DeInitModemC + mov byte[ModemInitStat],0 +.nodeinitmodem + mov byte[CNetType],1 + cmp byte[WhichRemote],2 + jne .noipx + mov byte[CNetType],0 +.noipx + cmp byte[WhichRemote],4 + jne .notcpip + cmp byte[TCPIPStatus],0 + je .nottcpipinit + call TCPIPDisconnect + mov byte[TCPIPStatus],0 +.nottcpipinit + mov byte[CNetType],4 +.notcpip + ret + +Checkfileexist: + mov edx,FileNameMod + call Open_File + jc .failed + mov bx,ax + mov ecx,1 + mov edx,.temp + call Read_File + jc .failed2 + call Close_File + jc .failed + xor eax,eax + ret +.failed2 + call Close_File +.failed + mov eax,1 + ret +.temp db 0 + +ProcessRemoteCommand: + cmp byte[WhichRemote],1 + jne .notmodem + push edx + call ModemCheckDCD + pop edx + cmp al,1 + jne near .nomulti +.notmodem + cmp byte[RemoteDisconnect],1 + je near .nomulti + call ProcRewind + ; 1 = Idle, 2 = Chat String, 3..7 = Player Select + ; 10 = Load Game, 11 = Proceed Load, 12 = Load failed, 13 = File not Found + ; 20 = Send Controls + cmp dl,1 + je near .finish + cmp dl,2 + je near .chatstr + cmp dl,10 + je near .loadstr + cmp dl,11 + je near .startloading + cmp dl,12 + je near .loadfail ; *************************** + cmp dl,13 + je near .loadfnf + cmp dl,14 + je near .loadstate + cmp dl,15 + je near .skipstate + cmp dl,20 + je near .latencychange + cmp dl,30 + je near .quitgui + cmp dl,40 + je near .guireset + cmp dl,8 + ja near .nomulti + cmp [HoldCommand],dl + je near .forgetcommand + cmp dl,3 + jne .nopl1 + cmp byte[pl1neten],1 + je .nopl1 + xor byte[pl1neten],2 +.nopl1 + cmp dl,4 + jne .nopl2 + cmp byte[pl2neten],1 + je .nopl2 + xor byte[pl2neten],2 +.nopl2 + cmp dl,5 + jne .nopl3 + cmp byte[pl3neten],1 + je .nopl3 + xor byte[pl3neten],2 +.nopl3 + cmp dl,6 + jne .nopl4 + cmp byte[pl4neten],1 + je .nopl4 + xor byte[pl4neten],2 +.nopl4 + cmp dl,7 + jne .nopl5 + cmp byte[pl5neten],1 + je .nopl5 + xor byte[pl5neten],2 +.nopl5 + cmp dl,8 + jne .nobackstate + xor byte[BackState],1 + cmp byte[BackState],0 + jne .notbstate0 + mov byte[Latency],10 + mov byte[Latencytochange],10 +.notbstate0 + cmp byte[BackState],1 + jne .notbstate1 + mov byte[Latency],3 + mov byte[Latencytochange],3 +.notbstate1 +.nobackstate + jmp .finish +.forgetcommand + mov byte[HoldCommand],1 + jmp .finish +.nomulti + cmp dl,50 + jne .nosramnone + cmp byte[HoldCommand],41 + je .forgetcommand + cmp byte[HoldCommand],42 + je .forgetcommand + mov byte[UseRemoteSRAMData],0 + jmp .finish +.nosramnone + cmp dl,41 + jne .nosramlocal + cmp byte[HoldCommand],40 + je .forgetcommand + cmp byte[HoldCommand],41 + je .forgetcommand + mov byte[UseRemoteSRAMData],2 + jmp .finish +.nosramlocal + cmp dl,42 + jne .nosramremote + cmp byte[HoldCommand],40 + je .forgetcommand + cmp byte[HoldCommand],42 + je .forgetcommand + mov byte[UseRemoteSRAMData],1 + jmp .finish +.nosramremote + cmp byte[NetQuitAfter],0 + je .noguiquit + mov byte[GUIQuit],1 +.noguiquit + ; error + call RemoteDeInit + ret +.loadfail + cmp dword[GUINetTextk2],'127.' + jne .nonum + cmp dword[GUINetTextk2+4],'0.0.' + jne .nonum + cmp byte[GUINetTextk2+8],'1' + je near .startloadingb +.nonum + mov esi,.filenotu + call ProcessModem.writestr + jmp .finish +.startloadingb + mov byte[UseRemoteSRAMData],0 + jmp .startloading +.loadfnf + mov esi,.filenotfr + call ProcessModem.writestr + jmp .finish +.loadstate + mov byte[CNetType],22 + call loadstaterecvinit +.skipstate + jmp .finish +.latencychange + cmp [HoldCommand],dl + je near .invlatencych +.keepgoinglc + call RemoteGetChar + cmp dh,0 + je .keepgoinglc + mov [Latency],dl + mov [Latencytochange],dl + jmp .finish +.quitgui + mov byte[GUIQuit],2 + jmp .finsend +.guireset + call GUIDoReset + jmp .finsend +.invlatencych + mov al,[Latency] + mov [Latencytochange],al + jmp .finsend +.loadstr + push edx + mov esi,.loading + call ProcessModem.writestr + xor ebx,ebx +.keepgoing2 + push ebx + call RemoteGetChar + pop ebx + cmp dh,0 + je .keepgoing2 + mov [FileNameMod+ebx],dl + inc ebx + or dl,dl + je .doneload + jmp .keepgoing2 +.doneload + mov esi,FileNameMod + call ProcessModem.writestr + mov dl,13 + call NetAddChar + mov dl,10 + call NetAddChar + pop edx + cmp byte[HoldCommand],11 + je .loadfailed + cmp [HoldCommand],dl + jne .okayload + ; ***** - Add comment +; jmp .okayload ; ************ +.loadfailed + ; load failed + mov esi,.filenotu + call ProcessModem.writestr + mov byte[RemoteCommand],12 + jmp .finish +.loadfailednf + ; File Not Found + mov esi,.filenotf + call ProcessModem.writestr + mov byte[RemoteCommand],13 + jmp .finish +.okayload + call Checkfileexist + cmp eax,0 + jne .loadfailednf + mov byte[RemoteCommand],11 +.trynext + cmp byte[GUIwinptr],0 + je near .noclose + xor eax,eax + mov al,[GUIwinptr] + dec eax + xor ebx,ebx + mov bl,[GUIwinorder+eax] + ; close window + mov byte[GUIwinorder+eax],0 + mov byte[GUIwinactiv+ebx],0 + dec byte[GUIwinptr] + cmp byte[GUIwinptr],0 + jne .noclose + mov al,[GUIpmenupos] + mov [GUIcmenupos],al + jmp .trynext +.noclose + jmp .finish +.chatstr + ; Keep receiving and printing characters until 0 is found +; mov dl,'R' +; call NetAddChar +; mov dl,'>' +; call NetAddChar +.keepgoing + call RemoteGetChar + cmp dh,0 + je .keepgoing + or dl,dl + je .finishst + call NetAddChar + jmp .keepgoing +.finishst + mov dl,13 + call NetAddChar + mov dl,10 + call NetAddChar +.finish + mov al,[HoldCommand] + cmp al,2 + jne .noprintst + mov dl,'L' +; call NetAddChar + mov dl,'>' +; call NetAddChar + xor ebx,ebx +.next + mov dl,[ChatString+ebx] + cmp dl,0 + je .donenac + push ebx +; call NetAddChar + pop ebx + inc ebx + jmp .next +.donenac + mov dl,13 +; call NetAddChar + mov dl,10 +; call NetAddChar + mov dword[ChatString],0 + jmp .skipcommand +.noprintst + cmp al,20 + jne .nolatencyc + mov al,[Latencytochange] + mov [Latency],al + jmp .skipcommand +.nolatencyc + cmp al,3 + jne .nopl1b + cmp byte[pl1neten],2 + je .nopl1b + xor byte[pl1neten],1 +.nopl1b + cmp al,4 + jne .nopl2b + cmp byte[pl2neten],2 + je .nopl2b + xor byte[pl2neten],1 +.nopl2b + cmp al,5 + jne .nopl3b + cmp byte[pl3neten],2 + je .nopl3b + xor byte[pl3neten],1 +.nopl3b + cmp al,6 + jne .nopl4b + cmp byte[pl4neten],2 + je .nopl4b + xor byte[pl4neten],1 +.nopl4b + cmp al,7 + jne .nopl5b + cmp byte[pl5neten],2 + je .nopl5b + xor byte[pl5neten],1 +.nopl5b + cmp al,8 + jne .nobackstateb + xor byte[BackState],1 + cmp byte[BackState],0 + jne .notbstate0b + mov byte[Latency],10 + mov byte[Latencytochange],10 +.notbstate0b + cmp byte[BackState],1 + jne .notbstate1b + mov byte[Latency],3 + mov byte[Latencytochange],3 +.notbstate1b +.nobackstateb + cmp al,50 + jne .nosramnoneb + mov byte[UseRemoteSRAMData],0 +.nosramnoneb + cmp al,41 + jne .nosramlocalb + mov byte[UseRemoteSRAMData],1 +.nosramlocalb + cmp al,42 + jne .nosramremoteb + mov byte[UseRemoteSRAMData],2 +.nosramremoteb + cmp al,11 + jne .noload +.startloading + mov byte[HoldCommand],1 + mov byte[RemoteCommand],1 + mov eax,FileNameMod + call GUIloadfilename.nocnettype + mov byte[sramsavedis],1 + call transfersram + ret +.noload +.skipcommand + mov al,[RemoteCommand] + mov [HoldCommand],al + cmp al,2 + jne near .nosendstcheck + cmp byte[ChatString],0 + jne .nosendstcheck + mov byte[RemoteCommand],1 + mov byte[HoldCommand],1 + mov al,1 +.nosendstcheck + cmp al,1 + je near .finsend + call PreparePacket + call RemoteSendChar +.nosend + mov al,[RemoteCommand] + cmp al,2 + jne near .nosendst + + push eax + ; Capitalize ChatString + mov eax,ChatString +.nextletter + cmp byte[eax],0 + je .doneletter + cmp byte[eax],'a' + jb .noletter + cmp byte[eax],'z' + jb .noletter + sub byte[eax],'a'-'A' +.noletter + inc eax + jmp .nextletter +.doneletter + cmp dword[ChatString],'/ME ' + je .action + cmp dword[ChatString],'/NIC' + jne .notaction + cmp word[ChatString+4],'K ' + je near .nickchange +.notaction + mov eax,.chatinitial + mov ebx,ChatString + call ConcatString + mov eax,ChatNick + mov ebx,ChatString + call ConcatString + jmp .noaction +.action + mov eax,ChatString + mov ebx,4 + call ClipString + mov eax,.actinitial2 + mov ebx,ChatString + call ConcatString + mov eax,ChatNick + mov ebx,ChatString + call ConcatString + mov eax,.actinitial + mov ebx,ChatString + call ConcatString + jmp .noaction +.nickchange + mov eax,ChatString + mov ebx,6 + call ClipString + ; Valid String? + mov eax,ChatString + xor ebx,ebx +.loopnickcheck + cmp byte[eax],0 + je .donestcheck + cmp byte[eax],'-' + je .okaystring + cmp byte[eax],'_' + je .okaystring + cmp byte[eax],'^' + je .okaystring + cmp byte[eax],'=' + je .okaystring + cmp byte[eax],'+' + je .okaystring + cmp byte[eax],'[' + je .okaystring + cmp byte[eax],']' + je .okaystring + cmp byte[eax],'0' + jb .notokaystring + cmp byte[eax],'9' + jbe .okaystring + cmp byte[eax],'A' + jb .notokaystring + cmp byte[eax],'Z' + jbe .okaystring + jmp .notokaystring +.okaystring + inc eax + inc ebx + jmp .loopnickcheck +.donestcheck + cmp ebx,9 + ja .notokaystringb + mov eax,ChatString + mov ebx,.tempnick + call CopyString + mov eax,.nickchangeb + mov ebx,ChatString + call ConcatString + mov eax,ChatNick + mov ebx,ChatString + call ConcatString + mov eax,.tempnick + mov ebx,ChatNick + call CopyString + jmp .noaction +.notokaystring + mov esi,.strinvalid + call WritetochatBuffer + pop eax + jmp .finsend +.notokaystringb + mov esi,.strtoolong + call WritetochatBuffer + pop eax + jmp .finsend +.noaction + pop eax + + xor ebx,ebx +.next2 + mov al,[ChatString+ebx] + push ebx + push eax + call RemoteSendChar + pop eax + pop ebx + inc ebx + cmp al,0 + jne .next2 + mov esi,ChatString + call WritetochatBuffer + mov dl,13 + call NetAddChar + mov dl,10 + call NetAddChar + jmp .finsend2 +.nosendst + cmp al,20 + jne .nolatencych + mov al,[Latencytochange] + call RemoteSendChar + jmp .finsend2 +.nolatencych +; FileNameMod times 29 db 0 + cmp al,10 + jne .nosendfn + xor ebx,ebx +.next3 + mov al,[FileNameMod+ebx] + push ebx + push eax + call RemoteSendChar + pop eax + pop ebx + inc ebx + cmp al,0 + jne .next3 + jmp .finsend2 +.nosendfn +.finsend2 + call SendPacket +.finsend + mov byte[RemoteCommand],1 + ret + +.chatinitial db '>',0 +.actinitial db '*',0 +.actinitial2 db ' ',0 +.loading db 'LOADING ',0 +.filenotf db 'FILE NOT FOUND!',13,10,0 +.filenotfr db 'FILE NOT FOUND AT REMOTE!',13,10,0 +.filenotu db 'UNABLE TO LOAD!',13,10,0 +.tempnick times 16 db 0 +.strinvalid db '** INVALID NICK **',13,10,0 +.strtoolong db '** NICK IS TOO LONG **',13,10,0 +.nickchangeb db ' IS NOW KNOWN AS ',0 + +transfersram: + cmp byte[SFXSRAM],0 + jne .nosram + cmp byte[SA1Enable],1 + je .nosram + cmp dword[ramsize],0 + je .nosram + cmp byte[UseRemoteSRAMData],1 + je .uselocal + cmp byte[UseRemoteSRAMData],2 + je near .useremote +.nosram + call clearsram + ret + +.uselocal + call PreparePacket + mov al,233 + call RemoteSendChar + call SendPacket +.notimer + pushad + call JoyRead + popad + call RemoteGetChar + cmp dh,0 + je .notimer + cmp dl,234 + jne .notimer + + ; send sram + mov ecx,[ramsize] + mov ebx,[sram] + xor esi,esi +.loop + push ebx + push ecx + mov ebx,esi + and ebx,0FFh + cmp ebx,0 + jne .notzero + call PreparePacket +.notzero + pop ecx + pop ebx + mov al,[ebx] + push ebx + push ecx + call RemoteSendChar + pop ecx + mov ebx,esi + and ebx,0FFh + cmp ebx,0FFh + jne .notsend + call SendPacket +.notsend + pop ebx + inc esi + inc ebx + loop .loop + mov byte[sramsavedis],0 + ret + +.useremote + call PreparePacket + mov al,234 + call RemoteSendChar + call SendPacket +.notimerb + pushad + call JoyRead + popad + call RemoteGetChar + cmp dh,0 + je .notimerb + cmp dl,233 + jne .notimerb + + ; receive sram + mov ecx,[ramsize] + mov ebx,[sram] +.loopb +.getnext + pushad + call JoyRead + popad + call RemoteGetChar + cmp dh,0 + je .getnext + mov [ebx],dl + inc ebx + loop .loopb + ret + +NEWSYM RemoteSendEAX +; call RemoteSendChar + shr eax,8 + call RemoteSendChar + shr eax,8 + call RemoteSendChar + shr eax,8 + call RemoteSendChar + ret + +NEWSYM RemoteGetEAX +;.getnext +; call RemoteGetChar +; cmp dh,0 +; je .getnext +; mov bl,dl + xor ebx,ebx +; shl ebx,8 +.getnext2 + call RemoteGetChar + cmp dh,0 + je .getnext2 + mov bl,dl + shl ebx,8 +.getnext3 + call RemoteGetChar + cmp dh,0 + je .getnext3 + mov bl,dl + shl ebx,8 +.getnext4 + call RemoteGetChar + cmp dh,0 + je .getnext4 + mov bl,dl + bswap ebx + mov eax,ebx + ret + + +NEWSYM RemoteSendChar + cmp byte[WhichRemote],1 + jne .nomodem + call ModemSendChar +.nomodem + cmp byte[WhichRemote],2 + jne .noipx + call ipxsendchar +.noipx + cmp byte[WhichRemote],4 + jne .notcpip + call TCPIPStoreByte +.notcpip + ret + +NEWSYM RemoteGetChar + cmp byte[WhichRemote],1 + jne .nomodem + call ModemGetChar +.nomodem + cmp byte[WhichRemote],2 + jne .noipx + call ipxgetchar +.noipx + cmp byte[WhichRemote],4 + jne .notcpip + call TCPIPGetByte +.notcpip + ret + +ModemSendStr: +.loop + mov al,[esi] + or al,al + jz .nomore + call ModemSendChar + inc esi + jmp .loop +.nomore + ret + +NetLoadHandle dw 0 +NetStateSize dd 0 +NetStateTotal dd 0 +NetStateQuit db 0 +NetStateBuffer times 2048 db 0 +Netfname db 'nettemp.zst',0 + +NetLoadStuff: + call loadnetopen + mov byte[NetStateQuit],0 + mov edx,fnamest+1 + call Open_File + jc .nostate + mov bx,ax + mov cx,0 + mov dx,0 + call File_Seek_End + shl edx,16 + mov dx,ax + mov [NetStateSize],edx + mov [NetStateTotal],edx + call Close_File + mov byte[CNetType],21 + call PreparePacket + mov al,14 + call RemoteSendChar + mov al,[NetStateSize] + call RemoteSendChar + mov al,[NetStateSize+1] + call RemoteSendChar + mov al,[NetStateSize+2] + call RemoteSendChar + call SendPacket + call ChangetoSRAMdir + mov edx,fnamest+1 + call Open_File + mov [NetLoadHandle],ax + call ChangetoLOADdir +.nostate + ret + +loadstaterecvinit: + mov byte[NetStateQuit],0 + mov dword[NetStateSize],0 +.noreceive + pushad + call JoyRead + popad + call RemoteGetChar + cmp dh,0 + je .noreceive + mov [NetStateSize],dl +.noreceive1 + call RemoteGetChar + cmp dh,0 + je .noreceive1 + mov [NetStateSize+1],dl +.noreceive2 + call RemoteGetChar + cmp dh,0 + je .noreceive2 + mov [NetStateSize+2],dl + call ChangetoSRAMdir + mov edx,Netfname + call Create_File + mov edx,[NetStateSize] + mov [NetStateTotal],edx + mov [NetLoadHandle],ax + call ChangetoLOADdir + ret + +loadstatesend: + call RemoteGetChar + cmp dh,0 + je .noreceived + cmp dl,15 + je .finished + call ProcessRemoteCommand +.noreceived + cmp byte[NetStateQuit],0 + je .noquit +.finished + call PreparePacket + mov al,15 + call RemoteSendChar + call SendPacket + mov byte[CNetType],20 + mov esi,StateLoadedFail + call ProcessModem.writestr + mov bx,[NetLoadHandle] + call Close_File + cmp byte[NetLoadState],0 + je .norun + mov byte[GUIQuit],2 +.norun + ret +.noquit + call PreparePacket + mov al,1 + call RemoteSendChar + mov ecx,[NetStateSize] + cmp ecx,2047 + jbe .notsmaller + mov ecx,2047 +.notsmaller + sub [NetStateSize],ecx + mov bx,[NetLoadHandle] + mov edx,NetStateBuffer + push ecx + call Read_File + pop ecx + mov edx,NetStateBuffer +.loop + mov al,[edx] + push edx + push ecx + call RemoteSendChar + pop ecx + pop edx + inc edx + loop .loop + call SendPacket + cmp dword[NetStateSize],0 + jne .notzero + pushad + call loadstate2 + mov byte[RestoreValues],0 + mov bx,[NetLoadHandle] + call Close_File + mov byte[CNetType],20 + mov esi,StateLoadedOk + call ProcessModem.writestr + cmp byte[NetLoadState],0 + je .norun2 + mov byte[GUIQuit],2 +.norun2 + popad +.notzero + ret + +loadstaterecv: + cmp byte[NetStateQuit],0 + je .noquit2 + mov byte[NetStateQuit],0 + call PreparePacket + mov al,15 + call RemoteSendChar + call SendPacket +.noquit2 + call RemoteGetChar + cmp dh,0 + jne .received + ret +.received + cmp dl,1 + je .noquit + mov byte[CNetType],20 + mov esi,StateLoadedFail + call ProcessModem.writestr + cmp byte[NetLoadState],0 + je .norun + mov byte[GUIQuit],2 +.norun + mov bx,[NetLoadHandle] + call Close_File + ret +.noquit + mov ecx,[NetStateSize] + cmp ecx,2047 + jbe .notsmaller + mov ecx,2047 +.notsmaller + sub [NetStateSize],ecx + mov edx,NetStateBuffer + push ecx +.loop + push edx + push ecx +.notrecv + call RemoteGetChar + cmp dh,0 + je .notrecv + mov al,dl + pop ecx + pop edx + mov [edx],al + inc edx + loop .loop + pop ecx + mov bx,[NetLoadHandle] + mov edx,NetStateBuffer + call Write_File + cmp dword[NetStateSize],0 + jne .notzero + pushad + mov bx,[NetLoadHandle] + call Close_File + call ChangetoSRAMdir + mov edx,Netfname + mov byte[RestoreValues],0 + call loadstate3 + call ChangetoLOADdir + cmp byte[NetLoadState],0 + je .norun2 + mov byte[GUIQuit],2 +.norun2 + mov byte[CNetType],20 + mov esi,StateLoadedOk + call ProcessModem.writestr + popad +.notzero + ret + +StateLoadedOk db 10,13,'STATE LOADED.',10,13,10,13,0 +StateLoadedFail db 10,13,'LOAD FAILED.',10,13,10,13,0 + + \ No newline at end of file diff --git a/zsnes/src/gui/guitools.inc b/zsnes/src/gui/guitools.inc new file mode 100644 index 00000000..7b5df303 --- /dev/null +++ b/zsnes/src/gui/guitools.inc @@ -0,0 +1,836 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + +; Tools for the GUI (string functions are also used elsewhere) + +NEWSYM CopyString + push eax +.again + mov dl,[eax] + mov [ebx],dl + inc eax + inc ebx + or dl,dl + jnz .again + pop eax + ret + +NEWSYM StringLength + xor ecx,ecx + push eax +.loop + cmp byte[eax],0 + je .done + inc eax + inc ecx + jmp .loop +.done + pop eax + ret + +NEWSYM ClipString + ; clip string eax by bl characters +.next + push eax +.again + mov dl,[eax+1] + mov [eax],dl + inc eax + or dl,dl + jnz .again + pop eax + dec bl + jnz .next + ret + +NEWSYM ConcatString + ; concat eax in front of ebx, store in ebx + ; move string forward by length of eax + pushad + mov esi,eax + cmp byte[esi],0 + je near .nomore3 +.next + inc esi + cmp byte[esi],0 + jne .next + dec esi +.again + mov dl,[esi] + push ebx + xor ecx,ecx +.loop + cmp byte[ebx],0 + je .nomore + inc ebx + inc ecx + jmp .loop +.nomore + inc ebx + inc ecx +.loop2 + or ecx,ecx + jz .nomore2 + mov dh,[ebx-1] + mov [ebx],dh + dec ebx + dec ecx + jmp .loop2 +.nomore2 + pop ebx + mov [ebx],dl + cmp eax,esi + je .nomore3 + dec esi + jmp .again +.nomore3 + popad + ret + +GUIoutputchar: + push edi + push esi + push eax + xor ebx,ebx + mov bl,al + mov edi,GUIFontData + lea ebx,[ebx*5] + add edi,ebx + mov cl,5 +.loopa + mov ah,[edi] + mov ch,5 +.loopb + test ah,80h + jz .nowrite + mov al,[GUItextcolor] + sub al,cl + sub al,ch + mov byte[esi],al +.nowrite + shl ah,1 + inc esi + dec ch + jnz .loopb + add esi,283 + inc edi + dec cl + jnz .loopa + pop eax + pop esi + pop edi + ret + +GUIOutputString: + xor eax,eax +.more + mov al,[edi] + or al,al + jz .nomore + mov al,[ASCII2Font+eax] + call GUIoutputchar + add esi,6 + inc edi + jmp .more +.nomore + ret + +%macro GUIOuttext 4 + mov edi,%2 + mov esi,edi + shl esi,8 + shl edi,5 + add esi,edi + add esi,[vidbuffer] + add esi,%1 + add esi,16 + mov edi,%3 + mov byte[GUItextcolor],%4 + call GUIOutputString +%endmacro + +GUIDrawBox: +.loop + push edi + push ecx + rep stosb + pop ecx + pop edi + add edi,288 + dec edx + jnz .loop + ret + +%macro GUIBox 5 + mov edi,[vidbuffer] + add edi,%1 + mov edx,%2 + mov ecx,edx + shl edx,8 + shl ecx,5 + add edx,ecx + add edi,edx + add edi,16 + mov ecx,%3 + sub ecx,%1 + inc ecx + mov edx,%4 + sub edx,%2 + inc edx + mov al,%5 + call GUIDrawBox +%endmacro + +GUIHLines: + cmp ecx,0 + jl near .nodraw + cmp eax,255 + jg near .nodraw + cmp eax,0 + jnl .noofx + mov eax,0 +.noofx + cmp ecx,255 + jng .noofx2 + mov ecx,255 +.noofx2 + cmp ebx,0 + jl .nodraw + cmp ebx,223 + jg .nodraw + + sub ecx,eax + inc ecx + + mov edi,[vidbuffer] + add edi,eax + add edi,16 + + mov eax,ebx + shl eax,8 + add edi,eax + mov eax,ebx + shl eax,5 + add edi,eax + mov eax,edx +.loop + mov [edi],ah + add eax,[GUIcolscaleval] + inc edi + dec ecx + jnz .loop + +.nodraw + ret + +GUIHLine: + cmp ecx,0 + jl near .nodraw + cmp eax,255 + jg near .nodraw + cmp eax,0 + jnl .noofx + mov eax,0 +.noofx + cmp ecx,255 + jng .noofx2 + mov ecx,255 +.noofx2 + cmp ebx,0 + jl .nodraw + cmp ebx,223 + jg .nodraw + sub ecx,eax + inc ecx + mov edi,[vidbuffer] + add edi,eax + add edi,16 + mov eax,ebx + shl eax,8 + add edi,eax + mov eax,ebx + shl eax,5 + add edi,eax + mov eax,edx + rep stosb +.nodraw + ret + +%macro GUIPal 4 + mov dx,03C8h + mov al,%1 + out dx,al + inc dx + mov al,%2 + out dx,al + mov al,%3 + out dx,al + mov al,%4 + out dx,al +%endmacro + +GUIDrawShadow: +.loop + push edi + push ecx +.loop2 + mov al,[edi-3*288-3] + cmp al,148 + jb .nomidshad + cmp al,167 + ja .mid2 + add byte[edi-3*288-3],20 + jmp .noshadow +.mid2 + cmp al,189 + jb .nomidshad + cmp al,220 + ja .nomidshad + sub al,189 + shr al,1 + add al,189 + mov byte[edi-288*3-3],al + jmp .noshadow +.nomidshad + mov al,[edi] + cmp al,32 + jae .noshadow + add al,96 + mov [edi],al +.noshadow + inc edi + dec ecx + jnz .loop2 + pop ecx + pop edi + add edi,288 + dec edx + jnz near .loop + ret + +%macro GUIShadow 4 + mov edi,[vidbuffer] + add edi,%1+%2*288+16 + mov ecx,%3-%1+1 + mov edx,%4-%2+1 + call GUIDrawShadow +%endmacro + + +GUIDrawShadow2: +.loop + push edi + push ecx +.loop2 + mov al,[edi] + cmp al,32 + jae .noshadow + add al,96 + mov [edi],al +.noshadow + inc edi + dec ecx + jnz .loop2 + pop ecx + pop edi + add edi,288 + dec ebx + jnz .loop + ret + +GUIoutputcharwin: + push edi + push esi + push eax + xor ebx,ebx + mov bl,al + mov edi,GUIFontData + lea ebx,[ebx*5] + add edi,ebx + mov cl,5 +.loopa + mov ah,[edi] + mov ch,5 + cmp esi,[vidbuffer] + jb .below + mov edx,[vidbuffer] + add edx,224*288 + cmp esi,edx + jb .loopb +.below + add esi,5 + jmp .nowrite2 +.loopb + test ah,80h + jz .nowrite + mov al,[GUItextcolor] + mov byte[esi],al +.nowrite + shl ah,1 + inc esi + dec ch + jnz .loopb +.nowrite2 + add esi,283 + inc edi + dec cl + jnz .loopa + pop eax + pop esi + pop edi + ret + +GUIOutputStringwin: + xor eax,eax +.more + mov al,[edi] + or al,al + jz .nomore + mov al,[ASCII2Font+eax] + cmp edx,-8 + jl .nodraw + cmp edx,255 + jg .nodraw + push esi + push edx + add esi,edx + call GUIoutputcharwin + pop edx + pop esi +.nodraw + add edx,6 + inc edi + jmp .more +.nomore + ret + +GUIOutputStringwinl: + xor eax,eax + mov ecx,[cloadmaxlen] +.more + mov al,[edi] + cmp byte[OSPort],1 + jbe .noperc + cmp al,'%' + jne .noperc + call ConvertPercValue +.noperc + or al,al + jz .nomore + mov al,[ASCII2Font+eax] + cmp edx,-8 + jl .nodraw + cmp edx,255 + jg .nodraw + push esi + push edx + push ecx + add esi,edx + call GUIoutputcharwin + pop ecx + pop edx + pop esi +.nodraw + add edx,6 + inc edi + dec ecx + jz .nomore + jmp .more +.nomore + ret + +ConvertPercValue: + mov al,[edi+2] + cmp al,'a' + jb .notlower + cmp al,'z' + ja .notlower + sub al,'a'-'A' +.notlower + mov ah,[edi+1] + cmp ah,'a' + jb .notlowerb + cmp ah,'z' + ja .notlowerb + sub ah,'a'-'A' +.notlowerb + cmp al,'0' + jb .noperc + cmp al,'9' + jbe .yesperc + cmp al,'F' + ja .noperc + cmp al,'A' + jb .noperc +.yesperc + cmp ah,'0' + jb .noperc + cmp ah,'9' + jbe .yesperc2 + cmp ah,'F' + ja .noperc + cmp ah,'A' + jb .noperc +.yesperc2 + sub al,'0' + cmp al,9 + jbe .nodec + sub al,'A'-'0'-10 +.nodec + sub ah,'0' + cmp ah,9 + jbe .nodecb + sub ah,'A'-'0'-10 +.nodecb + shl ah,4 + or al,ah + add edi,2 + and eax,0FFh + ret +.noperc + xor eax,eax + mov al,[edi] + ret + +OutputUnder: + cmp edx,-8 + jl .nodraw + cmp edx,255 + jg .nodraw + mov dword[esi+edx+5*288-1],0E8E8E8E8h + mov byte[esi+edx+5*288+3],0E8h +.nodraw + ret + +%macro GUIOuttextwin 1 + mov esi,ebx + mov eax,ebx + shl esi,8 + shl eax,5 + add esi,eax + add esi,16 + add esi,[vidbuffer] + mov edi,%1 + call GUIOutputStringwin +%endmacro + +%macro GUIOuttextwin2 4 + mov edx,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add edx,%2 + add ebx,%3 + + mov esi,ebx + mov eax,ebx + shl esi,8 + shl eax,5 + add esi,eax + add esi,16 + add esi,[vidbuffer] + mov edi,%4 + call GUIOutputStringwin +%endmacro + +%macro GUIOuttextwin2l 4 + mov edx,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add edx,%2 + add ebx,%3 + + mov esi,ebx + mov eax,ebx + shl esi,8 + shl eax,5 + add esi,eax + add esi,16 + add esi,[vidbuffer] + mov edi,%4 + call GUIOutputStringwinl +%endmacro + +%macro GUIOuttextwin2u 5 + mov edx,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add edx,%2 + add ebx,%3 + + mov esi,ebx + mov eax,ebx + shl esi,8 + shl eax,5 + add esi,eax + add esi,16 + add esi,[vidbuffer] + mov edi,%4 + add edx,%5*6 + call OutputUnder + sub edx,%5*6 + call GUIOutputStringwin +%endmacro + +GUIoutputiconwin: + cmp eax,-9 + jl .nodraw + cmp eax,256 + jl .draw +.nodraw + ret +.draw + mov esi,ebx + mov ecx,ebx + shl esi,8 + shl ecx,5 + add esi,ecx + add esi,16 + add esi,[vidbuffer] + add esi,eax + mov cl,10 +.loopa + mov ch,10 + cmp esi,[vidbuffer] + jb .below + mov edx,[vidbuffer] + add edx,224*288 + cmp esi,edx + jb .loopb +.below + add esi,10 + jmp .nowrite2 +.loopb + mov al,[edi] + or al,al + jz .transp + cmp al,189 + ja .col2 + cmp byte[GUIWincoladd],0 + je .col3 + inc al + jmp .col3 +.col2 + sub al,[GUIWincoladd] + dec al +.col3 + mov [esi],al +.transp + inc edi + inc esi + dec ch + jnz .loopb +.nowrite2 + add esi,278 + dec cl + jnz .loopa + ret + +%macro GUIDisplayIcon 1 + mov edi,%1 + call GUIoutputiconwin +%endmacro + +%macro GUIDisplayIconWin 4 + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add eax,%2 + add ebx,%3 + mov edi,%4 + call GUIoutputiconwin +%endmacro + +GUIDrawSlideBar: + cmp eax,-10 + jl .ret + cmp eax,256 + jg .ret + jmp .noret +.ret + ret +.noret + mov edi,[vidbuffer] + mov [vbuflimtop],edi + mov edi,[vidbuffer] + add edi,288*224 + sub edi,16 + mov [vbuflimbot],edi + mov edi,eax + mov eax,ebx + shl ebx,8 + shl eax,5 + add edi,ebx + add edi,eax + add edi,[vidbuffer] + add edi,16 + xor eax,eax + dec ecx +.loop + cmp edx,0 + je near .toparea + cmp ecx,0 + je near .bottomarea + cmp ah,1 + je .filleddisp + cmp edi,[vbuflimtop] + jb near .nodraw + cmp edi,[vbuflimbot] + ja near .nodraw + mov al,197 + sub al,byte[GUIWincoladd] + mov [edi],al + sub al,2 + mov [edi+1],al + dec al + mov [edi+2],al + dec al + mov [edi+3],al + mov [edi+4],al + inc al + mov [edi+5],al + inc al + mov [edi+6],al + add al,2 + mov [edi+7],al + jmp .fin +.filleddisp + cmp edi,[vbuflimtop] + jb near .nodraw + cmp edi,[vbuflimbot] + ja near .nodraw + mov al,202 + sub al,byte[GUIWincoladd] + mov [edi],al + sub al,2 + mov [edi+1],al + mov [edi+2],al + mov [edi+3],al + mov [edi+4],al + mov [edi+5],al + mov [edi+6],al + sub al,2 + mov [edi+7],al + jmp .fin +.toparea + cmp edi,[vbuflimtop] + jb near .nodraw + cmp edi,[vbuflimbot] + ja near .nodraw + mov al,202 + sub al,byte[GUIWincoladd] + mov [edi],al + add al,2 + mov [edi+1],al + mov [edi+2],al + mov [edi+3],al + mov [edi+4],al + mov [edi+5],al + mov [edi+6],al + mov [edi+7],al + mov ah,1 + jmp .fin +.bottomarea + cmp edi,[vbuflimtop] + jb near .nodraw + cmp edi,[vbuflimbot] + ja near .nodraw + mov al,6 + mov al,196 + sub al,byte[GUIWincoladd] + mov [edi],al + mov [edi+1],al + mov [edi+2],al + mov [edi+3],al + mov [edi+4],al + mov [edi+5],al + mov [edi+6],al + add al,2 + mov [edi+7],al + mov ah,0 +.fin +.nodraw + add edi,288 + dec ecx + dec edx + dec esi + jnz near .loop + ret + +%macro DrawSlideBarWin 8 + ; win#,X,Y start, %4-List Loc, %5-List size, %6-Screen size, %7-Bar Size + mov ebx,%5 + mov ecx,%4 + ; if (Screen Size > List Size) List Size = Screen Size + cmp ebx,%6 + jae %%noscrbig + mov ebx,%6 +%%noscrbig + ; If (ListLoc + ScreenSize > ListSize) ListLoc = ListSize - ScreenSize + mov eax,ecx + add eax,%6 + cmp eax,ebx + jbe %%nosetlloc + mov ecx,ebx + sub ecx,%6 +%%nosetlloc + ; Scrollbarsize = (Screen Size/List size)*Bar Size + push ebx + mov eax,%6 + mov ebx,%7 + mul ebx + pop ebx + div ebx + ; If (Scrollbarsize < 5) Scrollbarsize = 5 + cmp eax,5 + jae %%validscroll + mov eax,5 +%%validscroll + ; StartY = (Bar Size-Scrollbarsize)*(List Loc/(List size-ScreenSize)) + push eax + sub eax,%7 + neg eax + mul ecx + sub ebx,%6 + cmp ebx,0 + je %%zero + div ebx + jmp %%notzero +%%zero + xor eax,eax +%%notzero + mov edx,eax + pop eax + mov ecx,eax + add ecx,edx + ; ecx = endy, edx = starty + mov esi,%7 + sub esi,ecx + add esi,edx + dec esi + mov [%8],esi + mov [%8+4],edx + mov [%8+8],ecx + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add eax,%2 + add ebx,%3 + mov esi,%7 + call GUIDrawSlideBar +%endmacro + \ No newline at end of file diff --git a/zsnes/src/gui/guiwindp.inc b/zsnes/src/gui/guiwindp.inc new file mode 100644 index 00000000..abf3ae0c --- /dev/null +++ b/zsnes/src/gui/guiwindp.inc @@ -0,0 +1,5622 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + +; Window Display Routines +; Last button value used = 65 + +GUIStringGreater: + ; compares string at esi to edi and returns 1 to al if esi is >, else 0 + push esi + cmp word[esi],'.' + je .less + cmp word[esi+32],'.' + je .greater + cmp word[esi],'..' + je .less + cmp word[esi+32],'..' + je .greater +.nextchar + cmp byte[esi],0 + je .less + cmp byte[esi+32],0 + je .greater + mov al,[esi] + mov cl,[esi+32] + cmp al,'a' + jb .noucase1 + cmp al,'z' + ja .noucase1 + sub al,'z'-'Z' +.noucase1 + cmp cl,'a' + jb .noucase2 + cmp cl,'z' + ja .noucase2 + sub cl,'z'-'Z' +.noucase2 + cmp al,cl + jb .less + ja .greater + inc esi + jmp .nextchar +.less + mov al,0 + jmp .skip +.greater + mov al,1 +.skip + pop esi + ret + +GUIStringGreater2: + ; compares string at ebx to edx and returns 1 to al if esi is >, else 0 + push edx + push ebx + cmp word[ebx],'.' + je .less + cmp word[edx],'.' + je .greater + cmp word[ebx],'..' + je .less + cmp word[ebx],'..' + je .greater +.nextchar + cmp byte[ebx],0 + je .less + cmp byte[edx],0 + je .greater + mov al,[ebx] + mov cl,[edx] + cmp al,'a' + jb .noucase1 + cmp al,'z' + ja .noucase1 + sub al,'z'-'Z' +.noucase1 + cmp cl,'a' + jb .noucase2 + cmp cl,'z' + ja .noucase2 + sub cl,'z'-'Z' +.noucase2 + cmp al,cl + jb .less + ja .greater + inc ebx + inc edx + jmp .nextchar +.less + mov al,0 + jmp .skip +.greater + mov al,1 +.skip + pop ebx + pop edx + ret + +%Macro DrawGUILineSc 2 + mov dword[GUIcolscaleval],%2 + mov edx,%1 + push eax + push ecx + call GUIHLines + pop ecx + pop eax + inc ebx +%Endmacro + +%Macro DrawGUILine 0 + push eax + push ecx + call GUIHLine + pop ecx + pop eax + inc ebx +%Endmacro + +%macro DrawTitleBar 0 + mov edx,46+157+6 + sub edx,[GUIWincoladd] + DrawGUILine + + mov edx,42+157+4+4 + sub edx,[GUIWincoladd] + DrawGUILine + dec edx + DrawGUILine + dec edx + DrawGUILine + dec edx + DrawGUILine + dec edx + DrawGUILine + dec edx + DrawGUILine + dec edx + DrawGUILine + dec edx + DrawGUILine + + mov edx,38+157+4 + sub edx,[GUIWincoladd] + DrawGUILine + + sub ebx,10 + mov edx,44+157+4 + sub edx,[GUIWincoladd] + mov esi,9 + push ecx + mov ecx,eax +%%loop2 + DrawGUILine + dec esi + jnz %%loop2 + pop ecx + sub ebx,8 + + mov edx,40+157+4 + sub edx,[GUIWincoladd] + mov esi,9 + push eax + mov eax,ecx +%%loop3 + DrawGUILine + dec esi + jnz %%loop3 + pop eax +%endmacro + +%macro drawshadow2 3 + mov edx,[GUIwinposy+%1*4] + cmp edx,223 + jg near .noshadow + cmp edx,0 + jge .noshadclip + mov edx,0 +.noshadclip + mov ebx,edx + add ebx,%3 + add ebx,9 + cmp ebx,0 + jl near .noshadow + cmp ebx,223 + jng .noshadclip2 + mov ebx,223 +.noshadclip2 + sub ebx,edx + inc ebx + mov edi,edx + shl edi,8 + mov eax,edx + shl eax,5 + add edi,eax + mov edx,[GUIwinposx+%1*4] + mov ecx,edx + cmp edx,255 + jg .noshadow + cmp edx,-3 + jnl .noshadclip3 + mov edx,-3 +.noshadclip3 + add ecx,%2 + cmp ecx,0 + jl .noshadow + cmp ecx,255 + jng .noshadclip4 + mov ecx,255 +.noshadclip4 + sub ecx,edx + inc ecx + add edi,edx + add edi,[vidbuffer] + add edi,288*3+3+16 + call GUIDrawShadow2 +.noshadow +%endmacro + +%macro GUIDrawWindowBox 2 + mov dword[GUIWincoladd],4 + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone + mov dword[GUIWincol],148+5 +.noone + cmp byte[cwindrawn],0 + jne .nozero + mov dword[GUIWincoladd],0 + mov dword[GUIWincol],148 +.nozero + drawshadow2 %1,dword[GUIwinsizex+%1*4],dword[GUIwinsizey+%1*4] + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + mov ecx,eax + add ecx,dword[GUIwinsizex+%1*4] + DrawTitleBar + mov esi,dword[GUIwinsizey+%1*4] + dec esi + mov edx,dword[GUIWincol] + add edx,2 +.loop + DrawGUILine + dec esi + jnz .loop + mov edx,dword[GUIWincol] + DrawGUILine + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add ebx,10 + mov ecx,eax + mov esi,dword[GUIwinsizey+%1*4] + mov edx,dword[GUIWincol] + add edx,3 + dec esi +.loop2 + DrawGUILine + dec esi + jnz .loop2 + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add ebx,10 + add eax,dword[GUIwinsizex+%1*4] + mov ecx,eax + mov esi,dword[GUIwinsizey+%1*4] + mov edx,dword[GUIWincol] + add edx,1 +.loop3 + DrawGUILine + dec esi + jnz .loop3 + mov ebx,dword[GUIwinposy+%1*4] + add ebx,3 + mov edx,dword[GUIwinposx+%1*4] + add edx,3 + mov byte[GUItextcolor],184 + GUIOuttextwin %2 + mov ebx,dword[GUIwinposy+%1*4] + add ebx,2 + mov edx,dword[GUIwinposx+%1*4] + add edx,2 + mov byte[GUItextcolor],220 + cmp byte[GUIWincoladd],0 + je .zero2 + sub byte[GUItextcolor],6 +.zero2 + GUIOuttextwin %2 + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add eax,dword[GUIwinsizex+%1*4] + sub eax,10 + GUIDisplayIcon GUIIconDataClose +%endmacro + +%macro DrawGUIWinBox 6 + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add eax,%2 + add ebx,%3 + mov ecx,eax + add ecx,%4-%2+1 + mov dl,%6 + mov esi,%5-%3+1 +%%loop + DrawGUILine + dec esi + jnz %%loop +%endmacro + +%macro DrawGUIWinBox2 5 + mov eax,dword[GUIwinposx+%1*4] + add eax,%2 + mov ecx,eax + add ecx,%3-%2+1 + mov dl,%5 + cmp byte[GUIWincoladd],0 + je %%zero + inc dl +%%zero + mov esi,%4 + add ebx,dword[GUIwinposy+%1*4] +%%loop + DrawGUILine + dec esi + jnz %%loop +%endmacro + +%macro DrawGUIWinBox3 6 + mov ecx,%4 + mov eax,dword[GUIwinposx+%1*4] + mov ebx,dword[GUIwinposy+%1*4] + add eax,%2 + add ebx,%3 + add ecx,eax + sub ecx,%2 + inc ecx + mov dl,%6 + mov esi,%5-%3+1 +%%loop + DrawGUILine + dec esi + jnz %%loop +%endmacro + +%macro DrawGUIButton 9 + mov dl,byte[GUItextcolor] + sub dl,5 + cmp byte[GUICBHold],%7 + jne %%noa + sub dl,13 +%%noa + DrawGUIWinBox %1,%2,%3,%4,%3,dl + sub dl,3 + cmp byte[GUICBHold],%7 + jne %%nob + add dl,5 +%%nob + DrawGUIWinBox %1,%2,%3,%2,%5,dl + sub dl,3 + cmp byte[GUICBHold],%7 + jne %%noc + add dl,5 +%%noc + DrawGUIWinBox %1,%2+1,%3+1,%4-2,%5-2,dl + sub dl,3 + cmp byte[GUICBHold],%7 + jne %%nod + add dl,5 +%%nod + DrawGUIWinBox %1,%4+1,%3+1,%4-2,%5-2,dl + sub dl,3 + cmp byte[GUICBHold],%7 + jne %%noe + add dl,5 +%%noe + DrawGUIWinBox %1,%2,%5,%4-1,%5,dl + cmp byte[GUICBHold],%7 + je near %%no2 + sub byte[GUItextcolor],15 + GUIOuttextwin2 %1,%2+5+%8,%3+4+%9,%6 + add byte[GUItextcolor],15 + GUIOuttextwin2 %1,%2+4+%8,%3+3+%9,%6 + jmp %%yes +%%no2 + sub byte[GUItextcolor],18 + GUIOuttextwin2 %1,%2+6+%8,%3+5+%9,%6 + add byte[GUItextcolor],15 + GUIOuttextwin2 %1,%2+5+%8,%3+4+%9,%6 + add byte[GUItextcolor],3 +%%yes +%endmacro + +%macro GUIOuttextwin2load 3 + test dword[cloadnleft],80000000h + jnz %%skip + cmp byte[GUIloadfntype],0 + jne %%nottype0 + mov eax,[cloadnposb] + mov eax,[spcRamcmp+eax*4] + inc eax + mov [cloadnpos],eax + inc dword[cloadnposb] +%%nottype0 + GUIOuttextwin2l %1,%2,%3,[cloadnpos] + add dword[cloadnpos],32 + dec dword[cloadnleft] +%%skip +%endmacro + +%macro GUIDisplayButtonHole 5 + mov dword[GUITemp],GUIIconDataButtonHole + cmp %4,%5 + jne %%nofill + mov dword[GUITemp],GUIIconDataButtonFill +%%nofill + GUIDisplayIconWin %1,%2,%3,[GUITemp] +%endmacro + +; DGUIDisplay + +DisplayGUILoad: + GUIDrawWindowBox 1,GUILoadDisp + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + cmp byte[OSPort],2 + jae near .noloadtypeb + GUIOuttextwin2 1,21,166,GUILoadText3 + GUIOuttextwin2 1,21,174,GUILoadText4 + GUIOuttextwin2 1,21,182,GUILoadText5 +.noloadtypeb + GUIOuttextwin2 1,21,192,GUILoadText6 + GUIOuttextwin2 1,6,16,GUILoadText7 + GUIOuttextwin2 1,161,16,GUILoadText8 + GUIOuttextwin2 1,6,138,GUIcurrentdir + + mov dword[cloadmaxlen],39 + cmp dword[GUIcurrentfilewin],0 + jne .nofiles + cmp byte[OSPort],2 + jb .nofiles + mov eax,[GUIcurrentcursloc] + mov eax,[spcRamcmp+eax*4] + inc eax + mov [cloadnpos],eax + GUIOuttextwin2l 1,6,158,[cloadnpos] +.nofiles + + add byte[GUItextcolor],15 + cmp byte[OSPort],2 + jae near .noloadtypec + GUIOuttextwin2 1,20,165,GUILoadText3 + GUIOuttextwin2 1,20,173,GUILoadText4 + GUIOuttextwin2 1,20,181,GUILoadText5 +.noloadtypec + GUIOuttextwin2 1,20,191,GUILoadText6 + GUIOuttextwin2 1,5,15,GUILoadText7 + GUIOuttextwin2 1,160,15,GUILoadText8 + GUIOuttextwin2 1,5,137,GUIcurrentdir + + mov dword[cloadmaxlen],39 + cmp dword[GUIcurrentfilewin],0 + jne .nofilesb + cmp byte[OSPort],2 + jb .nofilesb + mov eax,[GUIcurrentcursloc] + mov eax,[spcRamcmp+eax*4] + inc eax + mov [cloadnpos],eax + GUIOuttextwin2l 1,5,157,[cloadnpos] +.nofilesb + + DrawGUIButton 1,186,167,228,178,GUILoadText9,1,0,0 + mov al,[GUIWincol] + mov byte[GUItextcolor],al +; GUIOuttextwin2 1,6,16,GUILoadText1 + cmp byte[OSPort],2 + jae near .noloadtypee + GUIOuttextwin2 1,6,157,GUILoadText2 +.noloadtypee + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 +; GUIOuttextwin2 1,5,15,GUILoadText1 + cmp byte[OSPort],2 + jae near .noloadtyped + GUIOuttextwin2 1,5,156,GUILoadText2 +.noloadtyped + DrawGUIWinBox 1,5,25,144,134,167 ; 126 = 6 * 21, 112 = 7 * 16 + DrawGUIWinBox 1,160,25,228,134,167 ; 78 = 6 * 13 + DrawGUIWinBox 1,5,145,228,152,167 ; 126 = 6 * 21, 112 = 7 * 16 + + xor ebx,ebx + mov bl,[GUILoadPos] + mov byte[GUILoadTextA+ebx],0 + test byte[GUILDFlash],8 + jnz .nound + mov byte[GUILoadTextA+ebx],'_' + mov byte[GUILoadTextA+ebx+1],0 +.nound + + mov ebx,[GUIcurrentcursloc] + sub ebx,[GUIcurrentviewloc] + cmp dword[GUIcurrentfilewin],0 + je .files + mov ebx,[GUIcurrentdircursloc] + sub ebx,[GUIcurrentdirviewloc] +.files + + mov eax,ebx + lea ebx,[ebx*4] + add ebx,eax + add ebx,eax + add ebx,eax + add ebx,27 + cmp dword[GUIcurrentfilewin],0 + jne .dir + DrawGUIWinBox2 1,5,144,7,224 + jmp .files2 +.dir + DrawGUIWinBox2 1,160,228,7,224 +.files2 + + mov byte[GUItextcolor],223 + GUIOuttextwin2 1,8,148, GUILoadTextA + mov eax,[spcBuffera] + inc eax + mov dword[cloadnpos],eax + mov eax,[GUIfileentries] + sub eax,[GUIcurrentviewloc] + dec eax + mov dword[cloadnleft],eax + mov eax,[GUIcurrentviewloc] + mov [cloadnposb],eax + shl eax,5 + add [cloadnpos],eax + mov dword[cloadmaxlen],23 + + GUIOuttextwin2load 1,8,29 + GUIOuttextwin2load 1,8,29+7 + GUIOuttextwin2load 1,8,29+7*2 + GUIOuttextwin2load 1,8,29+7*3 + GUIOuttextwin2load 1,8,29+7*4 + GUIOuttextwin2load 1,8,29+7*5 + GUIOuttextwin2load 1,8,29+7*6 + GUIOuttextwin2load 1,8,29+7*7 + GUIOuttextwin2load 1,8,29+7*8 + GUIOuttextwin2load 1,8,29+7*9 + GUIOuttextwin2load 1,8,29+7*10 + GUIOuttextwin2load 1,8,29+7*11 + GUIOuttextwin2load 1,8,29+7*12 + GUIOuttextwin2load 1,8,29+7*13 + GUIOuttextwin2load 1,8,29+7*14 + + mov eax,[spcBuffera] + inc eax + mov dword[cloadnpos],eax + mov eax,[GUIdirentries] + sub eax,[GUIcurrentdirviewloc] + dec eax + mov dword[cloadnleft],eax + mov eax,[GUIcurrentdirviewloc] + add eax,[GUIfileentries] + mov [cloadnposb],eax + shl eax,5 + add [cloadnpos],eax + mov dword[cloadmaxlen],11 + GUIOuttextwin2load 1,164,29 + GUIOuttextwin2load 1,164,29+7 + GUIOuttextwin2load 1,164,29+7*2 + GUIOuttextwin2load 1,164,29+7*3 + GUIOuttextwin2load 1,164,29+7*4 + GUIOuttextwin2load 1,164,29+7*5 + GUIOuttextwin2load 1,164,29+7*6 + GUIOuttextwin2load 1,164,29+7*7 + GUIOuttextwin2load 1,164,29+7*8 + GUIOuttextwin2load 1,164,29+7*9 + GUIOuttextwin2load 1,164,29+7*10 + GUIOuttextwin2load 1,164,29+7*11 + GUIOuttextwin2load 1,164,29+7*12 + GUIOuttextwin2load 1,164,29+7*13 + GUIOuttextwin2load 1,164,29+7*14 + + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + GUIOuttextwin2 1,7,147, GUILoadTextA + mov eax,[spcBuffera] + inc eax + mov dword[cloadnpos],eax + mov eax,[GUIfileentries] + sub eax,[GUIcurrentviewloc] + dec eax + mov dword[cloadnleft],eax + mov eax,[GUIcurrentviewloc] + mov [cloadnposb],eax + shl eax,5 + add [cloadnpos],eax + mov dword[cloadmaxlen],23 + GUIOuttextwin2load 1,7,28 + GUIOuttextwin2load 1,7,28+7 + GUIOuttextwin2load 1,7,28+7*2 + GUIOuttextwin2load 1,7,28+7*3 + GUIOuttextwin2load 1,7,28+7*4 + GUIOuttextwin2load 1,7,28+7*5 + GUIOuttextwin2load 1,7,28+7*6 + GUIOuttextwin2load 1,7,28+7*7 + GUIOuttextwin2load 1,7,28+7*8 + GUIOuttextwin2load 1,7,28+7*9 + GUIOuttextwin2load 1,7,28+7*10 + GUIOuttextwin2load 1,7,28+7*11 + GUIOuttextwin2load 1,7,28+7*12 + GUIOuttextwin2load 1,7,28+7*13 + GUIOuttextwin2load 1,7,28+7*14 + mov eax,[spcBuffera] + inc eax + mov dword[cloadnpos],eax + mov eax,[GUIdirentries] + sub eax,[GUIcurrentdirviewloc] + dec eax + mov dword[cloadnleft],eax + mov eax,[GUIcurrentdirviewloc] + add eax,[GUIfileentries] + mov [cloadnposb],eax + shl eax,5 + add [cloadnpos],eax + mov dword[cloadmaxlen],11 + GUIOuttextwin2load 1,163,28 + GUIOuttextwin2load 1,163,28+7 + GUIOuttextwin2load 1,163,28+7*2 + GUIOuttextwin2load 1,163,28+7*3 + GUIOuttextwin2load 1,163,28+7*4 + GUIOuttextwin2load 1,163,28+7*5 + GUIOuttextwin2load 1,163,28+7*6 + GUIOuttextwin2load 1,163,28+7*7 + GUIOuttextwin2load 1,163,28+7*8 + GUIOuttextwin2load 1,163,28+7*9 + GUIOuttextwin2load 1,163,28+7*10 + GUIOuttextwin2load 1,163,28+7*11 + GUIOuttextwin2load 1,163,28+7*12 + GUIOuttextwin2load 1,163,28+7*13 + GUIOuttextwin2load 1,163,28+7*14 + + xor ebx,ebx + mov bl,[GUILoadPos] + mov byte[GUILoadTextA+ebx],0 + + cmp byte[OSPort],2 + jae near .noloadtype + GUIDisplayButtonHole 1,9,163,byte[GUIloadfntype],0 + GUIDisplayButtonHole 1,9,171,byte[GUIloadfntype],1 + GUIDisplayButtonHole 1,9,179,byte[GUIloadfntype],2 +.noloadtype + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[showallext],1 + jne .nocheck + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck + GUIDisplayIconWin 1,10,187,[GUITemp] + + ; win#,X,Y start, %4-List Loc, %5-List size, %6-Screen size, %7-Bar Size + DrawSlideBarWin 1,146,33,[GUIcurrentviewloc],[GUIfileentries],15,94,GUILStA + cmp byte[GUICHold],1 + jne .noholda + add byte[GUIWincoladd],3 +.noholda + GUIDisplayIconWin 1,146,25,GUIIconDataUpArrow + cmp byte[GUICHold],1 + jne .noholda2 + sub byte[GUIWincoladd],3 +.noholda2 + cmp byte[GUICHold],2 + jne .noholdb + add byte[GUIWincoladd],3 +.noholdb + GUIDisplayIconWin 1,146,127,GUIIconDataDownArrow + cmp byte[GUICHold],2 + jne .noholdb2 + sub byte[GUIWincoladd],3 +.noholdb2 + DrawSlideBarWin 1,230,33,[GUIcurrentdirviewloc],[GUIdirentries],15,94,GUILStB + cmp byte[GUICHold],3 + jne .noholdc + add byte[GUIWincoladd],3 +.noholdc + GUIDisplayIconWin 1,230,25,GUIIconDataUpArrow + cmp byte[GUICHold],3 + jne .noholdc2 + sub byte[GUIWincoladd],3 +.noholdc2 + cmp byte[GUICHold],4 + jne .noholdd + add byte[GUIWincoladd],3 +.noholdd + GUIDisplayIconWin 1,230,127,GUIIconDataDownArrow + cmp byte[GUICHold],4 + jne .noholdd2 + sub byte[GUIWincoladd],3 +.noholdd2 + ; Draw borders + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + + mov dl,[GUIWincol] + DrawGUIWinBox 1,5,24,144,24,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 1,4,25,3,134,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 1,5,135,144,135,dl + + mov dl,[GUIWincol] + DrawGUIWinBox 1,160,24,228,24,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 1,159,25,158,134,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 1,160,135,228,135,dl + + mov dl,[GUIWincol] + DrawGUIWinBox 1,5,144,229,144,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 1,4,144,3,152,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 1,5,153,228,153,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 1,229,144,228,152,dl + ret + +GUILoadText1 db 'SELECT FILE TO LOAD :',0 +GUILoadText2 db 'DISPLAY TYPE :',0 +GUILoadText3 db 'NORMAL 8.3 FORMAT',0 +GUILoadText4 db 'SNES HEADER NAME',0 +GUILoadText5 db 'WIN95 LONG FILENAME',0 +GUILoadText6 db 'SHOW ALL EXTENSIONS',0 +GUILoadText7 db 'FILENAME',0 +GUILoadText8 db 'DIRECTORY',0 +GUILoadText9 db 'LOAD',0 +GUILoadTextA times 40 db 0 +GUILStA dd 0,0,0 +GUILStB dd 0,0,0 +GUILoadPos db 0 + +DisplayGUIReset: + GUIDrawWindowBox 12,GUIResetDisp + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + mov dl,224 + cmp byte[GUIWincoladd],0 + je .zero4 + inc dl +.zero4 + cmp byte[GUICResetPos],0 + je near .resetboxa + DrawGUIWinBox 12,79,29,117,42,dl + jmp .resetboxb +.resetboxa + DrawGUIWinBox 12,19,29,57,42,dl +.resetboxb + DrawGUIButton 12,20,30,56,41,GUIResetText2,2,0,0 + DrawGUIButton 12,80,30,116,41,GUIResetText3,3,0,0 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 12,6,16,GUIResetText1 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 12,5,15,GUIResetText1 + ret + +GUIResetText1 db 'RESET : ARE YOU SURE ?',0 +GUIResetText2 db 'YES',0 +GUIResetText3 db 'NO',0 + +DisplayGUIStates: + GUIDrawWindowBox 14,GUIStatesDisp + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + mov dl,224 + cmp byte[GUIWincoladd],0 + je .zero4 + inc dl +.zero4 + cmp byte[GUICStatePos],0 + je near .resetboxa + DrawGUIWinBox 14,79,29,117,42,dl + jmp .resetboxb +.resetboxa + DrawGUIWinBox 14,19,29,57,42,dl +.resetboxb + DrawGUIButton 14,20,30,56,41,GUIStatesText3,10,0,0 + DrawGUIButton 14,80,30,116,41,GUIStatesText4,11,0,0 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + cmp byte[GUIStatesText5],1 + je .load + GUIOuttextwin2 14,6,16,GUIStatesText1 + jmp .save +.load + GUIOuttextwin2 14,6,16,GUIStatesText2 +.save + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + cmp byte[GUIStatesText5],1 + je .load2 + GUIOuttextwin2 14,5,15,GUIStatesText1 + jmp .save2 +.load2 + GUIOuttextwin2 14,5,15,GUIStatesText2 +.save2 + ret + +GUIStatesText1 db 'OKAY TO SAVE STATE?',0 +GUIStatesText2 db 'OKAY TO LOAD STATE?',0 +GUIStatesText3 db 'YES',0 +GUIStatesText4 db 'NO',0 +GUIStatesText5 db 0 + +DisplayGUIChoseSave: + GUIDrawWindowBox 2,GUIStateSelDisp + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + mov byte[GUIChoseSaveText2],'0' + GUIOuttextwin2 2,21,31,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'1' + GUIOuttextwin2 2,41,31,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'2' + GUIOuttextwin2 2,61,31,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'3' + GUIOuttextwin2 2,81,31,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'4' + GUIOuttextwin2 2,101,31,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'5' + GUIOuttextwin2 2,21,46,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'6' + GUIOuttextwin2 2,41,46,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'7' + GUIOuttextwin2 2,61,46,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'8' + GUIOuttextwin2 2,81,46,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'9' + GUIOuttextwin2 2,101,46,GUIChoseSaveText2 + add byte[GUItextcolor],15 + mov byte[GUIChoseSaveText2],'0' + GUIOuttextwin2 2,20,30,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'1' + GUIOuttextwin2 2,40,30,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'2' + GUIOuttextwin2 2,60,30,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'3' + GUIOuttextwin2 2,80,30,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'4' + GUIOuttextwin2 2,100,30,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'5' + GUIOuttextwin2 2,20,45,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'6' + GUIOuttextwin2 2,40,45,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'7' + GUIOuttextwin2 2,60,45,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'8' + GUIOuttextwin2 2,80,45,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'9' + GUIOuttextwin2 2,100,45,GUIChoseSaveText2 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 2,6,16,GUIChoseSaveText1 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 2,5,15,GUIChoseSaveText1 + mov dword[GUITemp],GUIIconDataButtonHole + mov ebx,[statefileloc] + mov al,byte[fnamest+ebx] + mov [GUIChoseSaveText2],al + GUIDisplayButtonHole 2,10,28,byte[GUIChoseSaveText2],'T' + GUIDisplayButtonHole 2,30,28,byte[GUIChoseSaveText2],'1' + GUIDisplayButtonHole 2,50,28,byte[GUIChoseSaveText2],'2' + GUIDisplayButtonHole 2,70,28,byte[GUIChoseSaveText2],'3' + GUIDisplayButtonHole 2,90,28,byte[GUIChoseSaveText2],'4' + GUIDisplayButtonHole 2,10,43,byte[GUIChoseSaveText2],'5' + GUIDisplayButtonHole 2,30,43,byte[GUIChoseSaveText2],'6' + GUIDisplayButtonHole 2,50,43,byte[GUIChoseSaveText2],'7' + GUIDisplayButtonHole 2,70,43,byte[GUIChoseSaveText2],'8' + GUIDisplayButtonHole 2,90,43,byte[GUIChoseSaveText2],'9' + ret + +GUIChoseSaveText1 db 'SELECT SAVE SLOT :',0 +GUIChoseSaveText2 db '-',0 + +%macro DGOptnsDrawBox 3 + mov eax,dword[GUIwinposx+9*4] + mov ebx,dword[GUIwinposy+9*4] + add eax,%1 + add ebx,%2 + mov ecx,eax + add ecx,20 + mov dl,167 + mov esi,7 +%%loop + DrawGUILine + dec esi + jnz %%loop + mov eax,%3 + mov ebx,[ScanCodeListing+eax*3] + mov [GUIGameDisplayKy],ebx + mov byte[GUIGameDisplayKy+3],0 + mov byte[GUItextcolor],223 + GUIOuttextwin2 9,%1+3,%2+2,GUIGameDisplayKy + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je %%zero + mov byte[GUItextcolor],222 +%%zero + GUIOuttextwin2 9,%1+2,%2+1,GUIGameDisplayKy +%endmacro + +%macro DGOptnsDrawBox2 3 + mov eax,dword[GUIwinposx+3*4] + mov ebx,dword[GUIwinposy+3*4] + add eax,%1 + add ebx,%2 + mov ecx,eax + add ecx,20 + mov dl,167 + mov esi,7 +%%loop + DrawGUILine + dec esi + jnz %%loop + mov eax,%3 + mov ebx,[ScanCodeListing+eax*3] + mov [GUIGameDisplayKy],ebx + mov byte[GUIGameDisplayKy+3],0 + mov byte[GUItextcolor],223 + GUIOuttextwin2 3,%1+3,%2+2,GUIGameDisplayKy + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je %%zero + mov byte[GUItextcolor],222 +%%zero + GUIOuttextwin2 3,%1+2,%2+1,GUIGameDisplayKy +%endmacro + +%macro GUIInputDispKey 2 + mov eax,[edi] + mov [GUIInputTextQ],eax + push edi + DGOptnsDrawBox2 %1,%2,[GUIInputTextQ] + pop edi + add edi,4 +%endmacro + +DisplayGUIInput: + ; Player Select, Joystick/keyboard Type List, Button Assignments + GUIDrawWindowBox 3,GUIInputDisp + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + GUIOuttextwin2 3,6,102,GUIInputText3 + GUIOuttextwin2 3,6,112,GUIInputText4 + GUIOuttextwin2 3,6,122,GUIInputText5 + GUIOuttextwin2 3,6,132,GUIInputText6 + GUIOuttextwin2 3,6,142,GUIInputTextD + GUIOuttextwin2 3,6,152,GUIInputTextE + GUIOuttextwin2 3,76,102,GUIInputText7 + GUIOuttextwin2 3,76,112,GUIInputText8 + GUIOuttextwin2 3,76,122,GUIInputText9 + GUIOuttextwin2 3,76,132,GUIInputTextA + GUIOuttextwin2 3,76,142,GUIInputTextB + GUIOuttextwin2 3,76,152,GUIInputTextC + GUIOuttextwin2 3,20,167,GUIInputTextW + GUIOuttextwin2 3,156,102,GUIInputText7 + GUIOuttextwin2 3,156,112,GUIInputText8 + GUIOuttextwin2 3,116,102,GUIInputText9 + GUIOuttextwin2 3,116,112,GUIInputTextA + GUIOuttextwin2 3,153,137,GUIInputTextd + GUIOuttextwin2 3,153,147,GUIInputTexte + GUIOuttextwin2 3,113,137,GUIInputTextf + GUIOuttextwin2 3,113,147,GUIInputTextg + add byte[GUItextcolor],15 + GUIOuttextwin2 3,5,101,GUIInputText3 + GUIOuttextwin2 3,5,111,GUIInputText4 + GUIOuttextwin2 3,5,121,GUIInputText5 + GUIOuttextwin2 3,5,131,GUIInputText6 + GUIOuttextwin2 3,5,141,GUIInputTextD + GUIOuttextwin2 3,5,151,GUIInputTextE + GUIOuttextwin2 3,75,101,GUIInputText7 + GUIOuttextwin2 3,75,111,GUIInputText8 + GUIOuttextwin2 3,75,121,GUIInputText9 + GUIOuttextwin2 3,75,131,GUIInputTextA + GUIOuttextwin2 3,75,141,GUIInputTextB + GUIOuttextwin2 3,75,151,GUIInputTextC + GUIOuttextwin2 3,19,166,GUIInputTextW + GUIOuttextwin2 3,155,101,GUIInputText7 + GUIOuttextwin2 3,155,111,GUIInputText8 + GUIOuttextwin2 3,115,101,GUIInputText9 + GUIOuttextwin2 3,115,111,GUIInputTextA + GUIOuttextwin2 3,152,136,GUIInputTextd + GUIOuttextwin2 3,152,146,GUIInputTexte + GUIOuttextwin2 3,112,136,GUIInputTextf + GUIOuttextwin2 3,112,146,GUIInputTextg + mov dword[GUITemp],GUIIconDataCheckBoxUC + xor eax,eax + mov al,[cplayernum] + cmp byte[pl1p209+eax],0 + je .nocheckbox2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox2 + GUIDisplayIconWin 3,5,162,[GUITemp] + DrawGUIButton 3,125,34,155,45,GUIInputTextV,14,0,0 + cmp byte[OSPort],3 + je near .win32 + DrawGUIButton 3,125,50,185,61,GUIInputTexta,15,0,0 +.win32 + DrawGUIButton 3,125,66,179,77,GUIInputTexta2,15,0,0 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + mov al,[cplayernum] + add al,'1' + mov [GUIInputText1+8],al + GUIOuttextwin2 3,6,16,GUIInputText1 + GUIOuttextwin2 3,6,26,GUIInputText2 + GUIOuttextwin2 3,6,92,GUIInputTextP + GUIOuttextwin2 3,116,92,GUIInputTextb + GUIOuttextwin2 3,116,127,GUIInputTextc + xor eax,eax + mov al,[cplayernum] + mov ebx,[GUIInputRefP+eax*4] + mov al,[ebx] + mov al,[GUIInputRefB+eax] + mov ebx,eax + shl eax,4 + add eax,ebx + add eax,GUIInputNames + mov dword[GUITemp],eax + GUIOuttextwin2 3,7+24,83,[GUITemp] + GUIOuttextwin2 3,7,83,GUIInputTextT + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 3,5,15,GUIInputText1 + GUIOuttextwin2 3,5,25,GUIInputText2 + GUIOuttextwin2 3,5,91,GUIInputTextP + GUIOuttextwin2 3,115,91,GUIInputTextb + GUIOuttextwin2 3,115,126,GUIInputTextc + GUIOuttextwin2 3,6+24,82,[GUITemp] + GUIOuttextwin2 3,6,82,GUIInputTextT + DrawGUIWinBox 3,5,34,107,77,167 + mov ebx,[GUIcurrentinputcursloc] + sub ebx,[GUIcurrentinputviewloc] + mov eax,ebx + lea ebx,[ebx*8] + add ebx,36 + DrawGUIWinBox2 3,5,107,7,224 + mov edi,pl1selk + cmp byte[cplayernum],1 + jne .nopl2 + mov edi,pl2selk +.nopl2 + cmp byte[cplayernum],2 + jne .nopl3 + mov edi,pl3selk +.nopl3 + cmp byte[cplayernum],3 + jne .nopl4 + mov edi,pl4selk +.nopl4 + cmp byte[cplayernum],4 + jne .nopl5 + mov edi,pl5selk +.nopl5 + GUIInputDispKey 45,150 ; Select + GUIInputDispKey 45,140 ; Start + GUIInputDispKey 45,100 ; Up + GUIInputDispKey 45,110 ; Down + GUIInputDispKey 45,120 ; Left + GUIInputDispKey 45,130 ; Right + GUIInputDispKey 85,120 ; X + GUIInputDispKey 85,100 ; A + GUIInputDispKey 85,140 ; L + GUIInputDispKey 85,130 ; Y + GUIInputDispKey 85,110 ; B + GUIInputDispKey 85,150 ; R + mov edi,pl1Atk + cmp byte[cplayernum],1 + jne .nopl2t + mov edi,pl2Atk +.nopl2t + cmp byte[cplayernum],2 + jne .nopl3t + mov edi,pl3Atk +.nopl3t + cmp byte[cplayernum],3 + jne .nopl4t + mov edi,pl4Atk +.nopl4t + cmp byte[cplayernum],4 + jne .nopl5t + mov edi,pl5Atk +.nopl5t + GUIInputDispKey 165,100 ; A Turbo + GUIInputDispKey 165,110 ; B Turbo + GUIInputDispKey 125,100 ; X Turbo + GUIInputDispKey 125,110 ; Y Turbo + mov edi,pl1ULk + cmp byte[cplayernum],1 + jne .nopl2tb + mov edi,pl2ULk +.nopl2tb + cmp byte[cplayernum],2 + jne .nopl3tb + mov edi,pl3ULk +.nopl3tb + cmp byte[cplayernum],3 + jne .nopl4tb + mov edi,pl4ULk +.nopl4tb + cmp byte[cplayernum],4 + jne .nopl5tb + mov edi,pl5ULk +.nopl5tb + GUIInputDispKey 165,135 ; Up-Left + GUIInputDispKey 165,145 ; Up-Right + GUIInputDispKey 125,135 ; Down-Left + GUIInputDispKey 125,145 ; Down-Right + + mov byte[GUItextcolor],223 + mov eax,[GUIcurrentinputviewloc] + shl eax,4 + add eax,[GUIcurrentinputviewloc] + add eax,GUIInputNames + mov dword[GUITemp],eax + GUIOuttextwin2 3,11,38,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,11,38+8,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,11,38+8*2,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,11,38+8*3,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,11,38+8*4,[GUITemp] + + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero5 + mov byte[GUItextcolor],222 +.zero5 + mov eax,[GUIcurrentinputviewloc] + shl eax,4 + add eax,[GUIcurrentinputviewloc] + add eax,GUIInputNames + mov dword[GUITemp],eax + GUIOuttextwin2 3,10,37,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,10,37+8,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,10,37+8*2,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,10,37+8*3,[GUITemp] + add dword[GUITemp],17 + GUIOuttextwin2 3,10,37+8*4,[GUITemp] + + DrawSlideBarWin 3,109,42,[GUIcurrentinputviewloc],[NumInputDevices],5,28,GUIIStA + + cmp byte[GUICHold],9 + jne .noholda + add byte[GUIWincoladd],3 +.noholda + GUIDisplayIconWin 3,109,34,GUIIconDataUpArrow + cmp byte[GUICHold],9 + jne .noholda2 + sub byte[GUIWincoladd],3 +.noholda2 + cmp byte[GUICHold],10 + jne .noholdb + add byte[GUIWincoladd],3 +.noholdb + GUIDisplayIconWin 3,109,70,GUIIconDataDownArrow + cmp byte[GUICHold],10 + jne .noholdb2 + sub byte[GUIWincoladd],3 +.noholdb2 + + ; Draw border + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + mov dl,[GUIWincol] + DrawGUIWinBox 3,5,33,107,33,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 3,4,34,3,77,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 3,5,78,107,78,dl + ret + +GUIInputRefF db 0,1,2,3,5,18,6,7,8,9,10,11,14,15,16,17 +GUIInputRefB db 0,1,2,3,3,4,6,7,8,9,10,11,11,11,12,13,14,15,5 +GUIInputRefP dd pl1contrl,pl2contrl,pl3contrl,pl4contrl,pl5contrl +GUIInputText1 db 'PLAYER # CONTROL :',0 +GUIInputText2 db 'DEVICE :',0 +GUIInputText3 db ' UP',0 +GUIInputText4 db ' DOWN',0 +GUIInputText5 db ' LEFT',0 +GUIInputText6 db ' RIGHT',0 +GUIInputText7 db 'A',0 +GUIInputText8 db 'B',0 +GUIInputText9 db 'X',0 +GUIInputTextA db 'Y',0 +GUIInputTextB db 'L',0 +GUIInputTextC db 'R',0 +GUIInputTextD db ' START',0 +GUIInputTextE db 'SELECT',0 +GUIInputTextP db 'KEYS :',0 +GUIInputTextQ dd 0 +GUIInputTextT db 'CDV:',0 +GUIInputTextV db 'SET',0 +GUIInputTextW db 'USE JOYSTICK PORT 209H',0 +GUIInputTexta db 'CALIBRATE',0 +GUIInputTexta2 db 'SET KEYS',0 +GUIInputTextb db 'TURBO :',0 +GUIInputTextc db 'DIAGONALS :',0 +GUIInputTextd db 'UL',0 +GUIInputTexte db 'UR',0 +GUIInputTextf db 'DL',0 +GUIInputTextg db 'DR',0 +GUIIStA dd 0,0,0 + +GUIcurrentinputviewloc dd 0 +GUIcurrentinputcursloc dd 0 + +DisplayGUIOption: + ; Frame Rate/Auto Frame Rate/Max Frame Skip/New Gfx Engine/Save Confirm + GUIDrawWindowBox 4,GUIOptionDisp + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + mov dword[GUITemp],GUIOptionText1 + cmp byte[frameskip],0 + jne .noauto + mov dword[GUITemp],GUIOptionText3 +.noauto + GUIOuttextwin2 4,6,16,[GUITemp] + GUIOuttextwin2u 4,26,31,GUIOptionText2,0 + GUIOuttextwin2u 4,26,41,GUIOptionText4,0 + cmp byte[OSPort],3 + je near .win32b + GUIOuttextwin2u 4,26,51,GUIOptionText5,0 +.win32b + GUIOuttextwin2u 4,26,61,GUIOptionText6,0 + GUIOuttextwin2u 4,26,71,GUIOptionText7,0 + cmp byte[OSPort],3 + je near .win32b2 + GUIOuttextwin2u 4,26,81,GUIOptionTextA,0 +.win32b2 + GUIOuttextwin2u 4,26,91,GUIOptionTextB,1 + GUIOuttextwin2u 4,26,101,GUIOptionTextC,2 + GUIOuttextwin2 4,26,111,GUIOptionTextD + GUIOuttextwin2 4,26,121,GUIOptionTextE + GUIOuttextwin2 4,26,131,GUIOptionTextF + GUIOuttextwin2 4,26,141,GUIOptionTextG + GUIOuttextwin2 4,26,151,GUIOptionTextH + GUIOuttextwin2 4,26,161,GUIOptionTextI + GUIOuttextwin2 4,26,171,GUIOptionTextJ + GUIOuttextwin2 4,26,181,GUIOptionTextK + GUIOuttextwin2 4,26,191,GUIOptionTextL + add byte[GUItextcolor],15 + GUIOuttextwin2 4,5,15,[GUITemp] + GUIOuttextwin2 4,25,30,GUIOptionText2 + GUIOuttextwin2 4,25,40,GUIOptionText4 + cmp byte[OSPort],3 + je near .win32c + GUIOuttextwin2 4,25,50,GUIOptionText5 +.win32c + GUIOuttextwin2 4,25,60,GUIOptionText6 + GUIOuttextwin2 4,25,70,GUIOptionText7 + cmp byte[OSPort],3 + je near .win32c2 + GUIOuttextwin2 4,25,80,GUIOptionTextA +.win32c2 + GUIOuttextwin2 4,25,90,GUIOptionTextB + GUIOuttextwin2 4,25,100,GUIOptionTextC + GUIOuttextwin2 4,25,120,GUIOptionTextE + GUIOuttextwin2 4,25,110,GUIOptionTextD + GUIOuttextwin2 4,25,130,GUIOptionTextF + GUIOuttextwin2 4,25,140,GUIOptionTextG + GUIOuttextwin2 4,25,150,GUIOptionTextH + GUIOuttextwin2 4,25,160,GUIOptionTextI + GUIOuttextwin2 4,25,170,GUIOptionTextJ + GUIOuttextwin2 4,25,180,GUIOptionTextK + GUIOuttextwin2 4,25,190,GUIOptionTextL + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[TimerEnable],0 + je .nocheckboxt + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxt + GUIDisplayIconWin 4,11,106,[GUITemp] +.nocheckboxtb + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[frameskip],0 + jne .nocheckbox + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox + GUIDisplayIconWin 4,11,26,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[newengen],0 + je .nocheckbox1 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox1 + GUIDisplayIconWin 4,11,36,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[vsyncon],0 + je .nocheckbox2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox2 + cmp byte[OSPort],3 + je near .win32 + GUIDisplayIconWin 4,11,46,[GUITemp] +.win32 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[FPUCopy],2 + jne .nocheckbox3 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox3 + GUIDisplayIconWin 4,11,56,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[pl12s34],0 + je .nocheckbox4 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox4 + GUIDisplayIconWin 4,11,66,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[SidewinderFix],0 + je .nocheckbox5 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox5 + cmp byte[OSPort],3 + je near .win322 + GUIDisplayIconWin 4,11,76,[GUITemp] +.win322 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[FPSAtStart],0 + je .nocheckbox6 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox6 + GUIDisplayIconWin 4,11,86,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[Turbo30hz],0 + je .nocheckbox7 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox7 + GUIDisplayIconWin 4,11,96,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[FastFwdToggle],0 + je .nocheckbox8 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox8 + GUIDisplayIconWin 4,11,116,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[SRAMSave5Sec],0 + je .nocheckbox9 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox9 + GUIDisplayIconWin 4,11,126,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[OldGfxMode2],0 + je .nocheckbox10 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox10 + GUIDisplayIconWin 4,11,136,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[LatestSave],0 + je .nocheckbox11 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox11 + GUIDisplayIconWin 4,11,146,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[AutoState],0 + je .nocheckbox12 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox12 + GUIDisplayIconWin 4,11,156,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[DontSavePath],0 + je .nocheckbox13 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox13 + GUIDisplayIconWin 4,11,166,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[SPCDisable],0 + je .nocheckbox14 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox14 + GUIDisplayIconWin 4,11,176,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[GUIEnableTransp],0 + je .nocheckbox15 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox15 + GUIDisplayIconWin 4,11,186,[GUITemp] + cmp byte[frameskip],0 + je near .auto + DrawGUIWinBox 4,75,13,93,21,167 + mov al,[frameskip] + add al,47 + mov [GUIOptionText8],al + mov byte[GUItextcolor],223 + GUIOuttextwin2 4,85,16,GUIOptionText8 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + GUIOuttextwin2 4,84,15,GUIOptionText8 + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero6 + mov byte[GUItextcolor],211 +.zero6 + DrawGUIButton 4,97,12,105,22,GUIOptionText9,12,-2,0 + DrawGUIButton 4,108,12,116,22,GUIOptionText10,13,-2,0 + ret +.auto + DrawGUIWinBox 4,96,13,114,21,167 + mov al,[maxskip] + add al,48 + mov [GUIOptionText8],al + mov byte[GUItextcolor],223 + GUIOuttextwin2 4,107,16,GUIOptionText8 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero5 + mov byte[GUItextcolor],222 +.zero5 + GUIOuttextwin2 4,106,15,GUIOptionText8 + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero7 + mov byte[GUItextcolor],211 +.zero7 + DrawGUIButton 4,118,12,126,22,GUIOptionText9,12,-2,0 + DrawGUIButton 4,129,12,137,22,GUIOptionText10,13,-2,0 + ret + +GUIOptionText1 db 'FRAME RATE',0 +GUIOptionText2 db 'AUTO FRAME RATE',0 +GUIOptionText3 db 'MAX FRAME SKIP',0 +GUIOptionText4 db 'NEW GFX ENGINE',0 +GUIOptionText5 db 'VSYNC',0 +GUIOptionText6 db 'MMX SUPPORT',0 +GUIOptionText7 db 'USE PL3/4 AS PL1/2',0 +GUIOptionTextA db 'SIDEWINDER FIX',0 +GUIOptionTextB db 'FPS AT START',0 +GUIOptionTextC db 'USE 30HZ FOR TURBO',0 +GUIOptionTextD db 'ENABLE GAME CLOCK',0 +GUIOptionTextE db 'TOGGLED FAST FWD',0 +GUIOptionTextF db 'SRAM CHECK+SAVE',0 +GUIOptionTextG db 'OLD GFX MODE 2',0 +GUIOptionTextH db 'START AT LATEST SAVE',0 +GUIOptionTextI db 'AUTO STATE SAVE/LOAD',0 +GUIOptionTextJ db 'DON',39,'T SAVE CURRENT PATH',0 +GUIOptionTextK db 'DISABLE SOUND CPU EMU',0 +GUIOptionTextL db 'TRANSPARENT MESSAGES',0 +GUIOptionText8 db '-',0 +GUIOptionText9 db '+',0 +GUIOptionText10 db '-',0 + +DisplayGUIVideo: + cmp byte[TripBufAvail],0 + jne .notexttb + mov byte[Triplebufen],0 +.notexttb + cmp byte[FPUCopy],2 + jne .2xSaIdis + cmp byte[newgfx16b],0 + je .2xSaIdis + jmp .no2xSaIdis +.2xSaIdis + mov byte[En2xSaI],0 +.no2xSaIdis + cmp byte[En2xSaI],0 + je .no2xsaidis + mov byte[Triplebufen],0 +.no2xsaidis + cmp byte[En2xSaI],0 + je .no2xsaien + mov byte[scanlines],0 + mov byte[antienab],0 +.no2xsaien + ; Video Modes List/Scanlines/Interpolation/Full(Small) Screen + GUIDrawWindowBox 5,GUIVideoDisp + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + + cmp byte[OSPort],3 + jne near .nowin32pt2 + GUIOuttextwin2 5,12,76,GUIVideoTextw0 + GUIOuttextwin2 5,12,86,GUIVideoTextw1 + GUIOuttextwin2 5,12,96,GUIVideoTextw2 + GUIOuttextwin2 5,12,106,GUIVideoTextw3 +.nowin32pt2 + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUISLVID+eax],0 + je .notext2 + GUIOuttextwin2 5,26,108,GUIVideoText2 +.notext2 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIHSVID+eax],0 + je near .notexta + GUIOuttextwin2 5,26,118,GUIVideoTextb + GUIOuttextwin2 5,26,128,GUIVideoTexta +.notexta + xor eax,eax + mov al,[cvidmode] + cmp byte[GUI2xVID+eax],0 + je near .notextb + GUIOuttextwin2 5,26,138,GUIVideoTextc + GUIOuttextwin2 5,26,148,GUIVideoTextd + GUIOuttextwin2 5,26,158,GUIVideoTextd2 +.notextb + xor eax,eax + mov al,[cvidmode] + cmp byte[GUII2VID+eax],0 + je near .notextb2 + GUIOuttextwin2 5,26,168,GUIVideoText3 +.notextb2 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIINVID+eax],0 + je .notext3 + GUIOuttextwin2 5,26,78,GUIVideoText3 +.notext3 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIEAVID+eax],0 + je .notext4 + GUIOuttextwin2 5,26,78,GUIVideoText4 +.notext4 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIFSVID+eax],0 + je .notext5 + GUIOuttextwin2 5,26,88,GUIVideoText5 +.notext5 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUISSVID+eax],0 + je .notext6 + GUIOuttextwin2 5,26,98,GUIVideoText6 +.notext6 + xor eax,eax + mov al,[cvidmode] + cmp byte[TripBufAvail],0 + je near .notext7 + cmp byte[GUITBVID+eax],0 + je .notext7 + GUIOuttextwin2 5,26,168,GUIVideoText7 +.notext7 + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIM7VID+eax],0 + je .notext8 + cmp byte[newengen],0 + je .notext8 + GUIOuttextwin2 5,26,178,GUIVideoText8b +.notext8 + + add byte[GUItextcolor],15 + + cmp byte[OSPort],3 + jne near .nowin32pt + GUIOuttextwin2 5,11,75,GUIVideoTextw0 + GUIOuttextwin2 5,11,85,GUIVideoTextw1 + GUIOuttextwin2 5,11,95,GUIVideoTextw2 + GUIOuttextwin2 5,11,105,GUIVideoTextw3 +.nowin32pt + xor eax,eax + mov al,[cvidmode] + cmp byte[GUISLVID+eax],0 + je .notext2b + GUIOuttextwin2 5,25,107,GUIVideoText2 +.notext2b + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIHSVID+eax],0 + je near .notextab + GUIOuttextwin2 5,25,117,GUIVideoTextb + GUIOuttextwin2 5,25,127,GUIVideoTexta +.notextab + xor eax,eax + mov al,[cvidmode] + cmp byte[GUI2xVID+eax],0 + je near .notextbb + GUIOuttextwin2 5,25,137,GUIVideoTextc + GUIOuttextwin2 5,25,147,GUIVideoTextd + GUIOuttextwin2 5,25,157,GUIVideoTextd2 +.notextbb + xor eax,eax + mov al,[cvidmode] + cmp byte[GUII2VID+eax],0 + je near .notextb2b + GUIOuttextwin2 5,25,167,GUIVideoText3 +.notextb2b + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIINVID+eax],0 + je .notext3b + GUIOuttextwin2 5,25,77,GUIVideoText3 +.notext3b + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIEAVID+eax],0 + je .notext4b + GUIOuttextwin2 5,25,77,GUIVideoText4 +.notext4b + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIFSVID+eax],0 + je .notext5b + GUIOuttextwin2 5,25,87,GUIVideoText5 +.notext5b + xor eax,eax + mov al,[cvidmode] + cmp byte[GUISSVID+eax],0 + je .notext6b + GUIOuttextwin2 5,25,97,GUIVideoText6 +.notext6b + xor eax,eax + mov al,[cvidmode] + cmp byte[TripBufAvail],0 + je near .notext7b + cmp byte[GUITBVID+eax],0 + je .notext7b + GUIOuttextwin2 5,25,167,GUIVideoText7 +.notext7b + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIM7VID+eax],0 + je .notext8b + cmp byte[newengen],0 + je .notext8b + GUIOuttextwin2 5,25,177,GUIVideoText8b +.notext8b + DrawGUIButton 5,128,60,164,71,GUIVideoText8,4,0,0 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 5,6,16,GUIVideoText1 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 5,5,15,GUIVideoText1 + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUISLVID+eax],0 + je .nocheckboxb + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[scanlines],1 + jne .nocheckbox + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox + GUIDisplayIconWin 5,11,103,[GUITemp] +.nocheckboxb + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIHSVID+eax],0 + je near .nocheckboxw + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[scanlines],3 + jne .nocheckboxv + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxv + GUIDisplayIconWin 5,11,113,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[scanlines],2 + jne .nocheckboxv2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxv2 + GUIDisplayIconWin 5,11,123,[GUITemp] +.nocheckboxw + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUI2xVID+eax],0 + je near .nocheckboxx + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[En2xSaI],1 + jne .nocheckboxx2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxx2 + GUIDisplayIconWin 5,11,133,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[En2xSaI],2 + jne .nocheckboxx3 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxx3 + GUIDisplayIconWin 5,11,143,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[En2xSaI],3 + jne .nocheckboxx4 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxx4 + GUIDisplayIconWin 5,11,153,[GUITemp] +.nocheckboxx + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUII2VID+eax],0 + je near .nocheckboxi2 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[antienab],0 + je .nocheckbox1i2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox1i2 + GUIDisplayIconWin 5,11,163,[GUITemp] +.nocheckboxi2 + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUITBVID+eax],0 + je .nocheckboxtbb + cmp byte[TripBufAvail],0 + je near .nocheckboxtbb + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[Triplebufen],1 + jne .nocheckboxtb + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckboxtb + GUIDisplayIconWin 5,11,163,[GUITemp] +.nocheckboxtbb + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIM7VID+eax],0 + je near .nocheckboxm72 + cmp byte[newengen],0 + je near .nocheckboxm72 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[Mode7HiRes16b],0 + je .nocheckbox1m72 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox1m72 + GUIDisplayIconWin 5,11,173,[GUITemp] +.nocheckboxm72 + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIIEVID+eax],0 + je .nocheckbox1b + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[antienab],0 + je .nocheckbox1 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox1 + GUIDisplayIconWin 5,11,73,[GUITemp] +.nocheckbox1b + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUIFSVID+eax],0 + je .nocheckbox2b + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[ScreenScale],0 + je .nocheckbox2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox2 + GUIDisplayIconWin 5,11,83,[GUITemp] +.nocheckbox2b + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUISSVID+eax],0 + je .nocheckbox3b + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[smallscreenon],0 + je .nocheckbox3 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox3 + GUIDisplayIconWin 5,11,93,[GUITemp] +.nocheckbox3b + + DrawGUIWinBox 5,5,26,115,69,167 + DrawSlideBarWin 5,117,34,[GUIcurrentvideoviewloc],[NumVideoModes],5,28,GUIVStA + cmp byte[GUICHold],5 + jne .noholda + add byte[GUIWincoladd],3 +.noholda + GUIDisplayIconWin 5,117,26,GUIIconDataUpArrow + cmp byte[GUICHold],5 + jne .noholdb + sub byte[GUIWincoladd],3 +.noholdb + cmp byte[GUICHold],6 + jne .noholdc + add byte[GUIWincoladd],3 +.noholdc + GUIDisplayIconWin 5,117,62,GUIIconDataDownArrow + cmp byte[GUICHold],6 + jne .noholdd + sub byte[GUIWincoladd],3 +.noholdd + + mov ebx,[GUIcurrentvideocursloc] + sub ebx,[GUIcurrentvideoviewloc] + lea ebx,[ebx*8] + add ebx,28 + DrawGUIWinBox2 5,5,115,7,224 + + mov byte[GUItextcolor],223 + mov eax,[GUIcurrentvideoviewloc] + mov ebx,eax + shl eax,4 + add eax,ebx + add eax,ebx + add eax,GUIVideoModeNames + mov dword[GUITemp],eax + GUIOuttextwin2 5,11,30,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,11,30+8,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,11,30+8*2,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,11,30+8*3,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,11,30+8*4,[GUITemp] + + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero5 + mov byte[GUItextcolor],222 +.zero5 + mov eax,[GUIcurrentvideoviewloc] + mov ebx,eax + shl eax,4 + add eax,ebx + add eax,ebx + add eax,GUIVideoModeNames + mov dword[GUITemp],eax + GUIOuttextwin2 5,10,29,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,10,29+8,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,10,29+8*2,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,10,29+8*3,[GUITemp] + add dword[GUITemp],18 + GUIOuttextwin2 5,10,29+8*4,[GUITemp] + + ; Draw border + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + mov dl,[GUIWincol] + DrawGUIWinBox 5,5,25,115,25,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 5,4,26,3,69,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 5,5,70,115,70,dl + xor eax,eax + mov al,[cvidmode] + mov ebx,eax + shl eax,4 + add eax,ebx + add eax,ebx + add eax,GUIVideoModeNames + mov dword[GUITemp],eax + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 5,7,189,GUIVideoTextH + GUIOuttextwin2 5,49,189,[GUITemp] + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero6 + mov byte[GUItextcolor],164 +.zero6 + GUIOuttextwin2 5,6,188,GUIVideoTextH + GUIOuttextwin2 5,48,188,[GUITemp] + ret + +GUIVideoText1 db 'VIDEO MODES :',0 +GUIVideoText2 db 'FULL SCANLINES',0 +GUIVideoTexta db '25% SCANLINES',0 +GUIVideoTextb db '50% SCANLINES',0 +GUIVideoTextc db '2XSAI ENGINE',0 +GUIVideoTextd db 'SUPER EAGLE ENGINE',0 +GUIVideoTextd2 db 'SUPER 2XSAI ENGINE',0 +GUIVideoText3 db 'INTERPOLATION',0 ; -y +GUIVideoText4 db 'EAGLE ENGINE',0 ; -y +GUIVideoText5 db 'FULL SCREEN',0 ; -c +GUIVideoText6 db 'SMALL SCREEN',0 ; -c +GUIVideoText7 db 'TRIPLE BUFFERING',0 ; -c +GUIVideoText8b db 'HI-RESOLUTION MODE7',0 ; -c +GUIVideoText8 db 'SET',0 ; set button +GUIVideoTextH db 'MODE : ',0 +GUIVideoTextw0 db 'LEGEND:',0 +GUIVideoTextw1 db ' S = SCALED TO FIT SCREEN',0 +GUIVideoTextw2 db ' R = MATCHED SCREEN RATIO',0 +GUIVideoTextw3 db ' D = ALLOW 2XSAI,HIRES,ETC',0 +GUIVStA dd 0,0,0 + +GUIcurrentvideoviewloc dd 0 +GUIcurrentvideocursloc dd 0 + + +DisplayGUISound: + ; Enable Sound/Sampling Rate/Stereo/Sound Buffering/Volume + GUIDrawWindowBox 6,GUISoundDisp + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + ; E = Enable Sound, S = Stereo Sound, B = Sound Buffering + ; R = Sample Rate + GUIOuttextwin2u 6,26,26,GUISoundText1,0 + GUIOuttextwin2u 6,26,35,GUISoundText3,0 + cmp byte[OSPort],3 + je near .win32b + GUIOuttextwin2 6,26,44,GUISoundText2b +.win32b + GUIOuttextwin2u 6,26,106,GUISoundText4,8 + GUIOuttextwin2u 6,26,116,GUISoundTextH,2 + cmp byte[OSPort],3 + je near .win32s2 + GUIOuttextwin2 6,26,126,GUISoundTextI +.win32s2 + GUIOuttextwin2 6,26,136,GUISoundTextJ + GUIOuttextwin2 6,26,146,GUISoundTextK + GUIOuttextwin2 6,26,156,GUISoundTextL + add byte[GUItextcolor],15 + GUIOuttextwin2 6,25,25,GUISoundText1 + GUIOuttextwin2 6,25,34,GUISoundText3 + cmp byte[OSPort],3 + je near .win32c + GUIOuttextwin2 6,25,43,GUISoundText2b +.win32c + GUIOuttextwin2 6,25,105,GUISoundText4 + GUIOuttextwin2 6,25,115,GUISoundTextH + cmp byte[OSPort],3 + je near .win32s + GUIOuttextwin2 6,25,125,GUISoundTextI +.win32s + GUIOuttextwin2 6,25,135,GUISoundTextJ + GUIOuttextwin2 6,25,145,GUISoundTextK + GUIOuttextwin2 6,25,155,GUISoundTextL + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 6,6,16,GUISoundText6 + GUIOuttextwin2u 6,6,53,GUISoundText2,9 + GUIOuttextwin2 6,6,76,GUISoundText5 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 6,5,15,GUISoundText6 + GUIOuttextwin2 6,5,52,GUISoundText2 + GUIOuttextwin2 6,5,75,GUISoundText5 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[cfgsoundon],0 + je .nocheckbox + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox + GUIDisplayIconWin 6,11,21,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[cfgStereoSound],0 + je .nocheckbox1 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox1 + GUIDisplayIconWin 6,11,30,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[RaisePitch],0 + je .nocheckbox1b + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox1b + cmp byte[OSPort],3 + je near .win32 + GUIDisplayIconWin 6,11,39,[GUITemp] +.win32 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[SoundNoiseDis],0 + je .nocheckbox2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox2 + GUIDisplayIconWin 6,11,101,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[RevStereo],0 + je .nocheckbox3 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox3 + GUIDisplayIconWin 6,11,111,[GUITemp] + cmp byte[OSPort],3 + je near .nocheckbox42 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[Surround],0 + je .nocheckbox4 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox4 + GUIDisplayIconWin 6,11,121,[GUITemp] +.nocheckbox42 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[InterSound],0 + je .nocheckbox5 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox5 + GUIDisplayIconWin 6,11,131,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[LowPassFilter],0 + je .nocheckbox6 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox6 + GUIDisplayIconWin 6,11,141,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[SoundBufEn],0 + je .nocheckbox7 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox7 + GUIDisplayIconWin 6,11,151,[GUITemp] + DrawGUIWinBox 6,15,61,69,69,167 + mov dword[GUITemp],GUISoundText7 + xor eax,eax + mov al,[cfgSoundQuality] + shl eax,3 + add [GUITemp],eax + mov byte[GUItextcolor],223 + GUIOuttextwin2 6,23,64,[GUITemp] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + GUIOuttextwin2 6,22,63,[GUITemp] + + mov eax,dword[GUIwinposx+6*4] + mov ebx,dword[GUIwinposy+6*4] + mov ecx,eax + add eax,15 + add ecx,15+100 + add ebx,91 + xor edx,edx + mov dl,215 + sub dl,[GUIWincoladd] + DrawGUILine + inc ecx + inc eax + sub dl,13 + DrawGUILine + + xor eax,eax + mov al,[MusicRelVol] + mov dword[GUITemp],11 + add [GUITemp],eax + GUIDisplayIconWin 6,[GUITemp],87,GUIIconDataSlideBar + mov dword[GUISoundTextD],' ' + mov byte[GUISoundTextD+3],'%' + mov esi,GUISoundTextD+2 + xor eax,eax + mov al,[MusicRelVol] + mov ebx,10 + div bl + add ah,48 + mov [esi],ah + cmp al,0 + je .nomore + dec esi + xor ah,ah + div bl + add ah,48 + mov [esi],ah + cmp al,0 + je .nomore + dec esi + xor ah,ah + div bl + add ah,48 + mov [esi],ah +.nomore + mov [GUITemp],esi + mov byte[GUItextcolor],223 + GUIOuttextwin2 6,119,89,[GUITemp] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero5 + mov byte[GUItextcolor],222 +.zero5 + GUIOuttextwin2 6,118,88,[GUITemp] + ret + +GUISoundText1 db 'ENABLE SOUND',0 +GUISoundText2 db 'SAMPLING RATE :',0 +GUISoundText2b db 'RAISE PITCH LEVEL',0 +GUISoundText3 db 'STEREO SOUND',0 +GUISoundText4 db 'DISABLE NOISE SIM.',0 +GUISoundText5 db 'VOLUME LEVEL :',0 +GUISoundText6 db 'SOUND SWITCHES :',0 +GUISoundText7 db ' 8000HZ',0 +GUISoundText8 db '11025HZ',0 +GUISoundText9 db '22050HZ',0 +GUISoundTextA db '44100HZ',0 +GUISoundTextB db '16000HZ',0 +GUISoundTextC db '32000HZ',0 +GUISoundTextCb db '48000HZ',0 +GUISoundTextD db '---%',0 +GUISoundTextH db 'REVERSE STEREO',0 +GUISoundTextI db 'SURROUND SOUND',0 +GUISoundTextJ db 'SOUND INTERPOLATION',0 +GUISoundTextK db 'LOW PASS FILTER',0 +GUISoundTextL db 'SOUND BUFFERING',0 + +DisplayGUICheatConv: + mov eax,[ccheatnpos] + add eax,4 + xor ebx,ebx + mov ecx,3 + mov edx,GUICheatTextB +.loop + mov bl,[eax] + and bl,0Fh + mov bl,[GUICheatTextC+ebx] + mov [edx+1],bl + mov bl,[eax] + and bl,0F0h + shr bl,4 + mov bl,[GUICheatTextC+ebx] + mov [edx],bl + add edx,2 + dec eax + loop .loop + mov eax,[ccheatnpos] + inc eax + mov edx,GUICheatTextB+7 + mov bl,[eax] + and bl,0Fh + mov bl,[GUICheatTextC+ebx] + mov [edx+1],bl + mov bl,[eax] + and bl,0F0h + shr bl,4 + mov bl,[GUICheatTextC+ebx] + mov [edx],bl + mov eax,[ccheatnpos] + add eax,5 + mov edx,GUICheatTextB+10 + mov bl,[eax] + and bl,0Fh + mov bl,[GUICheatTextC+ebx] + mov [edx+1],bl + mov bl,[eax] + and bl,0F0h + shr bl,4 + mov bl,[GUICheatTextC+ebx] + mov [edx],bl + mov eax,[ccheatnpos] + test byte[eax-28],80h + jnz .src + test byte[eax],04h + jz .on + mov byte[GUICheatTextB+13],'O' + mov byte[GUICheatTextB+14],'F' + mov byte[GUICheatTextB+15],'F' + jmp .off +.on + test byte[eax],80h + jnz .repl + mov byte[GUICheatTextB+13],'O' + mov byte[GUICheatTextB+14],'N' + mov byte[GUICheatTextB+15],' ' + jmp .off +.repl + mov byte[GUICheatTextB+13],'R' + mov byte[GUICheatTextB+14],'P' + mov byte[GUICheatTextB+15],'L' + jmp .off +.src + mov byte[GUICheatTextB+13],'S' + mov byte[GUICheatTextB+14],'R' + mov byte[GUICheatTextB+15],'C' +.off + mov ecx,20 + add eax,8 + mov edx,GUICheatTextB+17 +.loop2 + mov bl,[eax] + mov [edx],bl + inc eax + inc edx + loop .loop2 + ret + +%macro GUIOuttextwin2cheat 2 + test dword[ccheatnleft],80000000h + jnz %%skip + call DisplayGUICheatConv + GUIOuttextwin2 7,%1,%2,GUICheatTextB + add dword[ccheatnpos],28 + dec dword[ccheatnleft] +%%skip +%endmacro + +DisplayGUICheat: + GUIDrawWindowBox 7,GUICheatDisp + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + GUIOuttextwin2 7,6,132,GUICheatText1 + GUIOuttextwin2 7,6,143,GUICheatText2 + GUIOuttextwin2 7,6,13,GUICheatText3 + GUIOuttextwin2 7,11,154,GUICheatTextD + GUIOuttextwin2 7,11,164,GUICheatTextE + GUIOuttextwin2 7,11,172,GUICheatTextF + GUIOuttextwin2 7,11,180,GUICheatTextG + GUIOuttextwin2 7,26,191,GUICheatTextJ + add byte[GUItextcolor],15 + GUIOuttextwin2 7,5,131,GUICheatText1 + GUIOuttextwin2 7,5,142,GUICheatText2 + GUIOuttextwin2 7,5,12,GUICheatText3 + GUIOuttextwin2 7,10,153,GUICheatTextD + GUIOuttextwin2 7,10,163,GUICheatTextE + GUIOuttextwin2 7,10,171,GUICheatTextF + GUIOuttextwin2 7,10,179,GUICheatTextG + GUIOuttextwin2 7,25,190,GUICheatTextJ + DrawGUIWinBox 7,5,20,229,108,167 + + DrawGUIButton 7,5,113,47,124,GUICheatText4,5,0,0 + DrawGUIButton 7,52,113,94,124,GUICheatText5,6,0,0 + DrawGUIButton 7,99,113,141,124,GUICheatText7,7,0,0 + DrawGUIButton 7,146,113,188,124,GUICheatText8,8,0,0 + DrawGUIButton 7,212,134,236,145,GUICheatText6,9,0,0 + DrawGUIButton 7,193,113,235,124,GUICheatTextI,33,0,0 + + cmp dword[GUIcurrentcheatwin],0 + jne near .nowinbox + mov ebx,[GUIcurrentcheatcursloc] + sub ebx,[GUIcurrentcheatviewloc] + mov eax,ebx + lea ebx,[ebx*8] + sub ebx,eax + add ebx,22 + DrawGUIWinBox2 7,5,229,7,224 +.nowinbox + + mov byte[GUItextcolor],223 + mov dword[ccheatnpos],cheatdata + mov eax,[NumCheats] + sub eax,[GUIcurrentcheatviewloc] + dec eax + mov dword[ccheatnleft],eax + mov eax,[GUIcurrentcheatviewloc] + mov ebx,eax + shl eax,5 + sub eax,ebx + sub eax,ebx + sub eax,ebx + sub eax,ebx + add [ccheatnpos],eax + GUIOuttextwin2cheat 12,24 + GUIOuttextwin2cheat 12,24+7 + GUIOuttextwin2cheat 12,24+7*2 + GUIOuttextwin2cheat 12,24+7*3 + GUIOuttextwin2cheat 12,24+7*4 + GUIOuttextwin2cheat 12,24+7*5 + GUIOuttextwin2cheat 12,24+7*6 + GUIOuttextwin2cheat 12,24+7*7 + GUIOuttextwin2cheat 12,24+7*8 + GUIOuttextwin2cheat 12,24+7*9 + GUIOuttextwin2cheat 12,24+7*10 + GUIOuttextwin2cheat 12,24+7*11 + + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + mov dword[ccheatnpos],cheatdata + mov eax,[NumCheats] + sub eax,[GUIcurrentcheatviewloc] + dec eax + mov dword[ccheatnleft],eax + mov eax,[GUIcurrentcheatviewloc] + mov ebx,eax + shl eax,5 + sub eax,ebx + sub eax,ebx + sub eax,ebx + sub eax,ebx + add [ccheatnpos],eax + GUIOuttextwin2cheat 11,23 + GUIOuttextwin2cheat 11,23+7 + GUIOuttextwin2cheat 11,23+7*2 + GUIOuttextwin2cheat 11,23+7*3 + GUIOuttextwin2cheat 11,23+7*4 + GUIOuttextwin2cheat 11,23+7*5 + GUIOuttextwin2cheat 11,23+7*6 + GUIOuttextwin2cheat 11,23+7*7 + GUIOuttextwin2cheat 11,23+7*8 + GUIOuttextwin2cheat 11,23+7*9 + GUIOuttextwin2cheat 11,23+7*10 + GUIOuttextwin2cheat 11,23+7*11 + + DrawSlideBarWin 7,231,28,[GUIcurrentcheatviewloc],[NumCheats],12,73,GUICStA + cmp byte[GUICHold],7 + jne .noholda + add byte[GUIWincoladd],3 +.noholda + GUIDisplayIconWin 7,231,20,GUIIconDataUpArrow + cmp byte[GUICHold],7 + jne .noholda2 + sub byte[GUIWincoladd],3 +.noholda2 + cmp byte[GUICHold],8 + jne .noholdb + add byte[GUIWincoladd],3 +.noholdb + GUIDisplayIconWin 7,231,101,GUIIconDataDownArrow + cmp byte[GUICHold],8 + jne .noholdb2 + sub byte[GUIWincoladd],3 +.noholdb2 + + ; Draw border + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + mov dl,[GUIWincol] + DrawGUIWinBox 7,5,19,229,19,dl + DrawGUIWinBox 7,82,128,172,128,dl + DrawGUIWinBox 7,82,139,196,139,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 7,4,20,3,108,dl + DrawGUIWinBox 7,81,129,80,136,dl + DrawGUIWinBox 7,81,140,80,147,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 7,5,109,229,109,dl + DrawGUIWinBox 7,82,137,172,137,dl + DrawGUIWinBox 7,82,148,196,148,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 7,174,129,173,136,dl + DrawGUIWinBox 7,156,140,197,147,dl + + ; Draw boxes + mov ebx,[GUIcurrentcheatcursloc] + sub ebx,[GUIcurrentcheatviewloc] + mov eax,ebx + lea ebx,[ebx*4] + add ebx,eax + add ebx,eax + add ebx,eax + add ebx,22 + mov dl,167 + cmp dword[GUIcurrentcheatwin],1 + jne .notopibox + mov dl,226 + cmp byte[GUIWincoladd],0 + je .nocoladd + inc dl +.nocoladd +.notopibox + DrawGUIWinBox 7,82,129,172,136,dl + mov dl,167 + cmp dword[GUIcurrentcheatwin],2 + jne .nobotibox + mov dl,226 + cmp byte[GUIWincoladd],0 + je .nocoladd2 + inc dl +.nocoladd2 +.nobotibox + DrawGUIWinBox 7,82,140,196,147,dl + mov byte[GUItextcolor],223 + GUIOuttextwin2 7,84,132,GUICheatText9 + GUIOuttextwin2 7,84,143,GUICheatTextA + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],222 +.zero3 + GUIOuttextwin2 7,83,131,GUICheatText9 + GUIOuttextwin2 7,83,142,GUICheatTextA + xor eax,eax + mov al,[GUICheatPosA] + mov byte[GUICheatText9+eax],0 + xor ebx,ebx + mov bl,[GUICheatPosB] + mov byte[GUICheatTextA+ebx],0 + test byte[GUICCFlash],8 + jnz .nound + cmp dword[GUIcurrentcheatwin],1 + je .win1 + cmp dword[GUIcurrentcheatwin],2 + je .win2 + jmp .nound +.win1 + mov byte[GUICheatText9+eax],'_' + jmp .nound +.win2 + mov byte[GUICheatTextA+ebx],'_' +.nound + + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[AutoLoadCht],1 + jne .nocheckbox + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckbox + GUIDisplayIconWin 7,11,186,[GUITemp] + ret + +GUICheatText1 db 'ENTER CODE :',0 +GUICheatText2 db 'DESCRIPTION:',0 +GUICheatText3 db 'ADDRESS CV PV TGL DESCRIPTION',0 +GUICheatText4 db 'REMOVE',0 +GUICheatText5 db 'TOGGLE',0 +GUICheatText6 db 'ADD',0 +GUICheatText7 db 'SAVE',0 +GUICheatText8 db 'LOAD',0 +GUICheatTextI db 'FIX',0 +GUICheatText9 db '_',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; 14 digits +GUICheatTextA db '_',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; 11 digits +GUICheatTextB db '000000 00 00 OFF BLAHBLAH---',0,0,0,0,0,0,0,0,0,0,0,0 +GUICheatTextC db '0123456789ABCDEF' +GUICheatTextD db 'VALID CODES : GAME GENIE, PAR, AND GF',0 +GUICheatTextE db 'NOTE : YOU MAY HAVE TO RESET THE GAME',0 +GUICheatTextF db ' AFTER ENTERING THE CODE. REMEMBER TO',0 +GUICheatTextG db ' INSERT THE "-" FOR GAME GENIE CODES',0 +GUICheatTextJ db 'AUTO-LOAD .CHT FILE AT GAME LOAD',0 +GUICheatPosA db 0 +GUICheatPosB db 0 +GUICStA dd 0,0,0 +GUIcurrentcheatviewloc dd 0 +GUIcurrentcheatcursloc dd 0 +GUIcurrentcheatwin dd 0 +ccheatnpos dd 0 +ccheatnleft dd 0 + +DrawWindowSearch: + GUIDrawWindowBox 13,GUISearchDisp + ret + +%macro TextWindowMacro 4 + sub byte[GUItextcolor],15 + GUIOuttextwin2 %1,%2+1,%3+1,%4 + add byte[GUItextcolor],15 + GUIOuttextwin2 %1,%2,%3,%4 +%endmacro + +CSRemoveFlash: +.loop + cmp byte[esi],'_' + je .flash + cmp byte[esi],0 + je .notflash + inc esi + jmp .loop +.flash + mov byte[esi],0 +.notflash + ret + +CSAddFlash: +.loop + cmp byte[esi],'_' + je .flash + cmp byte[esi],0 + je .notflash + inc esi + jmp .loop +.notflash + mov byte[esi],'_' + mov byte[esi+1],0 +.flash + ret + +DisplayGUISearch: + jmp .startcheat + call DrawWindowSearch + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + GUIOuttextwin2 13,6,16,GUISrcText1 + GUIOuttextwin2 13,6,26,GUISrcText2 + GUIOuttextwin2 13,6,36,GUISrcText3 + add byte[GUItextcolor],15 + GUIOuttextwin2 13,5,15,GUISrcText1 + GUIOuttextwin2 13,5,25,GUISrcText2 + GUIOuttextwin2 13,5,35,GUISrcText3 + ret +; DrawGUIButton 13,197,30,239,41,GUICSrcText8+2,40,0,0 + ret +.startcheat + cmp byte[CheatWinMode],1 + je near Incheatmode + cmp byte[CheatWinMode],2 + je near Cheatmodeview + cmp byte[CheatWinMode],3 + je near Cheatmodeadd + + mov dword[GUIwinsizex+13*4],170 + mov dword[GUIwinsizey+13*4],150 + call DrawWindowSearch + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 13,6,16,GUICSrcText1 + GUIOuttextwin2 13,6,101,GUICSrcText8 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 13,5,15,GUICSrcText1 + GUIOuttextwin2 13,5,100,GUICSrcText8 + + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero2 + mov byte[GUItextcolor],211 +.zero2 + TextWindowMacro 13,25,30,GUICSrcText2 + TextWindowMacro 13,25,40,GUICSrcText3 + TextWindowMacro 13,25,50,GUICSrcText4 + TextWindowMacro 13,25,60,GUICSrcText5 + TextWindowMacro 13,25,75,GUICSrcText6 + TextWindowMacro 13,25,85,GUICSrcText7 + TextWindowMacro 13,25,115,GUICSrcText9 + TextWindowMacro 13,25,125,GUICSrcTextA + DrawGUIButton 13,95,140,140,152,GUICSrcTextB,50,0,1 + GUIDisplayButtonHole 13,11,28,byte[CheatSrcByteSize],0 + GUIDisplayButtonHole 13,11,38,byte[CheatSrcByteSize],1 + GUIDisplayButtonHole 13,11,48,byte[CheatSrcByteSize],2 + GUIDisplayButtonHole 13,11,58,byte[CheatSrcByteSize],3 + GUIDisplayButtonHole 13,11,73,byte[CheatSrcByteBase],0 + GUIDisplayButtonHole 13,11,83,byte[CheatSrcByteBase],1 + GUIDisplayButtonHole 13,11,113,byte[CheatSrcSearchType],0 + GUIDisplayButtonHole 13,11,123,byte[CheatSrcSearchType],1 + ret +Incheatmode: + mov dword[GUIwinsizex+13*4],180 + mov dword[GUIwinsizey+13*4],150 + call DrawWindowSearch + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero2 + mov byte[GUItextcolor],211 +.zero2 + cmp byte[CheatSearchStatus],1 + jne near CheatSearching + TextWindowMacro 13,5,20,GUICSrcTextM + TextWindowMacro 13,5,30,GUICSrcTextN + TextWindowMacro 13,5,40,GUICSrcTextO + TextWindowMacro 13,5,50,GUICSrcTextP + jmp DisplayChtSrcRes.nosearch +CheatSearching: + cmp byte[CheatSrcSearchType],1 + je near CheatSearchingComp + + ; Exact Value Search + TextWindowMacro 13,5,20,GUICSrcTextD + DrawGUIWinBox 13,10,40,80,47,167 + ; Draw border + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + mov dl,[GUIWincol] + DrawGUIWinBox 13,10,39,80,39,dl ; 0,-1,0,-1 + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 13,9,40,8,47,dl ; -1,0,-2,0 + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 13,10,48,80,48,dl ; 0,1,0,1 + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 13,82,40,81,47,dl ; 2,0,1,0 + + test byte[GUICCFlash],8 + jnz .nound + mov esi,CSInputDisplay + call CSRemoveFlash +.nound + + mov byte[GUItextcolor],223 + cmp byte[CSOverValue],1 + jne .notdark + mov byte[GUItextcolor],202 +.notdark + GUIOuttextwin2 13,13,42,CSInputDisplay + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + cmp byte[CSOverValue],1 + jne .notdark2 + mov byte[GUItextcolor],207 +.notdark2 + GUIOuttextwin2 13,12,41,CSInputDisplay + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero2 + mov byte[GUItextcolor],211 +.zero2 + TextWindowMacro 13,5,65,GUICSrcTextT + + mov esi,CSInputDisplay + call CSAddFlash + + xor eax,eax + mov al,[CheatSrcByteSize] + mov eax,[SrcMask+eax*4] + mov esi,GUICSrcTextQ + cmp byte[CheatSrcByteBase],1 + je .hex + call convertnum + jmp .dec +.hex + xor ecx,ecx + mov cl,[CheatSrcByteSize] + inc ecx + call converthex +.dec + TextWindowMacro 13,71,65,GUICSrcTextQ + jmp DisplayChtSrcRes + +CheatSearchingComp: + ; Comparative search + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 13,6,16,GUICSrcTextE + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],164 +.zero3 + GUIOuttextwin2 13,5,15,GUICSrcTextE + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero2 + mov byte[GUItextcolor],211 +.zero2 + TextWindowMacro 13,25,35,GUICSrcTextF + TextWindowMacro 13,25,45,GUICSrcTextG + TextWindowMacro 13,25,55,GUICSrcTextH + TextWindowMacro 13,25,65,GUICSrcTextHb + GUIDisplayButtonHole 13,11,33,byte[CheatCompareValue],0 + GUIDisplayButtonHole 13,11,43,byte[CheatCompareValue],1 + GUIDisplayButtonHole 13,11,53,byte[CheatCompareValue],2 + GUIDisplayButtonHole 13,11,63,byte[CheatCompareValue],3 + jmp DisplayChtSrcRes + + +FindChtSrcRes: + inc edi + ; Calculate search results + mov eax,dword[vidbuffer] + add eax,129600+65536*2 + mov ecx,16384 + xor esi,esi + xor ebx,ebx +.searchloop + mov dl,[eax] + mov dh,8 +.sloop2 + test dl,1 + jz .notset + inc ebx + dec edi + jz .found +.notset + inc esi + shr dl,1 + dec dh + jnz .sloop2 + inc eax + loop .searchloop + mov eax,ebx + ret +.found + mov [CSStartEntry],esi + jmp .notset + +DisplayChtSrcRes: + DrawGUIButton 13,120,140,170,152,GUICSrcTextI,53,0,1 +.nosearch + DrawGUIButton 13,10,140,60,152,GUICSrcTextJ,51,0,1 + DrawGUIButton 13,70,140,110,152,GUICSrcTextL,52,0,1 + xor edi,edi + call FindChtSrcRes + mov esi,GUICSrcTextQ + call convertnum + TextWindowMacro 13,12,125,GUICSrcTextK + TextWindowMacro 13,97,125,GUICSrcTextQ + mov dword[GUIcurrentchtsrcviewloc],0 + mov dword[GUIcurrentchtsrccursloc],0 + ret + +Cheatmodeview: + mov byte[GUICSrcTextS+12],32 + cmp byte[CheatSrcByteSize],3 + jne .yesprev + cmp byte[CheatSrcByteBase],0 + jne .yesprev + mov byte[GUICSrcTextS+12],0 +.yesprev + + mov dword[GUIwinsizex+13*4],185 + mov dword[GUIwinsizey+13*4],150 + call DrawWindowSearch + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + TextWindowMacro 13,10,12,GUICSrcTextS + DrawGUIWinBox 13,5,20,171,108,167 + + ; Draw border + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + mov dl,[GUIWincol] + DrawGUIWinBox 13,5,19,171,19,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 13,4,20,3,108,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 13,5,109,171,109,dl + + mov edi,[GUIcurrentchtsrcviewloc] + call FindChtSrcRes + mov [NumCheatSrc],eax + mov dword[ccheatnpos],esi + ; Display Window Contents + + mov byte[GUItextcolor],223 + mov eax,[NumCheatSrc] + sub eax,[GUIcurrentchtsrcviewloc] + cmp eax,12 + jbe .notof + mov eax,12 +.notof + mov dword[ccheatnleft],eax + mov dword[ccheatnleftb],eax + + mov dword[CheatSearchYPos],24 + mov dword[CheatSearchXPos],10 + mov eax,[CSStartEntry] + mov [CSCurEntry],eax + + cmp dword[ccheatnleft],0 + je near .noentry + mov byte[CheatLooped],0 + mov ebx,[GUIcurrentchtsrccursloc] + sub ebx,[GUIcurrentchtsrcviewloc] + mov [curentryleft],ebx + mov eax,ebx + lea ebx,[ebx*8] + sub ebx,eax + add ebx,22 + DrawGUIWinBox2 13,5,171,7,224 +.nextdisplay + cmp dword[curentryleft],0 + jne .notzero + mov eax,[CSCurEntry] + mov [curentryval],eax +.notzero + dec dword[curentryleft] + + mov esi,GUICSrcTextQ + mov ecx,3 + mov eax,[CSCurEntry] + add eax,7E0000h + call converthex + GUIOuttextwin2 13,[CheatSearchXPos],[CheatSearchYPos],GUICSrcTextQ + + mov esi,GUICSrcTextQ + mov ebx,[wramdata] + add ebx,[CSCurEntry] + mov eax,[ebx] + cmp byte[CheatSrcByteBase],0 + je .dec + xor ecx,ecx + mov cl,[CheatSrcByteSize] + inc ecx + call converthex + jmp .hex +.dec + xor ebx,ebx + mov bl,[CheatSrcByteSize] + and eax,[SrcMask+ebx*4] + call convertnum +.hex + add dword[CheatSearchXPos],42 + GUIOuttextwin2 13,[CheatSearchXPos],[CheatSearchYPos],GUICSrcTextQ + + add dword[CheatSearchXPos],60 + cmp byte[GUICSrcTextS+12],0 + je near .noprevious + mov esi,GUICSrcTextQ + mov ebx,dword[vidbuffer] + add ebx,129600 + add ebx,[CSCurEntry] + mov eax,[ebx] + cmp byte[CheatSrcByteBase],0 + je .decb + xor ecx,ecx + mov cl,[CheatSrcByteSize] + inc ecx + call converthex + jmp .hexb +.decb + xor ebx,ebx + mov bl,[CheatSrcByteSize] + and eax,[SrcMask+ebx*4] + call convertnum +.hexb + GUIOuttextwin2 13,[CheatSearchXPos],[CheatSearchYPos],GUICSrcTextQ +.noprevious + sub dword[CheatSearchXPos],102 + add dword[CheatSearchYPos],7 + ; Search for next entry +.nextentry + inc dword[CSCurEntry] + mov eax,[CSCurEntry] + mov ecx,eax + and ecx,7 + mov edx,1 + shr eax,3 + shl edx,cl + add eax,dword[vidbuffer] + add eax,129600+65536*2 + test byte[eax],dl + jz .nextentry + dec dword[ccheatnleft] + jnz near .nextdisplay + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + mov dword[CheatSearchYPos],23 + mov dword[CheatSearchXPos],11 + mov eax,[CSStartEntry] + mov [CSCurEntry],eax + mov eax,dword[ccheatnleftb] + mov dword[ccheatnleft],eax + inc byte[CheatLooped] + cmp byte[CheatLooped],2 + jne near .nextdisplay +.noentry + + ; win#,X,Y start, %4-List Loc, %5-List size, %6-Screen size, %7-Bar Size + DrawSlideBarWin 13,173,28,[GUIcurrentchtsrcviewloc],[NumCheatSrc],12,73,GUICSStA + cmp byte[GUICHold],11 + jne .noholda + add byte[GUIWincoladd],3 +.noholda + GUIDisplayIconWin 13,173,20,GUIIconDataUpArrow + cmp byte[GUICHold],11 + jne .noholda2 + sub byte[GUIWincoladd],3 +.noholda2 + cmp byte[GUICHold],12 + jne .noholdb + add byte[GUIWincoladd],3 +.noholdb + GUIDisplayIconWin 13,173,101,GUIIconDataDownArrow + cmp byte[GUICHold],12 + jne .noholdb2 + sub byte[GUIWincoladd],3 +.noholdb2 + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],211 +.zero3 + DrawGUIButton 13,70,140,130,152,GUICSrcTextR,54,0,1 + DrawGUIButton 13,140,140,180,152,GUICSrcTextU,55,0,1 + ret + +Cheatmodeadd: + mov dword[GUIwinsizex+13*4],170 + mov dword[GUIwinsizey+13*4],165 + call DrawWindowSearch + + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],211 +.zero3 + + TextWindowMacro 13,5,20,GUICSrcTextV + TextWindowMacro 13,5,45,GUICSrcTextW + TextWindowMacro 13,5,70,GUICSrcTextX + TextWindowMacro 13,22,143,GUICSrcTextY + + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[CheatUpperByteOnly],1 + jne .nocheck + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck + GUIDisplayIconWin 13,8,139,[GUITemp] + + DrawGUIWinBox 13,10,30,80,37,167 + DrawGUIWinBox 13,10,55,126,62,167 + DrawGUIWinBox 13,10,80,80,120,167 + ; Draw border + mov dword[GUIWincol],148+10 + cmp byte[cwindrawn],1 + jne .noone2 + mov dword[GUIWincol],148+5 +.noone2 + cmp byte[cwindrawn],0 + jne .nozero2 + mov dword[GUIWincol],148 +.nozero2 + mov dl,[GUIWincol] + DrawGUIWinBox 13,10,29,80,29,dl ; 0,-1,0,-1 + DrawGUIWinBox 13,10,54,126,54,dl ; 0,-1,0,-1 + DrawGUIWinBox 13,10,79,80,79,dl ; 0,-1,0,-1 + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 13,9,30,8,37,dl ; -1,0,-2,0 + DrawGUIWinBox 13,9,55,8,62,dl ; -1,0,-2,0 + DrawGUIWinBox 13,9,80,8,120,dl ; -1,0,-2,0 + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 13,10,38,80,38,dl ; 0,1,0,1 + DrawGUIWinBox 13,10,63,126,63,dl ; 0,1,0,1 + DrawGUIWinBox 13,10,121,80,121,dl ; 0,1,0,1 + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 13,82,30,81,37,dl ; 2,0,1,0 + DrawGUIWinBox 13,128,55,127,62,dl ; 2,0,1,0 + DrawGUIWinBox 13,82,80,81,120,dl ; 2,0,1,0 + + DrawGUIButton 13,60,155,120,167,GUICSrcTextR,56,0,1 + DrawGUIButton 13,130,155,160,167,GUICSrcTextU,57,0,1 + + TextWindowMacro 13,5,130,GUICSrcTextT + xor eax,eax + mov al,[CheatSrcByteSize] + mov eax,[SrcMask+eax*4] + mov esi,GUICSrcTextQ + cmp byte[CheatSrcByteBase],1 + je .hex + call convertnum + jmp .dec +.hex + xor ecx,ecx + mov cl,[CheatSrcByteSize] + inc ecx + call converthex +.dec + TextWindowMacro 13,71,130,GUICSrcTextQ + + cmp byte[CurCStextpos],0 + jne near .nofirstbox + test byte[GUICCFlash],8 + jnz .nound +.nofirstbox + mov esi,CSInputDisplay + call CSRemoveFlash +.nound + mov byte[GUItextcolor],223 + cmp byte[CSOverValue],1 + jne .notdark + mov byte[GUItextcolor],202 +.notdark + GUIOuttextwin2 13,13,32,CSInputDisplay + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],222 +.zero4 + cmp byte[CSOverValue],1 + jne .notdark2 + mov byte[GUItextcolor],207 +.notdark2 + GUIOuttextwin2 13,12,31,CSInputDisplay + mov esi,CSInputDisplay + call CSAddFlash + + cmp byte[CurCStextpos],1 + jne .noundb + test byte[GUICCFlash],8 + jnz .noundb + mov esi,CSDescDisplay + call CSAddFlash +.noundb + mov byte[GUItextcolor],223 + GUIOuttextwin2 13,13,57,CSDescDisplay + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4b + mov byte[GUItextcolor],222 +.zero4b + GUIOuttextwin2 13,12,56,CSDescDisplay + mov esi,CSDescDisplay + call CSRemoveFlash + + cmp byte[CSOverValue],1 + je near .nodisplay + cmp byte[CSInputDisplay],'_' + je near .nodisplay + + mov dword[CheatSearchYPos],83 + mov eax,[curentryval] + mov [curaddrvalcs],eax + mov eax,[CSCurValue] + mov [curvaluecs],eax + xor ecx,ecx + mov cl,[CheatSrcByteSize] + inc cl + cmp byte[CheatUpperByteOnly],0 + je .cspardisploop + mov cl,1 +.cspardispagain + cmp dword[curvaluecs],0FFh + jbe .cspardisploop + shr dword[curvaluecs],8 + inc dword[curaddrvalcs] + jmp .cspardispagain +.cspardisploop + push ecx + mov esi,GUICSrcTextQ + mov ecx,3 + mov eax,[curaddrvalcs] + add eax,7E0000h + call converthex + mov esi,GUICSrcTextQ+6 + mov ecx,1 + mov al,[curvaluecs] + call converthex + shr dword[curvaluecs],8 + mov byte[GUItextcolor],223 + inc dword[CheatSearchYPos] + GUIOuttextwin2 13,13,[CheatSearchYPos],GUICSrcTextQ + dec dword[CheatSearchYPos] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero4c + mov byte[GUItextcolor],222 +.zero4c + GUIOuttextwin2 13,12,[CheatSearchYPos],GUICSrcTextQ + add dword[CheatSearchYPos],10 + inc dword[curaddrvalcs] + pop ecx + dec ecx + jnz near .cspardisploop + +.nodisplay + ret + +;CheatSrcByteSize db 0 +;CheatSrcByteBase db 0 +;CheatSrcSearchType db 0 +CheatWinMode db 0 +CheatSearchStatus db 0 +CheatCompareValue dd 0 +NumCheatSrc dd 0 +GUIcurrentchtsrcviewloc dd 0 +GUIcurrentchtsrccursloc dd 0 +CSStartEntry dd 0 +CSCurEntry dd 0 +CheatSearchXPos dd 0 +CheatSearchYPos dd 0 +CheatLooped dd 0 +ccheatnleftb dd 0 +CurCStextpos dd 0 +SrcMask dd 0FFh,0FFFFh,0FFFFFFh,0FFFFFFFFh +CSInputDisplay db '_',0,' ',0 +CSDescDisplay db ' ',0,0 +curentryval dd 0 +curentryleft dd 0 +curaddrvalcs dd 0 +curvaluecs dd 0 + +GUICSStA dd 0,0,0 + +GUISrcText1 db 'CHEAT SEARCH',0 +GUISrcText2 db 'HAS NOT BEEN',0 +GUISrcText3 db 'IMPLEMENTED YET',0 +GUICSrcText1 db 'SELECT SIZE AND FORMAT:',0 +GUICSrcText2 db '1 BYTE [0..255]',0 +GUICSrcText3 db '2 BYTES [0..65535]',0 +GUICSrcText4 db '3 BYTES [0..16777215]',0 +GUICSrcText5 db '4 BYTES [0..4294967295]',0 +GUICSrcText6 db 'DEC (BASE 10)',0 +GUICSrcText7 db 'HEX (BASE 16)',0 +GUICSrcText8 db 'SELECT SEARCH TYPE:',0 +GUICSrcText9 db 'EXACT VALUE SEARCH',0 +GUICSrcTextA db 'COMPARITIVE SEARCH',0 +GUICSrcTextB db 'START',0 +GUICSrcTextD db 'ENTER VALUE:',0 +GUICSrcTextE db 'SELECT COMPARISON:',0 +GUICSrcTextF db 'NEW VALUE IS > OLD VALUE',0 +GUICSrcTextG db 'NEW VALUE IS < OLD VALUE',0 +GUICSrcTextH db 'NEW VALUE IS = OLD VALUE',0 +GUICSrcTextHb db 'NEW VALUE IS != OLD VALUE',0 +GUICSrcTextI db 'SEARCH',0 +GUICSrcTextJ db 'RESTART',0 +GUICSrcTextK db '# OF RESULTS:',0 +GUICSrcTextL db 'VIEW',0 +GUICSrcTextQ db ' ',0 +GUICSrcTextM db 'NOW RETURN TO YOUR GAME',0 +GUICSrcTextN db 'AND COME BACK WHEN ',0 +GUICSrcTextO db 'THE NEXT SEARCH',0 +GUICSrcTextP db 'SHOULD BE PROCESSED',0 +GUICSrcTextR db 'RETURN',0 +GUICSrcTextS db 'ADDR VALUE PVALUE',0 +GUICSrcTextT db 'MAX VALUE:',0 +GUICSrcTextU db 'ADD',0 +GUICSrcTextV db 'ENTER NEW VALUE:',0 +GUICSrcTextW db 'ENTER CHEAT DESCRIPTION:',0 +GUICSrcTextX db 'PAR CODE EQUIVALENT:',0 +GUICSrcTextY db 'USE ONLY UPPER BYTE',0 + + +NEWSYM NetAddChar ; dl = color, dh = char + mov eax,ViewBuffer + add eax,[CCursLoc] + mov ebx,[CCursLoc] + sub ebx,[CViewLoc] + cmp ebx,32*12 + jbe .okay + mov ebx,[CCursLoc] + sub ebx,32*11 + and ebx,0FFE0h + mov [CViewLoc],ebx +.okay + cmp dword[CCursLoc],32*48 + jb .notbottom + call .movelistup + mov ebx,[CCursLoc] + sub ebx,32*12 + and ebx,0FFE0h + mov [CViewLoc],ebx + jmp NetAddChar +.notbottom + test dword[CCursLoc],1Fh + jnz .nobeginning + cmp dl,' ' + je near .skipaddchar + mov byte[eax],dh + inc dword[CCursLoc] + inc eax +.nobeginning + mov ebx,[CCursLoc] + and ebx,1Fh + cmp ebx,1Eh + jne near .noend + add dword[CCursLoc],2 + cmp dword[CCursLoc],32*48 + jb .notbottom2 + call .movelistup +.notbottom2 + mov ebx,[CCursLoc] + add ebx,ViewBuffer + sub ebx,3 + mov eax,12 + cmp byte[ebx],' ' + je .notfoundspace +.loop3 + cmp byte[ebx],' ' + je .foundspace + dec ebx + dec eax + jnz .loop3 + jmp .notfoundspace +.foundspace + mov ecx,[CCursLoc] + add ecx,ViewBuffer + inc ebx + cmp byte[ebx],0 + je .notfoundspace + mov [ecx],dh + inc ecx + mov byte[ecx],' ' + inc ecx + add dword[CCursLoc],2 +.loop2 + cmp byte[ebx],0 + je .skipaddingspace + mov al,[ebx] + mov [ecx],al + mov byte[ecx+1],0 + mov byte[ebx],' ' + inc ebx + inc ecx + inc dword[CCursLoc] + jmp .loop2 + jmp .skipaddingspace +.notfoundspace + mov ecx,[CCursLoc] + add ecx,ViewBuffer + mov [ecx],dh + inc ecx + mov byte[ecx],' ' + inc ecx + add dword[CCursLoc],2 +.skipaddingspace + jmp NetAddChar +.noend + cmp dl,13 + je .ret + cmp dl,10 + je .next + mov byte[eax],dl + mov byte[eax+1],0 + inc dword[CCursLoc] + ret +.next + add dword[CCursLoc],32 +.ret + and dword[CCursLoc],0FFE0h +.skipaddchar + mov ebx,[CViewLoc] + shr ebx,5 + mov [NViewLoc],ebx + ret + +.movelistup + ; move list up by 32 spaces + mov ebx,ViewBuffer + mov ecx,32*47 +.loop + mov al,[ebx+32] + mov [ebx],al + inc ebx + dec ecx + jnz .loop + and dword[CCursLoc],0FFE0h + mov dword[ViewBuffer+32*47],0 + sub dword[CCursLoc],32 + ret + + +CCursLoc dd 0 +CViewLoc dd 0 +NViewLoc dd 0 +TViewLoc dd 0 + + +DisplayNetOptns: + mov dword[GUIwinsizex+8*4],7*16 + mov dword[GUIwinsizey+8*4],57 + mov dword[GUINetDisp],'IPX ' + mov dword[GUINetDisp+4],' ' + mov byte[GUINetDisp+8],0 + cmp byte[per2exec],99 + je .netokay + mov dword[GUIwinsizex+8*4],7*16 + mov dword[GUIwinsizey+8*4],40 + mov dword[GUINetDisp],'ERRO' + mov dword[GUINetDisp+4],'R! ' + jmp .nomodem +.netokay + cmp byte[CNetType],8 + jne .noipxinvalid + mov dword[GUIwinsizex+8*4],7*16 + mov dword[GUIwinsizey+8*4],30 + mov dword[GUINetDisp],'ERRO' + mov dword[GUINetDisp+4],'R! ' +.noipxinvalid + + cmp byte[CNetType],22 + je .yesstate + cmp byte[CNetType],21 + jne .nostate +.yesstate + mov dword[GUIwinsizex+8*4],150 + mov dword[GUIwinsizey+8*4],59 + mov dword[GUINetDisp],'STAT' + mov dword[GUINetDisp+4],'E TR' + mov dword[GUINetDisp+8],'ANSF' + mov dword[GUINetDisp+12],'ER ' + mov dword[GUINetDisp+14],0 +.nostate + + cmp byte[CNetType],20 + jne .nochat + mov dword[GUIwinsizex+8*4],188 + mov dword[GUIwinsizey+8*4],179 + mov dword[GUINetDisp],'CHAT' + mov dword[GUINetDisp+4],0 +.nochat + cmp byte[CNetType],15 + je .yesterm + cmp byte[CNetType],12 + je .yesterm + cmp byte[CNetType],11 + je .yesterm + cmp byte[CNetType],10 + jne .noterm +.yesterm + mov dword[GUIwinsizex+8*4],188 + mov dword[GUIwinsizey+8*4],144 + mov dword[GUINetDisp],'TERM' + mov dword[GUINetDisp+4],'INAL' + mov byte[GUINetDisp+8],0 +.noterm + cmp byte[CNetType],4 + jne .notcpip + ; Your IP: + ; Start as Server + ; Client Options: + ; IP : + ; Port: + ; Connect + mov dword[GUIwinsizex+8*4],201 + mov dword[GUIwinsizey+8*4],98 + mov dword[GUINetDisp],'INTE' + mov dword[GUINetDisp+4],'RNET' + mov byte[GUINetDisp+8],0 + cmp byte[NetPlayNoMore],1 + jne .notcpip + mov dword[GUIwinsizex+8*4],201 + mov dword[GUIwinsizey+8*4],48 +.notcpip + cmp byte[CNetType],3 + je .yesmodem + cmp byte[CNetType],1 + jne .nomodem2 + jmp .skipmodem3 +.yesmodem + mov dword[GUIwinsizex+8*4],188 + mov dword[GUIwinsizey+8*4],45 + jmp .skipmodem2 +.skipmodem3 + mov dword[GUIwinsizex+8*4],95 + mov dword[GUIwinsizey+8*4],70 +.skipmodem2 + mov dword[GUINetDisp],'MODE' + mov dword[GUINetDisp+4],'M ' + mov byte[GUINetDisp+8],0 +.nomodem2 + cmp byte[CNetType],2 + jne .nomodem + mov dword[GUIwinsizex+8*4],188 + mov dword[GUIwinsizey+8*4],154 + mov dword[GUINetDisp],'MODE' + mov dword[GUINetDisp+4],'M SE' + mov dword[GUINetDisp+8],'TTIN' + mov word[GUINetDisp+12],'GS' + mov byte[GUINetDisp+14],0 +.nomodem + GUIDrawWindowBox 8,GUINetDisp + cmp byte[per2exec],99 + jne near DisplayNetOptnsInvalid + + cmp byte[CNetType],22 + je near DisplayNetTCPIPState + cmp byte[CNetType],21 + je near DisplayNetTCPIPState + + cmp byte[CNetType],1 + je near DisplayNetOptnsModem + cmp byte[CNetType],2 + je near DisplayNetOptnsModemConfig + cmp byte[CNetType],3 + je near DisplayNetOptnsModemDial + cmp byte[CNetType],4 + je near DisplayNetOptnsTCPIP + cmp byte[CNetType],10 + je near DisplayNetOptnsModemTerm + cmp byte[CNetType],11 + je near DisplayNetOptnsModemTerm + cmp byte[CNetType],12 + je near DisplayNetOptnsModemTerm + cmp byte[CNetType],15 + je near DisplayNetOptnsModemTerm + cmp byte[CNetType],20 + je near DisplayNetOptnsChatWindow + cmp byte[CNetType],7 + je near DisplayNetIPXStart + cmp byte[CNetType],8 + je near DisplayNetIPXInvalid + + jmp DisplayNetIPXStart + + cmp ax,0 + je .ipxokay + mov byte[CNetType],8 + jmp DisplayNetIPXInvalid +.ipxokay + cmp byte[CNetType],7 + jmp DisplayNetIPXStart + + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + mov dword[GUIEditStringcWin],0 + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,6,16,GUINetText1 + GUIOuttextwin2 8,6,26,GUINetText2 + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUINetText1 + GUIOuttextwin2 8,5,25,GUINetText2 + ret + +DisplayNetTCPIPState: + DrawGUIButton 8,73,48,127,59,GUITCPStateText3,64,0,0 + cmp byte[CNetType],22 + je near .receive + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,6,16,GUITCPStateText1 + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUITCPStateText1 + jmp .send +.receive + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,6,16,GUITCPStateText2 + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUITCPStateText2 +.send + DrawGUIWinBox 8,10,30,120,40,167 + cmp dword[NetStateTotal],0 + je near .nobox + mov eax,[NetStateTotal] + sub eax,[NetStateSize] + mov ebx,110 + mul ebx + mov ebx,[NetStateTotal] + div ebx + add eax,10 + cmp eax,10 + je near .nobox + push eax + inc eax + DrawGUIWinBox3 8,10,30,eax,40,226 + pop eax + DrawGUIWinBox3 8,10,30,eax,40,224 +.nobox + + mov dl,[GUIWincol] + DrawGUIWinBox 8,10,29,120,29,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 8,9,30,8,40,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 8,10,41,120,41,dl ; 0,1,0,1 + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 8,122,30,121,40,dl ; 2,0,1,0 + ret + +GUITCPStateText1 db 'SENDING STATUS',0 +GUITCPStateText2 db 'RECEIVING STATUS',0 +GUITCPStateText3 db 'CANCEL',0 + +DisplayNetIPXStart: + DrawGUIButton 8,53,48,87,59,GUINetTextZ,34,0,0 + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,6,16,GUINetText1c + GUIOuttextwin2 8,6,26,GUINetText2c + GUIOuttextwin2 8,6,36,GUINetText3c + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUINetText1c + GUIOuttextwin2 8,5,25,GUINetText2c + GUIOuttextwin2 8,5,35,GUINetText3c + ret + +DisplayNetIPXInvalid: + ret + +DisplayNetOptnsTCPIP: + ; Your IP: + ; Port: + ; Start as Server + ; Client Options: + ; IP : + ; Connect + + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + + cmp byte[NetPlayNoMore],1 + jne near .tcpip + GUIOuttextwin2 8,6,16,GUINetTextr1 + GUIOuttextwin2 8,6,36,GUINetTextr2 + GUIOuttextwin2 8,6,46,GUINetTextr3 + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUINetTextr1 + GUIOuttextwin2 8,5,35,GUINetTextr2 + GUIOuttextwin2 8,5,45,GUINetTextr3 + ret +.tcpip + GUIOuttextwin2 8,6,16,GUINetTextf2 + GUIOuttextwin2 8,6,26,GUINetTextf3 + GUIOuttextwin2 8,6,51,GUINetTexth2 + GUIOuttextwin2 8,6,61,GUINetTexti2 + GUIOuttextwin2 8,18,98,GUINetTextp2 + GUIOuttextwin2 8,6,88,hostname + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUINetTextf2 + GUIOuttextwin2 8,5,25,GUINetTextf3 + DrawGUIButton 8,5,35,129,46,GUINetTextg2,25,0,0 + GUIOuttextwin2 8,5,50,GUINetTexth2 + GUIOuttextwin2 8,5,60,GUINetTexti2 + DrawGUIButton 8,5,70,129,81,GUINetTextj2,26,0,0 + DrawGUIWinBox 8,55,13,95,21,167 + DrawGUIWinBox 8,55,23,119,31,167 + DrawGUIWinBox 8,26,58,191,66,167 + GUIOuttextwin2 8,17,97,GUINetTextp2 + GUIOuttextwin2 8,5,87,hostname + + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero2 + mov byte[GUItextcolor],222 +.zero2 + GUIOuttextwin2 8,59,15,GUINetTextl2 + GUIOuttextwin2 8,30,60,GUINetTextk2 + GUIOuttextwin2 8,59,25,ChatNick + mov byte[GUINetTextn2],'_' + test byte[GUINetTextm2+2],8 + jz .yesus + mov byte[GUINetTextn2],' ' +.yesus + xor eax,eax + mov al,[GUINetTextm2+1] + mov ebx,6 + mul ebx + cmp byte[GUINetTextm2],1 + je near .cursor2 + cmp byte[GUINetTextm2],2 + je near .cursor3 + add eax,30 + GUIOuttextwin2 8,eax,61,GUINetTextn2 + jmp .cursor1 +.cursor2 + xor eax,eax + mov ebx,GUINetTextl2 +.loopc + cmp byte[ebx],0 + je .donec + inc ebx + add eax,6 + jmp .loopc +.donec + add eax,59 + GUIOuttextwin2 8,eax,15,GUINetTextn2 + jmp .cursor1 +.cursor3 + xor eax,eax + mov ebx,ChatNick +.loopc2 + cmp byte[ebx],0 + je .donec2 + inc ebx + add eax,6 + jmp .loopc2 +.donec2 + add eax,59 + GUIOuttextwin2 8,eax,25,GUINetTextn2 +.cursor1 + + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[UDPConfig],1 + jne .nocheckm + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckm + GUIDisplayIconWin 8,5,93,[GUITemp] + ret + +DisplayNetOptnsInvalid: + mov byte[CNetType],255 + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + mov dword[GUIEditStringcWin],0 + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,6,16,GUINetText1b + GUIOuttextwin2 8,6,26,GUINetText2b + GUIOuttextwin2 8,6,36,GUINetText3b + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,15,GUINetText1b + GUIOuttextwin2 8,5,25,GUINetText2b + GUIOuttextwin2 8,5,35,GUINetText3b + ret +DisplayNetOptnsModem: + mov dword[GUIEditStringcWin],0 + DrawGUIButton 8,5,15,89,26,GUINetTextG,21,0,0 + DrawGUIButton 8,5,30,89,41,GUINetTextH,22,0,0 + DrawGUIButton 8,5,45,89,56,GUINetTexth,23,0,0 + DrawGUIButton 8,5,60,89,71,GUINetTextI,24,0,0 + ret +DisplayNetOptnsModemConfig: + cmp byte[ModemInitStat],0 + je .nodeinitmodem +; call DeInitModem + mov byte[ModemInitStat],0 +.nodeinitmodem + DrawGUIWinBox 8,31,70,50,78,167 + DrawGUIWinBox 8,21,125,175,133,167 + DrawGUIWinBox 8,21,136,175,144,167 + mov byte[GUINetText8],'0' + mov al,[ComIRQ] + cmp byte[ComIRQ],10 + jb .no10 + mov byte[GUINetText8],'1' + sub al,10 +.no10 + add al,'0' + mov [GUINetText8+1],al + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,21,28,GUINetText3 + GUIOuttextwin2 8,21,38,GUINetText4 + GUIOuttextwin2 8,21,48,GUINetText5 + GUIOuttextwin2 8,21,58,GUINetText6 + GUIOuttextwin2 8,6,73,GUINetText7 + GUIOuttextwin2 8,21,88,GUINetTextC + GUIOuttextwin2 8,21,98,GUINetTextD + GUIOuttextwin2 8,106,28,GUINetTextJ + GUIOuttextwin2 8,106,38,GUINetTextK + GUIOuttextwin2 8,106,48,GUINetTextL + GUIOuttextwin2 8,106,58,GUINetTextM + GUIOuttextwin2 8,106,68,GUINetTextN + GUIOuttextwin2 8,106,78,GUINetTextO + GUIOuttextwin2 8,106,88,GUINetTextP + GUIOuttextwin2 8,6,128,GUINetTexte + GUIOuttextwin2 8,6,139,GUINetTextf + GUIOuttextwin2 8,26,152,GUINetTextX + add byte[GUItextcolor],15 + GUIOuttextwin2 8,20,27,GUINetText3 + GUIOuttextwin2 8,20,37,GUINetText4 + GUIOuttextwin2 8,20,47,GUINetText5 + GUIOuttextwin2 8,20,57,GUINetText6 + GUIOuttextwin2 8,5,72,GUINetText7 + GUIOuttextwin2 8,20,87,GUINetTextC + GUIOuttextwin2 8,20,97,GUINetTextD + GUIOuttextwin2 8,105,27,GUINetTextJ + GUIOuttextwin2 8,105,37,GUINetTextK + GUIOuttextwin2 8,105,47,GUINetTextL + GUIOuttextwin2 8,105,57,GUINetTextM + GUIOuttextwin2 8,105,67,GUINetTextN + GUIOuttextwin2 8,105,77,GUINetTextO + GUIOuttextwin2 8,105,87,GUINetTextP + GUIOuttextwin2 8,5,127,GUINetTexte + GUIOuttextwin2 8,5,138,GUINetTextf + GUIOuttextwin2 8,25,151,GUINetTextX + DrawGUIButton 8,55,69,63,79,GUINetText9,25,-2,0 + DrawGUIButton 8,66,69,74,79,GUINetTextA,26,-2,0 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 8,6,16,GUINetTextR + GUIOuttextwin2 8,6,113,GUINetTextE + GUIOuttextwin2 8,91,16,GUINetTextQ + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],164 +.zero + GUIOuttextwin2 8,5,15,GUINetTextR + GUIOuttextwin2 8,5,112,GUINetTextE + GUIOuttextwin2 8,90,15,GUINetTextQ + mov byte[GUItextcolor],223 + GUIOuttextwin2 8,36,73,GUINetText8 + GUIOuttextwin2 8,25,128,GUIInitSt1 + GUIOuttextwin2 8,25,139,GUIInitSt2 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],222 +.zero3 + GUIOuttextwin2 8,35,72,GUINetText8 + GUIOuttextwin2 8,24,127,GUIInitSt1 + GUIOuttextwin2 8,24,138,GUIInitSt2 + GUIDisplayButtonHole 8,9,25,byte[ComNum],1 + GUIDisplayButtonHole 8,9,35,byte[ComNum],2 + GUIDisplayButtonHole 8,9,45,byte[ComNum],3 + GUIDisplayButtonHole 8,9,55,byte[ComNum],4 + GUIDisplayButtonHole 8,94,25,byte[BaudRate],0 + GUIDisplayButtonHole 8,94,35,byte[BaudRate],1 + GUIDisplayButtonHole 8,94,45,byte[BaudRate],2 + GUIDisplayButtonHole 8,94,55,byte[BaudRate],3 + GUIDisplayButtonHole 8,94,65,byte[BaudRate],4 + GUIDisplayButtonHole 8,94,75,byte[BaudRate],5 + GUIDisplayButtonHole 8,94,85,byte[BaudRate],6 + GUIDisplayButtonHole 8,9,85,byte[GUIDialSt+3],'T' + GUIDisplayButtonHole 8,9,95,byte[GUIDialSt+3],'P' + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[FossilUse],1 + jne .nocheckm + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheckm + GUIDisplayIconWin 8,12,147,[GUITemp] + ret +DisplayNetOptnsModemDial: + DrawGUIWinBox 8,5,25,175,33,167 + DrawGUIButton 8,141,38,175,49,GUINetTextT,28,0,0 + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,6,14,GUINetTextF + add byte[GUItextcolor],15 + GUIOuttextwin2 8,5,13,GUINetTextF + mov byte[GUItextcolor],223 + GUIOuttextwin2 8,9,28,DialNumber + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],222 +.zero3 + GUIOuttextwin2 8,8,27,DialNumber + mov dword[GUIEditString],DialNumber + mov dword[GUIEditStringmLen],27 +; mov dword[GUIEditStringmLenM],27 + mov dword[GUIEditStringcWin],1 + ret +DisplayNetOptnsModemTerm: + DrawGUIWinBox 8,6,15,181,127,167 + ; draw borders + mov dl,[GUIWincol] + DrawGUIWinBox 8,6,14,181,14,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 8,5,15,4,127,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 8,6,128,181,128,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 8,183,15,182,127,dl + + ; cancel button + DrawGUIButton 8,120,135,181,146,GUINetTextS,27,0,0 + ; draw text + mov dword[CurCStringPos],ViewBuffer+1 + mov ebx,[CViewLoc] + add dword[CurCStringPos],ebx + mov byte[GUItextcolor],223 + GUIOuttextwin2 8,9,28-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,36-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,44-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,52-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,60-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,68-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,76-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,84-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,92-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,100-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,108-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,116-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,124-5,[CurCStringPos] + add dword[CurCStringPos],32 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],222 +.zero3 + mov dword[CurCStringPos],ViewBuffer+1 + mov ebx,[CViewLoc] + add dword[CurCStringPos],ebx + GUIOuttextwin2 8,8,27-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,35-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,43-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,51-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,59-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,67-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,75-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,83-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,91-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,99-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,107-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,115-5,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,123-5,[CurCStringPos] + add dword[CurCStringPos],32 + ret + +%macro NetChatWindowHelp 3 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[%3],1 + jne %%nocheck + mov dword[GUITemp],GUIIconDataCheckBoxC +%%nocheck + cmp byte[%3],2 + jne %%nocheckb + mov dword[GUITemp],GUIIconDataCheckBoxX +%%nocheckb + GUIDisplayIconWin 8,%1,%2,[GUITemp] +%endmacro + +DisplayNetOptnsChatWindow: + mov byte[GUINetText8],'0' + mov al,[Latency] + cmp byte[Latency],10 + jb .no10b + mov byte[GUINetText8],'1' + sub al,10 +.no10b + add al,'0' + mov [GUINetText8+1],al + + DrawGUIWinBox 8,55,157,74,165,167 + + GUIDisplayButtonHole 8,111,137,byte[UseRemoteSRAMData],0 + GUIDisplayButtonHole 8,111,147,byte[UseRemoteSRAMData],1 + GUIDisplayButtonHole 8,111,157,byte[UseRemoteSRAMData],2 + NetChatWindowHelp 7,135,pl1neten + NetChatWindowHelp 32,135,pl2neten + NetChatWindowHelp 57,135,pl3neten + NetChatWindowHelp 7,145,pl4neten + NetChatWindowHelp 32,145,pl5neten + NetChatWindowHelp 7,175,BackState + + sub byte[GUItextcolor],15 + GUIOuttextwin2 8,21,140,GUINetTextW + GUIOuttextwin2 8,46,140,GUINetTextW+2 + GUIOuttextwin2 8,71,140,GUINetTextW+4 + GUIOuttextwin2 8,21,150,GUINetTextW+6 + GUIOuttextwin2 8,46,150,GUINetTextW+8 + GUIOuttextwin2 8,10,160,GUINetTextY + GUIOuttextwin2 8,124,140,GUINetTextb + GUIOuttextwin2 8,124,150,GUINetTextc + GUIOuttextwin2 8,124,160,GUINetTextd + GUIOuttextwin2 8,21,180,GUINetTexto2 + add byte[GUItextcolor],15 + GUIOuttextwin2 8,20,139,GUINetTextW + GUIOuttextwin2 8,45,139,GUINetTextW+2 + GUIOuttextwin2 8,70,139,GUINetTextW+4 + GUIOuttextwin2 8,20,149,GUINetTextW+6 + GUIOuttextwin2 8,45,149,GUINetTextW+8 + GUIOuttextwin2 8,9,159,GUINetTextY + GUIOuttextwin2 8,123,139,GUINetTextb + GUIOuttextwin2 8,123,149,GUINetTextc + GUIOuttextwin2 8,123,159,GUINetTextd + GUIOuttextwin2 8,20,179,GUINetTexto2 + + DrawGUIWinBox 8,6,15,181,112,167 + ; draw borders + mov dl,[GUIWincol] + DrawGUIWinBox 8,6,14,181,14,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox 8,5,15,4,112,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox 8,6,113,181,113,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox 8,183,15,182,112,dl + DrawGUIWinBox 8,6,117,181,125,167 + ; disconnect button + DrawGUIButton 8,111,169,181,180,GUINetTextU,27,0,0 + + DrawGUIButton 8,79,156,87,166,GUINetText9,29,-2,0 + DrawGUIButton 8,90,156,98,166,GUINetTextA,30,-2,0 + + + mov byte[GUItextcolor],223 + mov dword[CurCStringPos],ViewBuffer+1 + mov ebx,[CViewLoc] + add dword[CurCStringPos],ebx + GUIOuttextwin2 8,9,36-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,44-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,52-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,60-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,68-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,76-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,84-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,92-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,100-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,108-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,116-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,9,124-18,[CurCStringPos] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero3b + mov byte[GUItextcolor],222 +.zero3b + mov dword[CurCStringPos],ViewBuffer+1 + mov ebx,[CViewLoc] + add dword[CurCStringPos],ebx + GUIOuttextwin2 8,8,35-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,43-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,51-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,59-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,67-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,75-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,83-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,91-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,99-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,107-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,115-18,[CurCStringPos] + add dword[CurCStringPos],32 + GUIOuttextwin2 8,8,123-18,[CurCStringPos] + + ; Determine ChatString Position + push ecx + mov ebx,ChatString + mov ecx,[GUIEditStringcLen] + sub ecx,ebx + cmp ecx,26 + jb .nostring + cmp ecx,255 + ja .nostring + sub ecx,26 + add ebx,ecx +.nostring + mov [CurCStringPos],ebx + pop ecx + + mov byte[GUItextcolor],223 + GUIOuttextwin2 8,10,120,[CurCStringPos] + GUIOuttextwin2 8,60,160,GUINetText8 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],222 +.zero3 + GUIOuttextwin2 8,9,119,[CurCStringPos] + GUIOuttextwin2 8,59,159,GUINetText8 + mov dword[GUIEditString],ChatString + mov dword[GUIEditStringmLen],200 +; mov dword[GUIEditStringmLenM],26 + mov dword[GUIEditStringcWin],1 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 8,7,131,GUINetTextV + GUIOuttextwin2 8,111,131,GUINetTexta + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],164 +.zero + GUIOuttextwin2 8,6,130,GUINetTextV + GUIOuttextwin2 8,110,130,GUINetTexta + + ; ############# +; mov eax,[CViewLoc] +; shr eax,5 +; add eax,12 +; mov [TViewLoc],eax +; 181,112,167 +;CViewLoc dd 0 +;NViewLoc dd 0 +;TViewLoc dd 0 +; 15,181,112 +; DrawSlideBarWin 8,181,15,[NViewLoc],[TViewLoc],12,97,GUINCStA + ret + +NEWSYM GUINCStA, dd 0,0,0 +NEWSYM CNetType, db 0 +NEWSYM Latency, db 2 +NEWSYM Latencytochange, db 2 +NEWSYM LatencyLeft, db 2 +NEWSYM NetSwap, db 0 +RemCNetType db 0 +UseRemoteSRAMData db 0 +ChatString times 276 db 0 +FileNameMod times 512 db 0 +CurCStringPos dd 0 + +GUINetText1 db 'IPX HAS NOT BEEN',0 +GUINetText2 db 'IMPLEMENTED YET',0 +GUINetText1b db 'PLEASE SET THE',0 +GUINetText2b db 'PERCENTAGE OF',0 +GUINetText3b db 'EXECUTION TO 100',0 +GUINetText1c db 'IPX IS IN BETA',0 +GUINetText2c db 'STAGES. IT MAY',0 +GUINetText3c db 'NOT WORK RIGHT!',0 +GUINetText3 db 'COM1 (3F8)',0 +GUINetText4 db 'COM2 (2F8)',0 +GUINetText5 db 'COM3 (3E8)',0 +GUINetText6 db 'COM4 (2E8)',0 +GUINetText7 db 'IRQ ',0 +GUINetText8 db '00',0 +GUINetText9 db '+',0 +GUINetTextA db '-',0 +GUINetTextC db 'TONE (ATDT)',0 +GUINetTextD db 'PULSE (ATDP)',0 +GUINetTextE db 'INIT STRINGS :',0 +GUINetTexte db '1.',0 +GUINetTextf db '2.',0 +GUINetTextF db 'ENTER NUMBER TO DIAL :',0 +GUINetTextG db 'DIAL NUMBER',0 +GUINetTextH db 'WAIT FOR RING',0 +GUINetTexth db 'CONFIG MODEM',0 +GUINetTextI db 'MANUAL',0 +GUINetTextJ db '9600',0 +GUINetTextK db '14400',0 +GUINetTextL db '19200',0 +GUINetTextM db '28800',0 +GUINetTextN db '38400',0 +GUINetTextO db '57600',0 +GUINetTextP db '115200',0 +GUINetTextQ db 'BAUDRATE (BPS) :',0 +GUINetTextR db 'COMPORT :',0 +GUINetTextS db 'CANCEL',0 +GUINetTextT db 'DIAL',0 +GUINetTextU db 'DISCONNECT',0 +GUINetTextV db 'PLAYER SELECT :',0 +GUINetTextW db '1',0,'2',0,'3',0,'4',0,'5',0 +GUINetTextX db 'USE FOSSIL DRIVER',0 +GUINetTextY db 'LATENCY',0 +GUINetTextZ db 'OKAY',0 +GUINetTexta db 'SAVE DATA :',0 +GUINetTextb db 'NONE',0 +GUINetTextc db 'LOCAL',0 +GUINetTextd db 'REMOTE',0 +GUINetTexte2 db 'YOUR IP:',0 +GUINetTextf2 db 'PORT',0 +GUINetTextf3 db 'NICKNAME',0 +GUINetTextg2 db 'START AS SERVER',0 +GUINetTexth2 db 'CLIENT OPTIONS:',0 +GUINetTexti2 db 'IP:',0 +GUINetTextj2 db 'CONNECT TO SERVER',0 +NEWSYM GUINetTextk2, db '',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 +GUINetTextl2 db '7845',0,0,0 +GUINetTextm2 db 0,0,0 +GUINetTextn2 db '_',0 +GUINetTexto2 db 'BACK BUFFER',0 +GUINetTextp2 db 'ALLOW UDP CONNECTION',0 +GUINetTextr1 db 'PLEASE RESTART ZSNESW',0 +GUINetTextr2 db 'BEFORE STARTING A NEW',0 +GUINetTextr3 db 'NETPLAY SESSION',0 + +BaudVal dd 9600,14400,19200,28800,38400,57600,115200 + +DisplayGameOptns: + ; Key redefinition for : + ; Sound Channels 0 .. 7, Save/Select/Load States, Fast Forward + ; State Selection 0 .. 9 + ; Exit, Load, Reset, BG Disables, Reset, Windowing, New Gfx, OffsetMode + GUIDrawWindowBox 9,GUIGameDisp + + ; Draw Shadows + mov al,[GUIWincol] + mov [GUIGameOptnsColA],al + mov byte[GUIGameOptnsColB],202 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUIGameOptnsColB],196 +.zero3 + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,6,16,GUIGameOptnsText3 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + mov byte[GUIGameOptnsText4+2],'1' + GUIOuttextwin2 9,9,26,GUIGameOptnsText4 + mov byte[GUIGameOptnsText4+2],'2' + GUIOuttextwin2 9,9+45,26,GUIGameOptnsText4 + mov byte[GUIGameOptnsText4+2],'3' + GUIOuttextwin2 9,9+90,26,GUIGameOptnsText4 + mov byte[GUIGameOptnsText4+2],'4' + GUIOuttextwin2 9,9+135,26,GUIGameOptnsText4 + GUIOuttextwin2 9,9,34,GUIGameOptnsText5 + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,6,44,GUIGameOptnsTextC + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,9,54,GUIGameOptnsTextD + GUIOuttextwin2 9,9,62,GUIGameOptnsTextL + GUIOuttextwin2 9,9,70,GUIGameOptnsTextE + GUIOuttextwin2 9,9,78,GUIGameOptnsTextF + GUIOuttextwin2 9,9,86,GUIGameOptnsTextG + GUIOuttextwin2 9,9,94,GUIGameOptnsTextT + cmp byte[OSPort],3 + jne near .notwin32 + GUIOuttextwin2 9,109,46,GUIGameOptnsTextS +.notwin32 + GUIOuttextwin2 9,109,54,GUIGameOptnsTextH + GUIOuttextwin2 9,109,62,GUIGameOptnsTextM + GUIOuttextwin2 9,109,70,GUIGameOptnsTextN + GUIOuttextwin2 9,109,78,GUIGameOptnsTextO + GUIOuttextwin2 9,109,86,GUIGameOptnsTextP + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,6,104,GUIGameOptnsText1 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + mov byte[GUIGameOptnsText2+2],'1' + GUIOuttextwin2 9,9,114,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'2' + GUIOuttextwin2 9,9+45,114,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'3' + GUIOuttextwin2 9,9+45*2,114,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'4' + GUIOuttextwin2 9,9+45*3,114,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'5' + GUIOuttextwin2 9,9,122,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'6' + GUIOuttextwin2 9,9+45,122,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'7' + GUIOuttextwin2 9,9+45*2,122,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'8' + GUIOuttextwin2 9,9+45*3,122,GUIGameOptnsText2 + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,6,132,GUIGameOptnsText6 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + mov byte[GUIGameOptnsText7+2],'0' + GUIOuttextwin2 9,9+45*2,134,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'1' + GUIOuttextwin2 9,9+45*3,134,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'2' + GUIOuttextwin2 9,9,141,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'3' + GUIOuttextwin2 9,9+45,142,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'4' + GUIOuttextwin2 9,9+45*2,142,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'5' + GUIOuttextwin2 9,9+45*3,142,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'6' + GUIOuttextwin2 9,9,150,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'7' + GUIOuttextwin2 9,9+45,150,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'8' + GUIOuttextwin2 9,9+45*2,150,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'9' + GUIOuttextwin2 9,9+45*3,150,GUIGameOptnsText7 + GUIOuttextwin2 9,9,160,GUIGameOptnsTextI + GUIOuttextwin2 9,9+57,160,GUIGameOptnsTextJ + GUIOuttextwin2 9,9+114,160,GUIGameOptnsTextK + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,6,170,GUIGameOptnsText8 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,9,180,GUIGameOptnsText9 + GUIOuttextwin2 9,9+57,180,GUIGameOptnsTextA + GUIOuttextwin2 9,9+114,180,GUIGameOptnsTextB + GUIOuttextwin2 9,9,190,GUIGameOptnsTextQ + GUIOuttextwin2 9,9+57,190,GUIGameOptnsTextR + + mov byte[GUIGameOptnsColA],163 + mov byte[GUIGameOptnsColB],217 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUIGameOptnsColA],164 + mov byte[GUIGameOptnsColB],211 +.zero + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,5,15,GUIGameOptnsText3 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + mov byte[GUIGameOptnsText4+2],'1' + GUIOuttextwin2 9,8,25,GUIGameOptnsText4 + mov byte[GUIGameOptnsText4+2],'2' + GUIOuttextwin2 9,8+45,25,GUIGameOptnsText4 + mov byte[GUIGameOptnsText4+2],'3' + GUIOuttextwin2 9,8+90,25,GUIGameOptnsText4 + mov byte[GUIGameOptnsText4+2],'4' + GUIOuttextwin2 9,8+135,25,GUIGameOptnsText4 + GUIOuttextwin2 9,8,33,GUIGameOptnsText5 + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,5,43,GUIGameOptnsTextC + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,8,53,GUIGameOptnsTextD + GUIOuttextwin2 9,8,61,GUIGameOptnsTextL + GUIOuttextwin2 9,8,69,GUIGameOptnsTextE + GUIOuttextwin2 9,8,77,GUIGameOptnsTextF + GUIOuttextwin2 9,8,85,GUIGameOptnsTextG + GUIOuttextwin2 9,8,94,GUIGameOptnsTextT + cmp byte[OSPort],3 + jne near .notwin32b + GUIOuttextwin2 9,108,45,GUIGameOptnsTextS +.notwin32b + GUIOuttextwin2 9,108,53,GUIGameOptnsTextH + GUIOuttextwin2 9,108,61,GUIGameOptnsTextM + GUIOuttextwin2 9,108,69,GUIGameOptnsTextN + GUIOuttextwin2 9,108,77,GUIGameOptnsTextO + GUIOuttextwin2 9,108,85,GUIGameOptnsTextP + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,5,103,GUIGameOptnsText1 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + mov byte[GUIGameOptnsText2+2],'1' + GUIOuttextwin2 9,8,113,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'2' + GUIOuttextwin2 9,8+45,113,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'3' + GUIOuttextwin2 9,8+45*2,113,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'4' + GUIOuttextwin2 9,8+45*3,113,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'5' + GUIOuttextwin2 9,8,121,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'6' + GUIOuttextwin2 9,8+45,121,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'7' + GUIOuttextwin2 9,8+45*2,121,GUIGameOptnsText2 + mov byte[GUIGameOptnsText2+2],'8' + GUIOuttextwin2 9,8+45*3,121,GUIGameOptnsText2 + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,5,131,GUIGameOptnsText6 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + mov byte[GUIGameOptnsText7+2],'0' + GUIOuttextwin2 9,8+45*2,133,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'1' + GUIOuttextwin2 9,8+45*3,133,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'2' + GUIOuttextwin2 9,8,141,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'3' + GUIOuttextwin2 9,8+45,141,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'4' + GUIOuttextwin2 9,8+45*2,141,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'5' + GUIOuttextwin2 9,8+45*3,141,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'6' + GUIOuttextwin2 9,8,149,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'7' + GUIOuttextwin2 9,8+45,149,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'8' + GUIOuttextwin2 9,8+45*2,149,GUIGameOptnsText7 + mov byte[GUIGameOptnsText7+2],'9' + GUIOuttextwin2 9,8+45*3,149,GUIGameOptnsText7 + GUIOuttextwin2 9,8,159,GUIGameOptnsTextI + GUIOuttextwin2 9,8+57,159,GUIGameOptnsTextJ + GUIOuttextwin2 9,8+114,159,GUIGameOptnsTextK + mov al,byte[GUIGameOptnsColA] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,5,169,GUIGameOptnsText8 + mov al,byte[GUIGameOptnsColB] + mov byte[GUItextcolor],al + GUIOuttextwin2 9,8,179,GUIGameOptnsText9 + GUIOuttextwin2 9,8+57,179,GUIGameOptnsTextA + GUIOuttextwin2 9,8+114,179,GUIGameOptnsTextB + GUIOuttextwin2 9,8,189,GUIGameOptnsTextQ + GUIOuttextwin2 9,8+57,189,GUIGameOptnsTextR + + ; Draw black boxes + DGOptnsDrawBox 27,24,[KeyBGDisble0] + DGOptnsDrawBox 27+45,24,[KeyBGDisble1] + DGOptnsDrawBox 27+45*2,24,[KeyBGDisble2] + DGOptnsDrawBox 27+45*3,24,[KeyBGDisble3] + DGOptnsDrawBox 27,32,[KeySprDisble] + DGOptnsDrawBox 78,52,[KeyResetAll] + DGOptnsDrawBox 78,60,[KeyExtraEnab] + DGOptnsDrawBox 78,68,[KeyNewGfxSwt] + DGOptnsDrawBox 78,76,[KeyWinDisble] + DGOptnsDrawBox 78,84,[KeyOffsetMSw] + DGOptnsDrawBox 78,92,[KeySlowDown] + cmp byte[OSPort],3 + jne near .notwin32c + DGOptnsDrawBox 178,44,[KeyRewind] +.notwin32c + DGOptnsDrawBox 178,52,[KeyFastFrwrd] + DGOptnsDrawBox 178,60,[KeyVolUp] + DGOptnsDrawBox 178,68,[KeyVolDown] + DGOptnsDrawBox 178,76,[KeyFRateUp] + DGOptnsDrawBox 178,84,[KeyFRateDown] + DGOptnsDrawBox 27,112,[KeyDisableSC0] + DGOptnsDrawBox 27+45,112,[KeyDisableSC1] + DGOptnsDrawBox 27+45*2,112,[KeyDisableSC2] + DGOptnsDrawBox 27+45*3,112,[KeyDisableSC3] + DGOptnsDrawBox 27,120,[KeyDisableSC4] + DGOptnsDrawBox 27+45,120,[KeyDisableSC5] + DGOptnsDrawBox 27+45*2,120,[KeyDisableSC6] + DGOptnsDrawBox 27+45*3,120,[KeyDisableSC7] + DGOptnsDrawBox 27+45*2,132,[KeyStateSlc0] + DGOptnsDrawBox 27+45*3,132,[KeyStateSlc1] + DGOptnsDrawBox 27,140,[KeyStateSlc2] + DGOptnsDrawBox 27+45,140,[KeyStateSlc3] + DGOptnsDrawBox 27+45*2,140,[KeyStateSlc4] + DGOptnsDrawBox 27+45*3,140,[KeyStateSlc5] + DGOptnsDrawBox 27,148,[KeyStateSlc6] + DGOptnsDrawBox 27+45,148,[KeyStateSlc7] + DGOptnsDrawBox 27+45*2,148,[KeyStateSlc8] + DGOptnsDrawBox 27+45*3,148,[KeyStateSlc9] + DGOptnsDrawBox 8+25,158,[KeySaveState] + DGOptnsDrawBox 8+57+25,158,[KeyLoadState] + DGOptnsDrawBox 8+114+25,158,[KeyStateSelct] + DGOptnsDrawBox 8+25,178,[KeyQuickLoad] + DGOptnsDrawBox 8+57+31,178,[KeyQuickRst] + DGOptnsDrawBox 8+114+25,178,[KeyQuickExit] + DGOptnsDrawBox 8+25,188,[KeyQuickChat] + DGOptnsDrawBox 8+57+49,188,[KeyQuickSnapShot] + ret + +GUIGameOptnsColA db 0 +GUIGameOptnsColB db 0 +GUIGameDisplayKy dd 0 +GUIGameOptnsText1 db 'SOUND DISABLES :',0 +GUIGameOptnsText2 db 'CH#',0 +GUIGameOptnsText3 db 'BG DISABLES :',0 +GUIGameOptnsText4 db 'BG#',0 +GUIGameOptnsText5 db 'OBJ ',0 +GUIGameOptnsText6 db 'STATE SELECTS :',0 +GUIGameOptnsText7 db 'ST#',0 +GUIGameOptnsText8 db 'QUICK KEYS :',0 +GUIGameOptnsText9 db 'LOAD',0 +GUIGameOptnsTextA db 'RESET',0 +GUIGameOptnsTextB db 'EXIT',0 +GUIGameOptnsTextC db 'MISC TOGGLES :',0 +GUIGameOptnsTextD db 'CLRSWITCHES',0 +GUIGameOptnsTextE db 'NEW GFX ENG',0 +GUIGameOptnsTextF db 'BG WINDOW',0 +GUIGameOptnsTextG db 'OFFSET MODE',0 +GUIGameOptnsTextH db 'FASTFWD KEY',0 +GUIGameOptnsTextI db 'SAVE',0 +GUIGameOptnsTextJ db 'LOAD',0 +GUIGameOptnsTextK db 'PICK',0 +GUIGameOptnsTextL db 'EXTRADEVICE',0 +GUIGameOptnsTextM db '+VOL',0 +GUIGameOptnsTextN db '-VOL',0 +GUIGameOptnsTextO db '+FRAME RATE',0 +GUIGameOptnsTextP db '-FRAME RATE',0 +GUIGameOptnsTextQ db 'CHAT',0 +GUIGameOptnsTextR db 'SNAPSHOT',0 +GUIGameOptnsTextS db 'REWIND KEY',0 +GUIGameOptnsTextT db 'SLOWDWN KEY',0 + +DisplayGUIOptns: + GUIDrawWindowBox 10,GUIGUIDisp + mov eax,dword[GUIwinposx+10*4] + mov ebx,dword[GUIwinposy+10*4] + mov ecx,eax + add eax,25 + add ecx,25+32*4 + add ebx,124 + xor edx,edx + mov dl,215 + sub dl,[GUIWincoladd] + DrawGUILine + add ebx,11 + DrawGUILine + add ebx,11 + DrawGUILine + inc ecx + mov ebx,dword[GUIwinposy+10*4] + inc eax + add ebx,125 + sub dl,13 + DrawGUILine + add ebx,11 + DrawGUILine + add ebx,11 + DrawGUILine + xor eax,eax + mov al,[GUIRAdd] + shl eax,2 + mov dword[GUITemp],22 + add [GUITemp],eax + GUIDisplayIconWin 10,[GUITemp],120,GUIIconDataSlideBar + xor eax,eax + mov al,[GUIGAdd] + shl eax,2 + mov dword[GUITemp],22 + add [GUITemp],eax + GUIDisplayIconWin 10,[GUITemp],132,GUIIconDataSlideBar + xor eax,eax + mov al,[GUIBAdd] + shl eax,2 + mov dword[GUITemp],22 + add [GUITemp],eax + GUIDisplayIconWin 10,[GUITemp],144,GUIIconDataSlideBar + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[mousewrap],1 + jne .nocheck + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck + cmp byte[OSPort],3 + je near .win32 + GUIDisplayIconWin 10,12,23,[GUITemp] +.win32 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[mouseshad],1 + jne .nocheck2 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck2 + GUIDisplayIconWin 10,12,33,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[lastcursres],1 + jne .nocheck3 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck3 + GUIDisplayIconWin 10,12,43,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[resetposn],1 + je .nocheck4 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck4 + GUIDisplayIconWin 10,12,53,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[GUIClick],1 + jne .nocheck5 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck5 + GUIDisplayIconWin 10,12,63,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[JoyPad1Move],1 + jne .nocheck6 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck6 + GUIDisplayIconWin 10,12,73,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[GUIEffect],1 + jne .nocheck7 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck7 + GUIDisplayIconWin 10,12,83,[GUITemp] + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[GUIEffect],2 + jne .nocheck8 + mov dword[GUITemp],GUIIconDataCheckBoxC +.nocheck8 + GUIDisplayIconWin 10,12,93,[GUITemp] + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 10,6,111,GUIGUIOptnsText1 + GUIOuttextwin2 10,6,16,GUIGUIOptnsText5 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],164 +.zero + GUIOuttextwin2 10,5,110,GUIGUIOptnsText1 + GUIOuttextwin2 10,5,15,GUIGUIOptnsText5 + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],211 +.zero3 + sub byte[GUItextcolor],15 + cmp byte[OSPort],3 + je near .win32b + GUIOuttextwin2u 10,26,28,GUIGUIOptnsText2,0 +.win32b + GUIOuttextwin2u 10,26,38,GUIGUIOptnsText3,6 + GUIOuttextwin2u 10,26,48,GUIGUIOptnsText4,0 + GUIOuttextwin2u 10,26,58,GUIGUIOptnsText7,5 + GUIOuttextwin2u 10,26,68,GUIGUIOptnsText8,0 + GUIOuttextwin2u 10,26,78,GUIGUIOptnsTextA,0 + GUIOuttextwin2 10,26,88,GUIGUIOptnsTextB + GUIOuttextwin2 10,26,98,GUIGUIOptnsTextC + mov byte[GUIGUIOptnsText6],'R' + GUIOuttextwin2 10,16,123,GUIGUIOptnsText6 + mov byte[GUIGUIOptnsText6],'G' + GUIOuttextwin2 10,16,135,GUIGUIOptnsText6 + mov byte[GUIGUIOptnsText6],'B' + GUIOuttextwin2 10,16,147,GUIGUIOptnsText6 + add byte[GUItextcolor],15 + cmp byte[OSPort],3 + je near .win32c + GUIOuttextwin2 10,25,27,GUIGUIOptnsText2 +.win32c + GUIOuttextwin2 10,25,37,GUIGUIOptnsText3 + GUIOuttextwin2 10,25,47,GUIGUIOptnsText4 + GUIOuttextwin2 10,25,57,GUIGUIOptnsText7 + GUIOuttextwin2 10,25,67,GUIGUIOptnsText8 + GUIOuttextwin2 10,25,77,GUIGUIOptnsTextA + GUIOuttextwin2 10,25,87,GUIGUIOptnsTextB + GUIOuttextwin2 10,25,97,GUIGUIOptnsTextC + mov byte[GUIGUIOptnsText6],'R' + GUIOuttextwin2 10,15,122,GUIGUIOptnsText6 + mov byte[GUIGUIOptnsText6],'G' + GUIOuttextwin2 10,15,134,GUIGUIOptnsText6 + mov byte[GUIGUIOptnsText6],'B' + GUIOuttextwin2 10,15,146,GUIGUIOptnsText6 + + mov dword[GUIGUIOptnsText9],0 + mov esi,GUIGUIOptnsText9+2 + xor eax,eax + mov al,[GUIRAdd] + call .processnum + GUIOuttextwin2 10,160,123,[GUITemp] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero5 + mov byte[GUItextcolor],222 +.zero5 + GUIOuttextwin2 10,159,122,[GUITemp] + mov dword[GUIGUIOptnsText9],0 + mov esi,GUIGUIOptnsText9+2 + xor eax,eax + mov al,[GUIGAdd] + call .processnum + GUIOuttextwin2 10,160,135,[GUITemp] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero6 + mov byte[GUItextcolor],222 +.zero6 + GUIOuttextwin2 10,159,134,[GUITemp] + mov dword[GUIGUIOptnsText9],0 + mov esi,GUIGUIOptnsText9+2 + xor eax,eax + mov al,[GUIBAdd] + call .processnum + GUIOuttextwin2 10,160,147,[GUITemp] + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zero7 + mov byte[GUItextcolor],222 +.zero7 + GUIOuttextwin2 10,159,146,[GUITemp] + ret + +.processnum + mov ebx,10 + div bl + add ah,48 + mov [esi],ah + cmp al,0 + je .nomore + dec esi + xor ah,ah + div bl + add ah,48 + mov [esi],ah +.nomore + mov [GUITemp],esi + mov byte[GUItextcolor],223 + ret + +;mousewrap db 0 ; 0 = mouse boundries, 1 = mouse wrap +;mouseshad db 1 ; 0 = no mouse shadow, 1 = mouse shadow +;lastcursres db 0 ; 0 = go to load, 1 = go to previous menu, 2 = no menu +;resetposn db 1 ; 0 = no window reset, 1 = window reset + +GUIGUIOptnsText1 db 'BACK COLOR DISPLACEMENT :',0 +GUIGUIOptnsText2 db 'MOUSE WRAP',0 +GUIGUIOptnsText3 db 'MOUSE SHADOW',0 +GUIGUIOptnsText4 db 'KEEP MENU POSITION',0 +GUIGUIOptnsText5 db 'GUI SWITCHES :',0 +GUIGUIOptnsText6 db '@',0 +GUIGUIOptnsText7 db 'SAVE WINDOW POSITIONS',0 +GUIGUIOptnsText8 db 'CLICK ENTERS/EXITS GUI',0 +GUIGUIOptnsText9 dd 0 +GUIGUIOptnsTextA db 'USE JOYPAD1 TO CONTROL',0 +GUIGUIOptnsTextB dd 'ENABLE SNOW EFFECT',0 +GUIGUIOptnsTextC dd 'ENABLE WATER EFFECT',0 + +DisplayGUIAbout: + cmp byte[OSPort],3 + jne .notwin32 + mov dword[GUIwinsizey+11*4],94 +.notwin32 + mov byte[GUIGUIAboutText1+1],'S'+136 + mov byte[GUIGUIAboutText1+2],'N'-26 + add byte[GUIGUIAboutText1+2],26 + sub byte[GUIGUIAboutText1+1],136 + mov byte[GUIGUIAboutText1+4],'S'-97 + GUIDrawWindowBox 11,GUIAboutDisp + mov byte[GUItextcolor],217 + cmp byte[GUIWincoladd],0 + je .zero3 + mov byte[GUItextcolor],211 +.zero3 + add byte[GUIGUIAboutText1+4],97 + cmp byte[OSPort],3 + je near .win32 + sub byte[GUItextcolor],15 + GUIOuttextwin2 11,6,16,GUIGUIAboutText1 + GUIOuttextwin2 11,6,36,GUIGUIAboutText3 + GUIOuttextwin2 11,6,46,GUIGUIAboutText4 + GUIOuttextwin2 11,6,66,GUIGUIAboutText6 + add byte[GUItextcolor],15 + GUIOuttextwin2 11,5,15,GUIGUIAboutText1 + GUIOuttextwin2 11,5,35,GUIGUIAboutText3 + GUIOuttextwin2 11,5,45,GUIGUIAboutText4 + GUIOuttextwin2 11,5,65,GUIGUIAboutText6 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 11,6,26,GUIGUIAboutText2 + GUIOuttextwin2 11,6,56,GUIGUIAboutText5 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],164 +.zero + GUIOuttextwin2 11,5,25,GUIGUIAboutText2 + GUIOuttextwin2 11,5,55,GUIGUIAboutText5 + ret +.win32 + DrawGUIButton 11,5,87,74,98,GUIGUIAboutText8,65,0,0 + sub byte[GUItextcolor],15 + GUIOuttextwin2 11,6,16,GUIGUIAboutText1 + GUIOuttextwin2 11,6,26,GUIGUIAboutText7 + GUIOuttextwin2 11,6,46,GUIGUIAboutText3 + GUIOuttextwin2 11,6,56,GUIGUIAboutText4 + GUIOuttextwin2 11,6,76,GUIGUIAboutText6 + add byte[GUItextcolor],15 + GUIOuttextwin2 11,5,15,GUIGUIAboutText1 + GUIOuttextwin2 11,5,25,GUIGUIAboutText7 + GUIOuttextwin2 11,5,45,GUIGUIAboutText3 + GUIOuttextwin2 11,5,55,GUIGUIAboutText4 + GUIOuttextwin2 11,5,75,GUIGUIAboutText6 + mov al,[GUIWincol] + mov byte[GUItextcolor],al + GUIOuttextwin2 11,6,36,GUIGUIAboutText2 + GUIOuttextwin2 11,6,66,GUIGUIAboutText5 + mov byte[GUItextcolor],163 + cmp byte[GUIWincoladd],0 + je .zero2b + mov byte[GUItextcolor],164 +.zero2b + GUIOuttextwin2 11,5,35,GUIGUIAboutText2 + GUIOuttextwin2 11,5,65,GUIGUIAboutText5 + ret + +GUIGUIAboutText1 db 'ZSNES V0.Agh ',0 +GUIGUIAboutText2 db 'CODED BY : ',0 +GUIGUIAboutText3 db ' ZSKNIGHT',0 +GUIGUIAboutText4 db ' _DEMO_',0 +GUIGUIAboutText5 db 'ASSISTANT CODER : ',0 +GUIGUIAboutText6 db ' PHAROS',0 +GUIGUIAboutText7 db 'WIN PORT V0.85',0 +GUIGUIAboutText8 db 'HOMEPAGE',0 + +DisplayGUIMovies: + GUIDrawWindowBox 15,GUIMovieDisp + cmp byte[MovieRecordWinVal],0 + je near .displayboxa + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],211 +.zero4 + sub byte[GUItextcolor],15 + GUIOuttextwin2 15,9,16,GUIMovieText5 + GUIOuttextwin2 15,9,26,GUIMovieText6 + GUIOuttextwin2 15,9,41,GUIMovieText7 + add byte[GUItextcolor],15 + GUIOuttextwin2 15,8,15,GUIMovieText5 + GUIOuttextwin2 15,8,25,GUIMovieText6 + GUIOuttextwin2 15,8,40,GUIMovieText7 + DrawGUIButton 15,17,55,59,66,GUIMovieText8,19,0,0 + DrawGUIButton 15,70,55,112,66,GUIMovieText9,20,0,0 + ret +.displayboxa + mov dword[GUIMovieTextA+9],'INAC' + mov dword[GUIMovieTextA+13],'TIVE' + mov byte[GUIMovieTextA+17],' ' + cmp byte[MovieProcessing],1 + jne .noplay + mov dword[GUIMovieTextA+9],'PLAY' + mov dword[GUIMovieTextA+13],'ING ' + mov byte[GUIMovieTextA+17],' ' +.noplay + cmp byte[MovieProcessing],2 + jne .norec + mov dword[GUIMovieTextA+9],'RECO' + mov dword[GUIMovieTextA+13],'RDIN' + mov byte[GUIMovieTextA+17],'G' +.norec + DrawGUIButton 15,7,17,49,28,GUIMovieText1,16,0,0 + DrawGUIButton 15,7,33,49,44,GUIMovieText2,17,0,0 + DrawGUIButton 15,7,49,49,60,GUIMovieText3,18,0,0 + cmp byte[GUIWincoladd],0 + je .zero + mov byte[GUItextcolor],211 +.zero + sub byte[GUItextcolor],15 + GUIOuttextwin2 15,61,16,GUIMovieText4 + GUIOuttextwin2 15,7,70,GUIMovieTextA + mov byte[GUIChoseSaveText2],'0' + GUIOuttextwin2 15,71,28,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'1' + GUIOuttextwin2 15,91,28,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'2' + GUIOuttextwin2 15,111,28,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'3' + GUIOuttextwin2 15,131,28,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'4' + GUIOuttextwin2 15,71,43,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'5' + GUIOuttextwin2 15,91,43,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'6' + GUIOuttextwin2 15,111,43,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'7' + GUIOuttextwin2 15,131,43,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'8' + GUIOuttextwin2 15,71,58,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'9' + GUIOuttextwin2 15,91,58,GUIChoseSaveText2 + add byte[GUItextcolor],15 + GUIOuttextwin2 15,60,15,GUIMovieText4 + GUIOuttextwin2 15,6,69,GUIMovieTextA + mov byte[GUIChoseSaveText2],'0' + GUIOuttextwin2 15,70,27,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'1' + GUIOuttextwin2 15,90,27,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'2' + GUIOuttextwin2 15,110,27,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'3' + GUIOuttextwin2 15,130,27,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'4' + GUIOuttextwin2 15,70,42,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'5' + GUIOuttextwin2 15,90,42,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'6' + GUIOuttextwin2 15,110,42,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'7' + GUIOuttextwin2 15,130,42,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'8' + GUIOuttextwin2 15,70,57,GUIChoseSaveText2 + mov byte[GUIChoseSaveText2],'9' + GUIOuttextwin2 15,90,57,GUIChoseSaveText2 + GUIDisplayButtonHole 15,60,25,byte[CMovieExt],'V' + GUIDisplayButtonHole 15,80,25,byte[CMovieExt],'1' + GUIDisplayButtonHole 15,100,25,byte[CMovieExt],'2' + GUIDisplayButtonHole 15,120,25,byte[CMovieExt],'3' + GUIDisplayButtonHole 15,60,40,byte[CMovieExt],'4' + GUIDisplayButtonHole 15,80,40,byte[CMovieExt],'5' + GUIDisplayButtonHole 15,100,40,byte[CMovieExt],'6' + GUIDisplayButtonHole 15,120,40,byte[CMovieExt],'7' + GUIDisplayButtonHole 15,60,55,byte[CMovieExt],'8' + GUIDisplayButtonHole 15,80,55,byte[CMovieExt],'9' + ret + +GUIMovieText1 db 'PLAY',0 +GUIMovieText2 db 'RECORD',0 +GUIMovieText3 db 'STOP',0 +GUIMovieText4 db 'SELECT :',0 +GUIMovieText5 db 'WARNING : THIS MOVIE',0 +GUIMovieText6 db ' FILE ALREADY EXISTS',0 +GUIMovieText7 db 'OKAY TO OVERWRITE?',0 +GUIMovieText8 db 'YES',0 +GUIMovieText9 db 'NO',0 +GUIMovieTextA db 'STATUS : ',0 +CMovieExt db 'V' + +; Key types: Up, Down, Left, Right, A, B, X, Y, L, R (Press/Relase/P+R) +; Frame delays: 1 frame, 2, 3, 4, 5, 1 sec., 2, 3 ,4 ,5 + +%macro DrawBorderedBox 6 + ; draw borders + mov dl,[GUIWincol] + DrawGUIWinBox %1,%2,%6,%4,%3,dl ; For some reason, this freezes if I + ; replace %6 with %3-1 + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox %1,%2-1,%3,%2,%5,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox %1,%2,%5,%4,%5+1,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox %1,%4,%3,%4+1,%5,dl + DrawGUIWinBox %1,%2,%3,%4,%5,167 +%endmacro + +%macro DrawBorderedBoxB 7 ; Special function for combo displays + ; draw borders + mov dl,[GUIWincol] + DrawGUIWinBox %1,%2,%6,%4,%3,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox %1,%2-1,%3,%2,%5,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox %1,%2,%5,%4,%5+1,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox %1,%4,%3,%4+1,%5,dl + DrawGUIWinBox %1,%2,%3,%4,%5,167 + mov byte[GUIComboText3],%7 + mov byte[GUItextcolor],223 + GUIOuttextwin2 %1,%2+5,%3+2,GUIComboText3 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je %%zero + mov byte[GUItextcolor],222 +%%zero + GUIOuttextwin2 %1,%2+4,%3+1,GUIComboText3 +%endmacro + +%macro DrawBorderedBoxB2 7 ; Special function for combo displays + ; draw borders + mov dl,[GUIWincol] + DrawGUIWinBox %1,%2,%6,%4,%3,dl + mov dl,[GUIWincol] + add dl,1 + DrawGUIWinBox %1,%2-1,%3,%2,%5,dl + mov dl,[GUIWincol] + add dl,4 + DrawGUIWinBox %1,%2,%5,%4,%5+1,dl + mov dl,[GUIWincol] + add dl,3 + DrawGUIWinBox %1,%4,%3,%4+1,%5,dl + DrawGUIWinBox %1,%2,%3,%4,%5,167 + mov byte[GUIComboText3b+1],%7 + mov byte[GUItextcolor],223 + GUIOuttextwin2 %1,%2+2,%3+2,GUIComboText3b + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je %%zero + mov byte[GUItextcolor],222 +%%zero + GUIOuttextwin2 %1,%2+1,%3+1,GUIComboText3b +%endmacro + +%macro InitTextColor 0 + mov al,217 + cmp byte[GUIWincoladd],0 + je .zero3 + mov al,211 +.zero3 + sub al,15 + mov byte[TextColorSp+2],al + mov al,[GUIWincol] + mov byte[TextColorSp],al + mov al,163 + cmp byte[GUIWincoladd],0 + je .zero + mov al,164 + mov byte[GUItextcolor],164 +.zero + mov byte[TextColorSp+1],al +%endmacro + +%macro GUIOuttextwin2b 4 ; Normal, white text + mov al,[TextColorSp+2] + mov byte[GUItextcolor],al + GUIOuttextwin2 %1,%2,%3,%4 + add byte[GUItextcolor],15 + GUIOuttextwin2 %1,%2-1,%3-1,%4 +%endmacro + +%macro GUIOuttextwin2c 4 ; Special, yellow text + mov al,[TextColorSp] + mov byte[GUItextcolor],al + GUIOuttextwin2 %1,%2,%3,%4 + mov al,[TextColorSp+1] + mov byte[GUItextcolor],al + GUIOuttextwin2 %1,%2-1,%3-1,%4 +%endmacro + +%macro GUIOuttextwin2d 4 ; Boxed, green text + mov byte[GUItextcolor],223 + GUIOuttextwin2 %1,%2,%3,%4 + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je %%zero + mov byte[GUItextcolor],222 +%%zero + GUIOuttextwin2 %1,%2-1,%3-1,%4 +%endmacro + +%macro DrawSlideBar 10 + DrawSlideBarWin %1,%2,%3+8,%4,%5,%6,%7-16,%8 + mov al,[TextColorSp+2] + mov byte[GUItextcolor],al + cmp byte[GUICHold],%9 + jne .noholda + add byte[GUIWincoladd],3 +.noholda + GUIDisplayIconWin %1,%2,%3,GUIIconDataUpArrow + cmp byte[GUICHold],%9 + jne .noholda2 + sub byte[GUIWincoladd],3 +.noholda2 + mov al,[TextColorSp+2] + mov byte[GUItextcolor],al + cmp byte[GUICHold],%10 + jne .noholdb + add byte[GUIWincoladd],3 +.noholdb + GUIDisplayIconWin %1,%2,%3+%7-8,GUIIconDataDownArrow + cmp byte[GUICHold],%10 + jne .noholdb2 + sub byte[GUIWincoladd],3 +.noholdb2 +%endmacro + +%macro DrawCheckBox 4 + mov dword[GUITemp],GUIIconDataCheckBoxUC + cmp byte[%4],0 + je %%nocheck4 + mov dword[GUITemp],GUIIconDataCheckBoxC +%%nocheck4 + GUIDisplayIconWin %1,%2,%3,[GUITemp] +%endmacro + + +%macro DetermineChar 2 + cmp al,%1 + jne %%control + mov al,%2 +%%control +%endmacro + +DisplayGUICombo: + mov eax,[GUIccombcursloc] + cmp [GUIccomblcursloc],eax + je .nolastcurschange + mov [GUIccomblcursloc],eax + ; copy contents into temporary variables + mov esi,[GUIccombcursloc] + shl esi,6 + add esi,[GUIccombcursloc] + add esi,[GUIccombcursloc] + add esi,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespecb + sub esi,CombinDataGlob + add esi,CombinDataLocl +.nogamespecb + ; copy 20 bytes to GUIComboTextH + mov ecx,20 + mov edi,GUIComboTextH + rep movsb + ; copy 42 bytes to GUIComboData + mov ecx,42 + mov edi,GUIComboData + rep movsb + mov ax,[esi] + mov [GUIComboKey],ax + mov al,[esi+2] + mov [GUIComboPNum],al + mov al,[esi+3] + mov [GUIComboLHorz],al + ; determine length of combo data + mov eax,GUIComboData + xor ecx,ecx +.notfin + cmp byte[eax],0 + je .fin + inc eax + inc ecx + jmp .notfin +.fin + mov [GUINumCombo],cl +.nolastcurschange + + ; copy into data if description equal + mov esi,[GUIccombcursloc] + shl esi,6 + add esi,[GUIccombcursloc] + add esi,[GUIccombcursloc] + add esi,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespecc + sub esi,CombinDataGlob + add esi,CombinDataLocl +.nogamespecc + mov ecx,20 + mov edi,GUIComboTextH +.comploop + mov al,[esi] + cmp al,[edi] + jne near .notequal + or al,al + jz .donecomp + inc esi + inc edi + loop .comploop +.donecomp + call ComboClip + mov edi,[GUIccombcursloc] + shl edi,6 + add edi,[GUIccombcursloc] + add edi,[GUIccombcursloc] + add edi,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespecd + sub edi,CombinDataGlob + add edi,CombinDataLocl +.nogamespecd + mov ecx,20 + mov esi,GUIComboTextH + rep movsb + ; copy 42 bytes to GUIComboData + mov ecx,42 + mov esi,GUIComboData + rep movsb + mov ax,[GUIComboKey] + mov [edi],ax + mov al,[GUIComboPNum] + mov [edi+2],al + mov al,[GUIComboLHorz] + mov [edi+3],al +.notequal + InitTextColor + + cmp byte[GUIWincoladd],0 + je .zero4 + mov byte[GUItextcolor],211 +.zero4 + + GUIDrawWindowBox 16,GUIComboDisp + + DrawBorderedBox 16,10,20,190,80,19 + DrawBorderedBox 16,10,91,130,99,90 + DrawBorderedBox 16,135,91,157,99,90 + DrawBorderedBox 16,10,110,220,146,109 + + ; Draw SlideBar + ; win#,X,Y start,List Loc,List size,# Lines,Bar Size(Y),UpArrowResource#,DownArrowRes# + DrawSlideBar 16,192,20,[GUIccombviewloc],[NumCombo],8,61,GUICSStC,13,14 + + ; Draw control boxes + DrawBorderedBoxB 16,75,150,85,157,149,251 + DrawBorderedBoxB 16,89,150,99,157,149,252 + DrawBorderedBoxB 16,103,150,113,157,149,253 + DrawBorderedBoxB 16,117,150,127,157,149,254 + DrawBorderedBoxB 16,131,150,141,157,149,'A' + DrawBorderedBoxB 16,145,150,155,157,149,'B' + DrawBorderedBoxB 16,159,150,169,157,149,'X' + DrawBorderedBoxB 16,173,150,183,157,149,'Y' + DrawBorderedBoxB 16,187,150,197,157,149,'L' + DrawBorderedBoxB 16,201,150,211,157,149,'R' + DrawBorderedBoxB2 16,215,150,227,157,149,'T' + DrawBorderedBoxB2 16,231,150,243,157,149,'L' + + DrawBorderedBoxB 16,75,160,85,167,159,251 + DrawBorderedBoxB 16,89,160,99,167,159,252 + DrawBorderedBoxB 16,103,160,113,167,159,253 + DrawBorderedBoxB 16,117,160,127,167,159,254 + DrawBorderedBoxB 16,131,160,141,167,159,'A' + DrawBorderedBoxB 16,145,160,155,167,159,'B' + DrawBorderedBoxB 16,159,160,169,167,159,'X' + DrawBorderedBoxB 16,173,160,183,167,159,'Y' + DrawBorderedBoxB 16,187,160,197,167,159,'L' + DrawBorderedBoxB 16,201,160,211,167,159,'R' + DrawBorderedBoxB2 16,215,160,227,167,159,'T' + DrawBorderedBoxB2 16,231,160,243,167,159,'L' + + DrawBorderedBoxB 16,75,170,85,177,169,251 + DrawBorderedBoxB 16,89,170,99,177,169,252 + DrawBorderedBoxB 16,103,170,113,177,169,253 + DrawBorderedBoxB 16,117,170,127,177,169,254 + DrawBorderedBoxB 16,131,170,141,177,169,'A' + DrawBorderedBoxB 16,145,170,155,177,169,'B' + DrawBorderedBoxB 16,159,170,169,177,169,'X' + DrawBorderedBoxB 16,173,170,183,177,169,'Y' + DrawBorderedBoxB 16,187,170,197,177,169,'L' + DrawBorderedBoxB 16,201,170,211,177,169,'R' + DrawBorderedBoxB2 16,215,170,227,177,169,'T' + DrawBorderedBoxB2 16,231,170,243,177,169,'L' + + DrawBorderedBoxB 16,10,189,20,196,188,'1' + DrawBorderedBoxB 16,24,189,34,196,188,'2' + DrawBorderedBoxB 16,38,189,48,196,188,'3' + DrawBorderedBoxB 16,52,189,62,196,188,'4' + DrawBorderedBoxB 16,66,189,76,196,188,'5' + DrawBorderedBoxB 16,80,189,90,196,188,'9' + + DrawBorderedBoxB 16,107,189,117,196,188,250 + DrawBorderedBoxB 16,121,189,131,196,188,'1' + DrawBorderedBoxB 16,135,189,145,196,188,'2' + DrawBorderedBoxB 16,149,189,159,196,188,'3' + DrawBorderedBoxB 16,163,189,173,196,188,'4' + DrawBorderedBoxB 16,177,189,187,196,188,'5' + + DrawBorderedBoxB 16,204,189,218,196,188,255 + + ; Normal Text + GUIOuttextwin2b 16,10,13,GUIComboText1 + GUIOuttextwin2b 16,138,13,GUIComboText2 + GUIOuttextwin2b 16,10,84,GUIComboTextE + GUIOuttextwin2b 16,138,84,GUIComboTextF + GUIOuttextwin2b 16,10,103,GUIComboText4 + GUIOuttextwin2b 16,10,152,GUIComboText5 + GUIOuttextwin2b 16,10,162,GUIComboText6 + GUIOuttextwin2b 16,10,172,GUIComboText7 + GUIOuttextwin2b 16,10,182,GUIComboText8 + GUIOuttextwin2b 16,114,182,GUIComboText9 + GUIOuttextwin2b 16,204,182,GUIComboTextG + GUIOuttextwin2b 16,165,85,GUIComboTextI + GUIOuttextwin2b 16,176,93,GUIComboTextJ + GUIOuttextwin2b 16,176,101,GUIComboTextK + + ; Calculate Text Cursor Position / Draw Box Text + xor eax,eax +.nozerocp + cmp byte[GUIComboTextH+eax],0 + je .zerocp + inc eax + jmp .nozerocp +.zerocp + mov [GUIComboPos],al + test byte[GUICCFlash],8 + jnz .nound + mov byte[GUIComboTextH+eax],'_' + mov byte[GUIComboTextH+eax+1],0 +.nound + GUIOuttextwin2d 16,12,94,GUIComboTextH + xor eax,eax + mov al,[GUIComboPos] + mov byte[GUIComboTextH+eax],0 + + ; Display Current Combo Key + mov eax,[GUIComboKey] + mov ebx,[ScanCodeListing+eax*3] + mov [GUIGameDisplayKy],ebx + mov byte[GUIGameDisplayKy+3],0 + GUIOuttextwin2d 16,139,94,GUIGameDisplayKy + + ; Buttons + mov al,[TextColorSp+2] + add al,15 + mov byte[GUItextcolor],al + DrawGUIButton 16,202,20,246,31,GUIComboTextA,60,-1,0 + DrawGUIButton 16,202,35,246,46,GUIComboTextB,61,-1,0 + DrawGUIButton 16,202,50,246,61,GUIComboTextC,62,-1,0 + DrawGUIButton 16,202,65,246,76,GUIComboTextD,63,-1,0 + + ; Hole Switches + GUIDisplayButtonHole 16,178,82,byte[GUIComboPNum],0 + GUIDisplayButtonHole 16,196,82,byte[GUIComboPNum],1 + GUIDisplayButtonHole 16,214,82,byte[GUIComboPNum],2 + GUIDisplayButtonHole 16,232,82,byte[GUIComboPNum],3 + + ; Check Box + DrawCheckBox 16,163,88,GUIComboLHorz + DrawCheckBox 16,163,96,GUIComboGameSpec + + ; Draw Combination Keys (Each 15x11 -> 210x36) + xor eax,eax + mov al,[GUINumCombo] + or eax,eax + jz near .comboend + xor ebx,ebx + mov ecx,11 + mov edx,112 +.comboiconloop + push eax + mov al,[GUIComboData+ebx] + dec al + mov esi,GUIIconDataComboPressRelease + cmp al,12 + jb .doneicon + mov esi,GUIIconDataComboPress + sub al,12 + cmp al,12 + jb .doneicon + mov esi,GUIIconDataComboRelease + sub al,12 + cmp al,12 + jb .doneicon + mov esi,GUIIconDataComboFrame + cmp al,17 + jne .not9 + mov al,20 + jmp .doneicon +.not9 + cmp al,18 + jb .doneicon + sub al,7 + mov esi,GUIIconDataComboSecond + cmp al,11 + jne .notback + mov al,250-37 + jmp .doneicon +.notback +.doneicon + cmp al,11 + jbe .control + add al,37 +.control + DetermineChar 0,251 + DetermineChar 1,252 + DetermineChar 2,253 + DetermineChar 3,254 + DetermineChar 4,'A' + DetermineChar 5,'B' + DetermineChar 6,'X' + DetermineChar 7,'Y' + DetermineChar 8,'L' + DetermineChar 9,'R' + DetermineChar 10,'T' + DetermineChar 11,'E' + mov [GUIComboText3],al + pushad + mov eax,edx + add ecx,8 + add eax,5 + + mov byte[GUItextcolor],223 + push ecx + push eax + GUIOuttextwin2 16,ecx,eax,GUIComboText3 + pop eax + pop ecx + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zerocol + mov byte[GUItextcolor],222 +.zerocol + dec ecx + dec eax + GUIOuttextwin2 16,ecx,eax,GUIComboText3 + + popad + push ecx + push edx + push ebx + GUIDisplayIconWin 16,ecx,edx,esi + pop ebx + pop edx + pop ecx + pop eax + add ecx,15 + cmp ecx,11+15*14 + jne .notoverflowx + sub ecx,15*14 + add edx,11 +.notoverflowx + inc ebx + dec eax + jnz near .comboiconloop +.comboend + + ; Display Bordered Box + cmp dword[NumCombo],0 + je near .nowinbox + mov ebx,[GUIccombcursloc] + sub ebx,[GUIccombviewloc] + mov eax,ebx + lea ebx,[ebx*8] + sub ebx,eax + add ebx,23 + DrawGUIWinBox2 16,10,190,7,224 +.nowinbox + + ; Display Scroll Lines + ; Copy Description to GUIScrolBufA, Others to GUIScrolBufB + mov edi,[GUIccombviewloc] + shl edi,6 + add edi,[GUIccombviewloc] + add edi,[GUIccombviewloc] + add edi,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je .nogamespec + sub edi,CombinDataGlob + add edi,CombinDataLocl +.nogamespec + + mov ecx,12 + mov eax,25 + mov ebx,[NumCombo] + sub ebx,[GUIccombviewloc] + cmp ebx,0 + jle near .noscrolldisplay + cmp ebx,8 + jbe .scrolloop + mov ebx,8 +.scrolloop + push ebx + push edi + push eax + + xor eax,eax + mov ax,[edi+62] + mov eax,[ScanCodeListing+eax*3] + mov [GUIScrolBufB],eax + mov byte[GUIScrolBufB+3],32 + mov dword[GUIScrolBufB+4],20202020h + mov al,[edi+64] + add al,49 + mov [GUIScrolBufB+4],al + mov byte[GUIScrolBufB+7],'N' + cmp byte[edi+65],0 + je .yesnoff + mov byte[GUIScrolBufB+7],'Y' +.yesnoff + mov bl,20 + mov eax,GUIScrolBufA +.scloopb + mov bh,[edi] + mov [eax],bh + inc edi + inc eax + dec bl + jnz .scloopb + pop eax + + mov byte[GUItextcolor],223 + push ecx + push eax + GUIOuttextwin2 16,ecx,eax,GUIScrolBufA + pop eax + pop ecx + push ecx + push eax + add ecx,128 + GUIOuttextwin2 16,ecx,eax,GUIScrolBufB + pop eax + pop ecx + mov byte[GUItextcolor],221 + cmp byte[GUIWincoladd],0 + je .zerocolb + mov byte[GUItextcolor],222 +.zerocolb + push ecx + push eax + dec ecx + dec eax + push ecx + push eax + GUIOuttextwin2 16,ecx,eax,GUIScrolBufA + pop eax + pop ecx + add ecx,128 + GUIOuttextwin2 16,ecx,eax,GUIScrolBufB + pop eax + pop ecx + pop edi + pop ebx + add eax,7 + add edi,66 + dec ebx + jnz near .scrolloop +.noscrolldisplay + ret + +GUIccombviewloc dd 0 +GUIccombcursloc dd 0 +GUIccomblcursloc dd 0 +NEWSYM NumCombo, dd 0 +NumComboGlob dd 0 +NEWSYM NumComboLocl, dd 0 +GUICSStC dd 0,0,0 +GUIComboKey dd 0 +GUIComboPos db 0 +GUIComboPNum db 0 +GUIComboLHorz db 0 +NEWSYM GUINumCombo, db 0 +GUIComboData times 50 db 0 +GUIScrolBufA times 21 db 0 +GUIScrolBufB times 10 db 0 + + +;CombinDataGlob times 3300 db 0 ; 20-name, 42-combo, 2-key#, 1-P#, 1-ff +;CombinDataLocl times 3300 db 0 + +GUIComboText1 db 'DESCRIPTION',0 +GUIComboText2 db 'KEY P# LH',0 +GUIComboText3 db ' ',0 +GUIComboText3b db 'S ',0 +GUIComboText4 db 'COMBINATION KEYS:',0 +GUIComboText5 db 'PRESS+REL',0 +GUIComboText6 db 'PRESS ONLY',0 +GUIComboText7 db 'REL ONLY',0 +GUIComboText8 db 'FRAME DELAY',0 +GUIComboText9 db 'SECOND DELAY',0 +GUIComboTextA db 'CLEAR',0 +GUIComboTextB db 'ADD',0 +GUIComboTextC db 'REPLACE',0 +GUIComboTextD db 'DELETE',0 +GUIComboTextE db 'DESCRIPTION:',0 +GUIComboTextF db 'KEY:',0 +GUIComboTextG db 'DEL',0 +GUIComboTextH db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +GUIComboTextI db 'P# 1 2 3 4',0 +GUIComboTextJ db 254,' = LAST ',253,'/',254,0 +GUIComboTextK db 'GAME SPECFIC',0 + +GUIIconDataComboPressRelease: + db 0 ,166,0 ,0 ,166,0 ,0 ,0 ,0 ,0 + db 0 ,166,0 ,166,166,166,0 ,0 ,0 ,0 + db 0 ,166,0 ,0 ,166,0 ,0 ,0 ,0 ,0 + db 166,166,166,0 ,166,0 ,0 ,0 ,0 ,0 + db 0 ,166,0 ,0 ,166,0 ,0 ,0 ,0 ,0 + db 0 ,234,234,234,234,0 ,0 ,0 ,0 ,0 + db 234,234,234,234,234,234,0 ,0 ,0 ,0 + db 234,234,234,234,234,234,0 ,0 ,0 ,0 + db 235,234,234,234,234,235,0 ,0 ,0 ,0 + db 0 ,235,235,235,235,0 ,0 ,0 ,0 ,0 + +GUIIconDataComboPress: + db 0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,166,166,166,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,236,236,236,236,0 ,0 ,0 ,0 ,0 + db 236,236,236,236,236,236,0 ,0 ,0 ,0 + db 236,236,236,236,236,236,0 ,0 ,0 ,0 + db 237,236,236,236,236,237,0 ,0 ,0 ,0 + db 0 ,237,237,237,237,0 ,0 ,0 ,0 ,0 + +GUIIconDataComboRelease: + db 0 ,0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,166,166,166,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,166,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,238,238,238,238,0 ,0 ,0 ,0 ,0 + db 238,238,238,238,238,238,0 ,0 ,0 ,0 + db 238,238,238,238,238,238,0 ,0 ,0 ,0 + db 239,238,238,238,238,239,0 ,0 ,0 ,0 + db 0 ,239,239,239,239,0 ,0 ,0 ,0 ,0 + +GUIIconDataComboFrame: + db 0 ,0 ,0 ,0 ,58 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,56 ,46 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,54 ,44 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,52 ,0 ,42 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,50 ,40 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,48 ,38 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,46 ,36 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,44 ,0 ,34 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,42 ,32 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,40 ,32 ,0 ,0 ,0 ,0 ,0 ,0 + +GUIIconDataComboSecond: + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,51 ,45 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,51 ,45 ,0 ,0 ,0 ,0 ,0 ,0 + db 0 ,54 ,52 ,48 ,46 ,0 ,0 ,0 ,0 ,0 + db 53 ,46 ,50 ,50 ,48 ,45 ,0 ,0 ,0 ,0 + db 52 ,50 ,45 ,48 ,46 ,44 ,0 ,0 ,0 ,0 + db 51 ,50 ,50 ,46 ,50 ,43 ,0 ,0 ,0 ,0 + db 50 ,50 ,50 ,50 ,50 ,42 ,0 ,0 ,0 ,0 + db 0 ,48 ,46 ,44 ,42 ,0 ,0 ,0 ,0 ,0 + db 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 + +DisplayGUIAddOns: + GUIDrawWindowBox 17,GUIAddOnsDisp + sub byte[GUItextcolor],15 + GUIOuttextwin2 17,21,18,GUIAddOnText1 + GUIOuttextwin2 17,21,28,GUIAddOnText2 + GUIOuttextwin2 17,21,38,GUIAddOnText3 + GUIOuttextwin2 17,21,48,GUIAddOnText4 + GUIOuttextwin2 17,21,58,GUIAddOnText5 + add byte[GUItextcolor],15 + GUIOuttextwin2 17,20,17,GUIAddOnText1 + GUIOuttextwin2 17,20,27,GUIAddOnText2 + GUIOuttextwin2 17,20,37,GUIAddOnText3 + GUIOuttextwin2 17,20,47,GUIAddOnText4 + GUIOuttextwin2 17,20,57,GUIAddOnText5 + GUIDisplayButtonHole 17,9,15,byte[snesmouse],0 + GUIDisplayButtonHole 17,9,25,byte[snesmouse],1 + GUIDisplayButtonHole 17,9,35,byte[snesmouse],2 + GUIDisplayButtonHole 17,9,45,byte[snesmouse],3 + GUIDisplayButtonHole 17,9,55,byte[snesmouse],4 + ret + +GUIAddOnText1 db 'NONE',0 +GUIAddOnText2 db 'SNES MOUSE AT PORT #1',0 +GUIAddOnText3 db 'SNES MOUSE AT PORT #2',0 +GUIAddOnText4 db 'SUPER SCOPE',0 +GUIAddOnText5 db 'LETHAL ENFORCER GUN',0 + +GUILoadDisp db 'LOAD GAME',0 +GUIResetDisp db 'RESET GAME',0 +GUIStateSelDisp db 'STATE SELECT',0 +GUIInputDisp db 'INPUT DEVICE',0 +GUIOptionDisp db 'OPTIONS',0 +GUISoundDisp db 'SOUND CONFIG',0 +GUIVideoDisp db 'VIDEO CONFIG',0 +GUICheatDisp db 'CHEAT',0 +GUISearchDisp db 'CHEAT SEARCH',0 +GUINetDisp db 'REMOTE',0,0,0,0,0,0,0,0,0 +GUIGameDisp db 'GAME KEYS',0 +GUIGUIDisp db 'GUI OPTIONS',0 +GUIAboutDisp db 'ABOUT',0 +GUIMovieDisp db 'MOVIE OPTIONS',0 +GUIStatesDisp db 'STATE CONFIRM',0 +GUIComboDisp db 'KEY COMBINATION EDITOR',0 +GUIAddOnsDisp db 'ADD-ON SELECTOR',0 + +GUIItemBoxColor dd 0 +TextColorSp dd 0 + +NEWSYM GUIMenuItem, db 'GAME ',0 + db 'CONFIG',0 + db 'CHEAT ',0 + db 'NETPLAY',0 + db 'MISC ',0 + db 25,0 + \ No newline at end of file diff --git a/zsnes/src/gui/menu.asm b/zsnes/src/gui/menu.asm new file mode 100644 index 00000000..02e4625f --- /dev/null +++ b/zsnes/src/gui/menu.asm @@ -0,0 +1,1437 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM DSPMem,FPSOn,Makemode7Table,MessageOn,vesa2red10,scanlines,smallscreenon +EXTSYM MsgCount,Msgptr,OutputGraphicString,OutputGraphicString16b +EXTSYM PrepareSaveState,ResetState,breakatsignb,breakatsignc,cvidmode +EXTSYM cbitmode,copyvid,curblank,drawhline,drawhline16b,drawvline +EXTSYM drawvline16b,fnames,frameskip,mode7tab,pressed,spcA +EXTSYM spcBuffera,spcNZ,spcP,spcPCRam,spcRam,spcRamDP,spcS,spcX,spcY +EXTSYM spcon,vesa2_bpos,vesa2_clbit,vesa2_gpos,vesa2_rpos,vesa2selec +EXTSYM vidbuffer,spritetablea,sprlefttot,newengen,spcextraram,resolutn +EXTSYM Open_File,Close_File,Read_File,Write_File,Create_File,Get_Key,Get_Date +EXTSYM continueprog,ForceNonTransp,GUIOn,Check_Key,JoyRead +EXTSYM GetScreen, SSKeyPressed, StopSound, StartSound +EXTSYM ExecExitOkay,t1cc +EXTSYM Clear2xSaIBuffer +EXTSYM romdata,romtype +EXTSYM Voice0Disable,Voice1Disable,Voice2Disable,Voice3Disable +EXTSYM Voice4Disable,Voice5Disable,Voice6Disable,Voice7Disable + + + + + + + +GUIBufferData: + mov ecx,16384 + cmp byte[cbitmode],1 + jne near .16b + add ecx,16384 +.16b + ; copy to spritetable + mov esi,[vidbuffer] + mov edi,[spritetablea] +.loop + mov eax,[esi] + mov [edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .loop + mov edi,sprlefttot + mov ecx,64*5 +.a + mov dword[edi],0 + add edi,4 + dec ecx + jnz .a + ret + +GUIUnBuffer: + mov ecx,16384 + cmp byte[cbitmode],1 + jne near .16b + add ecx,16384 +.16b + ; copy from spritetable + mov esi,[vidbuffer] + mov edi,[spritetablea] +.loop + mov eax,[edi] + mov [esi],eax + add esi,4 + add edi,4 + dec ecx + jnz .loop + ret + + +NEWSYM nextmenupopup, db 0 +NEWSYM NoInputRead, db 0 +NEWSYM PrevMenuPos, db 0 +NEWSYM MenuDisplace, dd 0 +NEWSYM MenuDisplace16, dd 0 + +NEWSYM showmenu + mov byte[ForceNonTransp],1 + cmp byte[cbitmode],1 + je near .nopalread + mov edi,[vidbuffer] + add edi,100000 + mov dx,03C7h + mov al,0 + out dx,al + mov dx,03C9h + mov ecx,768 + mov byte[edi],12 + inc edi +.b + in al,dx + shl al,2 + mov [edi],al + inc edi + dec ecx + jnz .b +.nopalread + + mov byte[NoInputRead],0 + cmp byte[newengen],0 + je .nong16b + cmp byte[cbitmode],0 + je .nong16b + call GetScreen +.nong16b + cmp byte[SSKeyPressed],1 + jne .nosskey + mov byte[SSKeyPressed],0 + call savepcx + jmp .nopalwrite +.nosskey + test byte[pressed+14],1 + jz .nof12 + call savepcx + jmp .nopalwrite +.nof12 + mov dword[menucloc],0 + cmp byte[nextmenupopup],0 + je .nomenuinc2 + mov byte[pressed+1Ch],0 + mov dword[menucloc],40*288 + cmp byte[PrevMenuPos],1 + jne .nomenuinc + mov dword[menucloc],50*288 +.nomenuinc + cmp byte[PrevMenuPos],2 + jne .nomenuinc2 + mov dword[menucloc],60*288 +.nomenuinc2 + + mov byte[nextmenupopup],0 + mov byte[menu16btrans],0 + mov byte[pressed+1],0 + mov byte[pressed+59],0 + mov byte[curblank],00h + call GUIBufferData + ; Draw box + call menudrawbox8b + call menudrawbox8b + + cmp byte[newengen],0 + je .notng + mov byte[GUIOn],1 +.notng + pushad + call copyvid + popad + + call StopSound +.nextkey + call JoyRead + call Check_Key + or al,al + jz .nextkey + call Get_Key + cmp al,0 + jne near .processextend + call Get_Key + cmp al,72 + jne .noup + cmp dword[menucloc],0 + jne .nogoup + add dword[menucloc],70*288 +.nogoup + sub dword[menucloc],10*288 + call menudrawbox8b + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + jmp .nextkey +.noup + cmp al,80 + jne .nodown + cmp dword[menucloc],60*288 + jne .nogodown + sub dword[menucloc],70*288 +.nogodown + add dword[menucloc],10*288 + call menudrawbox8b + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + jmp .nextkey +.nodown + jmp .nextkey +.processextend + + cmp al,27 + je near .exitloop + cmp al,13 + je .done + jmp .nextkey +.done + call GUIUnBuffer + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + cmp dword[menucloc],0 + jne .nosavepcx + call savepcx +.nosavepcx + cmp dword[menucloc],40*288 + jne .nosavepcx2 + call savepcx + mov byte[ExecExitOkay],0 + mov byte[nextmenupopup],3 + mov byte[NoInputRead],1 + mov byte[t1cc],0 + mov byte[PrevMenuPos],0 +.nosavepcx2 + cmp dword[menucloc],50*288 + jne .noskipframe + mov byte[ExecExitOkay],0 + mov byte[nextmenupopup],3 + mov byte[NoInputRead],1 + mov byte[t1cc],0 + mov byte[PrevMenuPos],1 +.noskipframe + cmp dword[menucloc],60*288 + jne .nomovewin + mov byte[ExecExitOkay],0 + mov byte[nextmenupopup],1 + mov byte[NoInputRead],1 + mov byte[t1cc],0 + mov byte[PrevMenuPos],2 + cmp dword[MenuDisplace],0 + je .movewin + mov dword[MenuDisplace],0 + mov dword[MenuDisplace16],0 + jmp .nomovewin +.movewin + mov dword[MenuDisplace],90*288 + mov dword[MenuDisplace16],90*288*2 +.nomovewin + cmp dword[menucloc],10*288 + jne .nofps + cmp byte[frameskip],0 + je .yesfs + mov dword[Msgptr],.unablefps + mov eax,[MsgCount] + mov [MessageOn],eax + jmp .nofps +.yesfs + xor byte[FPSOn],1 +.nofps + cmp dword[menucloc],20*288 + jne near .nospcsave + cmp byte[spcon],0 + je .nospc + cmp byte[newengen],1 +; je .unablespc + mov dword[Msgptr],.search + mov eax,[MsgCount] + mov [MessageOn],eax + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al +; call breakatsignc +; cmp byte[prbreak],1 +; je .yesesc + call breakatsignb +; cmp byte[prbreak],1 +; je .yesesc + call savespcdata + mov byte[curblank],40h + mov dword[Msgptr],.saved + mov eax,[MsgCount] + mov [MessageOn],eax + jmp .nospcsave +.nospc + mov dword[Msgptr],.nosound + mov eax,[MsgCount] + mov [MessageOn],eax + jmp .nospcsave +.unablespc + mov dword[Msgptr],.unable + mov eax,[MsgCount] + mov [MessageOn],eax + jmp .nospcsave +.yesesc + mov dword[Msgptr],.escpress + mov eax,[MsgCount] + mov [MessageOn],eax +.nospcsave + cmp dword[menucloc],30*288 + jne .nosnddmp + call dumpsound + mov dword[Msgptr],.sndbufsav + mov eax,[MsgCount] + mov [MessageOn],eax +.nosnddmp +.exitloop + call GUIUnBuffer + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + cmp byte[cbitmode],1 + je near .nopalwrite + mov edi,[vidbuffer] + add edi,100000 + mov dx,03C8h + mov al,0 + out dx,al + mov dx,03C9h + mov ecx,768 + inc edi +.c + mov al,[edi] + shr al,2 + out dx,al + inc edi + dec ecx + jnz .c +.nopalwrite + mov byte[pressed+1],2 + mov byte[pressed+59],2 + call StartSound + mov byte[ForceNonTransp],0 + mov byte[GUIOn],0 + call Clear2xSaIBuffer + jmp continueprog + +.unablefps db 'NEED AUTO FRAMERATE ON',0 +.sndbufsav db 'BUFFER SAVED AS SOUNDDMP.RAW',0 +.search db 'SEARCHING FOR SONG START.',0 +.nosound db 'SOUND MUST BE ENABLED.',0 +.unable db 'CANNOT USE IN NEW GFX ENGINE.',0 +.escpress db 'ESC TERMINATED SEARCH.',0 +.saved db '.SPC FILE SAVED.',0 + +NEWSYM menudrawbox8b + cmp byte[cbitmode],1 + je near menudrawbox16b + ; set palette of colors 128,144, and 160 to white, blue, and red + mov al,128 + mov dx,03C8h + out dx,al + inc dx + mov al,63 + out dx,al + out dx,al + out dx,al + mov al,144 + mov dx,03C8h + out dx,al + inc dx + xor al,al + out dx,al + out dx,al + mov al,50 + out dx,al + mov al,160 + mov dx,03C8h + out dx,al + inc dx + mov al,45 + out dx,al + xor al,al + out dx,al + out dx,al + ; draw a small blue box with a white border + mov esi,40+20*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,150 + mov al,85 +.loop + mov byte[esi],144 + inc esi + loop .loop + add esi,288-150 + dec al + mov ecx,150 + jnz .loop + mov al,128 + ; Draw lines + mov esi,40+20*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,150 + call drawhline + mov esi,40+20*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,85 + call drawvline + mov esi,40+104*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,150 + call drawhline + mov esi,40+32*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,150 + call drawhline + mov esi,189+20*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,85 + call drawvline + call menudrawcursor8b + + mov esi,45+23*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.string + call OutputGraphicString + mov esi,45+35*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringa + call OutputGraphicString + mov esi,45+45*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringb + test byte[FPSOn],1 + jz .nofps + mov edi,.stringc +.nofps + call OutputGraphicString + mov esi,45+55*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringd + call OutputGraphicString + mov esi,45+65*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringe + call OutputGraphicString + mov esi,45+75*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringf + call OutputGraphicString + mov esi,45+85*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringg + call OutputGraphicString + mov esi,45+95*288 + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov edi,.stringh + call OutputGraphicString + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + ret + +.string db 'MISC OPTIONS',0 +.stringa db 'SAVE SNAPSHOT',0 +.stringb db 'SHOW FPS',0 +.stringc db 'HIDE FPS',0 +.stringd db 'SAVE SPC DATA',0 +.stringe db 'SOUND BUFFER DUMP',0 +.stringf db 'SNAPSHOT/INCR FRM',0 +.stringg db 'INCR FRAME ONLY',0 +.stringh db 'MOVE THIS WINDOW',0 + +NEWSYM menudrawcursor8b + cmp byte[cbitmode],1 + je near menudrawcursor16b + ; draw a small red box + mov esi,41+34*288 + add esi,[menucloc] + add esi,[vidbuffer] + add esi,[MenuDisplace] + mov ecx,148 + mov al,9 +.loop + mov byte[esi],160 + inc esi + loop .loop + add esi,288-148 + dec al + mov ecx,148 + jnz .loop + mov al,128 + ret + +NEWSYM menucloc, dd 0 + +NEWSYM menudrawbox16b + ; draw shadow behind box + cmp byte[menu16btrans],0 + jne .noshadow + mov byte[menu16btrans],1 + mov esi,50*2+30*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,150 + mov al,85 + mov ah,5 +.loop16b2 + mov dx,[esi] + and dx,[vesa2_clbit] + shr dx,1 + mov [esi],dx + add esi,2 + loop .loop16b2 + add esi,288*2-150*2 + dec al + mov ecx,150 + jnz .loop16b2 +.noshadow + + mov ax,01Fh + mov cl,[vesa2_rpos] + shl ax,cl + mov [.allred],ax + mov ax,012h + mov cl,[vesa2_bpos] + shl ax,cl + mov dx,ax + mov ax,01h + mov cl,[vesa2_gpos] + shl ax,cl + mov bx,ax + mov ax,01h + mov cl,[vesa2_rpos] + shl ax,cl + or bx,ax + + ; draw a small blue box with a white border + mov esi,40*2+20*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,150 + mov al,85 + mov ah,5 +.loop16b + mov [esi],dx + add esi,2 + loop .loop16b + add esi,288*2-150*2 + dec ah + jnz .nocolinc16b + add dx,bx + mov ah,5 +.nocolinc16b + dec al + mov ecx,150 + jnz .loop16b + + ; Draw lines + mov ax,0FFFFh + mov esi,40*2+20*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,150 + call drawhline16b + mov esi,40*2+20*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,85 + call drawvline16b + mov esi,40*2+104*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,150 + call drawhline16b + mov esi,40*2+32*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,150 + call drawhline16b + mov esi,189*2+20*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,85 + call drawvline16b + call menudrawcursor16b + + mov esi,45*2+23*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.string + call OutputGraphicString16b + mov esi,45*2+35*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringa + call OutputGraphicString16b + mov esi,45*2+45*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringb + test byte[FPSOn],1 + jz .nofps + mov edi,menudrawbox8b.stringc +.nofps + call OutputGraphicString16b + mov esi,45*2+55*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringd + call OutputGraphicString16b + mov esi,45*2+65*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringe + call OutputGraphicString16b + mov esi,45*2+75*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringf + call OutputGraphicString16b + mov esi,45*2+85*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringg + call OutputGraphicString16b + mov esi,45*2+95*288*2 + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov edi,menudrawbox8b.stringh + call OutputGraphicString16b + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + ret + +.allred dw 0 +.blue dw 0 +.stepb dw 0 + +NEWSYM menu16btrans, db 0 + +NEWSYM menudrawcursor16b + ; draw a small red box + mov esi,41*2+34*288*2 + add esi,[menucloc] + add esi,[menucloc] + add esi,[vidbuffer] + add esi,[MenuDisplace16] + mov ecx,148 + mov al,9 + mov bx,[menudrawbox16b.allred] +.loop + mov [esi],bx + add esi,2 + loop .loop + add esi,288*2-148*2 + dec al + mov ecx,148 + jnz .loop + mov al,128 + ret + +NEWSYM savespcdata + sub dword[spcPCRam],spcRam + ; Assemble N/Z flags into P + and byte[spcP],0FDh + test byte[spcNZ],0FFh + jnz .nozero + or byte[spcP],02h +.nozero + and byte[spcP],07Fh + test byte[spcNZ],80h + jz .noneg + or byte[spcP],80h +.noneg + mov ax,[spcPCRam] + mov [ssdatst+37],ax + mov al,[spcA] + mov [ssdatst+39],al + mov al,[spcX] + mov [ssdatst+40],al + mov al,[spcY] + mov [ssdatst+41],al + mov al,[spcP] + mov [ssdatst+42],al + mov al,[spcS] + mov [ssdatst+43],al + add dword[spcPCRam],spcRam +.savestuff + sub dword[spcPCRam],spcRam + sub dword[spcRamDP],spcRam + call PrepareSaveState + ; Copy from fnames to .spcfname, replacing .srm with .spc + mov esi,fnames+1 + mov edi,.spcfname +.next + mov al,[esi] + mov [edi],al + inc esi + inc edi + cmp al,'.' + jne .next + ; Save stuff + mov byte[edi],'S' + mov byte[edi+1],'P' + mov byte[edi+2],'C' + mov byte[edi+3],0 + ; Find an unoccupied file +.tryagainspc + mov edx,.spcfname + call Open_File + jc .nofileopen + mov bx,ax + call Close_File + cmp byte[edi+2],'C' + jne .noC + mov byte[edi+2],'1' + jmp .tryagainspc +.noC + cmp byte[edi+2],'9' + je .nofileopen + inc byte[edi+2] + jmp .tryagainspc +.nofileopen + mov al,[edi+2] + mov [showmenu.saved+3],al + ; copy spcextra ram to dspmem+192 + mov esi,spcextraram + mov edi,DSPMem+192 + mov ecx,64 +.loop + mov al,[esi] + mov [edi],al + inc esi + inc edi + dec ecx + jnz .loop + + ; Copy Game Title + + mov esi,[romdata] + add esi,7FC0h + cmp byte[romtype],2 + jne .nohirom2 + add esi,8000h +.nohirom2 + mov ecx,20 + mov edi,ssdatst+46+32 +.romloop + mov al,[esi] + mov [edi],al + inc esi + inc edi + loop .romloop + ; Copy Date of spc dumped + call Get_Date + mov [ssdatst+09Eh],dl + mov [ssdatst+09Fh],dh + mov [ssdatst+0A0h],cx + + ; Set Channel Disables + mov byte[ssdatst+0D0h],0 + cmp byte[Voice0Disable],1 + je .enable0 + or byte[ssdatst+0D0h],1 +.enable0 + cmp byte[Voice1Disable],1 + je .enable1 + or byte[ssdatst+0D0h],2 +.enable1 + cmp byte[Voice2Disable],1 + je .enable2 + or byte[ssdatst+0D0h],4 +.enable2 + cmp byte[Voice3Disable],1 + je .enable3 + or byte[ssdatst+0D0h],8 +.enable3 + cmp byte[Voice4Disable],1 + je .enable4 + or byte[ssdatst+0D0h],16 +.enable4 + cmp byte[Voice5Disable],1 + je .enable5 + or byte[ssdatst+0D0h],32 +.enable5 + cmp byte[Voice6Disable],1 + je .enable6 + or byte[ssdatst+0D0h],64 +.enable6 + cmp byte[Voice7Disable],1 + je .enable7 + or byte[ssdatst+0D0h],128 +.enable7 + +; times 32 db 0 ; Title of game (Offset 48) +; times 32 db 0 ; Song Name +; times 32 db 0 ; Author of Song +; times 32 db 0 ; Name of dumper +; times 32 db 0 ; Comments +; times 4 db 0 ; date of spc dumped +; times 4 db 0 ; time in milliseconds before fading out +; times 2 db 0 ; fade-out length in milliseconds +; db 0 ; default channel enables + + mov edx,.spcfname + call Create_File + mov bx,ax + mov ecx,256 + mov edx,ssdatst + call Write_File + + ; Save SPC stuff + mov ecx,65536 + mov edx,spcRam + call Write_File + mov ecx,256 + mov edx,DSPMem + call Write_File + call Close_File + add dword[spcPCRam],spcRam + add dword[spcRamDP],spcRam + call ResetState + ret + +.spcfname times 128 db 0 +;.SPC File Format + +;Offset 00000h - File Header : SNES-SPC700 Sound File Data v0.10 +;Offset 00021h - 0x26,0x26,0x26 +;Offset 00024h - Version #(/100) +;Offset 00025h - PC Register value (1 Word) +;Offset 00027h - A Register Value (1 byte) +;Offset 00028h - X Register Value (1 byte) +;Offset 00029h - Y Register Value (1 byte) +;Offset 0002Ah - Status Flags Value (1 byte) +;Offset 0002Bh - Stack Register Value (1 byte) +;Offset 0002Ch-000FFh - Reserved For Future Use +;Offset 00100h-100FFh - SPCRam +;Offset 10100h-101FFh - DSPRam + +;Offset 0002Eh-0004Dh - SubTitle/Song Name +;Offset 0004Eh-0006Dh - Title of Game +;Offset 0006Eh-0007Dh - Name of Dumper +;Offset 0007Eh-0009Dh - Comments +;Offset 0009Eh-000A4h - Date of SPC Dumped in decimal (DD/MM/YYYY) +;Offset 000A9h-000ABh - Time in seconds for the spc to play before fading +;Offset 000ACh-000AFh - Fade out time in milliseconds +;Offset 000B0h-000CFh - Author of Song +;Offset 000D0h - Default Channel Disables (0 = enable, 1 = disable) +;Offset 000D1h - Emulator used to dump .spc file +; (0 = UNKNOWN, 1 = ZSNES, 2 = SNES9X) +; (Note : Contact the authors if you're an snes emu +; author with an .spc capture in order to assign +; you a number) + +;Offset 0002Eh-0004Dh - Name of SPC (32 bytes) +;Offset 0004Eh-0005Dh - Name of Game (16 bytes) +;Offset 0006Eh-0007Dh - Name of SPC dumper (16 bytes) +;Offset 0007Eh-0009Dh - Comments (32 bytes) +;Offset 0009Eh-000A8h - Date the SPC was Dumped (10 bytes) +;Offset 000A9h-000ABh - Internal SPC timer (3 bytes) + +NEWSYM ssdatst + db 'SNES-SPC700 Sound File Data v0.30',26,26,26 ; offset 0 + db 10 ; Version #(/100), offset 36 + ; SPC Registers + dw 0 ; PC, offset 37 + db 0 ; A, offset 39 + db 0 ; X, offset 40 + db 0 ; Y, offset 41 + db 0 ; P, offset 42 + db 0 ; S, offset 43 + db 0,0 ; offset 44 (reserved) + + times 32 db 0 ; Title of game (Offset 46) + times 32 db 0 ; Song Name + times 16 db 0 ; Name of dumper + times 32 db 0 ; Comments + times 10 db 0 ; date of spc dumped + times 4 db 0 ; time in seconds before fading out + times 4 db 0 ; fade-out length in milliseconds + times 32 db 0 ; Author of Song + db 0 ; default channel enables + db 1 ; emulator used to dump .spc files + ; 32*5+20 = 180 + + times 48 db 0 ;(reserved), offset 224 + ; SPCRAM (offset 256), 64k + ; DSPRAM (offset 256+65536), 256 bytes + +NEWSYM dumpsound + mov cx,0 + mov edx,.filename + call Create_File + ; Process sound data + mov bx,ax + xor ecx,ecx + xor esi,esi +.loop + push eax + mov eax,[spcBuffera] + mov edx,dword[eax+ecx*4] + pop eax + cmp edx,0 + je .nowrite + mov [mode7tab+esi],edx + add esi,4 + cmp esi,65536 + je .savenow +.return +.nowrite + inc cx + jnz .loop + cmp esi,0 + je .nosave + mov ecx,esi + mov edx,mode7tab + call Write_File +.nosave + call Close_File + call Makemode7Table + ret + +.savenow + push ecx + mov ecx,65536 + mov edx,mode7tab + call Write_File + pop ecx + xor esi,esi + jmp .return + +.filename db 'SOUNDDMP.RAW',0 + +NEWSYM pcxheader + db 10,5,1,8 + dw 0,0,255,223 + dw 256,224 + times 48 db 0 + db 0,1 +.bpline dw 256 + times 128-68 db 0 + +NEWSYM picnum, dw 0 + +NEWSYM savepcx + mov byte[pressed+1],0 + mov byte[pressed+59],2 + cmp byte[cbitmode],1 + je near .save16b + mov edi,pcxheader + mov ecx,128 +.clearhead + mov byte[edi],0 + inc edi + dec ecx + jnz .clearhead + mov byte[pcxheader+0],10 + mov byte[pcxheader+1],5 + mov byte[pcxheader+2],1 + mov byte[pcxheader+3],8 + mov word[pcxheader+8],255 + mov word[pcxheader+10],222 + mov byte[pcxheader.bpline-1],1 + mov word[pcxheader.bpline],256 + cmp byte[resolutn],224 + je .res224ph + mov word[pcxheader+10],237 +.res224ph + + ; get unused filename + mov byte[.filename+5],'.' + mov byte[.filename+6],'P' + mov byte[.filename+7],'C' + mov byte[.filename+8],'X' + mov byte[.filename+9],0 + mov word[picnum],1 +.findagain + mov edx,.filename + call Open_File + jc near .nofile + mov bx,ax + call Close_File + + inc word[picnum] + cmp word[picnum],1000 + je .nofile + + mov ax,[picnum] + xor edx,edx + mov bx,100 + div bx + mov cl,al + mov ax,dx + xor edx,edx + mov bx,10 + div bx + mov esi,.filename+5 + add cl,48 + add al,48 + add dl,48 + cmp cl,48 + je .nohund + mov byte[esi],cl + mov byte[esi+1],al + mov byte[esi+2],dl + add esi,3 + jmp .finproc +.nohund + cmp al,48 + je .noten + mov byte[esi],al + mov byte[esi+1],dl + add esi,2 + jmp .finproc +.noten + mov byte[esi],dl + inc esi +.finproc + mov byte[esi],'.' + mov byte[esi+1],'P' + mov byte[esi+2],'C' + mov byte[esi+3],'X' + mov byte[esi+4],0 + jmp .findagain +.nofile + + mov edx,.filename + call Create_File + ; Save header + mov bx,ax + mov ecx,128 + mov edx,pcxheader + call Write_File + ; Save picture Data + mov byte[.rowsleft],223 + cmp byte[resolutn],224 + je .res224p + mov byte[.rowsleft],238 +.res224p + mov ecx,256 + mov edx,[vidbuffer] + add edx,16+288 +.a + xor ecx,ecx + mov esi,edx + mov edi,mode7tab + push ebx + mov ebx,256 +.loopp + mov al,[esi] + mov [edi],al + mov ah,al + and ah,0C0h + cmp ah,0C0h + jne .norep + mov byte[edi],0C1h + inc edi + inc ecx + mov byte[edi],al +.norep + inc ecx + inc esi + inc edi + dec ebx + jnz .loopp + pop ebx + xor al,al + push edx + mov edx,mode7tab + call Write_File + pop edx + add edx,288 + dec byte[.rowsleft] + jnz .a + ; Save Palette + mov ecx,769 + mov edx,[vidbuffer] + add edx,100000 + call Write_File + call Makemode7Table + call Close_File +; mov dword[Msgptr],.pcxsaved +; mov eax,[MsgCount] +; mov [MessageOn],eax + ret + +.save16b + test byte[pressed+14],1 + jnz near save16b2 + call prepare16b + mov edi,pcxheader + mov ecx,128 +.clearhead2 + mov byte[edi],0 + inc edi + dec ecx + jnz .clearhead2 + ; Initial header = 14 bytes + mov byte[pcxheader],'B' + mov byte[pcxheader+1],'M' + mov dword[pcxheader+2],02A01Ah-768 + mov dword[pcxheader+10],26 + + mov dword[pcxheader+14],12 + mov word[pcxheader+18],256 + mov word[pcxheader+20],223 + mov word[pcxheader+22],1 + mov word[pcxheader+24],24 + + cmp byte[resolutn],224 + je .res224b + add dword[pcxheader+2],768*15 + mov word[pcxheader+20],238 +.res224b + + ; get unused filename + mov byte[.filename2+5],'.' + mov byte[.filename2+6],'B' + mov byte[.filename2+7],'M' + mov byte[.filename2+8],'P' + mov byte[.filename2+9],0 + mov word[picnum],1 +.findagain2 + mov edx,.filename2 + call Open_File + jc near .nofile2 + mov bx,ax + call Close_File + + inc word[picnum] + cmp word[picnum],1000 + je near .nofile2 + + mov ax,[picnum] + xor edx,edx + mov bx,100 + div bx + mov cl,al + mov ax,dx + xor edx,edx + mov bx,10 + div bx + mov esi,.filename2+5 + add cl,48 + add al,48 + add dl,48 + cmp cl,48 + je .nohund2 + mov byte[esi],cl + mov byte[esi+1],al + mov byte[esi+2],dl + add esi,3 + jmp .finproc2 +.nohund2 + cmp al,48 + je .noten2 + mov byte[esi],al + mov byte[esi+1],dl + add esi,2 + jmp .finproc2 +.noten2 + mov byte[esi],dl + inc esi +.finproc2 + mov byte[esi],'.' + mov byte[esi+1],'B' + mov byte[esi+2],'M' + mov byte[esi+3],'P' + mov byte[esi+4],0 + jmp .findagain2 +.nofile2 + + mov edx,.filename2 + call Create_File + ; Save header + mov bx,ax + mov ecx,26 + mov edx,pcxheader + call Write_File + ; Save picture Data + mov byte[.rowsleft],223 + mov esi,[vidbuffer] + add esi,32+288*2*223 + cmp byte[resolutn],224 + je .res224b2 + mov byte[.rowsleft],238 + add esi,288*2*15 +.res224b2 + mov [.curdptr],esi +.a2 + mov ecx,256 + mov edi,mode7tab + mov esi,[.curdptr] + sub dword[.curdptr],288*2 +.b2 + push ecx + mov ax,[esi] + mov cl,[vesa2_bpos] + shr ax,cl + and ax,1Fh + shl al,3 + mov byte[edi],al + mov ax,[esi] + mov cl,[vesa2_gpos] + shr ax,cl + and ax,1Fh + shl al,3 + mov byte[edi+1],al + mov ax,[esi] + mov cl,[vesa2_rpos] + shr ax,cl + and ax,1Fh + shl al,3 + mov byte[edi+2],al + pop ecx + add edi,3 + add esi,2 + dec ecx + jnz .b2 + push edx + mov ecx,768 + mov edx,mode7tab + call Write_File + pop edx + add edx,288*2 + dec byte[.rowsleft] + jnz near .a2 + call Makemode7Table + call Close_File +; mov dword[Msgptr],.rawsaved +; mov eax,[MsgCount] +; mov [MessageOn],eax + call restore16b + ret + +.pcxsaved db 'SNAPSHOT SAVED TO ' +.filename db 'IMAGE.PCX',0,0,0,0 +.rawsaved db 'SNAPSHOT SAVED TO ' +.filename2 db 'IMAGE.BMP',0,0,0,0 +.rowsleft db 0 +.curdptr dd 0 + +NEWSYM save16b2 + call prepare16b + mov byte[pressed+14],2 + push es + mov edi,pcxheader + mov ecx,128 +.clearhead2 + mov byte[edi],0 + inc edi + dec ecx + jnz .clearhead2 + ; Initial header = 14 bytes + mov byte[pcxheader],'B' + mov byte[pcxheader+1],'M' + mov dword[pcxheader+2],02A01Ah-256*224*3+512*448*3 + mov dword[pcxheader+10],26 + mov dword[pcxheader+14],12 + mov word[pcxheader+18],512 + mov word[pcxheader+20],448 + mov word[pcxheader+22],1 + mov word[pcxheader+24],24 + + ; get unused filename + mov byte[.filename2+5],'.' + mov byte[.filename2+6],'B' + mov byte[.filename2+7],'M' + mov byte[.filename2+8],'P' + mov byte[.filename2+9],0 + mov word[picnum],1 +.findagain2 + mov edx,.filename2 + call Open_File + jc near .nofile2 + mov bx,ax + call Close_File + + inc word[picnum] + cmp word[picnum],1000 + je near .nofile2 + + mov ax,[picnum] + xor edx,edx + mov bx,100 + div bx + mov cl,al + mov ax,dx + xor edx,edx + mov bx,10 + div bx + mov esi,.filename2+5 + add cl,48 + add al,48 + add dl,48 + cmp cl,48 + je .nohund2 + mov byte[esi],cl + mov byte[esi+1],al + mov byte[esi+2],dl + add esi,3 + jmp .finproc2 +.nohund2 + cmp al,48 + je .noten2 + mov byte[esi],al + mov byte[esi+1],dl + add esi,2 + jmp .finproc2 +.noten2 + mov byte[esi],dl + inc esi +.finproc2 + mov byte[esi],'.' + mov byte[esi+1],'B' + mov byte[esi+2],'M' + mov byte[esi+3],'P' + mov byte[esi+4],0 + jmp .findagain2 +.nofile2 + + mov cx,0 + mov edx,.filename2 + call Create_File + ; Save header + mov bx,ax + mov ecx,26 + mov edx,pcxheader + call Write_File + ; Save picture Data + mov dword[.rowsleft],448 + mov ax,[vesa2selec] + mov es,ax + mov esi,32*2+640*2*223*2+640*2 + mov [.curdptr],esi +.a2 + mov ecx,512 + mov edi,mode7tab + mov esi,[.curdptr] + sub dword[.curdptr],640*2 +.b2 + push ecx + mov ax,[es:esi] + mov cl,[vesa2_bpos] + shr ax,cl + and ax,1Fh + shl al,3 + mov byte[edi],al + mov ax,[es:esi] + mov cl,[vesa2_gpos] + shr ax,cl + and ax,1Fh + shl al,3 + mov byte[edi+1],al + mov ax,[es:esi] + mov cl,[vesa2_rpos] + shr ax,cl + and ax,1Fh + shl al,3 + mov byte[edi+2],al + pop ecx + add edi,3 + add esi,2 + dec ecx + jnz .b2 + push edx + mov ecx,768*2 + mov edx,mode7tab + call Write_File + pop edx + add edx,288*2 + dec dword[.rowsleft] + jnz near .a2 + call Makemode7Table + call Close_File +; mov dword[Msgptr],.rawsaved +; mov eax,[MsgCount] +; mov [MessageOn],eax + pop es + call restore16b + ret + +.rawsaved db 'SNAPSHOT SAVED TO ' +.filename2 db 'IMAGE.BMP',0,0,0,0 +.rowsleft dd 0 +.curdptr dd 0 + +prepare16b: + cmp byte[vesa2red10],1 + jne .nored + cmp byte[cvidmode],5 + jne .nored + cmp byte[scanlines],1 + je .nored + cmp byte[smallscreenon],1 + je .nored + mov byte[vesa2_rpos],10 + mov byte[vesa2_gpos],5 +.nored + ret +restore16b: + cmp byte[vesa2red10],1 + jne .nored + mov byte[vesa2_rpos],11 + mov byte[vesa2_gpos],6 +.nored + ret + \ No newline at end of file diff --git a/zsnes/src/init.asm b/zsnes/src/init.asm new file mode 100644 index 00000000..66f84079 --- /dev/null +++ b/zsnes/src/init.asm @@ -0,0 +1,5327 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM DosExit,UpdateDevices,InitSPC,Makemode7Table,MusicRelVol,MusicVol +EXTSYM makesprprtable,romloadskip,start65816,startdebugger,SfxR0 +EXTSYM MovieProcessing +EXTSYM MovieFileHand,filefound,inittable,SA1inittable +EXTSYM MessageOn,Msgptr,MsgCount,sndrot,GenerateBank0Table,SnowTimer +EXTSYM inittableb,inittablec,FPUCopy,newgfx16b,cfgreinittime,EndMessage +EXTSYM Open_File,Read_File,Write_File,Close_File,Output_Text,Get_Key,CNetType +EXTSYM Delete_File,Get_First_Entry,Get_Next_Entry,Change_Dir,Get_Dir,InitDSP +EXTSYM Remove_Dir,Change_Single_Dir,Create_Dir,Get_Memfree,OSPort,Create_File +EXTSYM SPCDisable,osm2dis,CurRecv,BackupSystemVars +EXTSYM SnowData,SnowVelDist +EXTSYM cvidmode, newengen, cfgnewgfx, GUI16VID +EXTSYM NewEngEnForce +EXTSYM PrintChar +EXTSYM mode7tab +EXTSYM per2exec +EXTSYM MovieCounter +EXTSYM chaton +EXTSYM JoyRead,JoyReadControl,joy4218,joy4219 +EXTSYM joy421A,joy421B,pressed +EXTSYM pl3Ak,pl3Bk,pl3Lk,pl3Rk,pl3Xk,pl1p209,pl2p209,pl3p209,pl4p209 +EXTSYM pl3Yk,pl3contrl,pl3downk,pl3leftk,pl3rightk,pl3selk,pl3startk +EXTSYM pl3upk,pl4Ak,pl4Bk,pl4Lk,pl4Rk,pl4Xk,pl4Yk,pl4contrl,pl4downk +EXTSYM pl4leftk,pl4rightk,pl4selk,pl4startk,pl4upk,mousebuttons,mousexdir +EXTSYM pl5Ak,pl5Bk,pl5Lk,pl5Rk,pl5Xk,pl5Yk,pl5contrl,pl5downk +EXTSYM pl5leftk,pl5rightk,pl5selk,pl5startk,pl5upk +EXTSYM mouseydir,mousexpos,mouseypos,snesmouse,processmouse,ssautosw +EXTSYM GUIDelayB,pl12s34 +EXTSYM pl1Xtk,pl1Ytk,pl1Atk,pl1Btk,pl2Xtk,pl2Ytk,pl2Atk,pl2Btk +EXTSYM pl3Xtk,pl3Ytk,pl3Atk,pl3Btk,pl4Xtk,pl4Ytk,pl4Atk,pl4Btk +EXTSYM pl1ULk,pl1URk,pl1DLk,pl1DRk,pl2ULk,pl2URk,pl2DLk,pl2DRk +EXTSYM pl3ULk,pl3URk,pl3DLk,pl3DRk,pl4ULk,pl4URk,pl4DLk,pl4DRk +EXTSYM pl5ULk,pl5URk,pl5DLk,pl5DRk,pl5Xtk,pl5Ytk,pl5Atk,pl5Btk +EXTSYM Turbo30hz,RepeatFrame,nojoystickpoll +EXTSYM NumComboLocl,ComboBlHeader,ComboHeader,CombinDataLocl +EXTSYM CombinDataGlob,NumCombo,GUIComboGameSpec +EXTSYM mousexloc,mouseyloc +EXTSYM extlatch +EXTSYM BackState +EXTSYM FIRTAPVal0,FIRTAPVal1,FIRTAPVal2,FIRTAPVal3,FIRTAPVal4 +EXTSYM FIRTAPVal5,FIRTAPVal6,FIRTAPVal7,INTEnab,JoyAPos,JoyBPos +EXTSYM NMIEnab,SPCROM,VIRQLoc,coladdb,coladdg,coladdr,doirqnext +EXTSYM echobuf,forceblnk,nmiprevaddrh,nmiprevaddrl,nmiprevline +EXTSYM nmirept,nmistatus,opexec268,opexec268b,opexec268cph +EXTSYM opexec268cphb,opexec358,opexec358b,opexec358cph,spcextraram +EXTSYM opexec358cphb,prevoamptr,reg1read,reg2read,reg3read +EXTSYM reg4read,resolutn,romdata,scrndis,spcBuffera,spcP,spcRam +EXTSYM spcnumread,tableD,timeron,vidbright,DSPMem,OldGfxMode2 +EXTSYM SPC700read,SPC700write,GUIDoReset,spc700read +EXTSYM InitC4,SA1Reset,SetAddressingModesSA1,SetAddressingModes,SDD1BankA,SPC7110init +EXTSYM RTCinit +EXTSYM memaccessspc7110r8,memaccessspc7110r16,memaccessspc7110w8 +EXTSYM memaccessspc7110w16 +EXTSYM ram7f,snesmap2,snesmmap,sram,MultiTap +EXTSYM memaccessbankr848mb,memaccessbankr1648mb +EXTSYM cpuover,execloop +;EXTSYM execloopn,execloopns,execloops +;EXTSYM PHsizeofexecloop,PHsizeofexecloopn,PHsizeofexecloopns +;EXTSYM PHsizeofexecloops +EXTSYM curexecstate +EXTSYM debugdisble,vidbuffer +EXTSYM Sup16mbit,Sup48mbit,debugbufa,pal16b,pal16bcl,pal16bclha +EXTSYM pal16bxcl,ram7fa,regptra,regptwa,srama,vidmemch2,vidmemch4 +EXTSYM vidmemch8,vcache2b,vcache4b,vcache8b,vram,wramdata +EXTSYM wramdataa +EXTSYM fname,fnames,GetCurDir +EXTSYM GUIcurrentdir,extractzip,PrintStr +EXTSYM GUIsmcfind,GUIsfcfind,GUIswcfind,GUIfigfind,GUIfind058,GUIfind078,GUIfindBIN +EXTSYM GUIfindUSA,GUIfindJAP,GUIfindZIP,GUIfind1,DTALoc,GUIfindall,ZipError +EXTSYM spc7110romptr,allocspc7110 +EXTSYM SRAMDir,SRAMDrive,cfgloadsdir,fnamest,statefileloc +EXTSYM ForcePal,InitDir,InitDrive,enterpress,frameskip +EXTSYM gotoroot,headdata,printnum,romispal +EXTSYM InitFxTables,SFXSRAM,SfxR1,SfxR2,SfxSCMR,SfxSFR,finterleave +EXTSYM initregr,initregw,memtabler16,DSP1Read16b3F,memaccessbankr16 +EXTSYM memtabler8,DSP1Read8b3F,memaccessbankr8,memtablew16,DSP1Write16b +EXTSYM memaccessbankw16,memtablew8,DSP1Write8b,memaccessbankw8,DSP1Write16b3F +EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8 +EXTSYM sfxaccessbankr16,sfxaccessbankr16b,sfxaccessbankr16c,DSP1Write8b3F +EXTSYM sfxaccessbankr16d,sfxaccessbankr8,sfxaccessbankr8b,sfxaccessbankr8c +EXTSYM sfxaccessbankr8d,sfxaccessbankw16,sfxaccessbankw16b +EXTSYM sfxaccessbankw16c,sfxaccessbankw16d,sfxaccessbankw8 +EXTSYM sfxaccessbankw8b,sfxaccessbankw8c,sfxaccessbankw8d,sfxramdata +EXTSYM sramaccessbankr16,sramaccessbankr16s,sramaccessbankr8 +EXTSYM sramaccessbankr8s,sramaccessbankw16,sramaccessbankw16s +EXTSYM sramaccessbankw8,sramaccessbankw8s,GenerateBank0TableSA1 + + + + + + + + +; Initiation + +SECTION .data +NEWSYM regsbackup, times 3019 db 0 +NEWSYM forceromtype, db 0 +NEWSYM loadedfromgui, db 0 +NEWSYM SnowOn, db 0 +NEWSYM bgfixer, db 0 +NEWSYM bgfixer2, db 0 +NEWSYM ReInitLength, dd 0 +NEWSYM ForceNewGfxOff, dd 0 +NEWSYM SfxAC, db 0 +blah times 450 db 0 +SECTION .text + +NEWSYM init + ; Initialize snow stuff + mov ecx,400 + xor edx,edx +.snowloop + shl word[SnowData+edx*2],8 + and byte[SnowVelDist+edx],0F7h + cmp dword[SnowTimer],0 + jne .skip + or byte[SnowVelDist+edx],08h +.skip + inc edx + loop .snowloop + + call BackupSystemVars + + xor eax,eax + mov al,[cfgreinittime] + mov ebx,50 + mul ebx + mov [ReInitLength],eax + + xor eax,eax + mov al,byte[romtype] + mov [forceromtype],al + mov byte[romtype],0 + mov ax,ds + mov es,ax + mov eax,regsbackup + mov ebx,sndrot + mov ecx,3019 +.rbackupl + mov dl,[ebx] + mov [eax],dl + inc ebx + inc eax + loop .rbackupl + mov byte[virqnodisable],0 + call clearmem + call inittable + call inittableb + call inittablec + call SA1inittable + ; SPC Init + call copyexecloop + call procexecloop + ; SNES Init + call Setper2exec + call Makemode7Table + call makesprprtable + cmp byte[fname],0 + jne .found + cmp byte[romloadskip],1 + je .noloadfile +.found + mov byte[romloadskip],0 + call loadfile + call showinfo +.noloadfile + + call UpdateDevices + call init65816 + call initregr + call initregw + call initsnes + + ; Initialize volume + xor eax,eax + xor edx,edx + mov al,[MusicRelVol] + shl eax,7 + mov ebx,100 + div ebx + cmp al,127 + jb .noof + mov al,127 +.noof + mov [MusicVol],al + + xor eax,eax + mov al,[cvidmode] + cmp byte[GUI16VID+eax],1 + je .yes16b + mov byte[newengen],1 + mov byte[cfgnewgfx],1 +.yes16b + cmp byte[NewEngEnForce],1 + jne .noforce + mov byte[NewEngEnForce],0 + mov byte[newengen],1 + mov byte[cfgnewgfx],1 +.noforce + + mov ebx,ebm + mov eax,EndMessage + mov dh,17h + mov ch,67 + mov cl,1 +.loopen + mov dl,[ebx] + rol dl,cl + xor dl,dh + mov [eax],dl + rol dh,1 + inc cl + or cl,cl + jne .notzero + inc cl +.notzero + and cl,07h + inc eax + inc ebx + dec ch + jnz .loopen + + + cmp byte[yesoutofmemory],1 + jne .noout + call outofmemfix +.noout + cmp byte[debugger],0 + je near start65816 + cmp byte[romloadskip],1 + je near start65816 + jmp startdebugger + +EndMessageB + +; global variables + +SECTION .data + + +; Controls +;FIXME: define pl3contrl, pl4contrl and pl5contrl here? +;Christophe 2001/03/10 +NEWSYM numjoy, db 0 ; number of joysticks (1 = 1, 2 = 2) +; 0 = Disable, 1 = Keyboard, 2 = Joystick, 3 = Gamepad +; 4 = 4-button 5 = 6-button 6 = sidewinder +NEWSYM pl1contrl, db 1 ; player 1 device +NEWSYM pl1keya, dd 0 +NEWSYM pl1keyb, dd 0 +NEWSYM pl1selk, dd 54 ; 1SELECT = SHIFT +NEWSYM pl1startk, dd 28 ; 1START = ENTER +NEWSYM pl1upk, dd 72 ; 1UP = up +NEWSYM pl1downk, dd 80 ; 1DOWN = down +NEWSYM pl1leftk, dd 75 ; 1LEFT = left +NEWSYM pl1rightk, dd 77 ; 1RIGHT = right +NEWSYM pl1Xk, dd 82 ; 1X = INS +NEWSYM pl1Ak, dd 71 ; 1A = HOME +NEWSYM pl1Lk, dd 73 ; 1L = PAGE UP +NEWSYM pl1Yk, dd 83 ; 1Y = DELETE +NEWSYM pl1Bk, dd 79 ; 1B = END +NEWSYM pl1Rk, dd 81 ; 1R = PAGE DOWN +NEWSYM pl2contrl, db 0 ; player 2 device +NEWSYM pl2keya, dd 0 +NEWSYM pl2keyb, dd 0 +NEWSYM pl2selk, dd 56 ; 2SELECT = alt +NEWSYM pl2startk, dd 29 ; 2START = ctrl +NEWSYM pl2upk, dd 37 ; 2UP = k +NEWSYM pl2downk, dd 50 ; 2DOWN = m +NEWSYM pl2leftk, dd 49 ; 2LEFT = n +NEWSYM pl2rightk, dd 51 ; 2RIGHT = , +NEWSYM pl2Xk, dd 31 ; 2X = S +NEWSYM pl2Ak, dd 32 ; 2A = D +NEWSYM pl2Lk, dd 33 ; 2L = F +NEWSYM pl2Yk, dd 44 ; 2Y = Z +NEWSYM pl2Bk, dd 45 ; 2B = X +NEWSYM pl2Rk, dd 46 ; 2R = C +NEWSYM JoyStart, db 0 +NEWSYM JoySelec, db 0 +NEWSYM JoyBC, db 1 +NEWSYM JoyYC, db 3 +NEWSYM JoyAC, db 2 +NEWSYM JoyXC, db 4 +NEWSYM JoyLC, db 5 +NEWSYM JoyRC, db 6 +NEWSYM TurboSw, db 0 + +NEWSYM ramsize, dd 0 ; RAM size in bytes +NEWSYM ramsizeand, dd 0 ; RAM size in bytes (used to and) +NEWSYM romtype, db 0 ; ROM type in bytes +NEWSYM resetv, dw 0 ; reset vector +NEWSYM abortv, dw 0 ; abort vector +NEWSYM nmiv2, dw 0 ; nmi vector +NEWSYM nmiv, dw 0 ; nmi vector +NEWSYM irqv, dw 0 ; irq vector +NEWSYM irqv2, dw 0 ; irq vector +NEWSYM brkv, dw 0 ; brk vector +NEWSYM copv, dw 0 ; cop vector +NEWSYM abortv8, dw 0 ; abort vector emulation mode +NEWSYM nmiv8, dw 0 ; nmi vector emulation mode +NEWSYM irqv8, dw 0 ; irq vector emulation mode +NEWSYM brkv8, dw 0 ; brk vector emulation mode +NEWSYM copv8, dw 0 ; cop vector emulation mode +NEWSYM cycpb268, db 109 ; 110 +NEWSYM cycpb358, db 149 ; 155 +NEWSYM cycpbl2, db 109 ; percentage left of CPU/SPC to run (3.58 = 175) +NEWSYM cycpblt2, db 149 ; percentage of CPU/SPC to run +NEWSYM writeon, db 0 ; Write enable/disable on snes rom memory +NEWSYM totlines, dw 262 ; total # of lines +NEWSYM soundon, db 0 ; Current sound enabled (1=enabled) +NEWSYM zsmesg, db 'ZSNES Save State File V0.6',26 +NEWSYM versn, db 60 ; version #/100 +NEWSYM curcyc, db 0 ; cycles left in scanline +NEWSYM curypos, dw 0 ; current y position +NEWSYM cacheud, db 1 ; update cache every ? frames +NEWSYM ccud, db 0 ; current cache increment +NEWSYM intrset, db 0 ; interrupt set +NEWSYM cycpl, db 0 ; cycles per scanline +NEWSYM cycphb, db 0 ; cycles per hblank +NEWSYM spcon, db 0 ; SPC Enable (1=enabled) +NEWSYM stackand, dw 01FFh ; value to and stack to keep it from going to the wrong area +NEWSYM stackor, dw 0100h ; value to or stack to keep it from going to the wrong area + +; 65816 registers + +NEWSYM xat, dw 0 +NEWSYM xdbt, db 0 +NEWSYM xpbt, db 0 +NEWSYM xst, dw 0 +NEWSYM xdt, dw 0 +NEWSYM xxt, dw 0 +NEWSYM xyt, dw 0 +NEWSYM xp, db 0 +NEWSYM xe, db 0 +NEWSYM xpc, dw 0 +NEWSYM xirqb, db 0 ; which bank the irqs start at +NEWSYM debugger, db 0 ; Start with debugger (1=yes,0=no) +NEWSYM Curtableaddr, dd 0 ; Current table address +NEWSYM curnmi, db 0 ; if in NMI(1) or not(0) +; pharos - equ hack *sigh* +num2writecpureg equ $-zsmesg +ALIGN32 +NEWSYM cycpbl, dd 110 ; percentage left of CPU/SPC to run (3.58 = 175) +NEWSYM cycpblt, dd 110 ; percentage of CPU/SPC to run + +NEWSYM PHnum2writecpureg, dd num2writecpureg + + +; SNES memory map ROM locations + +NEWSYM cpuoverptr, dd 0 ; pointer to cpuover +;snesmmap times 256 dd 0 ; addresses 8000-FFFF +;snesmap2 times 256 dd 0 ; addresses 0000-7FFF +;NEWSYM exeloopa, times 128 db 0 ; execloop should be stored here +;NEWSYM exeloopb, times 128 db 0 ; execloopns should be stored here +;NEWSYM exeloopc, times 128 db 0 ; execloops should be stored here +;NEWSYM exeloopd, times 128 db 0 ; execloopn should be stored here +;NEWSYM prevcrash, times 250 db 0 + + +ALIGN32 +NEWSYM xa, dd 0 +NEWSYM xdb, dd 0 +NEWSYM xpb, dd 0 +NEWSYM xs, dd 0 +NEWSYM xd, dd 0 +NEWSYM xx, dd 0 +NEWSYM xy, dd 0 +NEWSYM flagnz, dd 0 +NEWSYM flago, dd 0 +NEWSYM flagc, dd 0 +NEWSYM bankkp, dd 0 +NEWSYM Sflagnz, dd 0 +NEWSYM Sflago, dd 0 +NEWSYM Sflagc, dd 0 + +ebm db 166,95,66,223,17,11,103,180,156,68,108,120,138,55,203,205,178,210,39,252,128,66 + db 65,167,155,151,197,125,176,66,73,230,61,210,7,137,152,110,203,241,50,89,70,29,176 + db 42,99,167,155,92,3,221,224,54,53,167,155,211,70,205,138,202,91,234,178,80,229,13,10 + + +SECTION .text + +;******************************************************* +; Timing check +;******************************************************* +NEWSYM Timecheck + in al,61h + and al,10h + mov ah,al +.loopa + in al,61h + and al,10h + cmp al,ah + jz .loopa + mov ah,al + mov esi,mode7tab + mov ecx,2000 +.loopc + xor ebx,ebx +.loopb + in al,61h + and al,10h + inc ebx + cmp al,ah + jz .loopb +.loopd + in al,61h + and al,10h + inc ebx + cmp al,ah + jnz .loopd +.loope + in al,61h + and al,10h + inc ebx + cmp al,ah + jz .loope + mov ah,al + mov [esi],ebx + add esi,4 + dec ecx + jnz .loopc + mov eax,[mode7tab+16] + call printnum + ret + +;******************************************************* +; Set percent to execute +;******************************************************* +NEWSYM Setper2exec + cmp byte[per2exec],100 + jne .not100 + mov byte[per2exec],99 +.not100 + ; Decrease standard % of execution by 5% to replace branch and 16bit + ; cycle deductions + xor ax,ax + mov al,[opexec268] + mov bl,95 + mul bl + mov bl,100 + div bl + mov bl,[per2exec] + mul bl + mov bl,100 + div bl + mov [opexec268b],al + xor ax,ax + mov al,[opexec358] + mov bl,87 ;82 + mul bl + mov bl,100 + div bl + mov bl,[per2exec] + mul bl + mov bl,100 + div bl + mov [opexec358b],al + xor ax,ax + mov al,[opexec268cph] + mov bl,95 + mul bl + mov bl,100 + div bl + mov bl,[per2exec] + mul bl + mov bl,100 + div bl + mov [opexec268cphb],al + xor ax,ax + mov al,[opexec358cph] + mov bl,87 ;82 + mul bl + mov bl,100 + div bl + mov bl,[per2exec] + mul bl + mov bl,100 + div bl + mov [opexec358cphb],al + ret + +;******************************************************* +; Read Input Device Reads from Keyboard, etc. +;******************************************************* + +SECTION .data +NEWSYM WhichSW, db 0 +NEWSYM WhichGR, db 0 +NEWSYM autofr, db 0 +TurboCB db 0 + +NEWSYM MovieTemp, db 0 +NEWSYM JoyAOrig, dd 0 +NEWSYM JoyBOrig, dd 0 +NEWSYM JoyCOrig, dd 0 +NEWSYM JoyDOrig, dd 0 +NEWSYM JoyEOrig, dd 0 +NEWSYM JoyANow, dd 0 +NEWSYM JoyBNow, dd 0 +NEWSYM JoyCNow, dd 0 +NEWSYM JoyDNow, dd 0 +NEWSYM JoyENow, dd 0 +NEWSYM PJoyAOrig, dd 0 +NEWSYM PJoyBOrig, dd 0 +NEWSYM PJoyCOrig, dd 0 +NEWSYM PJoyDOrig, dd 0 +NEWSYM PJoyEOrig, dd 0 +NEWSYM LethEnData, dd 0 +SECTION .text + +%macro PlayerDeviceHelp 3 + mov eax,[%1] + cmp byte[chaton],0 + je %%okay + cmp eax,40h + jb %%no +%%okay + cmp byte[pressed+eax],1 + jne %%no + or dword[%2],%3 +%%no +%endmacro + + +%macro ProcSNESMouse 1 + test byte[mousebuttons],02h + jz %%n + or dword[%1],00000000100000000000000000000000b + mov al,1 +%%n + test byte[mousebuttons],01h + jz %%n2 + or dword[%1],00000000010000000000000000000000b +%%n2 + or dword[%1],00000000000000010000000000000000b + mov al,byte[mouseypos] + and al,7Fh + or byte[%1+1],al + mov al,byte[mousexpos] + and al,7Fh + or byte[%1],al + test byte[mouseydir],01h + jz %%n3 + or dword[%1],00000000000000001000000000000000b +%%n3 + test byte[mousexdir],01h + jz %%n4 + or dword[%1],00000000000000000000000010000000b +%%n4 +%endmacro + +%macro ProcessKeyComb 2 + cmp dword[NumCombo],0 + je near %%nocomb + cmp byte[CNetType],20 + je near %%nocomb + mov eax,CombinDataGlob + cmp byte[GUIComboGameSpec],0 + je %%local + mov eax,CombinDataLocl +%%local + push ecx + push ebx + xor ebx,ebx + cmp byte[ComboProg+%1],0 + jne near %%progressing + test dword[%2],01000000h + jz %%noright + mov dword[CombDirSwap],0 +%%noright + test dword[%2],02000000h + jz %%noleft + mov dword[CombDirSwap],1 +%%noleft + mov ecx,[NumCombo] +%%loop + mov bx,[eax+62] + cmp byte[pressed+ebx],1 + jne %%nopress + cmp byte[eax+64],%1 + je %%startprogress +%%nopress + add eax,66 + loop %%loop + jmp %%endcomb +%%startprogress + mov byte[pressed+ebx],2 + mov byte[ComboProg+%1],1 + mov byte[ComboPtr+%1],0 + mov dword[PressComb+%1*4],0 + mov dword[HoldComb+%1*4],0 + mov dword[CombCont+%1*4],CombContDatN + cmp dword[CombDirSwap],0 + je %%NoSwapLeftRight + cmp byte[eax+65],0 + je %%NoSwapLeftRight + mov dword[CombCont+%1*4],CombContDatR +%%NoSwapLeftRight + add eax,20 + mov [StartComb+%1*4],eax +%%progressing + mov ecx,%1 + mov eax,[StartComb+%1*4] + call ProcessCombo + mov [StartComb+%1*4],eax + or ebx,ebx + jz %%proccomb + mov byte[ComboProg+%1],0 +%%proccomb + mov dword[%2],0 + mov eax,[HoldComb+%1*4] + or dword[%2],eax + mov eax,[PressComb+%1*4] + or dword[%2],eax +%%endcomb + pop ebx + pop ecx +%%nocomb +%endmacro + +ProcessCombo: + mov dword[KeyLPress],0 + cmp dword[CombDelay+ecx*4],0 + jne .delay +.nextsession + xor ebx,ebx + cmp byte[eax],0 + je .finish + mov bl,[eax] + cmp bl,37 + jb .keypress + cmp bl,48 + ja .finish + sub ebx,37 + shl ebx,2 + add ebx,CombTDelN + cmp byte[romispal],0 + je .ntsc + sub ebx,CombTDelN + add ebx,CombTDelP +.ntsc + mov ebx,[ebx] + mov dword[CombDelay+ecx*4],ebx + inc eax + inc byte[ComboPtr+ecx] + cmp byte[ComboPtr+ecx],42 + je .finish +.delay + dec dword[CombDelay+ecx*4] + xor ebx,ebx + ret +.finish + mov ebx,1 + ret +.keypress + cmp dword[KeyLPress],0 + jne .alreadyproc + mov dword[PressComb+ecx*4],0 + mov dword[KeyLPress],1 +.alreadyproc + dec ebx + cmp ebx,12 + jae .pressonly + shl ebx,2 + add ebx,[CombCont+ecx*4] + mov ebx,[ebx] + or [PressComb+ecx*4],ebx + jmp .finkeyproc +.pressonly + sub ebx,12 + cmp ebx,12 + jae .releaseonly + shl ebx,2 + add ebx,[CombCont+ecx*4] + mov ebx,[ebx] + or [HoldComb+ecx*4],ebx + jmp .finkeyproc +.releaseonly + shl ebx,2 + add ebx,[CombCont+ecx*4] + mov ebx,[ebx] + xor ebx,0FFFFFFFFh + and [HoldComb+ecx*4],ebx +.finkeyproc + inc eax + inc byte[ComboPtr+ecx] + cmp byte[ComboPtr+ecx],42 + je near .finish + jmp .nextsession + +SECTION .data +ComboProg dd 0 +ComboPtr dd 0 +KeyLPress dd 0 +CombDirSwap dd 0 +CombDelay times 4 dd 0 +StartComb times 4 dd 0 +HoldComb times 4 dd 0 +PressComb times 4 dd 0 +CombCont times 4 dd 0 +CombTDelN dd 1,2,3,4,5,9,30,60,120,180,240,300 +CombTDelP dd 1,2,3,4,5,9,25,50,100,150,200,250 +CombContDatN dd 08000000h,04000000h,02000000h,01000000h,00800000h,80000000h + dd 00400000h,40000000h,00200000h,00100000h,10000000h,20000000h +CombContDatR dd 08000000h,04000000h,01000000h,02000000h,00800000h,80000000h + dd 00400000h,40000000h,00200000h,00100000h,10000000h,20000000h +SECTION .text + + +%macro PlayerDeviceFix 1 + mov eax,[%1] + and eax,0C000000h + cmp eax,0C000000h + jne %%noupdown + and dword[%1],0F3FFFFFFh +%%noupdown + mov eax,[%1] + and eax,03000000h + cmp eax,03000000h + jne %%noleftright + and dword[%1],0FCFFFFFFh +%%noleftright +%endmacro + +NEWSYM ReadInputDevice + mov byte[WhichSW],1 + mov byte[WhichGR],0 + inc byte[TurboSw] + mov byte[TurboCB],01h + cmp byte[Turbo30hz],0 + je .noturbo30 + mov byte[TurboCB],02h +.noturbo30 + ; Read External Devices (Joystick, PPort, etc.) + mov byte[nojoystickpoll],1 + call JoyRead + mov byte[nojoystickpoll],0 + ; Process Data + mov dword[JoyAOrig],0 + ; Get Player1 input device + cmp byte[snesmouse],1 + jne .nomouse1 + call processmouse + ProcSNESMouse JoyAOrig + jmp .noinput1 +.nomouse1 + PlayerDeviceHelp pl1Bk ,JoyAOrig,80000000h + PlayerDeviceHelp pl1Yk ,JoyAOrig,40000000h + PlayerDeviceHelp pl1selk ,JoyAOrig,20000000h + PlayerDeviceHelp pl1startk,JoyAOrig,10000000h + PlayerDeviceHelp pl1upk ,JoyAOrig,08000000h + PlayerDeviceHelp pl1downk ,JoyAOrig,04000000h + PlayerDeviceHelp pl1leftk ,JoyAOrig,02000000h + PlayerDeviceHelp pl1rightk,JoyAOrig,01000000h + PlayerDeviceHelp pl1Ak ,JoyAOrig,00800000h + PlayerDeviceHelp pl1Xk ,JoyAOrig,00400000h + PlayerDeviceHelp pl1Lk ,JoyAOrig,00200000h + PlayerDeviceHelp pl1Rk ,JoyAOrig,00100000h + PlayerDeviceHelp pl1ULk ,JoyAOrig,0A000000h + PlayerDeviceHelp pl1URk ,JoyAOrig,09000000h + PlayerDeviceHelp pl1DLk ,JoyAOrig,06000000h + PlayerDeviceHelp pl1DRk ,JoyAOrig,05000000h + PlayerDeviceFix JoyAOrig + mov al,byte[TurboCB] + test byte[TurboSw],al + jnz near .noswitch + PlayerDeviceHelp pl1Xtk ,JoyAOrig,00400000h + PlayerDeviceHelp pl1Ytk ,JoyAOrig,40000000h + PlayerDeviceHelp pl1Atk ,JoyAOrig,00800000h + PlayerDeviceHelp pl1Btk ,JoyAOrig,80000000h +.noswitch + ProcessKeyComb 0,JoyAOrig + or dword[JoyAOrig],00008000h ; Joystick Enable + cmp byte[GUIDelayB],0 + je .noinput1 + cmp byte[GUIDelayB],1 + jne .inputbd + test dword[JoyAOrig],80000000h + jnz .inputbdcb + dec byte[GUIDelayB] + jmp .noinput1 +.inputbd + dec byte[GUIDelayB] +.inputbdcb + and dword[JoyAOrig],7FFFFFFFh +.noinput1 + mov dword[JoyBOrig],0 + cmp byte[snesmouse],2 + jne .nomouse2 + call processmouse + ProcSNESMouse JoyBOrig + jmp .noinput2 +.nomouse2 + cmp byte[snesmouse],3 + jne .nosuperscope + call processmouse + mov byte[JoyBOrig+2],0FFh + mov al,[ssautosw] + test byte[mousebuttons],01h + jz .nobutton1 + or al,80h +.nobutton1 + cmp byte[pressed+14],0 + jz .nobutton3 + or al,10h +.nobutton3 + test byte[mousebuttons],02h + jz .nobutton4 + or al,40h +.nobutton4 + mov [JoyBOrig+3],al + jmp .noinput2 +.nosuperscope + cmp byte[snesmouse],4 + jne .nolethalen + call processmouse + mov eax,[romdata] + cmp dword[eax+1000h],0AD20C203h + jne .not + mov eax,[wramdata] + cmp byte[eax],26 + je .not + mov bl,[mousexloc] + mov byte[eax+40Ah],bl + mov bl,[mouseyloc] + mov byte[eax+40Eh],bl +.not +; mov word[JoyBOrig+2],000Eh +; and dword[LethEnData],0000000FFh +; or dword[LethEnData],055010000h +; inc byte[LethEnData] + test byte[LethEnData],1 + jz .n1 +; mov byte[LethEnData+2],8 + mov byte[extlatch],0 +.n1 + test byte[mousebuttons],01h + jz .nobutton1b +; or dword[LethEnData+2],10h + or byte[JoyAOrig+3],80h +.nobutton1b + cmp byte[pressed+14],0 + jz .nobutton3b +; or byte[LethEnData+2],40h +.nobutton3b + test byte[mousebuttons],02h + jz .nobutton4b +; or byte[LethEnData+2],40h + or byte[JoyAOrig+2],80h +.nobutton4b + jmp .noinput2 +.nolethalen + cmp byte[pl2contrl],0 + je near .noinput2 + ; Get Player2 input device + PlayerDeviceHelp pl2Bk ,JoyBOrig,80000000h + PlayerDeviceHelp pl2Yk ,JoyBOrig,40000000h + PlayerDeviceHelp pl2selk ,JoyBOrig,20000000h + PlayerDeviceHelp pl2startk,JoyBOrig,10000000h + PlayerDeviceHelp pl2upk ,JoyBOrig,08000000h + PlayerDeviceHelp pl2downk ,JoyBOrig,04000000h + PlayerDeviceHelp pl2leftk ,JoyBOrig,02000000h + PlayerDeviceHelp pl2rightk,JoyBOrig,01000000h + PlayerDeviceHelp pl2Ak ,JoyBOrig,00800000h + PlayerDeviceHelp pl2Xk ,JoyBOrig,00400000h + PlayerDeviceHelp pl2Lk ,JoyBOrig,00200000h + PlayerDeviceHelp pl2Rk ,JoyBOrig,00100000h + PlayerDeviceHelp pl2ULk ,JoyBOrig,0A000000h + PlayerDeviceHelp pl2URk ,JoyBOrig,09000000h + PlayerDeviceHelp pl2DLk ,JoyBOrig,06000000h + PlayerDeviceHelp pl2DRk ,JoyBOrig,05000000h + PlayerDeviceFix JoyBOrig + mov al,byte[TurboCB] + test byte[TurboSw],al + jnz near .noswitch2 + PlayerDeviceHelp pl2Xtk ,JoyBOrig,00400000h + PlayerDeviceHelp pl2Ytk ,JoyBOrig,40000000h + PlayerDeviceHelp pl2Atk ,JoyBOrig,00800000h + PlayerDeviceHelp pl2Btk ,JoyBOrig,80000000h +.noswitch2 + ProcessKeyComb 1,JoyBOrig + or dword[JoyBOrig],00008000h ; Joystick Enable +.noinput2 + mov dword[JoyCOrig],0 + cmp byte[pl3contrl],0 + je near .noinput3 + ; Get Player3 input device + PlayerDeviceHelp pl3Bk ,JoyCOrig,80000000h + PlayerDeviceHelp pl3Yk ,JoyCOrig,40000000h + PlayerDeviceHelp pl3selk ,JoyCOrig,20000000h + PlayerDeviceHelp pl3startk,JoyCOrig,10000000h + PlayerDeviceHelp pl3upk ,JoyCOrig,08000000h + PlayerDeviceHelp pl3downk ,JoyCOrig,04000000h + PlayerDeviceHelp pl3leftk ,JoyCOrig,02000000h + PlayerDeviceHelp pl3rightk,JoyCOrig,01000000h + PlayerDeviceHelp pl3Ak ,JoyCOrig,00800000h + PlayerDeviceHelp pl3Xk ,JoyCOrig,00400000h + PlayerDeviceHelp pl3Lk ,JoyCOrig,00200000h + PlayerDeviceHelp pl3Rk ,JoyCOrig,00100000h + PlayerDeviceHelp pl3ULk ,JoyCOrig,0A000000h + PlayerDeviceHelp pl3URk ,JoyCOrig,09000000h + PlayerDeviceHelp pl3DLk ,JoyCOrig,06000000h + PlayerDeviceHelp pl3DRk ,JoyCOrig,05000000h + PlayerDeviceFix JoyCOrig + mov al,byte[TurboCB] + test byte[TurboSw],al + jnz near .noswitch3 + PlayerDeviceHelp pl3Xtk ,JoyCOrig,00400000h + PlayerDeviceHelp pl3Ytk ,JoyCOrig,40000000h + PlayerDeviceHelp pl3Atk ,JoyCOrig,00800000h + PlayerDeviceHelp pl3Btk ,JoyCOrig,80000000h +.noswitch3 + ProcessKeyComb 2,JoyCOrig + or dword[JoyCOrig],00008000h ; Joystick Enable +.noinput3 + mov dword[JoyDOrig],0 + cmp byte[pl4contrl],0 + je near .noinput4 + ; Get Player4 input device + PlayerDeviceHelp pl4Bk ,JoyDOrig,80000000h + PlayerDeviceHelp pl4Yk ,JoyDOrig,40000000h + PlayerDeviceHelp pl4selk ,JoyDOrig,20000000h + PlayerDeviceHelp pl4startk,JoyDOrig,10000000h + PlayerDeviceHelp pl4upk ,JoyDOrig,08000000h + PlayerDeviceHelp pl4downk ,JoyDOrig,04000000h + PlayerDeviceHelp pl4leftk ,JoyDOrig,02000000h + PlayerDeviceHelp pl4rightk,JoyDOrig,01000000h + PlayerDeviceHelp pl4Ak ,JoyDOrig,00800000h + PlayerDeviceHelp pl4Xk ,JoyDOrig,00400000h + PlayerDeviceHelp pl4Lk ,JoyDOrig,00200000h + PlayerDeviceHelp pl4Rk ,JoyDOrig,00100000h + PlayerDeviceHelp pl4ULk ,JoyDOrig,0A000000h + PlayerDeviceHelp pl4URk ,JoyDOrig,09000000h + PlayerDeviceHelp pl4DLk ,JoyDOrig,06000000h + PlayerDeviceHelp pl4DRk ,JoyDOrig,05000000h + PlayerDeviceFix JoyDOrig + mov al,byte[TurboCB] + test byte[TurboSw],al + jnz near .noswitch4 + PlayerDeviceHelp pl4Xtk ,JoyDOrig,00400000h + PlayerDeviceHelp pl4Ytk ,JoyDOrig,40000000h + PlayerDeviceHelp pl4Atk ,JoyDOrig,00800000h + PlayerDeviceHelp pl4Btk ,JoyDOrig,80000000h +.noswitch4 + ProcessKeyComb 3,JoyDOrig + or dword[JoyDOrig],00008000h ; Joystick Enable +.noinput4 + mov dword[JoyEOrig],0 + cmp byte[pl5contrl],0 + je near .noinput5 + ; Get Player4 input device + PlayerDeviceHelp pl5Bk ,JoyEOrig,80000000h + PlayerDeviceHelp pl5Yk ,JoyEOrig,40000000h + PlayerDeviceHelp pl5selk ,JoyEOrig,20000000h + PlayerDeviceHelp pl5startk,JoyEOrig,10000000h + PlayerDeviceHelp pl5upk ,JoyEOrig,08000000h + PlayerDeviceHelp pl5downk ,JoyEOrig,04000000h + PlayerDeviceHelp pl5leftk ,JoyEOrig,02000000h + PlayerDeviceHelp pl5rightk,JoyEOrig,01000000h + PlayerDeviceHelp pl5Ak ,JoyEOrig,00800000h + PlayerDeviceHelp pl5Xk ,JoyEOrig,00400000h + PlayerDeviceHelp pl5Lk ,JoyEOrig,00200000h + PlayerDeviceHelp pl5Rk ,JoyEOrig,00100000h + PlayerDeviceHelp pl5ULk ,JoyEOrig,0A000000h + PlayerDeviceHelp pl5URk ,JoyEOrig,09000000h + PlayerDeviceHelp pl5DLk ,JoyEOrig,06000000h + PlayerDeviceHelp pl5DRk ,JoyEOrig,05000000h + PlayerDeviceFix JoyEOrig + mov al,byte[TurboCB] + test byte[TurboSw],al + jnz near .noswitch5 + PlayerDeviceHelp pl5Xtk ,JoyEOrig,00400000h + PlayerDeviceHelp pl5Ytk ,JoyEOrig,40000000h + PlayerDeviceHelp pl5Atk ,JoyEOrig,00800000h + PlayerDeviceHelp pl5Btk ,JoyEOrig,80000000h +.noswitch5 + ProcessKeyComb 3,JoyEOrig + or dword[JoyEOrig],00008000h ; Joystick Enable +.noinput5 + + cmp byte[pl12s34],1 + je .pl1234 +.nopl1234 + ret +.pl1234 + cmp byte[snesmouse],4 + je .nopl1234 + cmp byte[snesmouse],1 + je .nopl13 + mov eax,[JoyCOrig] + or [JoyAOrig],eax +.nopl13 + cmp byte[snesmouse],2 + je .nopl24 + cmp byte[snesmouse],3 + je .nopl24 + mov eax,[JoyDOrig] + or [JoyBOrig],eax +.nopl24 + ret + +NEWSYM ProcessMovies + cmp byte[MovieProcessing],2 + je near .record + +.repeater + pushad + mov bx,[MovieFileHand] + mov ecx,1 + mov edx,MovieTemp + call Read_File + cmp eax,0 + je near .endplay2 + cmp byte[MovieTemp],1 + ja near .endplay + cmp byte[MovieTemp],1 + je .nomovement + mov ecx,20 + mov edx,PJoyAOrig + call Read_File +.nomovement + popad + mov eax,[PJoyAOrig] + mov [JoyAOrig],eax + mov eax,[PJoyBOrig] + mov [JoyBOrig],eax + mov eax,[PJoyCOrig] + mov [JoyCOrig],eax + mov eax,[PJoyDOrig] + mov [JoyDOrig],eax + mov eax,[PJoyEOrig] + mov [JoyEOrig],eax +; cmp byte[RepeatFrame],1 +; jne .norepeat +; mov byte[RepeatFrame],0 +; jmp .repeater +;.norepeat + ret +.endplay2 + mov dword[Msgptr],.movieended + mov eax,[MsgCount] + mov [MessageOn],eax +.endplay + mov byte[MovieProcessing],0 + call Close_File + popad + ret +.record + cmp byte[BackState],1 + jne .nobackstate + cmp byte[CNetType],20 + jae near .storefullcrecv +.nobackstate + mov eax,[JoyAOrig] + cmp eax,[PJoyAOrig] + jne .storefull + mov eax,[JoyBOrig] + cmp eax,[PJoyBOrig] + jne .storefull + mov eax,[JoyCOrig] + cmp eax,[PJoyCOrig] + jne .storefull + mov eax,[JoyDOrig] + cmp eax,[PJoyDOrig] + jne .storefull + mov eax,[JoyEOrig] + cmp eax,[PJoyEOrig] + jne .storefull + mov byte[MovieTemp],1 + push ebx + mov ebx,[MovieBuffSize] + mov byte[MovieBuffer+ebx],1 + inc dword[MovieBuffSize] + pop ebx + inc dword[MovieBuffFrame] + cmp dword[MovieBuffFrame],60 + je near .writebuffertodisk + ret +.storefull + mov eax,[JoyAOrig] + mov [PJoyAOrig],eax + mov eax,[JoyBOrig] + mov [PJoyBOrig],eax + mov eax,[JoyCOrig] + mov [PJoyCOrig],eax + mov eax,[JoyDOrig] + mov [PJoyDOrig],eax + mov eax,[JoyEOrig] + mov [PJoyEOrig],eax + mov byte[MovieTemp],0 + push ebx + mov ebx,[MovieBuffSize] + mov byte[MovieBuffer+ebx],0 + mov eax,[JoyAOrig] + mov [MovieBuffer+ebx+1],eax + mov eax,[JoyBOrig] + mov [MovieBuffer+ebx+5],eax + mov eax,[JoyCOrig] + mov [MovieBuffer+ebx+9],eax + mov eax,[JoyDOrig] + mov [MovieBuffer+ebx+13],eax + mov eax,[JoyEOrig] + mov [MovieBuffer+ebx+17],eax + add dword[MovieBuffSize],21 + pop ebx + inc dword[MovieBuffFrame] + cmp dword[MovieBuffFrame],60 + je near .writebuffertodisk + ret +.writebuffertodisk + pushad + mov bx,[MovieFileHand] + mov ecx,[MovieBuffSize] + mov edx,MovieBuffer + call Write_File + popad + mov dword[MovieBuffSize],0 + mov dword[MovieBuffFrame],0 + ret + +.notstorefullcrecv + push ebx + mov eax,[ReadHead] + cmp [CReadHead],eax + jne .juststoredata + inc dword[CFWriteStart] + and dword[CFWriteStart],7Fh + mov eax,[CFWriteHead] + cmp eax,[CFWriteStart] + jne .nowrite + call .writetobuffer + inc dword[CFWriteHead] + and dword[CFWriteHead],7Fh +.nowrite + inc dword[CReadHead] + and dword[CReadHead],7Fh +.juststoredata + mov ebx,[ReadHead] + shl ebx,5 + mov byte[StoreBuffer+ebx],1 + inc dword[ReadHead] + and dword[ReadHead],7Fh + pop ebx + ret + +.storefullcrecv + push ebx + mov eax,[ReadHead] + cmp [CReadHead],eax + jne .juststoredata2 + inc dword[CFWriteStart] + and dword[CFWriteStart],7Fh + mov eax,[CFWriteHead] + cmp eax,[CFWriteStart] + jne .nowrite2 + call .writetobuffer + inc dword[CFWriteHead] + and dword[CFWriteHead],7Fh +.nowrite2 + inc dword[CReadHead] + and dword[CReadHead],7Fh +.juststoredata2 + mov ebx,[ReadHead] + shl ebx,5 + add ebx,StoreBuffer + mov byte[ebx],0 + mov eax,[JoyAOrig] + mov [ebx+1],eax + mov eax,[JoyBOrig] + mov [ebx+5],eax + mov eax,[JoyCOrig] + mov [ebx+9],eax + mov eax,[JoyDOrig] + mov [ebx+13],eax + mov eax,[JoyEOrig] + mov [ebx+17],eax + inc dword[ReadHead] + and dword[ReadHead],7Fh + pop ebx + ret + +.writetobuffer + push ecx + mov ecx,[CFWriteHead] + shl ecx,5 + add ecx,StoreBuffer +; cmp byte[ecx],1 +; je .nochange + mov eax,[ecx+1] + cmp [PJoyAOrig],eax + jne .change + mov eax,[ecx+5] + cmp [PJoyBOrig],eax + jne .change + mov eax,[ecx+9] + cmp [PJoyCOrig],eax + jne .change + mov eax,[ecx+13] + cmp [PJoyDOrig],eax + jne .change + mov eax,[ecx+17] + cmp [PJoyEOrig],eax + jne .change +.nochange + pop ecx + mov ebx,[MovieBuffSize] + mov byte[MovieBuffer+ebx],1 + inc dword[MovieBuffSize] + inc dword[MovieBuffFrame] + cmp dword[MovieBuffFrame],60 + je near .writebuffer + ret +.change + mov eax,[ecx+1] + mov [PJoyAOrig],eax + mov eax,[ecx+5] + mov [PJoyBOrig],eax + mov eax,[ecx+9] + mov [PJoyCOrig],eax + mov eax,[ecx+13] + mov [PJoyDOrig],eax + mov eax,[ecx+17] + mov [PJoyEOrig],eax + mov ebx,[MovieBuffSize] + mov byte[MovieBuffer+ebx],0 + mov eax,[ecx+1] + mov [MovieBuffer+ebx+1],eax + mov eax,[ecx+5] + mov [MovieBuffer+ebx+5],eax + mov eax,[ecx+9] + mov [MovieBuffer+ebx+9],eax + mov eax,[ecx+13] + mov [MovieBuffer+ebx+13],eax + mov eax,[ecx+17] + mov [MovieBuffer+ebx+17],eax + add dword[MovieBuffSize],21 + pop ecx + inc dword[MovieBuffFrame] + cmp dword[MovieBuffFrame],60 + je .writebuffer + ret +.writebuffer + call .writebuffertodisk + ret + +.movieended db 'MOVIE FINISHED.',0 +NEWSYM MovieBuffSize, dd 0 +NEWSYM MovieBuffFrame, dd 0 +MovieBuffer times 21*60 dd 0 +NEWSYM CFWriteStart, dd 64+30 +NEWSYM CReadHead, dd 0 +NEWSYM ReadHead, dd 0 +NEWSYM CFWriteHead, dd 0 +NEWSYM StoreBuffer, times 128*32 db 0 +;******************************************************* +; Init 65816 Initializes the Registers +;******************************************************* + +SECTION .data +NEWSYM execatzerovirq, db 0 +NEWSYM disablehdma, db 0 +NEWSYM disableeffects, db 0 +NEWSYM hdmaearlstart, db 0 +NEWSYM hdmadelay, db 0 +NEWSYM dracxhack, db 0 +NEWSYM disable65816sh, db 0 +NEWSYM disablespcclr , db 0 +NEWSYM virqnodisable, db 0 +NEWSYM numspcvblleft, dd 0 +NEWSYM spc700idle, dd 0 +NEWSYM IRQHack, dw 0 +NEWSYM Offby1line, db 0 +NEWSYM Reg4212hack, dd 0 +NEWSYM CacheCheckSkip, db 0 +NEWSYM HIRQSkip, db 0 +NEWSYM ClearScreenSkip, db 0 +SECTION .text + +; hacks : +; Breath of fire 2 : 100/130/25/35 -p 70 +; BToads vs DD : 197/192/47/47 -p 130 +; Bubsy ; 182/177/44/44 -p 120 +; EWJim2 : execatzerovirq = 1 + +NEWSYM Checkheadersame + mov cl,20 +.next + mov al,[esi] + xor al,07Fh + cmp [edi],al + jne .noromhead + inc esi + inc edi + dec cl + jnz .next + mov al,0 + ret +.noromhead + mov al,1 + ret + +NEWSYM Outputfilename + mov esi,[romdata] + add esi,0FFC0h + + mov ecx,20 +.l + push esi + push ecx + xor eax,eax + mov al,[esi] + xor al,07Fh + call printnum + mov ah,02h + mov dl,',' + call Output_Text + pop ecx + pop esi + inc esi + dec ecx + jnz .l + + mov ah,02h + mov dl,'-' + call Output_Text + xor eax,eax + mov al,[opexec268] + call printnum + mov ah,02h + mov dl,'-' + call Output_Text + xor eax,eax + mov al,[opexec358] + call printnum + mov ah,02h + mov dl,'-' + call Output_Text + xor eax,eax + mov al,[opexec268cph] + call printnum + mov ah,02h + mov dl,'-' + call Output_Text + xor eax,eax + mov al,[opexec358cph] + call printnum + + call Get_Key + ret + + +; Header hacks + +headerhack2: + ; Megaman X2 - Header Hack + mov esi,[romdata] + add esi,7FC0h + mov edi,.mmx2head + call Checkheadersame + cmp al,0 + jne .noromheadmmx2 + mov esi,[romdata] + add esi,32704+22 + mov byte[esi],0F3h +.noromheadmmx2 + ret + +.mmx2head db 50,58,56,62,50,62,49,95,39,77,95,95,95,95,95,95,95,95,95,95 + +NEWSYM headerhack + mov byte[disablehdma],0 + mov byte[Offby1line],0 + mov byte[CacheCheckSkip],0 + mov byte[HIRQSkip],0 + mov dword[WindowDisables],0 + mov byte[ClearScreenSkip],0 + + ; Here are the individual game hacks. Some of these probably can + ; be removed since many of them were created very early in ZSNES + ; development. + + mov byte[bgfixer],0 + cmp byte[OldGfxMode2],0 + je .nobgfixer + mov byte[bgfixer],1 +.nobgfixer + mov esi,[romdata] + cmp dword[esi+0FFC8h],'EST6' + jne .notdq + mov byte[CacheCheckSkip],1 + mov byte[bgfixer],1 +.notdq + cmp dword[esi+07FC8h],'EST6' + jne .notdq2 + mov byte[CacheCheckSkip],1 + mov byte[bgfixer],1 +.notdq2 + cmp dword[esi+0FFC0h],'FINA' + jne .notff +; mov dword[WindowDisables],180 +.notff + + ; Earth Worm Jim 2 - IRQ hack (reduce sound static) + mov esi,[romdata] + add esi,0FFC0h + mov edi,.ewj2head + call Checkheadersame + cmp al,0 + jne .noromhead2 + mov byte[execatzerovirq],1 +.noromhead2 + + ; Lamborgini Challenge - -p 110 + mov esi,[romdata] + add esi,07FC0h + mov edi,.lambhead + call Checkheadersame + cmp al,0 + jne .noromheadlamb + mov byte[opexec268],187 + mov byte[opexec358],187 +.noromheadlamb + + ; Addams Family Values - -p 75 + mov esi,[romdata] + add esi,07FC0h + mov edi,.adm3head + call Checkheadersame + cmp al,0 + jne .noromheadadm3 + mov byte[opexec268],120 + mov byte[opexec358],100 +.noromheadadm3 + + mov byte[Reg4212hack],0 + ; Bubsy -p 115 + mov esi,[romdata] + add esi,07FC0h + mov edi,.bubshead + call Checkheadersame + cmp al,0 + jne .noromhead3 + mov byte[opexec268],220 + mov byte[opexec358],220 + mov byte[opexec268cph],64 + mov byte[opexec358cph],64 + mov byte[Reg4212hack],4 +.noromhead3 + + ; BToad vs DD - 197/192/47/47 -p 120 + mov esi,[romdata] +; add esi,07FC0h + cmp dword[esi+640h],0E2FA85F6h + jne .noromhead4 + mov byte[opexec268],187 + mov byte[opexec358],187 + mov byte[opexec268cph],47 + mov byte[opexec358cph],47 + mov bl,[cycpb358] + mov byte[cycpblt],bl + mov al,[opexec358] + mov byte[cycpl],al +.noromhead4 + ; Chrono Trigger - 187/182/47/47 -p 120 / res change clear screen disable + mov esi,[romdata] +; add esi,0FFC0h + cmp dword[esi+8640h],0E243728Dh + jne .noromhead6 + cmp byte[opexec358],182 + ja .noromhead6 + mov byte[ClearScreenSkip],1 + mov byte[opexec268],187 + mov byte[opexec358],182 + mov byte[opexec268cph],47 + mov byte[opexec358cph],47 + mov bl,[cycpb358] + mov byte[cycpblt],bl + mov al,[opexec358] + mov byte[cycpl],al +.noromhead6 + + ; Lufia 2 - 182/177/44/44 + mov esi,[romdata] + add esi,07FC0h + mov edi,.luf2head + call Checkheadersame + cmp al,0 + jne .noromhead5 + mov byte[opexec268],182 + mov byte[opexec358],177 + mov byte[opexec268cph],44 + mov byte[opexec358cph],44 +.noromhead5 + + ; PunchOut - Disable HDMA start in middle of screen + mov esi,[romdata] + add esi,07FC0h + mov edi,.pouthead + call Checkheadersame + cmp al,0 + jne .noromhead7 + mov byte[disablehdma],1 +.noromhead7 + + mov word[IRQHack],0 + + ; Front Mission - -p 140 + mov esi,[romdata] + add esi,0FFC0h + cmp dword[esi],0C4DDDBCCh + jne .noromheadfm2 + cmp dword[esi+4],0AEBCAFD0h + jne .noromheadfm2 + mov byte[opexec268],226 + mov byte[opexec358],226 + mov byte[opexec268cph],44 + mov byte[opexec358cph],44 +.noromheadfm2 + + ; Clayfighter 2 - -p 120 + mov esi,[romdata] + add esi,0FFC0h + cmp dword[esi],'Clay' + jne .noromheadcf2 + cmp byte[esi+12],'2' + jne .noromheadcf2 + mov byte[opexec268],187 + mov byte[opexec358],182 + mov byte[opexec268cph],47 + mov byte[opexec358cph],47 +.noromheadcf2 + + mov esi,[romdata] + add esi,0FFC0h + cmp dword[esi],'Donk' + jne .noromheaddk + cmp word[ramsize],2048 + jne .noromheaddk + mov word[ramsize],4096 + mov word[ramsizeand],4095 +.noromheaddk + + ; Front Mission - -p 140 + mov esi,[romdata] + add esi,0FFC0h + cmp dword[esi],'FRON' + jne .noromheadfm + cmp dword[esi+4],'T MI' + jne .noromheadfm + mov byte[opexec268],226 + mov byte[opexec358],226 + mov byte[opexec268cph],44 + mov byte[opexec358cph],44 +.noromheadfm + + ret + +.ewj2head db 58,62,45,43,55,40,48,45,50,95,53,54,50,95,77,95,95,95,95,95 +.bubshead db 61,10,29,12,06,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95 +.btvdhead db 61,62,43,43,51,58,43,48,62,59,44,95,59,81,59,81,95,95,95,95 +.luf2head db 51,10,25,22,30,95,54,54,87,58,12,11,15,16,19,22,12,95,54,54 +.pouthead db 44,10,15,26,13,95,47,10,17,28,23,82,48,10,11,94,94,95,95,95 +.drcxhead db 41,62,50,47,54,45,58,44,95,52,54,44,44,95,95,95,95,95,95,95 +.drx2head db 60,62,44,43,51,58,41,62,49,54,62,95,59,45,62,60,42,51,62,95 +.ctrghead db 60,55,45,48,49,48,95,43,45,54,56,56,58,45,95,95,95,95,95,95 +.lambhead db 51,62,50,61,48,45,56,55,54,49,54,95,62,50,58,45,54,60,62,49 +.adm3head db 62,59,59,62,50,44,95,57,62,50,54,51,38,95,41,62,51,42,58,44 +.fmishead db 57,13,16,17,11,95,50,22,12,12,22,16,17,95,87,58,86,95,95,95 + + + +NEWSYM idledetectspc + inc dword[numspcvblleft] + cmp byte[SPCStallSetting],2 + jae .fullstall + inc byte[SPCStallSetting] + mov byte[ReturnFromSPCStall],1 + ret +.fullstall + mov dword[spc700idle],29 + mov dword[Msgptr],.unableskip + mov eax,[MsgCount] + mov [MessageOn],eax + ret +.unableskip db 'SPC700 STALL DETECTED.',0 + +SECTION .data +NEWSYM ReturnFromSPCStall, db 0 +NEWSYM SPCStallSetting, db 0 +NEWSYM SPCSkipXtraROM, db 0 +NEWSYM WindowDisables, dd 0 +SECTION .text + + +%macro helpclearmem 2 + mov edi,%1 + mov ecx,%2 + rep stosb +%endmacro + +NEWSYM init65816 + mov byte[osm2dis],0 + mov byte[bgfixer2],0 + cmp byte[SA1Enable],0 + je .nosa1init + call SA1Reset + call SetAddressingModesSA1 +.nosa1init + cmp byte[C4Enable],0 + je .noc4init + mov byte[osm2dis],1 + mov byte[bgfixer2],1 + call InitC4 +.noc4init + cmp byte[RTCEnable],0 + je .noRTCinit + call RTCinit +.noRTCinit + cmp byte[SPC7110Enable],0 + je .nospc7110init + call SPC7110init + mov dword[memtabler8+50h*4],memaccessspc7110r8 + mov dword[memtabler16+50h*4],memaccessspc7110r16 + mov dword[memtablew8+50h*4],memaccessspc7110w8 + mov dword[memtablew16+50h*4],memaccessspc7110w16 + mov eax,[romdata] + add eax,510000h + mov dword[snesmmap+50h*4],eax + mov dword[snesmap2+50h*4],eax + mov ecx,16384 +.spc7110clear + mov dword[eax],0 + add eax,4 + loop .spc7110clear +.nospc7110init + mov byte[cycpb268],125 + mov byte[cycpb358],147 + mov byte[cycpbl2],125 + mov byte[cycpblt2],125 + mov byte[cycpbl],125 + mov byte[cycpblt],125 + + cmp byte[SPC7110Enable],0 + jne .specialtimer + cmp byte[SDD1Enable],0 + jne .specialtimer + jmp .nospecialtimer +.specialtimer + mov byte[cycpb268],69 + mov byte[cycpb358],81 + mov byte[cycpbl2],69 + mov byte[cycpblt2],69 + mov byte[cycpbl],69 + mov byte[cycpblt],69 +.nospecialtimer + mov byte[SPCSkipXtraROM],0 + cmp byte[ReturnFromSPCStall],1 + jne near .nostall + mov byte[cycpb268],69 + mov byte[cycpb358],81 + mov byte[cycpbl2],69 + mov byte[cycpblt2],69 + mov byte[cycpbl],69 + mov byte[cycpblt],69 + mov byte[SPCSkipXtraROM],1 + cmp byte[SPCStallSetting],2 + jne .nostall2 + mov byte[cycpb268],240 + mov byte[cycpb358],240 + mov byte[cycpbl],240 + mov byte[cycpblt],240 + mov byte[cycpbl2],240 + mov byte[cycpblt2],240 + mov byte[SPCSkipXtraROM],0 +.nostall2 + jmp .stalled +.nostall + mov byte[SPCStallSetting],0 +.stalled + mov dword[numspcvblleft],60*8 + mov dword[SPC700write],0 + mov dword[SPC700read],0 + cmp dword[spc700read],0 + mov dword[spc700idle],0 + xor esi,esi +.loopa + mov al,[SPCROM+esi] + mov byte[spcextraram+esi],0FFh + mov [spcRam+0FFC0h+esi],al + inc esi + cmp esi,040h + jne .loopa + + ; Clear Sound buffer + mov edi,[spcBuffera] + mov ecx,65536 + xor eax,eax + rep stosd + + ; Clear Echo buffer + mov edi,echobuf + mov ecx,25000 + xor eax,eax + rep stosd + + ; Clear DSPMem + mov edi,DSPMem + mov ecx,64 + xor eax,eax + rep stosd + + mov byte[prevoamptr],0FFh + mov byte[execatzerovirq],0 + mov byte[disablehdma],0 + mov byte[disableeffects],0 + mov byte[dracxhack],0 + mov al,[opexec268b] + mov [opexec268],al + mov al,[opexec358b] + mov [opexec358],al + mov al,[opexec268cphb] + mov [opexec268cph],al + mov al,[opexec358cphb] + mov [opexec358cph],al + + mov dword[FIRTAPVal0],7Fh + mov dword[FIRTAPVal1],0 + mov dword[FIRTAPVal2],0 + mov dword[FIRTAPVal3],0 + mov dword[FIRTAPVal4],0 + mov dword[FIRTAPVal5],0 + mov dword[FIRTAPVal6],0 + mov dword[FIRTAPVal7],0 + mov byte[disable65816sh],0 + +; call Outputfilename + + ; Check Headers + mov esi,[romdata] + mov byte[hdmaearlstart],0 + add esi,07FC0h + cmp byte[esi],'Y' + jne .nohdmaearlstart + mov byte[hdmaearlstart],2 +.nohdmaearlstart + + call headerhack + + mov byte [spcRam+0F4h],0 + mov byte [spcRam+0F5h],0 + mov byte [spcRam+0F6h],0 + mov byte [spcRam+0F7h],0 + mov byte [reg1read],0 + mov byte [reg2read],0 + mov byte [reg3read],0 + mov byte [reg4read],0 + mov dword[cycpbl],0 + mov byte[spcnumread],0 + mov dword[coladdr],0 + mov byte[NMIEnab],1 + mov word[VIRQLoc],0 + mov byte[doirqnext],0 + mov dword[reg1read],0 + mov word[resolutn],224 + mov byte[vidbright],0 + mov byte[forceblnk],0 + mov byte [spcP],0 + mov byte[timeron],0 + mov byte[JoyAPos],0 + mov byte[JoyBPos],0 + mov byte[coladdr],0 + mov byte[coladdg],0 + mov byte[coladdb],0 + + mov byte[INTEnab],0 + mov word[xa],0 + mov byte[xdb],0 + mov byte[xpb],0 + mov byte[xirqb],0 + mov word[xs],01FFh + mov word[xd],0 + mov word[xx],0 + mov word[xy],0 + mov dword[SDD1BankA],03020100h + mov byte[xp],00110100b ; NVMXDIZC + + mov byte[xe],1 ; E + mov ax,[resetv] + mov word[xpc],ax + mov byte[intrset],0 + cmp byte[romtype],1 + je .nohirom + mov byte[xpb],00h + mov byte[xirqb],00h +.nohirom + cmp word[xpc],8000h + jae .n + add word[xpc],8000h +; mov byte[xpb],40h +.n + mov al,[opexec268] + mov byte[cycpl],al ; 2.68 Mhz / 3.58 Mhz = 228 + mov byte[curcyc],al + mov al,[opexec268cph] + mov byte[cycphb],al ; 2.68 Mhz / 3.58 Mhz = 56 + mov byte[cycpbl],110 ; 3.58Mhz = 175 + mov byte[cycpblt],110 + mov word[curypos],0 + mov eax,tableD + mov [Curtableaddr],eax + mov byte[scrndis],00h + mov word[stackand],01FFh + mov word[stackor],0100h + + mov dword[nmiprevaddrl],0 + mov dword[nmiprevaddrh],0 + mov byte[nmirept],0 + mov byte[nmiprevline],224 + mov byte[nmistatus],0 + + mov eax,080808080h + + ; Mario Paint, Clear WRAM w/ 0x00 (due to corrupt rom w/ trainer removed) + mov esi,[romdata] + add esi,07FC0h + cmp dword[esi],'MARI' + jne .notmpaint + xor eax,eax +.notmpaint + + mov esi,[romdata] + add esi,07FC0h + cmp word[esi],'BS' ; 7FFFFFA + jne .notbsx +.yesbsx + mov eax,0FFFFFFFFh + pushad + xor edx,edx + mov eax,128 + mov ebx,[NumofBanks] + div ebx + mov ecx,eax + dec ecx + jz .skipbsxmove + mov ebx,[NumofBanks] + shl ebx,15 + mov edx,ebx + add ebx,[romdata] +.loopbsx + mov esi,[romdata] + mov edi,edx +.loopbsx2 + mov al,[esi] + xor al,al + mov [ebx],al + inc esi + inc ebx + dec edi + jnz .loopbsx2 + loop .loopbsx +.skipbsxmove + popad +.notbsx + + helpclearmem wramdataa, 65536 + helpclearmem ram7fa, 65536 + cmp word[esi],'BS' + jne .notbsx2 + mov dword[ram7fa+65528],01010101h + mov dword[ram7fa+65532],01010101h +.notbsx2 + xor eax,eax + helpclearmem [vram], 65536 + helpclearmem vidmemch2, 4096 + helpclearmem vidmemch4, 4096 + helpclearmem vidmemch8, 4096 + ret + +.boffound db '.....',0 + +;******************************************************* +; Init SNES Sets the pointers, etc. +;******************************************************* +; Set banks according to : +; Banks 00-3F,80-BF : WRAM (0000h-7FFFh), ROM Data (8000h-FFFFh) +; Banks 40-7F,C0-FF : ROM Data (0000h-FFFFh) +; Bank 70-77 : SRAM (0000h-7FFFh) +; Bank 7E : WRAM (0000h-FFFFh) +; Bank 7F : ExtendRAM (0000h-FFFFh) + +SECTION .data +NEWSYM curromsize, db 0 +NEWSYM cromptradd, dd 0 +SECTION .text + +NEWSYM initsnes + mov byte[ForceNewGfxOff],0 + + mov esi,[romdata] + add esi,7FC0h + cmp word[esi],'BS' ; 7FFFFFA + je near .bslorom + + mov esi,[romdata] + add esi,32704+22 + cmp byte[romtype],2 + jne .nohirom2b + add esi,8000h +.nohirom2b + mov byte[MultiTap],1 + cmp byte[pl12s34],1 + je .nomtap + cmp byte[pl3contrl],0 + jne .mtap + cmp byte[pl4contrl],0 + jne .mtap + cmp byte[pl5contrl],0 + jne .mtap +.nomtap + mov byte[MultiTap],0 +.mtap + + mov al,[esi] + and al,0F0h + cmp byte[romtype],1 + jne .nosfx + cmp al,10h + je near .sfx +.nosfx + cmp al,30h + je near SA1memmap + cmp al,40h + je near SDD1memmap + + cmp byte[SPC7110Enable],1 + je near .hirom + cmp byte[curromsize],13 + je near .lorom48 + cmp byte[romtype],1 + jne near .hirom + + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] + sub eax,8000h + mov ecx,40h +.loopa + stosd + add eax,8000h + loop .loopa + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov ecx,40h +.loopb + stosd + add eax,8000h + loop .loopb + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] + sub eax,8000h + mov cx,40h +.loopc + stosd + add eax,8000h + loop .loopc + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov ecx,40h +.loopd + stosd + add eax,8000h + loop .loopd + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa2 + stosd + loop .loopa2 + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,200000h + mov ecx,40h +.loopb2 + stosd + add eax,8000h + loop .loopb2 + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov ecx,40h +.loopc2 + stosd + loop .loopc2 + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,200000h + mov ecx,40h +.loopd2 + stosd + add eax,8000h + loop .loopd2 + ; set bank 70 + mov eax,[sram] + xor ebx,ebx + mov bl,70h +.nextsram + mov [snesmap2+ebx*4],eax + inc bl + cmp bl,77h + jbe .nextsram + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + ret + +.bslorom + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] + sub eax,8000h + mov ecx,40h +.loopas + stosd + add eax,8000h + loop .loopas + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov ecx,40h +.loopbs + stosd + add eax,8000h + loop .loopbs + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] + sub eax,8000h + mov cx,40h +.loopcs + stosd + add eax,8000h + loop .loopcs + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,8000h + mov ecx,40h +.loopds + stosd + add eax,8000h + loop .loopds + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa2s + stosd + loop .loopa2s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,200000h + mov ecx,40h +.loopb2s + stosd + add eax,8000h + loop .loopb2s + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov ecx,40h +.loopc2s + stosd + loop .loopc2s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,8000h + mov ecx,40h +.loopd2s + stosd + add eax,8000h + loop .loopd2s + ; set bank 70 + mov eax,[sram] + xor ebx,ebx + mov bl,70h +.nextsrams + mov [snesmap2+ebx*4],eax + inc bl + cmp bl,77h + jbe .nextsrams + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + ret + +.lorom48 + mov edi,memtabler8+40h*4 + mov ecx,30h + mov eax,memaccessbankr848mb + rep stosd + mov edi,memtabler16+40h*4 + mov ecx,30h + mov eax,memaccessbankr1648mb + rep stosd + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] + sub eax,8000h + mov ecx,40h +.loopa3 + stosd + add eax,8000h + loop .loopa3 + ; set banks 40-6F (30h x 64KB ROM banks @ 8000h) + mov eax,[romdata] + sub eax,8000h + mov ecx,40h +.loopb32 + stosd + add eax,8000h + loop .loopb32 + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] + sub eax,8000h + mov cx,40h +.loopc3 + stosd + add eax,8000h + loop .loopc3 + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,200000h + mov ecx,40h +.loopd3 + stosd + add eax,10000h + loop .loopd3 + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa23 + stosd + loop .loopa23 + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,100000h + mov ecx,40h +.loopb3 + stosd + add eax,8000h + loop .loopb3 + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov ecx,40h +.loopc23 + stosd + loop .loopc23 + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,200000h + mov ecx,40h +.loopd23 + stosd + add eax,10000h + loop .loopd23 + ; set bank 70 + mov eax,[sram] + xor ebx,ebx + mov bl,70h +.nextsram3 + mov [snesmap2+ebx*4],eax + inc bl + cmp bl,77h + jbe .nextsram3 + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + call prepare48mbit + ret + +.hirom + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] + mov ecx,40h +.loopab + stosd + add eax,10000h + loop .loopab + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + mov ecx,40h +.loopbb + stosd + add eax,10000h + loop .loopbb + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] + mov ecx,40h +.loopcb + stosd + add eax,10000h + loop .loopcb + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + mov ecx,40h +.loopdb + stosd + add eax,10000h + loop .loopdb + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa2b + stosd + loop .loopa2b + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + mov cx,40h +.loopb2b + stosd + add eax,10000h + loop .loopb2b + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov cx,40h +.loopc2b + stosd + loop .loopc2b + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + mov cx,40h +.loopd2b + stosd + add eax,10000h + loop .loopd2b + ; set bank 70 + mov eax,[sram] + xor ebx,ebx + mov bl,70h +.nextsramb + mov [snesmap2+ebx*4],eax + inc bl + cmp bl,77h + jbe .nextsramb + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + ret + +.sfx + mov byte[MultiTap],0 + ; Clear sfxregisters + mov edi,SfxR0 + mov ecx,16 + xor eax,eax + rep stosd + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] +; sub eax,8000h + mov ecx,40h +.loopa3s + stosd + add eax,10000h + loop .loopa3s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] +; add eax,200000h + add eax,8000h + mov ecx,40h +.loopb3s + stosd + add eax,20000h + loop .loopb3s + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] +; sub eax,8000h + mov cx,40h +.loopc3s + stosd + add eax,10000h + loop .loopc3s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] +; add eax,200000h + add eax,8000h + mov ecx,40h +.loopd3s + stosd + add eax,20000h + loop .loopd3s + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa23s + stosd + loop .loopa23s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,8000h + mov ecx,40h +.loopb23s + stosd + add eax,20000h + loop .loopb23s + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov ecx,40h +.loopc23s + stosd + loop .loopc23s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,8000h + mov ecx,40h +.loopd23s + stosd + add eax,20000h + loop .loopd23s + ; set bank 70 + mov eax,[sram] + mov [snesmap2+78h*4],eax + mov [snesmap2+79h*4],eax + mov eax,[sfxramdata] + mov [snesmap2+70h*4],eax + add eax,65536 + mov [snesmap2+71h*4],eax + add eax,65536 + mov [snesmap2+72h*4],eax + add eax,65536 + mov [snesmap2+73h*4],eax + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + call preparesfx + ret + +SA1memmap: + mov eax,[romdata] + cmp dword[eax+0B95h],0ADCF10A9h + jne .nosuccess + mov byte[eax+0B96h],0 +.nosuccess + mov byte[MultiTap],0 + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] + sub eax,8000h + mov ecx,40h +.loopa3s + stosd + add eax,8000h + loop .loopa3s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] +; add eax,400000h + mov ecx,40h +.loopb3s + stosd + add eax,10000h + loop .loopb3s + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] + add eax,200000h + sub eax,8000h + mov cx,40h +.loopc3s + stosd + add eax,8000h + loop .loopc3s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,00000h + mov ecx,40h +.loopd3s + stosd + add eax,10000h + loop .loopd3s + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa23s + stosd + loop .loopa23s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,400000h + mov ecx,40h +.loopb23s + stosd + add eax,10000h + loop .loopb23s + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov ecx,40h +.loopc23s + stosd + loop .loopc23s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,00000h + mov ecx,40h +.loopd23s + stosd + add eax,10000h + loop .loopd23s + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + ret + +SDD1memmap: + mov eax,[romdata] + cmp dword[eax+0B95h],0ADCF10A9h + jne .nosuccess + mov byte[eax+0B96h],0 +.nosuccess + mov byte[MultiTap],0 + ; set addresses 8000-FFFF + ; set banks 00-3F (40h x 32KB ROM banks @ 8000h) + mov edi,snesmmap + mov eax,[romdata] + sub eax,8000h + mov ecx,40h +.loopa3s + stosd + add eax,8000h + loop .loopa3s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] +; add eax,400000h + mov ecx,40h +.loopb3s + stosd + add eax,10000h + loop .loopb3s + ; set banks 80-BF (40h x 32KB ROM banks @ 8000h) + mov eax,[romdata] +; add eax,200000h + sub eax,8000h + mov cx,40h +.loopc3s + stosd + add eax,8000h + loop .loopc3s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,00000h + mov ecx,40h +.loopd3s + stosd + add eax,10000h + loop .loopd3s + ; set addresses 0000-7FFF (01h x 32KB WRAM @ 0000h) + ; set banks 00-3F + mov edi,snesmap2 + mov eax,[wramdata] + mov ecx,40h +.loopa23s + stosd + loop .loopa23s + ; set banks 40-6F (30h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,400000h + mov ecx,40h +.loopb23s + stosd + add eax,10000h + loop .loopb23s + ; set banks 80-BF (01h x 32KB WRAM @ 0000h) + mov eax,[wramdata] + mov ecx,40h +.loopc23s + stosd + loop .loopc23s + ; set banks C0-FF (40h x 64KB ROM banks @ 0000h) + mov eax,[romdata] + add eax,00000h + mov ecx,40h +.loopd23s + stosd + add eax,10000h + loop .loopd23s + ; set bank 7E + mov eax,[wramdata] + mov [snesmmap+7Eh*4],eax + mov [snesmap2+7Eh*4],eax + ; set bank 7F + mov eax,[ram7f] + mov [snesmmap+7Fh*4],eax + mov [snesmap2+7Fh*4],eax + ret + +;******************************************************* +; Prepare 48mbit Moves blocks around for 48mbit +;******************************************************* + +SECTION .data +NEWSYM memdest, dd 0 +NEWSYM SFXCounter, dd 0 +SECTION .text + +NEWSYM prepare48mbit + ; make table 2 (64,0,65,1,...) + mov edi,mode7tab+128 + mov ecx,64 + mov al,64 + mov ah,0 +.nextl2 + mov [edi],al + mov [edi+1],ah + inc al + inc ah + add edi,2 + dec ecx + jnz .nextl2 + mov eax,[romdata] + add eax,200000h + mov [memdest],eax + call ProcessSwapTable + cmp byte[romtype],1 + je .nothirom + call UnInterleave48mbit +.nothirom + ret + +UnInterleave48mbit: + pushad + ; make table 2 (0 .. 255) + mov edi,mode7tab+256 + mov ecx,256 + xor al,al +.nextlb2 + mov [edi],al + inc al + inc edi + dec ecx + jnz .nextlb2 + + mov esi,mode7tab+256 + mov ecx,40h + xor al,al +.loop + mov [esi+40h],al + inc al + inc esi + loop .loop + mov esi,mode7tab+256 + mov ecx,40h + mov al,40h+1 +.loop2 + mov [esi+80h],al + add al,2 + inc esi + loop .loop2 + mov esi,mode7tab+256 + mov ecx,20h + mov al,40h +.loop3 + mov [esi+20h],al + add al,2 + mov [esi],al + add al,2 + inc esi + loop .loop3 + call SwapTable256 + popad + ret + +NEWSYM ProcessSwapTable + ; make table 1 (0 .. 127) + mov edi,mode7tab + mov ecx,128 + xor al,al +.nextl + mov [edi],al + inc al + inc edi + dec ecx + jnz .nextl + + xor eax,eax + xor ebx,ebx + ; sort memory + ; start at first entry in table 2 + mov esi,mode7tab+128 + mov ecx,128 +.nextentry + ; find which blocks to swap + ; search entry from table 2 in table 1 + mov al,[esi] + mov edi,mode7tab +.findnext + mov bl,[edi] + cmp bl,al + je .foundit + inc edi + jmp .findnext +.foundit + mov bl,[esi-128] + mov [esi-128],al + mov [edi],bl + mov eax,esi + sub eax,mode7tab+128 + mov ebx,edi + sub ebx,mode7tab + ; swap blocks at memory location $200000+al*8000h with $200000+bl*8000h + shl eax,15 + add eax,[memdest] + shl ebx,15 + add ebx,[memdest] + push esi + mov esi,eax + mov edi,ebx + mov edx,2000h +.loopa + mov eax,[esi] + mov ebx,[edi] + mov [esi],ebx + mov [edi],eax + add esi,4 + add edi,4 + dec edx + jnz .loopa + pop esi + xor eax,eax + xor ebx,ebx + inc esi + dec ecx + jnz near .nextentry + + call Makemode7Table + ret + +NEWSYM preparesfx + mov byte[SFXCounter],0 + mov esi,[romdata] + add esi,07FC0h + cmp dword[esi],'FX S' + je .yessfxcounter + cmp dword[esi],'Stun' + jne .nosfxcounter + mov byte[ForceNewGfxOff],1 +.yessfxcounter + mov byte[SFXCounter],1 +.nosfxcounter + + ; make table + mov byte[SfxAC],0 + mov eax,[romdata] + cmp dword[eax+02B80h],0AB6CAB6Ch + jne .noac + mov byte[SfxAC],1 +.noac + cmp dword[eax+0EFFBBh], 21066396h + je .yesinterleaved + cmp dword[eax+048000h],0E702E1F6h + je .yesinterleaved + jmp .noswapper +.yesinterleaved + mov edi,mode7tab+128 + mov ecx,128 + mov al,0 +.nextl2 + mov ah,al + and ah,11100001b + mov bl,al + and bl,00000110b + shl bl,2 + or ah,bl + mov bl,al + and bl,00011000b + shr bl,2 + or ah,bl + mov [edi],ah + inc al + inc edi + dec ecx + jnz .nextl2 + mov eax,[romdata] + mov [memdest],eax + call ProcessSwapTable +.noswapper + ; duplicate sfx data + mov esi,[romdata] + mov edi,[romdata] + add esi,1F8000h + add edi,3F0000h + mov dl,40h +.swaploopb + mov ecx,32768 +.swaploop + mov al,[esi] + mov [edi],al + mov [edi+32768],al + inc esi + inc edi + loop .swaploop + sub edi,65536+32768 + sub esi,65536 + dec dl + jnz .swaploopb + ret + + ; copy address 0 to 200000h + ; make table 1 (0 .. 127) + mov esi,[romdata] + mov edi,[romdata] + add edi,200000h + mov ecx,200000h +.n + mov al,[esi] + mov [edi],al + inc esi + inc edi + dec ecx + jnz .n + ret + +NEWSYM UnInterleave + pushad + + ; NumofBanks contains # of 32k banks + + ; make table 2 (0 .. 255) + mov edi,mode7tab+256 + mov ecx,256 + xor al,al +.nextlb2 + mov [edi],al + inc al + inc edi + dec ecx + jnz .nextlb2 + + mov eax,[NumofBanks] + shr eax,1 + mov edi,mode7tab+256 + mov ecx,eax + mov bl,al + xor bh,bh +.nextl + mov [edi],bl + mov [edi+1],bh + inc bl + inc bh + add edi,2 + dec ecx + jnz .nextl + + call SwapTable256 + popad + ret + +SwapTable256: + ; make table 1 (0 .. 255) + mov edi,mode7tab + mov ecx,256 + xor al,al +.nextlb + mov [edi],al + inc al + inc edi + dec ecx + jnz .nextlb + + xor eax,eax + xor ebx,ebx + ; sort memory + ; start at first entry in table 2 + mov esi,mode7tab+256 + mov ecx,[NumofBanks] + shr ecx,1 + add ecx,ecx +.nextentry + ; find which blocks to swap + ; search entry from table 2 in table 1 + mov al,[esi] + mov edi,mode7tab +.findnext + mov bl,[edi] + cmp bl,al + je .foundit + inc edi + jmp .findnext +.foundit + mov bl,[esi-256] + mov [esi-256],al + mov [edi],bl + + mov eax,edi + add eax,256 + cmp eax,esi + je near .skipthis + + mov eax,esi + sub eax,mode7tab+256 + mov ebx,edi + sub ebx,mode7tab + ; swap blocks at memory location $200000+al*8000h with $200000+bl*8000h + shl eax,15 + add eax,[romdata] + shl ebx,15 + add ebx,[romdata] + push esi + mov esi,eax + mov edi,ebx + mov edx,2000h +.loopa + mov eax,[esi] + mov ebx,[edi] + mov [esi],ebx + mov [edi],eax + add esi,4 + add edi,4 + dec edx + jnz .loopa + pop esi +.skipthis + xor eax,eax + xor ebx,ebx + inc esi + dec ecx + jnz near .nextentry +.endthis + call Makemode7Table + ret + +;******************************************************* +; Copy execloop +;******************************************************* + +NEWSYM copyexecloop + ret + +;******************************************************* +; Process execloop +;******************************************************* +NEWSYM procexecloop + cmp byte[spcon],0 + jne .noprocloop + mov byte[curexecstate],1 + ret +.noprocloop + mov byte[curexecstate],3 + ret + +;******************************************************* +; Change execloop +;******************************************************* +NEWSYM changeexecloop + ret + +;******************************************************* +; Clear Memory +;******************************************************* +;vidbuffera resb 131072 +;romdataa resb 4194304+32768+2097152 +;wramdataa resb 65536 +;ram7fa resb 65536 +;vrama resb 65536 +;srama resb 32768 +;debugbufa resb 80000 +;regptra resb 49152 +;regptwa resb 49152 +;vcache2ba resb 262144 +;vcache4ba resb 131072 +;vcache8ba resb 65536 + +%macro helpclearmem2 2 + mov edi,%1 + mov ecx,%2 + rep stosd +%endmacro + + +NEWSYM clearmem + xor eax,eax + helpclearmem [vidbuffer], 131072 + helpclearmem wramdataa, 65536 + helpclearmem ram7fa, 65536 + helpclearmem [vram], 65536 + helpclearmem srama, 65536 + helpclearmem debugbufa, 80000 + helpclearmem regptra, 49152 + helpclearmem regptwa, 49152 + helpclearmem [vcache2b], 262144 + helpclearmem [vcache4b], 131072 + helpclearmem [vcache8b], 65536 + helpclearmem vidmemch2, 4096 + helpclearmem vidmemch4, 4096 + helpclearmem vidmemch8, 4096 + helpclearmem pal16b, 1024 + helpclearmem pal16bcl, 1024 + helpclearmem pal16bclha, 1024 + mov eax,0FFFFh + helpclearmem2 pal16bxcl, 256 + xor al,al + mov al,0FFh + mov edi,[romdata] + mov ecx,4194304+32768 + cmp byte[Sup48mbit],0 + je .no48mb + add ecx,2097152 +.no48mb + cmp byte[Sup16mbit],0 + je .no16mb + sub ecx,2097152 +.no16mb + rep stosb +; ret +NEWSYM clearmem2 + mov edi,[sram] + mov eax,0FFFFFFFFh + mov ecx,8192*2 + rep stosd + mov al,0FFh + mov edi,spcRam + mov ecx,65472 + rep stosb + ret + +;******************************************************* +; Print Hexadecimal (16-bit/8-bit) +;******************************************************* +NEWSYM printhex + mov ecx,4 + xor ebx,ebx +.loopa + mov bx,ax + and bx,0F000h + shr bx,12 + mov dl,[.hexdat+ebx] + push ax + mov ah,02h + call Output_Text + pop ax + shl ax,4 + loop .loopa + ret + +.hexdat db '0123456789ABCDEF' + +NEWSYM printhex8 + mov ecx,2 + xor ebx,ebx +.loopb + mov bx,ax + and bx,0F0h + shr bx,4 + mov dl,[.hexdat+ebx] + push ax + mov ah,02h + call Output_Text + pop ax + shl ax,4 + loop .loopb + ret + +.hexdat db '0123456789ABCDEF' +;******************************************************* +; Load File +;******************************************************* +; Search for header size first which is filesize MOD 32768 + +NEWSYM RetrieveDataIPS + xor ah,ah + cmp ecx,10000 + jne .notoverflow + push edx + push ecx + mov edx,wramdataa + mov ecx,10000 + call Read_File + cmp eax,0 + jne .notempty + mov ah,1 + jmp .empty +.notempty + xor ah,ah +.empty + pop ecx + pop edx + xor ecx,ecx +.notoverflow + mov al,[wramdataa+ecx] + inc ecx + ret + +IPSSL dd 0 + +NEWSYM PatchIPS + mov byte[IPSPatched],0 + mov dword[IPSOffset],0 + cmp byte[Header512],0 + je .no512head + mov dword[IPSOffset],512 +.no512head + mov dword[IPSLimit],4096*1024 + cmp byte[Sup48mbit],0 + je .not48 + mov dword[IPSLimit],6144*1024 +.not48 + cmp byte[Sup16mbit],0 + je .not16 + mov dword[IPSLimit],2048*1024 +.not16 + ; 1965-1970, >1969*1024+712 (812/850/1000) + ; upper bound: 1969*1024+1024 + ; between 1965-<1970 / 1968,1970 +; mov dword[IPSLimit],208062h +; mov dword[IPSSL],208832h + ; font = 208062h-208832h + + mov eax,fname+1 + ; search for . or 0 +.next + cmp byte[eax],0 + je .foundend + inc eax + jmp .next +.foundend + mov ebx,eax +.findnext2 + dec eax + cmp eax,fname + je .failfound + cmp byte[eax],'\' + je .failfound + cmp byte[eax],'.' + je .foundokay + jmp .findnext2 +.failfound + mov eax,ebx +.foundokay + mov ebx,[eax] + mov [Prevextn],ebx + mov dword[eax],'.IPS' + mov byte[eax+4],0 + push eax + mov edx,fname+1 + call Open_File + jc near .failed + mov bx,ax + mov edx,Headchek + mov ecx,5 + call Read_File + cmp dword[Headchek],'PATC' + jne near .ipsfaileddet + cmp byte[Headchek+4],'H' + jne near .ipsfaileddet + mov ecx,10000 +.ipxloop +.findnext + xor edx,edx + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + mov dh,al + shl edx,8 + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + mov dh,al + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + mov dl,al + cmp edx,454F46h + je near .ipsokay + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + sub edx,[IPSOffset] + mov [IPSCount+1],al + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + mov [IPSCount],al + cmp word[IPSCount],0 + je .ipsclear +.loop + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed +; cmp edx,[IPSSL] +; jae .nolimit + cmp edx,[IPSLimit] + jae .limit +.nolimit + mov esi,[romdata] + mov [esi+edx],al +.limit + inc edx + dec word[IPSCount] + jnz .loop + jmp .findnext +.ipsclear + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + mov [IPSCount+1],al + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + mov [IPSCount],al + call RetrieveDataIPS + cmp ah,0 + jne near .ipsfailed + cmp word[IPSCount],0 + je near .findnext + mov esi,[romdata] +.loop2 + cmp edx,[IPSLimit] + jae .limit2 + mov [esi+edx],al +.limit2 + inc edx + dec word[IPSCount] + jnz .loop2 + jmp .findnext +.ipsokay + mov dword[Msgptr],.ipsokaymsg + mov dword[MessageOn],60*4 + mov byte[IPSPatched],1 + jmp .ipsfaileddet +.ipsfailed + mov dword[Msgptr],.ipsnokaymsg + mov dword[MessageOn],60*4 + mov byte[IPSPatched],1 +.ipsfaileddet + call Close_File +.failed + pop eax + mov ebx,[Prevextn] + mov [eax],ebx + ; font = 208062h-208832h +; mov esi,[romdata] +; mov [esi+208062h],0 + ;0-768, 3072-3072+256, 4096-4096+256 +; mov edx,2079*1024 ;+2048+2048*40 +; mov ecx,2048 +; mov esi,[romdata] +;.ltop +; mov byte[esi+edx],0 +; inc edx +; loop .ltop + ret +.ipsokaymsg db 'IPS PATCHED.',0 +.ipsnokaymsg db 'IPS IS CORRUPT.',0 + +section .data +NEWSYM Header512, db 0 +NEWSYM Prevextn, dd 0 +NEWSYM Headchek, db 0,0,0,0,0 +NEWSYM IPSLimit, dd 0 +NEWSYM IPSOffset, dd 0 +NEWSYM IPSCount, dd 0 +IPSPatched db 0 +section .text + +OpenCombFile: + mov edx,fnames+1 +.next + cmp byte[edx],0 + je .found + inc edx + jmp .next +.found + dec edx + cmp byte[edx],'.' + je .found2 + jmp .found +.found2 + mov dword[edx],'.CMB' + push edx + mov dword[NumComboLocl],0 + mov edx,fnames+1 + call Open_File + jc .failb + mov bx,ax + mov edx,ComboBlHeader + mov ecx,23 + call Read_File + mov al,byte[ComboBlHeader+22] + or al,al + jz .done + mov [NumComboLocl],al + mov ecx,[NumComboLocl] + mov edx,ecx + shl ecx,6 + add ecx,edx + add ecx,edx + mov edx,CombinDataLocl + call Read_File +.done + call Close_File +.failb + pop edx + mov dword[edx],'.SRM' + ret + +NEWSYM SaveCombFile + cmp byte[romloadskip],0 + jne near .notfound + mov edx,fnames+1 +.next + cmp byte[edx],0 + je .found + inc edx + jmp .next +.found + dec edx + cmp byte[edx],'.' + je .found2 + jmp .found +.found2 + mov dword[edx],'.CMB' + push edx + mov al,[NumComboLocl] + or al,al + jz .failb + mov [ComboHeader+22],al + mov edx,fnames+1 + call Create_File + jc .failb + mov bx,ax + mov edx,ComboHeader + mov ecx,23 + call Write_File + mov ecx,[NumComboLocl] + mov edx,ecx + shl ecx,6 + add ecx,edx + add ecx,edx + mov edx,CombinDataLocl + call Write_File + call Close_File +.failb + pop edx + mov dword[edx],'.SRM' +.notfound + ret + +NEWSYM loadfile + call GetCurDir + mov byte[InGUI],0 + jmp loadfileGUI.nogui + + + mov dword[MessageOn],0 + mov byte[loadedfromgui],0 + mov byte[yesoutofmemory],0 + mov byte[Header512],0 + mov byte[.fail],0 + ; determine header size + mov dword[.curfileofs],0 + mov byte[.first],1 + mov byte[.multfound],0 + ; open file + mov edx,fname+1 + call Open_File + jc near .failed +.nextfile + cmp byte[.first],1 + je .nomul + cmp byte[.multfound],0 + jne .nomul + push eax + push edx + mov byte[.multfound],1 + mov edx,.mult + mov ah,9 + call Output_Text + pop edx + pop eax +.nomul + mov bx,ax + mov ecx,4194304+32768 + cmp byte[Sup48mbit],0 + je .no48mb + add ecx,2097152 +.no48mb + cmp byte[Sup16mbit],0 + je .no16mb + sub ecx,2097152 +.no16mb + sub ecx,[.curfileofs] + jnc .nooverflow + xor ecx,ecx +.nooverflow + mov edx,[headdata] + add edx,[.curfileofs] + call Read_File + jc near .failed + or eax,eax + jz near .success + mov ecx,eax + shr eax,15 + shl eax,15 + mov esi,[headdata] + add esi,[.curfileofs] + mov edi,[headdata] + add edi,[.curfileofs] + sub ecx,eax + or ecx,ecx + jz .nonoheader + add eax,ecx + sub eax,512 + mov ecx,512 + mov byte[Header512],1 +; mov ecx,512 +; and eax,0FFFF8000h +; add eax,8000h +.nonoheader + add [.curfileofs],eax + add edi,ecx + +.next + mov cl,[edi] + mov [esi],cl + inc esi + inc edi + dec eax + jnz .next + mov ecx,1 + mov edx,.temp + call Read_File + cmp eax,0 + je .success + mov byte[.fail],1 +.success + call Close_File + jc near .failed + ; check for 2nd+ part of file + mov edi,fname+1 + mov byte[.cchar],'\' + ; get position of . or \ +.nextsearch + cmp byte[edi],0 + je .nomore + cmp byte[edi],'.' + jne .notdot + mov byte[.cchar],'.' + mov [.dotpos],edi +.notdot + cmp byte[edi],'\' + jne .notslash + mov byte[.cchar],'\' +.notslash + inc edi + jmp .nextsearch +.nomore + cmp byte[.cchar],'\' + jne .noslashb + mov [.dotpos],edi +.noslashb + mov edi,[.dotpos] + ; search for .1, .2, etc. + cmp byte[edi],'.' + jne .nonumer + cmp byte[edi+1],'1' + jb .nonumer + cmp byte[edi+1],'8' + ja .nonumer + cmp byte[edi+2],0 + jne .nonumer + inc byte[edi+1] + xor ecx,ecx + mov byte[.first],2 + mov edx,fname+1 + call Open_File + jnc near .nextfile + dec byte[edi+1] +.nonumer + ; search for A,B,C, etc. + cmp byte[.first],0 + je .yesgd + cmp byte[edi-1],'A' + je .yesgd + cmp byte[edi-1],'a' + je .yesgd + jmp .nogdformat +.yesgd + mov byte[.first],0 + inc byte[edi-1] + mov edx,fname+1 + call Open_File + jnc near .nextfile + dec byte[edi-1] +.nogdformat + call convertsram + mov byte[SramExists],0 + + ; change to sram dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + ; open .srm file + mov edx,fnames+1 + call Open_File + jc .notexist + mov byte[SramExists],1 + mov bx,ax + mov ecx,65536 + mov edx,[sram] + call Read_File + jc .failed + call Close_File + jc .failed +.notexist + call OpenCombFile + mov edx,.opened + mov ah,9 + call Output_Text + ; Verify checksum + mov ecx,[.curfileofs] + mov esi,[headdata] + xor eax,eax + xor ebx,ebx +.nextcs + mov al,[esi] + inc esi + add ebx,eax + dec ecx + jnz .nextcs + mov [Checksumvalue],bx + mov eax,[.curfileofs] + mov [NumofBytes],eax + shr eax,15 + mov [NumofBanks],eax + cmp byte[.fail],0 + je .notfailed + mov byte[yesoutofmemory],1 +.notfailed + call PatchIPS + ret + +.failed + mov edx,.failop + mov ah,9 + call Output_Text + jmp DosExit + +SECTION .data +.multfound db 0 +.first db 0 +.cchar db 0 +.dotpos dd 0 +.curfileofs dd 0 +.filehand dw 0 +.failop db 'Error opening file!',13,10,0 +.opened db 'File opened successfully!',13,10,0 +.mult db 'Multiple file format detected.',13,10,13,10,0 +.temp db 0 +.fail db 0 + + +NEWSYM Checksumvalue, dw 0 +NEWSYM SramExists, db 0 +NEWSYM NumofBanks, dd 0 +NEWSYM NumofBytes, dd 0 +NEWSYM ZipSupport, db 0 +InGUI db 0 +tempdirname db 'zziptmp_.__z',0 +PrevDir db '..',0 +SECTION .text + + +GUIfindBlank db '*.',0 + +%macro UnZipSearch 1 + mov cx,20h + mov edx,%1 + call Get_First_Entry + jc %%notfound + test byte[DTALoc+15h],10h + jnz %%notfound + jmp .found +%%notfound +%endmacro + +InvalidZip db 'ZSNES Version A does not support .ZIP files.',13,10,'Please use Version C for this feature.',10,13,0 + +UnZipFile: + cmp byte[OSPort],1 + jne .noasm + mov ax,03h + int 10h + mov edx,InvalidZip + call PrintStr + jmp DosExit +.noasm + ; get Drive/Dir + mov ebx,GUIcurrentdir+3 + mov edx,GUIcurrentdir + call Get_Dir + add byte[GUIcurrentdir],65 + cmp byte[InGUI],0 + je near .nochange + ; locate end of string & append filename + mov eax,GUIcurrentdir+3 +.loop + cmp byte[eax],0 + je .endfound + inc eax + jmp .loop +.endfound + cmp byte[eax-2],':' + je .noaddslash + mov byte[eax],'\' + inc eax +.noaddslash + mov ebx,fname+1 +.loopb + mov cl,[ebx] + mov [eax],cl + or cl,cl + jz .zero + inc eax + inc ebx + jmp .loopb +.zero + ; Change to Save Directory + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir +.nochange + ; Change to Temp Directory + mov edx,tempdirname + call Change_Single_Dir + jnc near .notfail + ; Create Temp Directory + mov edx,tempdirname + call Create_Dir +; jc near .fail + ; Change to Temp Directory + mov edx,tempdirname + call Change_Single_Dir + jc near .fail +.notfail + +; mov ax,03h +; int 10h +; mov edx,GUIcurrentdir +; call PrintStr +; jmp DosExit + + ; Erase contents of the zip directory if there are any stuff + mov esi,mode7tab + call ZipDeleteRecurse + + ; UnZip File + mov eax,GUIcurrentdir + cmp byte[InGUI],1 + je .nogui + mov eax,fname+1 +.nogui + push eax + call extractzip + pop eax + cmp byte[ZipError],0 + jne near .failed + + + ; Find valid rom file + UnZipSearch GUIsmcfind + UnZipSearch GUIsfcfind + UnZipSearch GUIswcfind + UnZipSearch GUIfigfind + UnZipSearch GUIfind058 + UnZipSearch GUIfind078 + UnZipSearch GUIfindUSA + UnZipSearch GUIfindJAP + UnZipSearch GUIfindBIN + UnZipSearch GUIfindZIP + UnZipSearch GUIfind1 + UnZipSearch GUIfindBlank +.failed + call ZipDelete + jmp .fail +.found + mov byte[ZipSupport],1 + mov edx,DTALoc+1Eh + mov eax,fname+1 +.continue + mov bl,[edx] + mov [eax],bl + inc eax + inc edx + or bl,bl + jnz .continue + ret + mov ax,3 + int 10h + mov edx,DTALoc+1Eh +; mov edx,GUIcurrentdir + call PrintStr + jmp DosExit +.fail + mov byte[ZipSupport],2 + ret + +ZipDelete: + mov esi,mode7tab + call ZipDeleteRecurse + mov edx,PrevDir + call Change_Single_Dir + mov edx,tempdirname + call Remove_Dir + call Makemode7Table + ret + +tempzip db 0 + +ZipDeleteRecurse: + ; Find all directories + mov edx,GUIfindall + mov cx,10h + call Get_First_Entry + jc near .notfounddir +.moreentries2 + test byte[DTALoc+15h],10h + jz .nodir + cmp byte[DTALoc+1Eh],'.' + jne .founddir +.nodir + call Get_Next_Entry + jnc .moreentries2 + jmp .notfounddir +.founddir + + cmp byte[tempzip],3 + jne .notone + mov ax,03h + int 10h + jmp DosExit +.notone + + push edx + mov ecx,43 + mov edi,DTALoc +.loop + mov al,[edi] + mov [esi],al + inc edi + inc esi + loop .loop + mov edx,DTALoc+1Eh + call Change_Single_Dir + + inc byte[tempzip] + + call ZipDeleteRecurse + sub esi,43 + mov edx,PrevDir + call Change_Single_Dir + mov edx,esi + add edx,1Eh + call Remove_Dir + jc .faildirdel + pop edx + jmp ZipDeleteRecurse +.faildirdel + pop edx +.notfounddir + + ; ah = 41h, edx = ptr to file + mov cx,20h + mov edx,GUIfindall + call Get_First_Entry + jc .notfound +.moreentries + push edx + mov edx,DTALoc+1Eh + call Delete_File + pop edx + call Get_Next_Entry + jnc .moreentries +.notfound + ret + +SPC7110Allocated db 0 +SPC7110DIRA db 'FEOEZSP7',0 +SPC7110DIRB db 'SMHT-SP7',0 +SDD1DIRA db 'SOCNSDD1',0 +SDD1DIRB db 'SFA2SDD1',0 +SPC7110IndexName db 'INDEX.BIN',0 +SPC7110DirEntry db '*.BIN',0 +SPC7110CPtr dd 0 +SPC7110CPtr2 dd 0 +NEWSYM SPC7110nfname, db ' \ .bin',0 +NEWSYM SPC7110IndexSize, dd 0 +NEWSYM SPC7110Entries, dd 0 +spc7110notfound db 'DECOMPRESSED PACK NOT FOUND',0 +spc7110notfoundb db 'INDEX DATA NOT FOUND',0 + +NEWSYM SPC7110Load + mov dword[SPC7110Entries],0 + mov esi,[romdata] + add esi,32704+22 + add esi,8000h + mov al,[esi] + cmp byte[romtype],2 + jne .nothirom + cmp al,0F9h + je .spc7110 + cmp al,0F5h + je .spc7110 +.nothirom + cmp byte[romtype],1 + jne .notlorom + mov esi,[romdata] + add esi,32704+22 + mov al,[esi] + ; Star Ocean = 45h, SFA2 = 43h + cmp al,43h + je .sdd1 + cmp al,45h + je .sdd1 +.notlorom +.sdd1 + ret +.spc7110 + mov edx,SPC7110DIRA + cmp al,0F9h + je .noSPC7110b + mov edx,SPC7110DIRB +.noSPC7110b + cmp al,043h + jne .noSDD1 + mov edx,SDD1DIRB + jmp .sdd1b +.noSDD1 + cmp al,045h + jne .noSDD1b + mov edx,SDD1DIRA + jmp .sdd1b +.noSDD1b + mov eax,[edx] + mov [SPC7110nfname],eax + mov eax,[edx+4] + mov [SPC7110nfname+4],eax + call Change_Single_Dir + jc near .nodir + mov edx,SPC7110IndexName + call Open_File + jc near .noindex + mov bx,ax + mov edx,[romdata] + add edx,580000h + mov ecx,12*32768 + call Read_File + mov [SPC7110IndexSize],eax + call Close_File + mov dword[SPC7110Entries],0 + mov edx,PrevDir + call Change_Single_Dir + ret +.sdd1b + cmp byte[SPC7110Allocated],0 + jne .notalloc + push edx + call allocspc7110 + mov byte[SPC7110Allocated],1 + pop edx +.notalloc + call Change_Single_Dir + jc near .nodir + mov eax,[spc7110romptr] + mov [SPC7110CPtr],eax + add eax,65536 + mov [SPC7110CPtr2],eax + mov edx,SPC7110DirEntry + mov cx,20h + call Get_First_Entry + jc near .notfound +.moreentries + pushad + mov edx,DTALoc+1Eh + xor ecx,ecx + xor eax,eax +.loop + cmp byte[edx],'.' + je .fin + cmp byte[edx],0 + je .fin + cmp byte[edx],'-' + je .skipthisone + mov al,[edx] + cmp al,'A' + jb .num + cmp al,'a' + jb .uppercl + sub al,'a'-10 + jmp .done +.uppercl + sub al,'A'-10 + jmp .done +.num + sub al,'0' +.done + shl ecx,4 + add ecx,eax +.skipthisone + inc edx + jmp .loop +.fin + ; spc7110romptr format: + ; 64K - address/pointer/length table + mov ebx,[SPC7110CPtr2] + mov eax,[SPC7110CPtr] + mov [eax],ecx + mov [eax+4],ebx + mov edx,DTALoc+1Eh + call Open_File + jc near .failed + mov bx,ax + add dword[SPC7110CPtr],8 + mov edx,[SPC7110CPtr2] + mov ecx,65536 + call Read_File + add dword[SPC7110CPtr2],eax + mov edx,dword[SPC7110CPtr] + mov [edx],eax + add dword[SPC7110CPtr],4 + call Close_File + inc dword[SPC7110Entries] +.failed + popad + call Get_Next_Entry + jnc near .moreentries + mov edx,PrevDir + call Change_Single_Dir + ret +.notfound + mov edx,PrevDir + call Change_Single_Dir +.nodir + mov dword[Msgptr],spc7110notfound + mov dword[MessageOn],60*6 + ret +.noindex + mov edx,PrevDir + call Change_Single_Dir + mov dword[Msgptr],spc7110notfoundb + mov dword[MessageOn],60*6 + ret + +NEWSYM loadfileGUI + mov byte[InGUI],1 +.nogui + mov byte[spcon],0 + cmp byte[SPCDisable],1 + je .nosound + mov byte[spcon],1 +.nosound + ; determine if it's a .zip file or not + mov eax,fname + mov byte[ZipSupport],0 +.ziploop + inc eax + cmp byte[eax],0 + jne .ziploop + sub eax,4 + cmp byte[eax+1],'.' + jne .finishzipd2 + cmp byte[eax+2],'g' + je .zokay4 + cmp byte[eax+2],'G' + jne .finishzipd2 +.zokay4 + cmp byte[eax+3],'z' + je .zokay5 + cmp byte[eax+3],'Z' + jne .finishzipd2 +.zokay5 + jmp .zokay3 +.finishzipd2 + cmp byte[eax],'.' + jne near .finishzipd + inc eax + cmp byte[eax],'z' + je .zokay1 + cmp byte[eax],'Z' + jne .finishzipd +.zokay1 + inc eax + cmp byte[eax],'i' + je .zokay2 + cmp byte[eax],'I' + jne .finishzipd +.zokay2 + inc eax + cmp byte[eax],'p' + je .zokay3 + cmp byte[eax],'P' + jne .finishzipd +.zokay3 + call UnZipFile + cmp byte[ZipSupport],2 + jne .finishzipd + cmp byte[InGUI],1 + je .zipfail + jmp .failed +.zipfail + ret +.finishzipd + mov dword[MessageOn],0 + mov byte[loadedfromgui],1 + mov byte[Header512],0 + mov byte[yesoutofmemory],0 + mov byte[.fail],0 + ; determine header size + mov dword[.curfileofs],0 + mov byte[.first],1 + mov byte[.multfound],0 + mov dword[.curromspace],0 + ; open file + mov edx,fname+1 + call Open_File + jc near .failed +.nextfile + cmp byte[.first],1 + je .nomul + cmp byte[.multfound],0 + jne .nomul + push eax + push edx + mov byte[.multfound],1 + cmp byte[InGUI],1 + je .ingui +; mov edx,.mult +; mov ah,9 +; call Output_Text +.ingui + pop edx + pop eax +.nomul + mov bx,ax + mov ecx,4194304+32768 + cmp byte[Sup48mbit],0 + je .no48mb + add ecx,2097152 +.no48mb + cmp byte[Sup16mbit],0 + je .no16mb + sub ecx,2097152 +.no16mb + mov [.maxromspace],ecx + sub dword[.maxromspace],32768 + sub ecx,[.curfileofs] + jnc .nooverflow + xor ecx,ecx +.nooverflow + mov edx,[headdata] + add edx,[.curfileofs] + call Read_File + jc near .failed + or eax,eax + jz near .success2 + add dword[.curromspace],eax + mov ecx,eax + shr eax,15 + shl eax,15 + mov esi,[headdata] + add esi,[.curfileofs] + mov edi,[headdata] + add edi,[.curfileofs] + add [.curfileofs],eax + sub ecx,eax +; xor ecx,ecx +; or ecx,ecx + cmp ecx,512 + jne .nonoheader + mov byte[Header512],1 + mov ecx,512 + and eax,0FFFF8000h + add eax,8000h + jmp .yesheader +.nonoheader + add eax,ecx + xor ecx,ecx +.yesheader + add edi,ecx + ; check if .smc header + push esi + push eax + mov esi,[headdata] + add esi,7FDCh + add esi,512 + mov ax,[esi] + xor ax,[esi+2] + cmp ax,0FFFFh + je .yessmc + add esi,8000h + mov ax,[esi] + xor ax,[esi+2] + cmp ax,0FFFFh + je .yessmc + pop eax + pop esi + jmp .next +.yessmc + pop eax + pop esi + mov edi,esi + add edi,512 + and eax,0FFFF8000h + add eax,8000h + ; move eax # of bytes from edi to esi + sub dword[.curromspace],512 +.next + mov cl,[edi] + mov [esi],cl + inc esi + inc edi + dec eax + jnz .next + mov ecx,1 + mov edx,.temp + call Read_File + cmp eax,0 + je .success + mov byte[.fail],1 + jmp .success +.success2 + mov byte[.fail],0 +.success + call Close_File + jc near .failed + ; check for 2nd+ part of file + mov edi,fname+1 + mov byte[.cchar],'\' + ; get position of . or \ +.nextsearch + cmp byte[edi],0 + je .nomore + cmp byte[edi],'.' + jne .notdot + mov byte[.cchar],'.' + mov [.dotpos],edi +.notdot + cmp byte[edi],'\' + jne .notslash + mov byte[.cchar],'\' +.notslash + inc edi + jmp .nextsearch +.nomore + cmp byte[.cchar],'\' + jne .noslashb + mov [.dotpos],edi +.noslashb + mov edi,[.dotpos] + ; search for .1, .2, etc. + cmp byte[edi],'.' + jne .nonumer + cmp byte[edi+1],'1' + jb .nonumer + cmp byte[edi+1],'8' + ja .nonumer + cmp byte[edi+2],0 + jne .nonumer + inc byte[edi+1] + xor ecx,ecx + mov byte[.first],2 + mov edx,fname+1 + call Open_File + jnc near .nextfile + dec byte[edi+1] +.nonumer + ; search for A,B,C, etc. + cmp byte[.first],0 + je .yesgd + cmp byte[edi-1],'A' + je .yesgd + cmp byte[edi-1],'a' + je .yesgd + jmp .nogdformat +.yesgd + mov byte[.first],0 + inc byte[edi-1] + mov edx,fname+1 + call Open_File + jnc near .nextfile + dec byte[edi-1] +.nogdformat + + mov byte[IPSPatched],0 + cmp byte[ZipSupport],1 + jne .nottempdirdel + call PatchIPS + call ZipDelete +.nottempdirdel + + call convertsram + mov byte[SramExists],0 + + ; change to sram dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + ; open .srm file + mov edx,fnames+1 + call Open_File + jc .notexist + mov byte[SramExists],1 + mov bx,ax + mov ecx,65536 + mov edx,[sram] + call Read_File + call Close_File + jc near .failed2 +.notexist + call OpenCombFile + cmp byte[InGUI],1 + je .inguib + mov edx,.opened + mov ah,9 + call Output_Text +.inguib + + ; mirror image + mov eax,[.curromspace] + cmp dword[.maxromspace],eax + jbe .nomir + mov edx,[romdata] + mov ebx,[romdata] + add edx,[.curromspace] + mov ecx,[.curromspace] +.nextmir + mov al,[ebx] + mov [edx],al + inc ebx + inc edx + inc ecx + cmp ecx,[.maxromspace] + jne .nextmir +.nomir + + mov eax,[.curfileofs] + mov [NumofBytes],eax + shr eax,15 + mov [NumofBanks],eax + + ; calculate checksum + mov ecx,[.curfileofs] + mov esi,[headdata] + xor eax,eax + xor ebx,ebx +.nextcs + mov al,[esi] + inc esi + add ebx,eax + dec ecx + jnz .nextcs + mov [Checksumvalue],bx + mov eax,[.curfileofs] + shr eax,15 + mov [NumofBanks],eax + cmp byte[.fail],0 + je .notfailed + mov byte[yesoutofmemory],1 +.notfailed + + ; copy fnames to fname + cmp byte[InGUI],1 + je .nosramtof + mov eax,fname+1 + mov ebx,fnames+1 +.loopsc + mov dl,[ebx] + mov [eax],dl + inc ebx + inc eax + or dl,dl + jnz .loopsc +.nosramtof + cmp byte[IPSPatched],0 + jne .patched + call PatchIPS +.patched + ret + +.failed + cmp byte[ZipSupport],1 + jne .nottempdirdelb + call ZipDelete +.nottempdirdelb +.failed2 + cmp byte[InGUI],1 + je .noguic + mov edx,.failop + mov ah,9 + call Output_Text +.noguic + mov byte[GUIloadfailed],1 + jmp DosExit + +SECTION .data +.multfound db 0 +.first db 0 +.cchar db 0 +.dotpos dd 0 +.curfileofs dd 0 +.filehand dw 0 +.temp db 0 +.fail db 0 +.failop db 'Error opening file!',13,10,0 +.opened db 'File opened successfully!',13,10,0 +.mult db 'Multiple file format detected.',13,10,13,10,0 +.maxromspace dd 0 +.curromspace dd 0 +NEWSYM GUIloadfailed, db 0 + +SECTION .text + + +NEWSYM convertsram + cmp byte[cfgloadsdir],1 + je .sdrivechange + ret +.sdrivechange + ; copy fnames/fnamest to not have any '\' in them + mov esi,fnames+1 + mov ebx,0 +.next + mov al,[esi] + cmp al,0 + je .fincutoff + cmp al,'\' + je .cutoff + cmp al,'/' + je .cutoff + cmp al,':' + je .cutoff + inc esi + jmp .next +.cutoff + inc esi + mov ebx,esi + jmp .next +.fincutoff + cmp ebx,0 + je .nocutoff + mov esi,ebx + mov edi,fnames+1 +.next2 + mov al,[esi] + mov [edi],al + inc esi + inc edi + cmp al,0 + jne .next2 +.nocutoff + mov esi,fnamest+1 + mov ebx,0 +.nextb + mov al,[esi] + cmp al,0 + je .fincutoffb + cmp al,'\' + je .cutoffb + cmp al,'/' + je .cutoffb + cmp al,':' + je .cutoffb + inc esi + jmp .nextb +.cutoffb + inc esi + mov ebx,esi + jmp .nextb +.fincutoffb + cmp ebx,0 + je .nocutoffb + mov esi,ebx + sub esi,fnamest+1 + sub [statefileloc],esi + mov esi,ebx + mov edi,fnamest+1 +.next2b + mov al,[esi] + mov [edi],al + inc esi + inc edi + cmp al,0 + jne .next2b +.nocutoffb + ; change to sram directory + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + ret + +;******************************************************* +; Show Information +;******************************************************* +; +; Maker Code = FFB0-FFB1 +; Game Code = FFB2-FFB5 +; Expansion RAM Size = FFBD (0=none, 1=16kbit, 3=64kbit, 5=256kbit,etc. +; Map Mode = FFD5 2.68-20h=map20h,21h=map21h,22h=reserved,23h=SA-1,25h=map25h +; 3.58-30h=map20h,31h=map21h,35h=map25h,highspeed +; Rom Mask Version = FFDB +; FFD6 (ROM Type) : 0*=DSP,1*=SFX,2*=OBC1,3*=SA-1,E*-F*=other +; *3=ROM,*4=ROM+RAM,*5=ROM+RAM+BATTERY,*6=ROM+BATTERY +; F3=C4 + +; Convert to interleaved - If LoROM and offset 7FD5 contains 21h, then +; uninterleave + +NEWSYM showinfo + mov edx,.romsizea + cmp byte[Sup48mbit],0 + je .no48 + mov edx,.romsizeb + cmp byte[newgfx16b],0 + je .no48 + mov edx,.romsized +.no48 + cmp byte[Sup16mbit],0 + je .no16 + mov edx,.romsizec +.no16 + mov ah,9 + call Output_Text + mov edx,.filename + mov ah,9 + call Output_Text + xor ecx,ecx + mov cl,[fname] + mov esi,fname+1 + mov ah,2 +.loopa + lodsb + mov dl,al + call Output_Text + loop .loopa + mov edx,.ret + mov ah,9 + call Output_Text + ; frameskip = ? + mov edx,.frameskip + mov ah,9 + call Output_Text + mov dl,[frameskip] + test dl,0FFh + jnz .yesfs + mov edx,.auto + mov ah,9 + call Output_Text + jmp .skip +.yesfs + mov ah,2 + add dl,47 + call Output_Text + mov edx,.ret + mov ah,9 + call Output_Text +.skip + ; debugger on/off + mov edx,.debugon + mov ah,9 + call Output_Text + mov al,[debugger] + test al,0FFh + jnz .debugron + mov edx,.off + mov ah,9 + call Output_Text + jmp .skip2 +.debugron + mov edx,.on + mov ah,9 + call Output_Text +.skip2 + mov edx,.ret + mov ah,9 + call Output_Text + ; memory free + mov edx,.memryfr + call Output_Text + mov edx,.memfree + call Get_Memfree + mov eax,[.memfree] + call printnum + mov edx,.ret + mov ah,9 + call Output_Text + call Output_Text + + ; ROM Information + mov edx,.smcname + mov ah,9 + call Output_Text + + ; determine whether hirom or lorom is used + cmp byte[romtype],0 + jnz near .donecheck + call CheckROMType + + cmp byte[ROMTypeNOTFound],0 + je .donecheck + mov ah,09h + mov edx,.doh + call Output_Text + jmp DosExit + +.donecheck + +; COP Software 00FFF4,5 00FFE4,5 N/A +; ABORT Hardware 00FFF8,9 00FFE8,9 2 +; NMI Hardware 00FFFA,B 00FFEA,B 3 +; RES Hardware 00FFFC.D 00FFFC,D 1 +; BRK Software 00FFFE,F 00FFE6,7 N/A +; IRQ Hardware 00FFFE,F 00FFEE,F 4 + + call SetIRQVectors + + ; Output Name + mov esi,[romdata] + add esi,7FC0h + cmp byte[romtype],2 + jne .nohirom2 + add esi,8000h +.nohirom2 + mov ecx,21 +.loopb + lodsb + mov dl,al + mov ah,2 + call Output_Text + loop .loopb + inc esi + mov edx,.ret + + ; ROM Type + mov ah,9 + call Output_Text + mov edx,.romtyp + call Output_Text + mov edx,.hirom + cmp byte[romtype],1 + jne .nolorom + mov edx,.lorom +.nolorom + call Output_Text + mov edx,.romtype + xor ebx,ebx + mov bl,[esi] + +; xor eax,eax +; mov al,bl +; call printnum +; jmp DosExit + + mov al,bl + inc esi + cmp al,055h + jne .noRTC + mov bl,12 + jmp .nochip +.noRTC + cmp al,0F5h + je .yesSPC7110 + cmp al,0F9h + jne .noSPC7110 +.yesSPC7110 + mov bl,11 + jmp .nochip +.noSPC7110 + cmp al,0F3h + jne .noC4 + mov bl,9 + jmp .nochip +.noC4 + and bl,0F0h + cmp bl,10h + je .sfx + cmp bl,30h + je .sa1 + cmp bl,40h + je .sdd1 + mov bl,20 + cmp al,5 + ja .okay + mov bl,al +.okay + jmp .nochip +.sfx + mov bl,6 + jmp .nochip +.sa1 + mov bl,7 + jmp .nochip +.sdd1 + mov bl,10 + jmp .nochip +.nochip + cmp bl,20 + je .unknown + shl bl,4 + add edx,ebx + call Output_Text + jmp .nounknown +.unknown + mov edx,.unknowns + call Output_Text + mov al,[esi-1] + call printhex8 + mov edx,.brackets + mov ah,9 + call Output_Text +.nounknown + ; Memory Map +; cmp byte[intldone],0 +; je .nointerl +; mov ah,09h +; mov edx,.intlvd +; call Output_Text +;.nointerl + + mov ah,09h + mov edx,.memmap + call Output_Text + push esi + mov esi,[romdata] + add esi,7FD5h + xor eax,eax + mov al,byte[esi] + and al,2Fh + pop esi + call printhex8 + mov ah,09h + mov edx,.ret + call Output_Text + + ; ROM Size + mov edx,.romsize + mov ah,9 + call Output_Text + mov cl,[esi] + mov [curromsize],cl +; cmp byte[NumofBanks],160 +; jb .not48 +; mov byte[curromsize],13 +;.not48 + + inc esi + xor eax,eax + sub cl,7 + mov al,1 + shl al,cl + call printnum + mov edx,.megabit + mov ah,9 + call Output_Text + + ; RAM Size + mov edx,.sramsize + mov ah,9 + call Output_Text + and eax,0FFFFh + mov cl,[esi] + inc esi + xor eax,eax + mov al,1 + shl al,cl + cmp al,1 + jne .yessram + mov al,0 +.yessram + call printnum + shl eax,10 + cmp eax,65536 + jbe .nosramc + mov eax,65536 +.nosramc + mov [ramsize],eax + dec eax + mov [ramsizeand],eax + mov edx,.kilobit + mov ah,9 + call Output_Text + mov al,[esi] + cmp byte[ForcePal],1 + jne .nontsc + mov al,0 +.nontsc + cmp byte[ForcePal],2 + jne .nopal2 + mov al,2 +.nopal2 + mov byte[romispal],0 + mov word[totlines],262 + mov dword[MsgCount],120 + cmp al,1 + jbe .nopal + cmp al,0Fh + je .nopal + mov byte[romispal],1 + mov word[totlines],314 + mov dword[MsgCount],100 + mov edx,.romtypep + mov ah,9 + call Output_Text + jmp .yespal +.nopal + mov edx,.romtypen + mov ah,9 + call Output_Text +.yespal + mov esi,[headdata] + add esi,7FBDh + cmp byte[romtype],2 + jne .nohirom4 + add esi,8000h +.nohirom4 + cmp byte[esi],0 + je .nochipram + jmp .nochipram + mov edx,.ramsize + mov ah,9 + call Output_Text + xor eax,eax + mov al,[esi] + shl eax,12 + call printnum + mov edx,.kilobit + mov ah,9 + call Output_Text +.nochipram +;FFBD (0=none, 1=16kbit, 3=64kbit, 5=256kbit,etc. + mov edx,.checksumc + mov ah,9 +; call Output_Text + mov ax,[Checksumvalue] + mov esi,[headdata] + add esi,7FDCh+2 + cmp byte[romtype],2 + jne .nohirom3 + add esi,8000h +.nohirom3 + cmp ax,[esi] + jne .failed + mov edx,.cpassed + jmp .passed +.failed + mov edx,.cfailed +.passed + mov ah,9 +; call Output_Text + ; Display NMI & Reset + mov edx,.nmidisp + mov ah,9 + call Output_Text + xor eax,eax + mov ax,[nmiv] + call printhex + mov edx,.ret + mov ah,9 + call Output_Text + mov edx,.resetdisp + mov ah,9 + call Output_Text + mov ax,[resetv] + call printhex + mov edx,.ret + mov ah,9 + call Output_Text + cmp byte[intldone],1 + jne .nointerl + mov edx,.intlvd + mov ah,9 + call Output_Text +.nointerl + + mov edx,.ret + mov ah,9 + call Output_Text + mov edx,.waitkey + mov ah,9 + call Output_Text + ; wait for key + cmp byte[enterpress],0 + jne .noesc + cmp byte[OSPort],3 + je .noesc + call Get_Key + cmp al,27 + jne .noesc + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + jmp DosExit +.noesc + mov edx,.ret + call Output_Text + ret + +SECTION .data +.memfree times 30 db 0 +.filename db 'Filename : ',0 +.frameskip db 'Frame Skip : ',0 +.percexec db '% to Exec : ',0 +.debugon db 'Debugger : ',0 +.memryfr db 'Memory Free : ',0 +.auto db 'AUTO',13,10,0 +.on db 'ON',13,10,0 +.off db 'OFF',13,10,0 +.ret db 13,10,0 +.waitkey db 'Press Any Key to Continue.',0 +.smcname db 'Cartridge name : ',0 +.romtyp db 'ROM type : ',0 +.memmap db 'Memory Map : ',0 +.hirom db 'HIROM/',0 +.lorom db 'LOROM/',0 +.romtype db 'ROM ',13,10,0 + db 'ROM/RAM ',13,10,0 + db 'ROM/SRAM ',13,10,0 + db 'ROM/DSP1 ',13,10,0 + db 'RAM/DSP1/RAM ',13,10,0 + db 'ROM/DSP1/SRAM',13,10,0 + db 'SFX ',13,10,0 + db 'SA-1 ',13,10,0 + db 'SFX2/RAM ',13,10,0 + db 'C4/ROM ',13,10,0 + db 'SDD-1 ',13,10,0 + db 'SPC7110 ',13,10,0 + db 'S-RTC ',13,10,0 +.unknowns db 'UNKNOWN (',0 +.brackets db ')',13,10,0 +.romsize db 'ROM size : ',0 +.sramsize db 'SRAM size : ',0 +.ramsize db 'CartRAM size : ',0 +.romtypep db 'ROM Type : PAL',13,10,0 +.romtypen db 'ROM Type : NTSC',13,10,0 +.checksumc db 'Checksum : ',0 +.cpassed db 'PASSED',13,10,0 +.cfailed db 'FAILED',13,10,0 +.romsizea db 13,10,'Max 32mbit ROM support',13,10,13,10,0 +.romsizeb db 13,10,'Max 48mbit ROM support + SuperFX/C4 support',13,10,13,10,0 +.romsizec db 13,10,'Max 16mbit ROM support',13,10,13,10,0 +.romsized db 13,10,'Max 48mbit ROM support + SuperFX/C4 support + 16bit New Gfx Engine',13,10,13,10,0 +.megabit db ' Megabits',13,10,0 +.kilobit db ' Kilobytes',13,10,0 +.nmidisp db 'NMI Vector Location : ',0 +.resetdisp db 'Reset Vector Location : ',0 +.doh db 'Cannot detect whether cartridge is HiROM or LoROM.',13,10,'Please use -h/-l',13,10,0 +.intlvd db 'Image is uninterleaved.',13,10,0 + +NEWSYM DSP1Type, db 0 +NEWSYM intldone, db 0 +SECTION .text + +NEWSYM CheckROMType + call SetAddressingModes + call GenerateBank0Table + call headerhack2 + mov byte[ROMTypeNOTFound],0 + ; check reset vectors +; RES Hardware 00FFFC.D 00FFFC,D 1 + mov esi,[romdata] + mov ax,[esi+0FFFCh] + mov bx,[esi+07FFCh] + test ax,8000h + jnz .checkloarea + test bx,8000h + jz .notfound2 + mov byte[romtype],1 + jmp .donecheck +.checkloarea + test bx,8000h + jnz .notfound2 + mov byte[romtype],2 + jmp .donecheck +.notfound2 + + mov esi,[romdata] + add esi,7FECh + cmp word[esi],8000h + jb .checkhirom + mov esi,[romdata] + add esi,32704+23 + cmp byte[esi],32 + ja .checkhirom + mov esi,[romdata] + add esi,7FDCh + lodsw + mov bx,ax + lodsw + xor bx,ax + cmp bx,0FFFFh + jne .checkhirom + cmp ax,0 + je .checkhirom + cmp ax,0FFFFh + je .checkhirom + mov byte[romtype],1 + jmp .donecheck +.checkhirom + mov esi,[romdata] + add esi,32704+23+32768 + cmp byte[esi],32 + ja .cantcheck + mov esi,[romdata] + add esi,0FFDCh + lodsw + mov bx,ax + lodsw + xor bx,ax + cmp bx,0FFFFh + jne .cantcheck + mov byte[romtype],2 + jmp .donecheck +.cantcheck + ; check for a header with mostly letters or spaces + mov esi,[romdata] + add esi,32704 + mov ecx,21 + mov al,0 +.nextletter + cmp byte[esi],32 + je .yesletter + cmp byte[esi],'0' + jb .noletter + cmp byte[esi],'9' + jbe .yesletter + cmp byte[esi],'A' + jb .noletter + cmp byte[esi],'Z' + jbe .yesletter + cmp byte[esi],'a' + jb .noletter + cmp byte[esi],'z' + ja .noletter +.yesletter + inc al +.noletter + inc esi + loop .nextletter + cmp al,12 + jna .checkhiromletter + mov byte[romtype],1 + jmp .donecheck +.checkhiromletter + mov esi,[romdata] + add esi,65472 + mov ecx,21 + mov al,0 +.nextletterb + cmp byte[esi],32 + je .yesletterb + cmp byte[esi],'0' + jb .noletterb + cmp byte[esi],'9' + jbe .yesletterb + cmp byte[esi],'A' + jb .noletterb + cmp byte[esi],'Z' + jbe .yesletterb + cmp byte[esi],'a' + jb .noletterb + cmp byte[esi],'z' + ja .noletterb +.yesletterb + inc al +.noletterb + inc esi + loop .nextletterb + cmp al,12 + jna .notfound + mov byte[romtype],2 + jmp .donecheck +.notfound + + mov esi,[romdata] + mov ax,[esi+0FFFCh] + mov bx,[esi+07FFCh] + cmp ax,8000h + jne .checkloarea8000 + cmp bx,8000h + je .notfound28000 + mov byte[romtype],2 + jmp .donecheck +.checkloarea8000 + cmp bx,8000h + jne .notfound28000 + mov byte[romtype],1 + jmp .donecheck +.notfound28000 + + mov byte[ROMTypeNOTFound],1 +.donecheck + + cmp byte[forceromtype],0 + je .noforce + mov al,[forceromtype] + mov [romtype],al + mov byte[forceromtype],0 + mov byte[ROMTypeNOTFound],0 + jmp .doneinterl +.noforce + + mov byte[intldone],0 + cmp byte[romtype],1 + jne .nointerlcheck + mov esi,[romdata] + add esi,7FD5h + cmp byte[esi],21h + je .interleaved + cmp byte[esi],92h + je .interleaved + mov eax,[romdata] + add eax,07FC0h + cmp dword[eax+8],'EST3' + je .interleaved + cmp byte[eax],'T' + je .nointerlcheck + cmp byte[esi],31h + jne .nointerlcheck +.interleaved + cmp byte[finterleave],1 + je .doneinterl +.interleaved2 + mov byte[intldone],1 + call UnInterleave + mov byte[romtype],2 + jmp .doneinterl +.nointerlcheck + cmp byte[finterleave],1 + je .interleaved2 +.doneinterl + mov esi,[romdata] + add esi,0FFC0h + mov byte[disablespcclr],0 + mov eax,50205040h + or eax,0A000302h + cmp dword[esi],eax + jne .nospcdis + mov byte[disablespcclr],1 +.nospcdis + mov eax,[esi] + mov byte[DSP1Type],0 + mov esi,[romdata] + add esi,32704+22 + cmp byte[romtype],2 + jne .nohirom2 + add esi,8000h +.nohirom2 + mov al,[esi] + cmp al,3 + je .dsp1 + cmp al,4 + je .dsp1 + cmp al,5 + je .dsp1 + jmp .nodsp1 +.dsp1 + call InitDSP + mov byte[DSP1Type],1 + cmp byte[romtype],2 + jne .nodsp1 + mov byte[DSP1Type],2 +.nodsp1 + ; banks 0-3Fh + mov dword[memtabler8+3Fh*4],regaccessbankr8 + mov dword[memtablew8+3Fh*4],regaccessbankw8 + mov dword[memtabler16+3Fh*4],regaccessbankr16 + mov dword[memtablew16+3Fh*4],regaccessbankw16 + mov dword[memtabler8+0BFh*4],regaccessbankr8 + mov dword[memtablew8+0BFh*4],regaccessbankw8 + mov dword[memtabler16+0BFh*4],regaccessbankr16 + mov dword[memtablew16+0BFh*4],regaccessbankw16 + mov dword[memtabler8+70h*4],sramaccessbankr8 + mov dword[memtablew8+70h*4],sramaccessbankw8 + mov dword[memtabler16+70h*4],sramaccessbankr16 + mov dword[memtablew16+70h*4],sramaccessbankw16 + mov dword[memtabler8+71h*4],sramaccessbankr8 + mov dword[memtablew8+71h*4],sramaccessbankw8 + mov dword[memtabler16+71h*4],sramaccessbankr16 + mov dword[memtablew16+71h*4],sramaccessbankw16 + mov dword[memtabler8+72h*4],sramaccessbankr8 + mov dword[memtablew8+72h*4],sramaccessbankw8 + mov dword[memtabler16+72h*4],sramaccessbankr16 + mov dword[memtablew16+72h*4],sramaccessbankw16 + mov dword[memtabler8+73h*4],sramaccessbankr8 + mov dword[memtablew8+73h*4],sramaccessbankw8 + mov dword[memtabler16+73h*4],sramaccessbankr16 + mov dword[memtablew16+73h*4],sramaccessbankw16 + mov dword[memtabler8+78h*4],memaccessbankr8 + mov dword[memtablew8+78h*4],memaccessbankw8 + mov dword[memtabler16+78h*4],memaccessbankr16 + mov dword[memtablew16+78h*4],memaccessbankw16 + mov dword[memtabler8+79h*4],memaccessbankr8 + mov dword[memtablew8+79h*4],memaccessbankw8 + mov dword[memtabler16+79h*4],memaccessbankr16 + mov dword[memtablew16+79h*4],memaccessbankw16 + mov esi,[romdata] + add esi,32704+22 + cmp byte[romtype],2 + jne .nohirom2b + add esi,8000h +.nohirom2b + mov byte[SFXEnable],0 + mov byte[C4Enable],0 + mov byte[SPC7110Enable],0 + mov byte[RTCEnable],0 + mov byte[SA1Enable],0 + mov byte[SDD1Enable],0 + mov byte[SFXSRAM],0 + mov al,[esi] + cmp al,055h + jne .noRTC + mov byte[RTCEnable],1 +.noRTC + cmp al,0F5h + je .yesSPC7110 + cmp al,0F9h + jne .noSPC7110 +.yesSPC7110 + mov byte[SPC7110Enable],1 + jmp .nosfx +.noSPC7110 + cmp al,0F3h + jne .noc4chip + mov byte[C4Enable],1 + jmp .nosfx +.noc4chip + and al,0F0h + cmp al,10h + je .yessfx + cmp al,30h + je near .yessa1 + cmp al,40h + je near .yessdd1 + jmp .nosfx +.yessfx + mov al,[esi] + and al,0Fh + cmp al,5 + je .sram + cmp al,6 + jne .nosram +.sram + mov byte[SFXSRAM],1 +.nosram + cmp byte[Sup48mbit],1 + je .sfxokay + mov byte[yesoutofmemory],1 + jmp .nosfx +.sfxokay + mov byte[SFXEnable],1 + mov dword[memtabler8+70h*4],sfxaccessbankr8 + mov dword[memtablew8+70h*4],sfxaccessbankw8 + mov dword[memtabler16+70h*4],sfxaccessbankr16 + mov dword[memtablew16+70h*4],sfxaccessbankw16 + mov dword[memtabler8+71h*4],sfxaccessbankr8b + mov dword[memtablew8+71h*4],sfxaccessbankw8b + mov dword[memtabler16+71h*4],sfxaccessbankr16b + mov dword[memtablew16+71h*4],sfxaccessbankw16b + mov dword[memtabler8+72h*4],sfxaccessbankr8c + mov dword[memtablew8+72h*4],sfxaccessbankw8c + mov dword[memtabler16+72h*4],sfxaccessbankr16c + mov dword[memtablew16+72h*4],sfxaccessbankw16c + mov dword[memtabler8+73h*4],sfxaccessbankr8d + mov dword[memtablew8+73h*4],sfxaccessbankw8d + mov dword[memtabler16+73h*4],sfxaccessbankr16d + mov dword[memtablew16+73h*4],sfxaccessbankw16d + mov dword[memtabler8+78h*4],sramaccessbankr8s + mov dword[memtablew8+78h*4],sramaccessbankw8s + mov dword[memtabler16+78h*4],sramaccessbankr16s + mov dword[memtablew16+78h*4],sramaccessbankw16s + mov dword[memtabler8+79h*4],sramaccessbankr8s + mov dword[memtablew8+79h*4],sramaccessbankw8s + mov dword[memtabler16+79h*4],sramaccessbankr16s + mov dword[memtablew16+79h*4],sramaccessbankw16s + mov dword[SfxR1],0 + mov dword[SfxR2],0 + mov esi,[sfxramdata] + mov ecx,65536 +.loopsfxclear + mov dword[esi],0 + add esi,4 + dec ecx + jnz .loopsfxclear + cmp byte[SramExists],0 + je .nosramsfx + mov esi,[sram] + mov edi,[sfxramdata] + mov ecx,16384 +.sfxsramloop + mov eax,[esi] + mov [edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .sfxsramloop +.nosramsfx + call InitFxTables +.nosfx + jmp .nosa1 +.yessdd1 + mov byte[SDD1Enable],1 + jmp .nosa1 +.yessa1 + mov byte[SA1Enable],1 +.nosa1 + mov dword[SfxSFR],0 + mov byte[SfxSCMR],0 + call initregr + call initregw + cmp byte[SA1Enable],0 + je .nosa1init + call GenerateBank0TableSA1 + call SetAddressingModesSA1 + ; open .srm file + mov edx,fnames+1 + call Open_File + jc .nosa1init + mov byte[SramExists],1 + mov bx,ax + mov ecx,65536*2 + mov edx,[romdata] + add edx,1024*4096 + call Read_File + jc .nosa1init + call Close_File +.nosa1init + cmp byte[DSP1Type],1 + jne .nodsp1lorom + mov dword[memtabler8+3Fh*4],DSP1Read8b3F + mov dword[memtablew8+3Fh*4],DSP1Write8b3F + mov dword[memtabler16+3Fh*4],DSP1Read16b3F + mov dword[memtablew16+3Fh*4],DSP1Write16b3F + mov dword[memtabler8+0BFh*4],DSP1Read8b3F + mov dword[memtablew8+0BFh*4],DSP1Write8b3F + mov dword[memtabler16+0BFh*4],DSP1Read16b3F + mov dword[memtablew16+0BFh*4],DSP1Write16b3F +.nodsp1lorom + mov dword[wramdata],wramdataa + call SPC7110Load + ret + +SECTION .data +NEWSYM SFXEnable, db 0 +NEWSYM C4Enable, db 0 +NEWSYM SPC7110Enable, db 0 +NEWSYM RTCEnable, db 0 +NEWSYM SA1Enable, db 0 +NEWSYM SDD1Enable, db 0 +NEWSYM C4RamR, dd 0 +NEWSYM C4RamW, dd 0 +NEWSYM C4Ram, dd 0 +NEWSYM ROMTypeNOTFound, db 0 +SECTION .text + +NEWSYM SetIRQVectors + ; Get Vectors (NMI & Reset) + mov esi,[romdata] + add esi,32704+21 + cmp byte[romtype],2 + jne .nohirom9 + add esi,8000h +.nohirom9 + mov al,[esi] + test al,0F0h + jnz .yesfastrom + mov al,[opexec268] + mov [opexec358],al + mov al,[opexec268cph] + mov [opexec358cph],al + mov al,[cycpb268] + mov [cycpb358],al +.yesfastrom + mov esi,[romdata] + add esi,7FE4h + cmp byte[romtype],2 + jne .nohirom + add esi,8000h +.nohirom + cmp word[esi+24],0FFFFh + jne .notreseterror + mov word[esi+6],0FF9Ch + mov word[esi+24],0FF80h +.notreseterror + lodsw + mov [copv],ax + lodsw + mov [brkv],ax + lodsw + mov [abortv],ax + lodsw + mov [nmiv],ax + mov [nmiv2],ax + add esi,2 + lodsw + mov [irqv],ax + mov [irqv2],ax + add esi,4 + ; 8-bit and reset + lodsw + mov [copv8],ax + inc esi + inc esi + lodsw + mov [abortv8],ax + lodsw + mov [nmiv8],ax + lodsw + mov [resetv],ax + lodsw + mov [brkv8],ax + mov [irqv8],ax + cmp byte[yesoutofmemory],0 + je .notfailed + mov word[resetv],8000h + mov esi,[romdata] + mov word[esi],0FE80h + mov word[esi+8000h],0FE80h +.notfailed + ret + +NEWSYM outofmemfix + mov esi,[romdata] + cmp byte[romtype],2 + je .hirom + mov word[resetv],8000h + mov word[xpc],8000h + mov byte[esi],58h + mov byte[esi+1],80h + mov byte[esi+2],0FEh + mov dword[Msgptr],outofmemoryerror + cmp byte[newgfx16b],1 + jne .notso + mov dword[Msgptr],outofmemoryerror2 +.notso + mov dword[MessageOn],0FFFFFFFFh + ret +.hirom + add esi,8000h + mov word[resetv],8000h + mov word[xpc],8000h + mov byte[esi],58h + mov byte[esi+1],80h + mov byte[esi+2],0FEh + mov dword[Msgptr],outofmemoryerror + cmp byte[newgfx16b],1 + jne .notso2 + mov dword[Msgptr],outofmemoryerror2 +.notso2 + mov dword[MessageOn],0FFFFFFFFh + ret + +SECTION .data +NEWSYM yesoutofmemory, db 0 +NEWSYM outofmemoryerror, db 'OUT OF MEMORY.',0 +NEWSYM outofmemoryerror2, db 'ROM IS TOO BIG.',0 +SECTION .text + + \ No newline at end of file diff --git a/zsnes/src/link.win32 b/zsnes/src/link.win32 new file mode 100644 index 00000000..15aba783 --- /dev/null +++ b/zsnes/src/link.win32 @@ -0,0 +1,2 @@ +/Fezsnesw.exe chips\dsp1proc.obj dos\sw.obj dos\gppro.obj dos\vesa12.obj dos\zsipx.obj dos\modemrtn.obj dos\joy.obj dos\debug.obj dos\vesa2.obj dos\initvid.obj cfgload.obj endmem.obj fixsin.obj init.obj ui.obj vcache.obj water.obj video\procvid.obj win\copyvwin.obj win\winintrf.obj win\winlink.obj win\zloaderw.obj win\ztcp.obj win\zfilew.obj win\zipxw.obj video\makev16b.obj video\makev16t.obj video\makevid.obj video\mode716.obj video\mode716b.obj video\mode716d.obj video\mode716e.obj video\mode716t.obj video\mode7.obj video\mode7ext.obj video\mv16tms.obj video\newg162.obj video\newgfx16.obj video\newgfx2.obj video\newgfx.obj video\m716text.obj video\2xsaiw.obj video\2xsai.obj gui\gui.obj gui\menu.obj cpu\addrni.obj cpu\dma.obj cpu\dsp.obj cpu\dspproc.obj cpu\execute.obj cpu\irq.obj cpu\memory.obj cpu\spc700.obj cpu\stable.obj cpu\table.obj cpu\tableb.obj cpu\tablec.obj chips\dsp1emu.obj chips\fxemu2.obj chips\fxemu2b.obj chips\fxemu2c.obj chips\fxtable.obj chips\sa1proc.obj chips\sa1regs.obj chips\sfxproc.obj obj\unzip.obj obj\zzip.obj zlib.lib wsock32.lib user32.lib gdi32.lib shell32.lib ddraw.lib dsound.lib dinput.lib d3dx.lib /link /section:.text,erw + \ No newline at end of file diff --git a/zsnes/src/macros.mac b/zsnes/src/macros.mac new file mode 100644 index 00000000..92a07f7d --- /dev/null +++ b/zsnes/src/macros.mac @@ -0,0 +1,48 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +bits 32 +section .text +; Zsnes required macros +%imacro newsym 1 + GLOBAL _%1 + _%1: + %1: +%endmacro + +%imacro newsym 2+ + GLOBAL _%1 + _%1: + %1: %2 +%endmacro + +%macro ALIGN32 0 + times ($$-$) & 1Fh nop ; Long word alignment +%endmacro + +%macro ALIGN16 0 + times ($$-$) & 1Fh nop ; Long word alignment +%endmacro + +%imacro extsym 1-* +%rep %0 + EXTERN _%1 + %define %1 _%1 +%rotate 1 +%endrep +%endmacro \ No newline at end of file diff --git a/zsnes/src/makefile.dos b/zsnes/src/makefile.dos new file mode 100644 index 00000000..5001e489 --- /dev/null +++ b/zsnes/src/makefile.dos @@ -0,0 +1,185 @@ +#Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +# +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; either +#version 2 of the License, or (at your option) any later +#version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +CHIPDIR=chips +CPUDIR=cpu +DOSDIR=dos +GUIDIR=gui +VIDEODIR=video +WINDIR=win +OBJDIR=obj + +CHIPSOBJ=${CHIPDIR}/dsp1emu.o ${CHIPDIR}/fxemu2.o ${CHIPDIR}/sfxproc.o\ + ${CHIPDIR}/fxemu2b.o ${CHIPDIR}/fxemu2c.o ${CHIPDIR}/fxtable.o\ + ${CHIPDIR}/sa1proc.o ${CHIPDIR}/sa1regs.o ${CHIPDIR}/dsp1proc.o + +CPUOBJ=${CPUDIR}/addrni.o ${CPUDIR}/dma.o ${CPUDIR}/dsp.o ${CPUDIR}/dspproc.o\ + ${CPUDIR}/execute.o ${CPUDIR}/irq.o ${CPUDIR}/memory.o\ + ${CPUDIR}/spc700.o ${CPUDIR}/stable.o ${CPUDIR}/table.o\ + ${CPUDIR}/tableb.o ${CPUDIR}/tablec.o + +GUIOBJ=${GUIDIR}/gui.o ${GUIDIR}/menu.o + +VIDEOBJ=${VIDEODIR}/makev16b.o ${VIDEODIR}/makev16t.o ${VIDEODIR}/makevid.o\ + ${VIDEODIR}/mode716.o ${VIDEODIR}/mode716b.o ${VIDEODIR}/mode716d.o\ + ${VIDEODIR}/mode716e.o ${VIDEODIR}/mode716t.o ${VIDEODIR}/mode7.o\ + ${VIDEODIR}/mode7ext.o ${VIDEODIR}/mv16tms.o ${VIDEODIR}/newg162.o\ + ${VIDEODIR}/newgfx16.o ${VIDEODIR}/newgfx2.o ${VIDEODIR}/newgfx.o\ + ${VIDEODIR}/m716text.o ${VIDEODIR}/2xsai.o ${VIDEODIR}/procvid.o + +DOSOBJ= ${DOSDIR}/dosintrf.o ${DOSDIR}/gppro.o ${DOSDIR}/debug.o\ + ${DOSDIR}/initvid.o ${DOSDIR}/modemrtn.o ${DOSDIR}/sw32.o\ + ${DOSDIR}/joy.o ${DOSDIR}/sw.o ${DOSDIR}/vesa12.o ${DOSDIR}/vesa2.o\ + ${DOSDIR}/zloader.o ${DOSDIR}/zsipx.o ${DOSDIR}/zfile.o + +WINOBJ=${WINDIR}/copywin.o ${WINDIR}/winintrf.o ${WINDIR}/winlink.o\ + ${WINDIR}/zloaderw.o ${WINDIR}/ztcp.o ${WINDIR}/zipxw.o + +PREOBJ=${OBJDIR}/dosbuff.o ${OBJDIR}/ipx.o ${OBJDIR}/unzip.o\ + ${OBJDIR}/zipx.o ${OBJDIR}/zzip.o + +MAINOBJ=cfgload.o endmem.o fixsin.o init.o ui.o vcache.o water.o + + +OBJS=${CHIPSOBJ} ${CPUOBJ} ${DOSOBJ} ${GUIOBJ} ${VIDEOBJ} ${PREOBJ} ${MAINOBJ} +LIBS=-lz -lgcc -lm +CFLAGS= +ASM=nasm +ASMFLAGS=-f coff +CC=gcc +PP=gpp + + +.SUFFIXES: .c .cpp .asm + +%.o: %.c + ${CC} ${CFLAGS} -o $@ -c $< + +%.o: %.cpp + ${PP} ${CFLAGS} -o $@ -c $< + +%.o: %.asm + ${ASM} ${ASMFLAGS} -o $@ $< + + +ALL: zsnes.exe + +zsnes.exe: ${OBJS} + ${CC} -Ws -s -o zsnes.exe ${OBJS} ${LIBS} + +${DOSDIR}/zloader.o: ${DOSDIR}/zloader.c +fixsin.o: fixsin.c +water.o: water.c +${DOSDIR}/zfile.o: ${DOSDIR}/zfile.c +${VIDEODIR}/2xsai.o: ${VIDEODIR}/2xsai.cpp +${VIDEODIR}/procvid.o: ${VIDEODIR}/procvid.asm macros.mac ${VIDEODIR}/copyvid.inc ${VIDEODIR}/2xSaImmx.inc +${CHIPDIR}/dsp1proc.o: ${CHIPDIR}/dsp1proc.asm macros.mac +${CHIPDIR}/sa1regs.o: ${CHIPDIR}/sa1regs.asm macros.mac\ + ${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac +${CHIPDIR}/sfxproc.o: ${CHIPDIR}/sfxproc.asm macros.mac\ + ${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac + +${CHIPDIR}/dsp1emu.o: ${CHIPDIR}/dsp1emu.c betauser.mac +ui.o: ui.asm macros.mac betauser.mac +cfgload.o:cfgload.asm macros.mac +init.o:init.asm macros.mac +${DOSDIR}/debug.o: ${DOSDIR}/debug.asm macros.mac +${CPUDIR}/execute.o: ${CPUDIR}/execute.asm macros.mac +${CPUDIR}/table.o: ${CPUDIR}/table.asm ${CPUDIR}/65816d.inc\ + ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816.inc\ + ${CPUDIR}/regs.mac ${CPUDIR}/regs.inc ${CPUDIR}/regsw.mac\ + ${CPUDIR}/regsw.inc macros.mac +${CPUDIR}/tableb.o: ${CPUDIR}/tableb.asm ${CPUDIR}/65816db.inc\ + ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816b.inc\ + ${CPUDIR}/regs.mac macros.mac +${CPUDIR}/tablec.o: ${CPUDIR}/tablec.asm ${CPUDIR}/65816dc.inc\ + ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816c.inc\ + ${CPUDIR}/regs.mac macros.mac +${CPUDIR}/stable.o: ${CPUDIR}/stable.asm ${CPUDIR}/s65816d.inc\ + ${CPUDIR}/saddress.inc ${CPUDIR}/saddrni.inc ${CPUDIR}/se65816.inc\ + macros.mac +${CPUDIR}/memory.o: ${CPUDIR}/memory.asm macros.mac +${CPUDIR}/dma.o: ${CPUDIR}/dma.asm macros.mac +${DOSDIR}/dosintrf.o: ${DOSDIR}/dosintrf.asm macros.mac +vcache.o:vcache.asm macros.mac +${DOSDIR}/initvid.o:${DOSDIR}/initvid.asm macros.mac +${VIDEODIR}/makevid.o: ${VIDEODIR}/makevid.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/makev16b.o: ${VIDEODIR}/makev16b.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/makev16t.o: ${VIDEODIR}/makev16t.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/mv16tms.o: ${VIDEODIR}/mv16tms.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/mode7.o: ${VIDEODIR}/mode7.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode716.o: ${VIDEODIR}/mode716.asm ${VIDEODIR}/mode716.mac\ + macros.mac +${VIDEODIR}/mode716b.o:${VIDEODIR}/mode716b.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode716t.o:${VIDEODIR}/mode716t.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode716d.o:${VIDEODIR}/mode716d.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode7ext.o:${VIDEODIR}/mode7ext.asm macros.mac +${VIDEODIR}/mode716e.o:${VIDEODIR}/mode716e.asm macros.mac +${VIDEODIR}/m716text.o:${VIDEODIR}/m716text.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${CPUDIR}/irq.o: ${CPUDIR}/irq.asm macros.mac +${CPUDIR}/dspproc.o: ${CPUDIR}/dspproc.asm macros.mac +${CPUDIR}/spc700.o:${CPUDIR}/spc700.asm macros.mac\ + ${CPUDIR}/regsw.mac ${CPUDIR}/spcdef.inc ${CPUDIR}/spcaddr.inc +${CPUDIR}/dsp.o: ${CPUDIR}/dsp.asm macros.mac +${DOSDIR}/vesa2.o: ${DOSDIR}/vesa2.asm macros.mac +${DOSDIR}/vesa12.o: ${DOSDIR}/vesa12.asm macros.mac +${DOSDIR}/joy.o: ${DOSDIR}/joy.asm macros.mac +${DOSDIR}/sw.o: ${DOSDIR}/sw.asm macros.mac +${GUIDIR}/gui.o: ${GUIDIR}/gui.asm ${GUIDIR}/guitools.inc\ + ${GUIDIR}/guimisc.inc ${GUIDIR}/guimouse.inc ${GUIDIR}/guiwindp.inc\ + ${GUIDIR}/guinetpl.inc ${GUIDIR}/guikeys.inc ${GUIDIR}/guicheat.inc\ + ${GUIDIR}/guicombo.inc ${GUIDIR}/guiload.inc macros.mac +${GUIDIR}/menu.o: ${GUIDIR}/menu.asm macros.mac +${VIDEODIR}/newgfx.o:${VIDEODIR}/newgfx.asm ${VIDEODIR}/vidmacro.mac\ + ${VIDEODIR}/newgfx2.mac ${VIDEODIR}/newgfx.mac macros.mac +${VIDEODIR}/newgfx2.o:${VIDEODIR}/newgfx2.asm ${VIDEODIR}/newgfxwn.mac\ + ${VIDEODIR}/newgfx.mac macros.mac +${VIDEODIR}/newgfx16.o: ${VIDEODIR}/newgfx16.asm macros.mac ${VIDEODIR}/vidmacro.mac\ + ${VIDEODIR}/newgfx16.mac ${VIDEODIR}/newg162.mac +${VIDEODIR}/newg162.o: macros.mac ${VIDEODIR}/newg162.asm ${VIDEODIR}/newg162.mac\ + ${VIDEODIR}/vidmacro.mac ${VIDEODIR}/newg16wn.mac +${CHIPDIR}/fxemu2.o: ${CHIPDIR}/fxemu2.asm ${CHIPDIR}/fxemu2.mac\ + macros.mac +${CHIPSDIR}/fxemu2b.o: ${CHIPDIR}/fxemu2b.asm ${CHIPDIR}/fxemu2.mac\ + ${CHIPDIR}/fxemu2b.mac +${CHIPSDIR}/fxemu2c.o: ${CHIPDIR}/fxemu2c.asm macros.mac ${CHIPDIR}/fxemu2.mac\ + ${CHIPDIR}/fxemu2b.mac ${CHIPDIR}/fxemu2c.mac +${CHIPDIR}/fxtable.o: ${CHIPDIR}/fxtable.asm macros.mac +${DOSDIR}/gppro.o: ${DOSDIR}/gppro.asm macros.mac +${DOSDIR}/zsipx.o: ${DOSDIR}/zsipx.asm +${CHIPDIR}/sa1proc.o: ${CHIPDIR}/sa1proc.asm macros.mac +endmem.o: endmem.asm macros.mac +${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac + +clean: + del *.o + del ${CHIPDIR}\*.o + del ${CPUDIR}\*.o + del ${VIDEODIR}\*.o + del ${GUIDIR}\*.o + del ${DOSDIR}\*.o + del zsnes.exe +  \ No newline at end of file diff --git a/zsnes/src/makefile.win b/zsnes/src/makefile.win new file mode 100644 index 00000000..4e9a9a31 --- /dev/null +++ b/zsnes/src/makefile.win @@ -0,0 +1,212 @@ +#Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +# +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; either +#version 2 of the License, or (at your option) any later +#version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#This file depends on link.win32 so if you modify this makefile, +#don't forget to update link.win32 +#it is quite ugly but without that trick, the compilation didn't +#work for me (command line too long) + +#put the correct path to your directx sdk here +DXDIR=f:\mssdk + +CHIPDIR=chips +CPUDIR=cpu +DOSDIR=dos +GUIDIR=gui +VIDEODIR=video +WINDIR=win +OBJDIR=obj + +CHIPSOBJ=${CHIPDIR}/sfxproc.obj ${CHIPDIR}/fxemu2.obj ${CHIPDIR}/dsp1proc.obj\ + ${CHIPDIR}/fxemu2b.obj ${CHIPDIR}/fxemu2c.obj ${CHIPDIR}/fxtable.obj\ + ${CHIPDIR}/sa1proc.obj ${CHIPDIR}/sa1regs.obj ${CHIPDIR}/dsp1emu.obj + +CPUOBJ=${CPUDIR}/addrni.obj ${CPUDIR}/dma.obj ${CPUDIR}/dsp.obj ${CPUDIR}/dspproc.obj\ + ${CPUDIR}/execute.obj ${CPUDIR}/irq.obj ${CPUDIR}/memory.obj \ + ${CPUDIR}/spc700.obj ${CPUDIR}/stable.obj ${CPUDIR}/table.obj\ + ${CPUDIR}/tableb.obj ${CPUDIR}/tablec.obj + +GUIOBJ=${GUIDIR}/gui.obj ${GUIDIR}/menu.obj + +VIDEOBJ=${VIDEODIR}/makev16b.obj ${VIDEODIR}/makev16t.obj ${VIDEODIR}/makevid.obj\ + ${VIDEODIR}/mode716.obj ${VIDEODIR}/mode716b.obj ${VIDEODIR}/mode716d.obj\ + ${VIDEODIR}/mode716e.obj ${VIDEODIR}/mode716t.obj ${VIDEODIR}/mode7.obj\ + ${VIDEODIR}/mode7ext.obj ${VIDEODIR}/mv16tms.obj ${VIDEODIR}/newg162.obj\ + ${VIDEODIR}/newgfx16.obj ${VIDEODIR}/newgfx2.obj ${VIDEODIR}/newgfx.obj\ + ${VIDEODIR}/m716text.obj ${VIDEODIR}/2xsaiw.obj ${VIDEODIR}/2xsai.obj\ + ${VIDEODIR}/procvid.obj + +WINOBJ=${WINDIR}/copyvwin.obj ${WINDIR}/winintrf.obj ${WINDIR}/winlink.obj\ + ${WINDIR}/zloaderw.obj ${WINDIR}/ztcp.obj ${WINDIR}/zipxw.obj\ + ${WINDIR}/zfilew.obj + +WINDOSOBJ=${DOSDIR}/debug.obj ${DOSDIR}/joy.obj ${DOSDIR}/modemrtn.obj ${DOSDIR}/vesa2.obj\ + ${DOSDIR}/initvid.obj ${DOSDIR}/sw.obj ${DOSDIR}/gppro.obj ${DOSDIR}/vesa12.obj + +PREOBJ=${OBJDIR}/unzip.obj ${OBJDIR}/zzip.obj ${DOSDIR}/zsipx.obj + +MAINOBJ=cfgload.obj endmem.obj fixsin.obj init.obj ui.obj vcache.obj water.obj + + + +OBJS=${CHIPSOBJ} ${CPUOBJ} ${WINOBJ} ${GUIOBJ} ${VIDEOBJ} ${PREOBJ} ${MAINOBJ} ${WINDOSOBJ} +LIBS= +CFLAGS=/c +ASM=nasm +ASMFLAGS=-f win32 +CC=cl + +.SUFFIXES: .c .cpp .asm + +%.obj : %.c + ${CC} ${CFLAGS} /Fo$@ $< + +%.obj: %.cpp + ${CC} ${CFLAGS} /Fo$@ $< + +%.obj: %.asm + ${ASM} ${ASMFLAGS} -o $@ $< + + +ALL: zsnesw.exe + +zsnesw.exe: ${OBJS} ${WINDIR}/zsnes.res + cl @link.win32 ${WINDIR}/zsnes.res /link /libpath:${DXDIR}\lib + +${WINDIR}/zsnes.res: ${WINDIR}/zsnes.rc + rc ${WINDIR}/zsnes.rc +${WINDIR}/copyvwin.obj: ${WINDIR}/copyvwin.asm macros.mac +${WINDIR}/winintrf.obj: ${WINDIR}/winintrf.asm macros.mac +${WINDIR}/zfilew.obj: ${WINDIR}/zfilew.c +${WINDIR}/zipxw.obj: ${WINDIR}/zipxw.c +${WINDIR}/zloaderw.obj: ${WINDIR}/zloaderw.c +${WINDIR}/ztcp.obj: ${WINDIR}/ztcp.c +${WINDIR}/winlink.obj: ${WINDIR}/winlink.cpp ${WINDIR}/resource.h +${DOSDIR}/initvid.o:${DOSDIR}/initvid.asm macros.mac +${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac +${DOSDIR}/zsipx.o: ${DOSDIR}/zsipx.asm +${DOSDIR}/debug.obj: ${DOSDIR}/debug.asm macros.mac +${DOSDIR}/joy.obj: ${DOSDIR}/joy.asm macros.mac +${DOSDIR}/vesa2.obj: ${DOSDIR}/vesa2.asm macros.mac +${DOSDIR}/gppro.o: ${DOSDIR}/gppro.asm macros.mac +${DOSDIR}/sw.o: ${DOSDIR}/sw.asm macros.mac +${DOSDIR}/vesa12.o: ${DOSDIR}/vesa12.asm macros.mac +fixsin.obj: fixsin.c +water.obj: water.c +${VIDEODIR}/2xsaiw.obj: ${VIDEODIR}/2xsaiw.asm macros.mac +${VIDEODIR}/2xsai.obj: ${VIDEODIR}/2xsai.cpp +${VIDEODIR}/procvid.obj: ${VIDEODIR}/procvid.asm macros.mac ${VIDEODIR}/copyvid.inc ${VIDEODIR}/2xSaImmx.inc +${CHIPDIR}/sa1regs.obj: ${CHIPDIR}/sa1regs.asm macros.mac\ + ${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac +${CHIPDIR}/sfxproc.obj: ${CHIPDIR}/sfxproc.asm macros.mac\ + ${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac + +${CHIPDIR}/dsp1emu.obj: ${CHIPDIR}/dsp1emu.c betauser.mac +${CHIPDIR}/dsp1proc.obj: ${CHIPDIR}/dsp1proc.asm macros.mac +ui.obj: ui.asm macros.mac betauser.mac +cfgload.obj:cfgload.asm macros.mac +init.obj:init.asm macros.mac +${DOSDIR}/debug.obj: ${DOSDIR}/debug.asm macros.mac +${CPUDIR}/addrni.obj: ${CPUDIR}/addrni.asm +${CPUDIR}/execute.obj: ${CPUDIR}/execute.asm macros.mac +${CPUDIR}/table.obj: ${CPUDIR}/table.asm ${CPUDIR}/65816d.inc\ + ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816.inc\ + ${CPUDIR}/regs.mac ${CPUDIR}/regs.inc ${CPUDIR}/regsw.mac\ + ${CPUDIR}/regsw.inc macros.mac +${CPUDIR}/tableb.obj: ${CPUDIR}/tableb.asm ${CPUDIR}/65816db.inc\ + ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816b.inc\ + ${CPUDIR}/regs.mac macros.mac +${CPUDIR}/tablec.obj: ${CPUDIR}/tablec.asm ${CPUDIR}/65816dc.inc\ + ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816c.inc\ + ${CPUDIR}/regs.mac macros.mac +${CPUDIR}/stable.obj: ${CPUDIR}/stable.asm ${CPUDIR}/s65816d.inc\ + ${CPUDIR}/saddress.inc ${CPUDIR}/saddrni.inc ${CPUDIR}/se65816.inc\ + macros.mac +${CPUDIR}/memory.obj: ${CPUDIR}/memory.asm macros.mac +${CPUDIR}/dma.obj: ${CPUDIR}/dma.asm macros.mac +${DOSDIR}/dosintrf.obj: ${DOSDIR}/dosintrf.asm macros.mac +vcache.obj:vcache.asm macros.mac +${DOSDIR}/initvid.obj:${DOSDIR}/initvid.asm macros.mac +${VIDEODIR}/makevid.obj: ${VIDEODIR}/makevid.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/makev16b.obj: ${VIDEODIR}/makev16b.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/makev16t.obj: ${VIDEODIR}/makev16t.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/mv16tms.obj: ${VIDEODIR}/mv16tms.asm ${VIDEODIR}/vidmacro.mac\ + macros.mac +${VIDEODIR}/mode7.obj: ${VIDEODIR}/mode7.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode716.obj: ${VIDEODIR}/mode716.asm ${VIDEODIR}/mode716.mac\ + macros.mac +${VIDEODIR}/mode716b.obj:${VIDEODIR}/mode716b.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode716t.obj:${VIDEODIR}/mode716t.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode716d.obj:${VIDEODIR}/mode716d.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${VIDEODIR}/mode7ext.obj:${VIDEODIR}/mode7ext.asm macros.mac +${VIDEODIR}/mode716e.obj:${VIDEODIR}/mode716e.asm macros.mac +${VIDEODIR}/m716text.obj:${VIDEODIR}/m716text.asm ${VIDEODIR}/mode7.mac\ + macros.mac +${CPUDIR}/irq.obj: ${CPUDIR}/irq.asm macros.mac +${CPUDIR}/dspproc.obj: ${CPUDIR}/dspproc.asm macros.mac +${CPUDIR}/spc700.obj:${CPUDIR}/spc700.asm macros.mac\ + ${CPUDIR}/regsw.mac ${CPUDIR}/spcdef.inc ${CPUDIR}/spcaddr.inc +${CPUDIR}/dsp.obj: ${CPUDIR}/dsp.asm macros.mac +${DOSDIR}/vesa2.obj: ${DOSDIR}/vesa2.asm macros.mac +${DOSDIR}/vesa12.obj: ${DOSDIR}/vesa12.asm macros.mac +${DOSDIR}/joy.obj: ${DOSDIR}/joy.asm macros.mac +${DOSDIR}/sw.obj: ${DOSDIR}/sw.asm macros.mac +${GUIDIR}/gui.obj: ${GUIDIR}/gui.asm ${GUIDIR}/guitools.inc\ + ${GUIDIR}/guimisc.inc ${GUIDIR}/guimouse.inc ${GUIDIR}/guiwindp.inc\ + ${GUIDIR}/guinetpl.inc ${GUIDIR}/guikeys.inc ${GUIDIR}/guicheat.inc\ + ${GUIDIR}/guicombo.inc ${GUIDIR}/guiload.inc macros.mac +${GUIDIR}/menu.obj: ${GUIDIR}/menu.asm macros.mac +${VIDEODIR}/newgfx.obj:${VIDEODIR}/newgfx.asm ${VIDEODIR}/vidmacro.mac\ + ${VIDEODIR}/newgfx2.mac ${VIDEODIR}/newgfx.mac macros.mac +${VIDEODIR}/newgfx2.obj:${VIDEODIR}/newgfx2.asm ${VIDEODIR}/newgfxwn.mac\ + ${VIDEODIR}/newgfx.mac macros.mac +${VIDEODIR}/newgfx16.obj: ${VIDEODIR}/newgfx16.asm macros.mac ${VIDEODIR}/vidmacro.mac\ + ${VIDEODIR}/newgfx16.mac ${VIDEODIR}/newg162.mac +${VIDEODIR}/newg162.obj: macros.mac ${VIDEODIR}/newg162.asm ${VIDEODIR}/newg162.mac\ + ${VIDEODIR}/vidmacro.mac ${VIDEODIR}/newg16wn.mac +${CHIPDIR}/fxemu2.obj: ${CHIPDIR}/fxemu2.asm ${CHIPDIR}/fxemu2.mac\ + macros.mac +${CHIPDIR}/fxemu2b.obj: ${CHIPDIR}/fxemu2b.asm ${CHIPDIR}/fxemu2.mac\ + ${CHIPDIR}/fxemu2b.mac +${CHIPDIR}/fxemu2c.obj: ${CHIPDIR}/fxemu2c.asm macros.mac ${CHIPDIR}/fxemu2.mac\ + ${CHIPDIR}/fxemu2b.mac ${CHIPDIR}/fxemu2c.mac +${CHIPDIR}/fxtable.obj: ${CHIPDIR}/fxtable.asm macros.mac +${DOSDIR}/gppro.obj: ${DOSDIR}/gppro.asm macros.mac +${DOSDIR}/zsipx.obj: ${DOSDIR}/zsipx.asm +${CHIPDIR}/sa1proc.obj: ${CHIPDIR}/sa1proc.asm macros.mac +endmem.obj: endmem.asm macros.mac +${DOSDIR}/modemrtn.obj: ${DOSDIR}/modemrtn.asm macros.mac + +clean: + del *.obj + del ${CHIPDIR}\*.obj + del ${CPUDIR}\*.obj + del ${VIDEODIR}\*.obj + del ${GUIDIR}\*.obj + del ${WINDIR}\*.obj + del ${WINDIR}\zsnes.res + del ${DOSDIR}\*.obj + del zsnesw.exe + + \ No newline at end of file diff --git a/zsnes/src/ui.asm b/zsnes/src/ui.asm new file mode 100644 index 00000000..a165a9b1 --- /dev/null +++ b/zsnes/src/ui.asm @@ -0,0 +1,1330 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM getcfg,soundon,SBHDMA,StereoSound,init,GUIRestoreVars,GUIClick,MouseDis +EXTSYM ConvertJoyMap,ConvertJoyMap1,ConvertJoyMap2,printhex,InitSPC +EXTSYM StartUp,PrintStr,WaitForKey,PrintChar,MMXCheck,ZFileSystemInit +EXTSYM SPCDisable,SystemInit,allocmem +EXTSYM xa +EXTSYM SBPort,SBInt,SBIrq,SBDMA,SBDMAPage,SBHDMAPage,getenv +EXTSYM ram7fa,wramdataa +EXTSYM malloc,free +EXTSYM StateBackup +EXTSYM OSPort +EXTSYM ADSRGAINSwitch,FPUCopy,ScreenScale,SoundQuality +EXTSYM debugger,pl1contrl,pl2contrl,romtype,smallscreence +EXTSYM smallscreenon,spcon +EXTSYM statefileloc,LatestSave +EXTSYM Open_File, Get_File_Date, Close_File, Change_Dir, Get_Dir +EXTSYM romloadskip +EXTSYM cfgloadgdir,cfgloadsdir +EXTSYM init18_2hz + +%include "betauser.mac" + + + + + + +; Function 0501h +; User Interface +; Search for CMDLINE= for commandline entry +SECTION .text + +NEWSYM zstart + call StartUp + + mov edx,welcome ;welcome message + call PrintStr + + call SystemInit + + cld ;clear direction flag + + call setnoise + call InitSPC + mov byte[soundon],1 + call allocmem ;allocate memory + +; xor eax,eax +; mov al,[soundon] +; call printnum + +; jmp DosExit + + cmp byte[soundon],0 + jne .yessound + cmp byte[SPCDisable],1 + je .yessound + mov byte[soundon],1 + mov byte[spcon],1 + mov byte[DSPDisable],1 +.yessound + cmp byte[SPCDisable],1 + jne .nodissound + mov byte[soundon],0 + mov byte[spcon],0 +.nodissound + + mov al,[gammalevel] + shr al,1 + mov [gammalevel16b],al + call MMXCheck + + mov edx,.failedalignc + mov eax,outofmemory + test eax,3h + jnz .failalign + mov edx,.failedalignd + mov eax,xa + test eax,3h + jnz .failalign + jmp init +.failalign + push eax + call PrintStr + pop eax + and eax,1Fh + call printnum + call WaitForKey + jmp init + +.failedalignd db 'Data Alignment Failure : ',0 +.failedalignc db 'Code Alignment Failure : ',0 + +ALIGN32 +NEWSYM outofmemory + mov edx,outofmem + call PrintStr + jmp DosExit + +;SECTION .data +NEWSYM outofmem, db 'You don',39,'t have enough memory to run this program!',13,10,0 +%define ZVERSION '17b ' +;%define ZBETA 0 +NEWSYM welcome + + +%ifdef ZBETA + db 'ZSNES v1.',ZVERSION,' beta (c)1997-2001, Compiled under NASM, GCC, and WDOSX',13,10 + db 'PRIVATE BETA VERSION!!! PLEASE DO NOT DISTRIBUTE!!! Thank you!',13,10 + db 'Private Beta is Registered to : ',USERNAMEN,13,10 +%else + db 'ZSNES v1.',ZVERSION,' beta (c)1997-2001 ZSNES Team (zsKnight - _Demo_)',13,10 + db 'Compiled under NASM, GCC, and WDOSX',13,10,13,10 +%endif + db ' Programmers : zsKnight, _Demo_',13,10 + db ' Assistant Coder : Pharos',13,10,13,10 + db 'ZSNES comes with ABSOLUTELY NO WARRANTY. This is free software,',10,13 + db 'and you are welcome to redistribute it under certain conditions;',10,13 + db 'check licence.txt.',10,13,10,13 + db 'Use ZSNES -? for command line definitions',13,10,13,10,0 + + +; global variables +NEWSYM string, times 512 db 0 +NEWSYM fname, times 512 db 0 +NEWSYM fnames, times 512 db 0 ; sram filename +NEWSYM fnamest, times 512 db 0 ; state filename + +ALIGN32 +NEWSYM prevvid, dd 0 +NEWSYM selc0040, dd 0 +NEWSYM selcA000, dd 0 +NEWSYM selcB800, dd 0 +NEWSYM filefound, dd 0 ; Parameter String Found +NEWSYM prevdash, dd 0 ; Previous Dash Value +NEWSYM frameskip, dd 0 ; 0 = Auto, 1-10 = Skip 0 .. 9 +NEWSYM per2exec, dd 100 ; percentage of opcodes to execute +NEWSYM vidbuffer, dd 0 ; video buffer (1024x239 = 244736) +NEWSYM ngwinptr, dd 0 +NEWSYM vidbufferm, dd 0 ; video buffer mirror +NEWSYM vidbufferofsa, dd 0 ; offset 1 +NEWSYM vidbufferofsb, dd 0 ; offset 2 +NEWSYM vidbufferofsc, dd 0 ; offset 2 +NEWSYM vidbufferofsmos, dd 0 ; mosaic offset for new graphics engine +NEWSYM headdata, dd 0 +NEWSYM romdata, dd 0 ; rom data (4MB = 4194304) +NEWSYM sfxramdata, dd 0 ; SuperFX Ram Data +NEWSYM wramdata, dd 0 ; stack (64K = 32768) +NEWSYM ram7f, dd 0 ; ram @ 7f = 65536 +NEWSYM vram, dd 0 ; vram = 65536 +NEWSYM sram, dd 0 ; sram = 32768 +NEWSYM spritetablea, dd 0 ; +NEWSYM spcBuffera, dd 0 ; +NEWSYM debugbuf, dd 0 ; debug buffer = 38x1000 = 38000 +NEWSYM regptr, dd 0 ; pointer to registers +NEWSYM regptw, dd 0 ; pointer to registers +NEWSYM vcache2b, dd 0 ; 2-bit video cache +NEWSYM vcache4b, dd 0 ; 4-bit video cache +NEWSYM vcache8b, dd 0 ; 8-bit video cache +NEWSYM vcache2bs, dd 0 ; 2-bit video secondary cache +NEWSYM vcache4bs, dd 0 ; 4-bit video secondary cache +NEWSYM vcache8bs, dd 0 ; 8-bit video secondary cache +NEWSYM romispal, db 0 ; 0 = NTSC, 1 = PAL +NEWSYM enterpress, db 0 ; if enter is to be issued (0 = yes) +NEWSYM SoundCompD, db 1 ; Disable Sound Compression Buffering (1=y) +NEWSYM newgfx16b, db 0 +NEWSYM BitConv32Ptr, dd 0 + +NEWSYM previdmode, db 0 ; previous video mode +NEWSYM cvidmode, db 1 ; video mode, 0=320x240, 1=256x256 +NEWSYM cbitmode, db 0 ; bit mode, 0=8bit, 1=16bit +NEWSYM opexec268, db 171 ; # of opcodes/scanline in 2.68Mhz mode +NEWSYM opexec358, db 180 ; # of opcodes/scanline in 3.58Mhz mode (228/180) +NEWSYM opexec268cph, db 42 ; # of opcodes/hblank in 2.68Mhz mode +NEWSYM opexec358cph, db 45 ; # of opcodes/hblank in 3.58Mhz mode (56/50) +NEWSYM opexec268b, db 171 ; # of opcodes/scanline in 2.68Mhz mode +NEWSYM opexec358b, db 180 ; # of opcodes/scanline in 3.58Mhz mode (228/180) +NEWSYM opexec268cphb, db 42 ; # of opcodes/hblank in 2.68Mhz mode +NEWSYM opexec358cphb, db 45 ; # of opcodes/hblank in 3.58Mhz mode (56/50) +NEWSYM debugdisble, db 1 ; debugger disable. 0 = no, 1 = yes +NEWSYM gammalevel, db 0 ; gamma level +NEWSYM gammalevel16b, db 0 ; gamma level +NEWSYM scanlines, db 0 ; scanlines on/off +NEWSYM vsyncon, db 0 ; vsync on/off +NEWSYM guioff, db 0 ; gui off (1) +NEWSYM AddSub256, db 0 ; screen add/sub in 256 colors +NEWSYM Sup48mbit, db 1 ; Support 48mbit roms +NEWSYM Sup16mbit, db 0 ; Support 16mbit roms +NEWSYM dmadeddis, db 0 ; DMA deduction +NEWSYM antienab, db 0 ; Interpolation Enabled +NEWSYM snesmouse, db 0 ; Mouse enabled (=1) +NEWSYM OldStyle, db 1 ; Old style joystick on +NEWSYM SecondPort, db 0 ; Secondary Joystick Port Enabled (209h) + +; New Variables +NEWSYM ForcePal, db 0 ; 1 = NTSC, 2 = PAL +NEWSYM Force8b, db 0 ; Force 8-bit sound on +NEWSYM dssel, dw 0 +NEWSYM Doublevbuf, db 1 ; Double video buffer +NEWSYM V8Mode, db 0 ; Vegetable mode! =) +NEWSYM fastmemptr, db 0 +NEWSYM showallext, db 0 +NEWSYM finterleave, db 0 +NEWSYM DSPDisable, db 0 +NEWSYM Palette0, db 0 +NEWSYM DisplayS, db 0 +NEWSYM SPC700sh, db 0 +NEWSYM OffBy1Line, db 0 +NEWSYM DosPort, db 3 +NEWSYM spc7110romptr, dd 0 + +NEWSYM MusicRelVol, db 75 +NEWSYM MusicVol, db 0 +;NEWSYM BetaUser, db 37,38,210,56,78,23,7,7,0 + +;SECTION .text + +;******************************************************* +; Set Noise Data +;******************************************************* + +NEWSYM setnoise + mov edi,NoiseData + mov ebx,256 + mov ecx,128 + xor esi,esi + xor edx,edx +.next + mov al,[.samplenoise+esi] + add al,[.samplenoise+edx] + mov [edi],al + inc edi + inc esi + and esi,07Fh + dec edx + and edx,07Fh + dec ecx + jnz .next + dec edx + and edx,07Fh + mov ecx,128 + dec ebx + jnz .next + ret + +SECTION .data +.samplenoise + db 27,232,234,138,187,246,176,81,25,241,1,127,154,190,195,103,231,165,220,238 + db 232,189,57,201,123,75,63,143,145,159,13,236,191,142,56,164,222,80,88,13 + db 148,118,162,212,157,146,176,0,241,88,244,238,51,235,149,50,77,212,186,241 + db 88,32,23,206,1,24,48,244,248,210,253,77,19,100,83,222,108,68,11,58 + db 152,161,223,245,4,105,3,82,15,130,171,242,141,2,172,218,152,97,223,157 + db 93,75,83,238,104,238,131,70,22,252,180,82,110,123,106,133,183,209,48,230 + db 157,205,27,21,107,63,85,164 +SECTION .text + +;******************************************************* +; Allocate Memory, ebx = size,eax returned = LFB pointer +;******************************************************* + +NEWSYM AllocMem + mov ax,0501h + mov cx,bx + shr ebx,16 + int 31h + jc near outofmemory + mov ax,bx + shl eax,16 + mov ax,cx + ret + +;******************************************************* +; Get Command Line Locates SET CMDLINE environment +;******************************************************* + +NEWSYM getcmdline + mov edx,.string2s + push edx + call getenv + pop edx + cmp eax,0 + je near .nfound + mov esi,eax + mov edi,CMDLineStr + cmp byte[esi],0 + je near .nfound +.a + mov dl,[esi] + cmp dl,'a' + jb .nocap + cmp dl,'z' + ja .nocap + sub dl,'a'-'A' +.nocap + mov [edi],dl + mov [edi+256],dl + inc esi + inc edi + cmp dl,32 + je .b + cmp dl,0 + jne .a +.b + mov esi,CMDLineStr + mov eax,CMDLineStr +.next2 + cmp eax,edi + je .nomore + cmp byte[eax],'\' + je .found + cmp byte[eax],':' + jne .next +.found + mov esi,eax + inc esi +.next + inc eax + jmp .next2 +.nomore + mov [FilenameStart],esi + mov byte[esi],'Z' + mov byte[esi+1],'S' + mov byte[esi+2],'N' + mov byte[esi+3],'E' + mov byte[esi+4],'S' + mov byte[esi+5],'.' + mov byte[esi+6],'C' + mov byte[esi+7],'F' + mov byte[esi+8],'G' + mov byte[esi+9],0 + mov byte[esi+256],'Z' + mov byte[esi+1+256],'G' + mov byte[esi+2+256],'U' + mov byte[esi+3+256],'I' + mov byte[esi+4+256],'C' + mov byte[esi+5+256],'F' + mov byte[esi+6+256],'G' + mov byte[esi+7+256],'.' + mov byte[esi+8+256],'D' + mov byte[esi+9+256],'A' + mov byte[esi+10+256],'T' + mov byte[esi+11+256],0 + mov byte[esi+512],'D' + mov byte[esi+1+512],'A' + mov byte[esi+2+512],'T' + mov byte[esi+3+512],'A' + mov byte[esi+4+512],'.' + mov byte[esi+5+512],'C' + mov byte[esi+6+512],'M' + mov byte[esi+7+512],'B' + mov byte[esI+8+512],0 + ret +.nfound + mov edx,.stringnf + call PrintStr + mov esi,CMDLineStr + mov [FilenameStart],esi + mov byte[esi],'Z' + mov byte[esi+1],'S' + mov byte[esi+2],'N' + mov byte[esi+3],'E' + mov byte[esi+4],'S' + mov byte[esi+5],'.' + mov byte[esi+6],'C' + mov byte[esi+7],'F' + mov byte[esi+8],'G' + mov byte[esi+9],0 + mov byte[esi+256],'Z' + mov byte[esi+1+256],'G' + mov byte[esi+2+256],'U' + mov byte[esi+3+256],'I' + mov byte[esi+4+256],'C' + mov byte[esi+5+256],'F' + mov byte[esi+6+256],'G' + mov byte[esi+7+256],'.' + mov byte[esi+8+256],'D' + mov byte[esi+9+256],'A' + mov byte[esi+10+256],'T' + mov byte[esi+11+256],0 + mov byte[esi+512],'D' + mov byte[esi+1+512],'A' + mov byte[esi+2+512],'T' + mov byte[esi+3+512],'A' + mov byte[esi+4+512],'.' + mov byte[esi+5+512],'C' + mov byte[esi+6+512],'M' + mov byte[esi+7+512],'B' + mov byte[esI+8+512],0 + ret + +SECTION .data +.string2s db 'CMDLINE',0 +.stringnf db 'SET CMDLINE LINE NOT FOUND!',0 + +NEWSYM CMDLineStr, times 256 db 0 +NEWSYM GUIFName, times 256 db 0 +NEWSYM GUICName, times 256 db 0 +NEWSYM FilenameStart, dd 0 + +SECTION .text + +;******************************************************* +; Get Blaster Locates SET BLASTER environment +;******************************************************* +NEWSYM getblaster + mov edx,.string2s + push edx + call getenv + pop edx + cmp eax,0 + je near .nfound + + mov esi,eax + mov byte[.cursetting],0 +.a + mov dl,[esi] + cmp dl,'a' + jb .nocap + cmp dl,'z' + ja .nocap + sub dl,'a'-'A' +.nocap + inc esi + mov byte[.blfound],1 + cmp dl,'A' + jne .afound + mov byte[.cursetting],1 + mov word[SBPort],0 + jmp .src +.afound + cmp dl,'I' + jne .ifound + mov byte[.cursetting],2 + mov byte[SBIrq],0 + jmp .src +.ifound + cmp dl,'D' + jne .dfound + mov byte[.cursetting],3 + mov byte[SBDMA],0 + jmp .src +.dfound + cmp dl,'H' + jne .hfound + mov byte[.cursetting],4 + mov byte[SBHDMA],0 + jmp .src +.hfound + cmp dl,' ' + je .src2 + cmp dl,0 + je .src2 + jmp .src3 +.src2 + mov byte[.cursetting],0 + jmp .src +.src3 + cmp byte[.cursetting],1 + jne .nproca + shl word[SBPort],4 + sub dl,48 + add byte[SBPort],dl + add dl,48 +.nproca + cmp byte[.cursetting],2 + jne .nproci + cmp byte[SBIrq],1 + jne .no1 + mov byte[SBIrq],10 +.no1 + sub dl,48 + add [SBIrq],dl + add dl,48 +.nproci + cmp byte[.cursetting],3 + jne .nprocd + sub dl,48 + mov [SBDMA],dl + add dl,48 +.nprocd + cmp byte[.cursetting],4 + jne .nproch + sub dl,48 + mov [SBHDMA],dl + add dl,48 +.nproch +.src + cmp dl,0 + jne near .a + cmp byte[.blfound],0 + je near .nfound + cmp byte[SBIrq],2 + jne .noirq9 + mov byte[SBIrq],9 +.noirq9 + mov al,[SBIrq] + add al,08h + cmp byte[SBIrq],7 + jbe .nohighirq + add al,60h + add byte[PICRotateP],80h + add byte[PICMaskP],80h +.nohighirq + mov [SBInt],al + cmp byte[SBDMA],0 + jne .dma0 + mov byte[SBDMAPage],87h +.dma0 + cmp byte[SBDMA],1 + jne .dma1 + mov byte[SBDMAPage],83h +.dma1 + cmp byte[SBDMA],2 + jne .dma2 + mov byte[SBDMAPage],81h +.dma2 + cmp byte[SBDMA],3 + jne .dma3 + mov byte[SBDMAPage],82h +.dma3 + cmp byte[SBHDMA],4 + jae .hdma + mov byte[SBHDMA],0 +.hdma + cmp byte[SBHDMA],4 + jne .hdma4 + mov byte[SBHDMAPage],8Fh +.hdma4 + cmp byte[SBHDMA],5 + jne .hdma5 + mov byte[SBHDMAPage],8Bh +.hdma5 + cmp byte[SBHDMA],6 + jne .hdma6 + mov byte[SBHDMAPage],89h +.hdma6 + cmp byte[SBHDMA],7 + jne .hdma7 + mov byte[SBHDMAPage],8Ah +.hdma7 + cmp byte[DisplayS],1 + je .displaysoundstuff + ret +.nfound + cmp byte[soundon],0 + je .nosound + mov byte[soundon],0 + mov edx, .blasterstr + call PrintStr + call WaitForKey +.nosound + ret +.displaysoundstuff + mov edx,.blasterinfo + call PrintStr + xor eax,eax + mov ax,[SBPort] + call printhex + mov edx,.blinfob + call PrintStr + xor eax,eax + mov al,[SBIrq] + call printnum + mov edx,.blinfoc + call PrintStr + xor eax,eax + mov al,[SBDMA] + call printnum + mov edx,.blinfod + call PrintStr + xor eax,eax + mov al,[SBHDMA] + call printnum + mov edx,.blasterstr2b + call PrintStr + call WaitForKey + ret + +SECTION .data +.string2s db 'BLASTER',0 +.blfound db 0 +.blasterstr db 'ERROR : SET BLASTER environment NOT found!',10,13 +.blasterstr2 db 'Unable to enable sound.' +.blasterstr2b db 10,13,10,13 +.blasterstr3 db 'Press any key to continue.',0 +.blasterinfo db 'Sound Blaster Detection Values : ',10,13,10,13 +.blinfoa db 'PORT : ',0 +.blinfob db 13,10,'IRQ : ',0 +.blinfoc db 13,10,'DMA : ',0 +.blinfod db 13,10,'HDMA : ',0 +.cursetting db 0 + +NEWSYM PICRotateP, db 20h +NEWSYM PICMaskP, db 21h +SECTION .text +;******************************************************* +; Variable section +;******************************************************* + +SECTION .data + +ALIGN32 + +NEWSYM vrama, times 65536 db 0 +NEWSYM mode7tab, times 65536 db 0 +NEWSYM srama, times 65536 db 0 +NEWSYM debugbufa, times 10000 db 0 +NEWSYM regptra, times 49152 db 0 +NEWSYM regptwa, times 49152 db 0 + +; vcache.asm + +; table.asm + +; vesa2.asm + +NEWSYM fulladdtab, times 65536 dw 0 + +; init.asm +NEWSYM echobuf, times 90000 db 0 + +; dspproc.asm + +NEWSYM spcRamcmp, times 65536 db 0 +NEWSYM VolumeConvTable, times 32768 dw 0 +NEWSYM dspWptr, times 256 dd 0 +NEWSYM dspRptr, times 256 dd 0 +NEWSYM NoiseData, times 32768 db 0 + +; makevid.asm + +; makevid.asm +NEWSYM vcache2ba, times 262144+256 db 0 +NEWSYM vcache4ba, times 131072+256 db 0 +NEWSYM vcache8ba, times 65536+256 db 0 + +ZSNESBase dd 0 +BlockSize dd 0 ; Set before calling +LinearAddress dd 0 ; Returned by function +BlockHandle dd 0 ; Returned by function +ZSNESAddress dd 0 ; Returned by function + +SECTION .text + +;******************************************************* +; Allocate Pointer Sets variables with pointer values +;******************************************************* + + +AllocateLDTDescriptor: +;Get ZSNES Base + mov ax,ds + mov bx,ax + mov eax,0006h + int 31h + jc .FatalError + mov [ZSNESBase+2],cx + mov [ZSNESBase],dx + ret +.FatalError +; maybe dosexit? + ret + + +AllocateBlock: + mov eax,0501h + mov bx,[BlockSize+2] + mov cx,[BlockSize] + int 31h + jc .FatalError + mov [LinearAddress+2],bx + mov [LinearAddress],cx + mov [BlockHandle+2],si + mov [BlockHandle],di + mov eax,[LinearAddress] + sub eax,[ZSNESBase] + and eax,0FFFFFFE0h + add eax,40h + mov [ZSNESAddress],eax + xor ebx,ebx + ret +.FatalError + mov ebx,1 + ret + + +SECTION .data + +ALIGN32 +vbufaptr dd 0 +vbufeptr dd 0 +ngwinptrb dd 0 +romaptr dd 0 +vbufcptr dd 0 +NEWSYM vbufdptr, dd 0 +vc2bptr dd 0 +vc4bptr dd 0 +vc8bptr dd 0 +cmemallocptr dd 0 +memfreearray times 12 dd 0 + +SECTION .text + + + + +%macro AllocmemFail 3 + mov ebx,%1 + add ebx,1000h + push ebx + call malloc + pop ebx + cmp eax,0 + je near %3 + mov ebx,dword[cmemallocptr] + add dword[cmemallocptr],4 + mov [ebx],eax + and eax,0FFFFFFE0h + add eax,40h + mov [%2],eax +%endmacro + +%macro AllocmemOkay 3 + mov ebx,%1 + add ebx,1000h + push ebx + call malloc + pop ebx + push eax + and eax,0FFFFFFE0h + add eax,40h + mov [%2],eax + pop eax + cmp eax,0 + je %%nomalloc + mov ebx,dword[cmemallocptr] + add dword[cmemallocptr],4 + mov [ebx],eax +%%nomalloc + cmp eax,0 + jne near %3 +%endmacro + +NEWSYM allocspc7110 + AllocmemFail 8192*1024+4096,spc7110romptr,outofmemoryb + ret + +outofmemoryb + cmp byte[OSPort],1 + ja .notdos + mov ax,3 + int 10h +.notdos + jmp outofmemory + +NEWSYM allocptr + mov dword[cmemallocptr],memfreearray + + + cmp byte[OSPort],3 + jne near .nostate + AllocmemFail 4096*128*16+4096+65536*16,StateBackup,outofmemory + mov eax,[StateBackup] + add eax,4096*128*16 + mov [BitConv32Ptr],eax +.nostate + + ; Memory Allocation + AllocmemFail 65536*4+4096,spcBuffera,outofmemory + AllocmemFail 256*512+4096,spritetablea,outofmemory + AllocmemFail 512*296*4+4096+512*296,vbufaptr,outofmemory + AllocmemFail 288*2*256+4096,vbufeptr,outofmemory + AllocmemFail 256*224+4096,ngwinptrb,outofmemory + AllocmemFail 1024*296,vbufdptr,outofmemory + AllocmemFail 65536*4*4+4096,vcache2bs,outofmemory + AllocmemFail 65536*4*2+4096,vcache4bs,outofmemory + AllocmemFail 65536*4+4096,vcache8bs,outofmemory + mov byte[newgfx16b],1 + AllocmemOkay 4096*1024+32768*2+2048*1024+4096,romaptr,.memoryokay + mov byte[Sup48mbit],0 + AllocmemOkay 4096*1024+32768*2+4096,romaptr,.donememalloc + mov byte[Sup16mbit],1 + AllocmemOkay 2048*1024+32768*2+4096,romaptr,.donememalloc + jmp outofmemory +.memoryokay +.donememalloc + + ; Set up memory values + mov eax,[vbufaptr] + and eax,0FFFFFFF8h + add eax,8 + mov dword[vidbuffer],eax + mov dword[vidbufferofsa],eax + add eax,75036 + mov dword[vidbufferofsmos],eax + + mov eax,[ngwinptrb] + and eax,0FFFFFFF8h + add eax,2048 + mov [ngwinptr],eax + + mov eax,[vbufeptr] + and eax,0FFFFFFF8h + add eax,8 + mov dword[vidbufferofsb],eax + + mov eax,[vbufdptr] + and eax,0FFFFFFF8h + add eax,8 + mov dword[vidbufferofsc],eax + + mov eax,[romaptr] + and eax,0FFFFFFF8h + add eax,8 + mov dword[headdata],eax + mov dword[romdata],eax + add eax,4194304 + mov dword[sfxramdata],eax + + mov esi,[romdata] + cmp byte[Sup48mbit],0 + je .no48mbit + add esi,4096*1024+2048*1024 + jmp .done +.no48mbit + cmp byte[Sup16mbit],0 + je .no16mbit + add esi,2048*1024 + jmp .done +.no16mbit + add esi,4096*1024 +.done + mov byte[esi],58h + mov byte[esi+1],80h + mov byte[esi+2],0FEh + + mov dword[wramdata],wramdataa + mov dword[ram7f],ram7fa + mov dword[vram],vrama + mov dword[sram],srama + mov dword[debugbuf],debugbufa + mov dword[regptr],regptra + sub dword[regptr],8000h ; Since register address starts @ 2000h + mov dword[regptw],regptwa + sub dword[regptw],8000h ; Since register address starts @ 2000h + + ; 2-bit = 256k + mov eax,vcache2ba + and eax,0FFFFFFF8h + add eax,8 + mov dword[vcache2b],eax + ; 4-bit = 128k + mov eax,vcache4ba + and eax,0FFFFFFF8h + add eax,8 + mov dword[vcache4b],eax + ; 8 bit = 64k + mov eax,vcache8ba + and eax,0FFFFFFF8h + add eax,8 + mov dword[vcache8b],eax + ret + +;******************************************************* +; Print Numbers Prints # in EAX to screen +;******************************************************* +NEWSYM printnum + ; process through each digit + push edx + push eax + push ebx + push cx + xor edx,edx ; clear high byte + xor cx,cx ; clear counter variable + mov ebx,10 + .loopa + div ebx ; get quotent and remainder + push edx ; store number to stack + inc cl + xor edx,edx + test eax,0FFFFFFFFh + jnz .loopa + .loopb + pop edx ; get number back from stack + add dl,30h ; adjust to ASCII value + call PrintChar + dec cl + jnz .loopb + pop cx + pop ebx + pop eax + pop edx + ret + +NEWSYM convertnum + ; process through each digit + push edx + push eax + push ebx + push cx + xor edx,edx ; clear high byte + xor cx,cx ; clear counter variable + mov ebx,10 + .loopa + div ebx ; get quotent and remainder + push edx ; store number to stack + inc cl + xor edx,edx + test eax,0FFFFFFFFh + jnz .loopa + .loopb + pop edx ; get number back from stack + add dl,30h ; adjust to ASCII value + mov [esi],dl + inc esi + dec cl + jnz .loopb + pop cx + pop ebx + pop eax + pop edx + mov byte[esi],0 + ret + +; eax = value, ecx = # of bytes +NEWSYM converthex + mov ebx,ecx + mov ecx,4 + sub ecx,ebx + shl ecx,3 + shl eax,cl + mov ecx,ebx + xor ebx,ebx + add ecx,ecx +.loopb + mov ebx,eax + and ebx,0F0000000h + shr ebx,28 + mov dl,[.hexdat+ebx] + mov [esi],dl + inc esi + shl eax,4 + loop .loopb + mov byte[esi],0 + ret + +.hexdat db '0123456789ABCDEF' + +;******************************************************* +; Check Parameter This Processes the Parameters +;******************************************************* + +SECTION .text + +ShowIdentStr: + mov dl,[.idstrdata] + xor dl,76 + call .prst + mov dl,[.idstrdata+1] + xor dl,89 + call .prst + mov dl,[.idstrdata+2] + xor dl,178 + call .prst + mov dl,[.idstrdata+3] + xor dl,34 + call .prst + mov dl,[.idstrdata+4] + xor dl,217 + call .prst + jmp DosExit + ret +.prst + call PrintChar + ret + +SECTION .data +.idstrdata db USERNAMEC +newestfileloc db 0 +newestfiledate dd 0 +SECTION .text + +NEWSYM makeextension + xor ecx,ecx + xor ebx,ebx + xor ah,ah + mov cl,[fname] + mov [fnames],cl + mov [fnamest],cl + mov dl,cl + inc ebx +.loopc + mov al,[fname+ebx] + mov [fnames+ebx],al + mov [fnamest+ebx],al + inc ebx + inc ah + loop .loopc + ; find for '.' or '\' + mov cl,dl + mov edx,ebx +.loopz + dec edx + mov al,[fnames+edx] + cmp al,'\' + je .addext + cmp al,'.' + je .addb + dec cl + jnz .loopz + jmp .addext +.addb + mov ebx,edx +.addext + mov byte[fnames+ebx],'.' + mov byte[fnamest+ebx],'.' + inc ebx + mov byte[fnames+ebx],'S' + mov byte[fnamest+ebx],'Z' + inc ebx + mov byte[fnames+ebx],'R' + mov byte[fnamest+ebx],'S' + inc ebx + mov byte[fnames+ebx],'M' + mov byte[fnamest+ebx],'T' + mov dword[statefileloc],ebx + inc ebx + mov byte[fnames+ebx],0 + mov byte[fnamest+ebx],0 + add ah,4 + mov [fnames],ah + mov [fnamest],ah + cmp byte[LatestSave],1 + je .latestsave + ret +.latestsave + ; change dir to Save Dir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + + call DetermineNewest + + ; change dir to LoadDrive/LoadDir + mov dl,[LoadDrive] + mov ebx,LoadDir + call Change_Dir + ret + +%macro determinenewhelp 2 + mov bl,%1 + mov byte[fnamest+eax],%2 + call DetermineNew +%endmacro + + +DetermineNew: + push eax + push ebx + mov edx,fnamest+1 + call Open_File + jc near .nodraw + mov bx,ax + mov edx,fnamest+1 + call Get_File_Date + shl edx,16 + mov dx,cx + push edx + call Close_File + pop edx + pop ebx + pop eax + ; date = edx, position = bl + cmp edx,[newestfiledate] + jbe .notlatest + mov [newestfiledate],edx + mov [newestfileloc],bl +.notlatest + ret +.nodraw + pop ebx + pop eax + ret + +DetermineNewest: + mov eax,[statefileloc] + mov dword[newestfiledate],0 + mov byte[newestfileloc],0 + determinenewhelp 0,'T' + determinenewhelp 1,'1' + determinenewhelp 2,'2' + determinenewhelp 3,'3' + determinenewhelp 4,'4' + determinenewhelp 5,'5' + determinenewhelp 6,'6' + determinenewhelp 7,'7' + determinenewhelp 8,'8' + determinenewhelp 9,'9' + mov bl,[newestfileloc] + add bl,'0' + cmp bl,'0' + jne .nott + mov bl,'T' +.nott + mov [fnamest+eax],bl + ret + +;******************************************************* +; Get Parameters Get Parameters Individually +;******************************************************* + +NEWSYM tparms + .donestring + test byte[.numparam],0FFh + jz .nochars + mov al,byte[filefound] + test al,0FFh + jz .nostring + ret + + .nostring + cmp byte[guioff],0 + je .yesgui + + mov edx,.nostr + call PrintStr + jmp DosExit + + .nochars + cmp byte[guioff],0 + je .yesgui + cmp byte[fname],0 + jne .yesgui + jmp displayparams + +.yesgui + mov byte[romloadskip],1 + ret + +SECTION .data +.numparam db 0 +.nostr db 'This emulator will not work without a filename!',13,10,0 +.waitkey db 'Press Any Key to Continue.',0 +.ret db 13,10,0 + +SECTION .text +NEWSYM displayparams + mov edx,.noparams ;use extended + call PrintStr + call WaitForKey + mov edx,.noparms2 ;use extended + call PrintStr + call WaitForKey + mov edx,.noparms3 ;use extended + call PrintStr + jmp DosExit + +SECTION .data +.noparams db 'Usage : ZSNES [-d,-f #, ... ] ',13,10 + db ' Eg : ZSNES -s -r 2 game.smc',13,10,13,10 + db ' -0 Disable Color 0 modification in 256 color modes',13,10 + db ' -1 #/-2 # Select Player 1/2 Input :',13,10 + db ' 0 = None 1 = Keyboard 2 = Joystick 3 = Gamepad',13,10 + db ' 4 = 4Button 5 = 6Button 6 = Sidewinder ',13,10 + db ' -7 Disable SPC700 speedhack',13,10 + db ' -8 Force 8-bit sound',13,10 + db ' -9 Off by 1 line fix',13,10 + db ' -a Turn on auto frame skip',13,10 + db ' -c Scale to fit screen (320x240 VESA2/640x480 VESA2)',13,10 + db ' -cb Remove Background Color in 256 color video modes',13,10 + db ' -cc No image scale and center image in screen (640x480 VESA2)',13,10 + db ' -d Start with debugger',13,10 + db ' -dd Disable sound DSP emulation',13,10 + db ' -e Skip enter key press at the beginning',13,10 + db ' -f # Turn on frame skip [0..9]',13,10 + db ' -g # Set Gamma Correction [0..5, 0 = Normal]',13,10 + db ' -h Force HiROM',13,10 + db ' -i Uninterleave ROM Image',13,10 + db ' -j Disable Mouse (Automatically turns off right mouse click)',13,10 + db ' -k # Set Volume Level (0 .. 100)',13,10 + db 'Press any key to continue.',0 +.noparms2 db 13,' -l Force LoROM ',13,10 + db ' -m Disable GUI',13,10 + db ' -n Turn scanlines on (256x256 and 640x480 only)',13,10 + db ' -o Enable FPU copy ',13,10 + db ' -om Enable MMX copy',13,10 + db ' -p # Percentage of instructions to execute [50..120]',13,10 + db ' -r # Set Sampling Sound Blaster Sampling Rate & Bit :',13,10 + db ' 0 = 8000Hz 1 = 11025Hz 2 = 22050Hz 3 = 44100Hz',13,10 + db ' 4 = 16000Hz 5 = 32000Hz',13,10 + db ' -s Enable SPC700/DSP emulation (Sound)',13,10 + db ' -sa Show all extensions in GUI (*.*)',13,10 + db ' -sn Enable Snowy GUI Background',13,10 + db ' -t Force NTSC timing',13,10 + db ' -u Force PAL timing',13,10 + db ' -v # Select Video Mode :',13,10 + db ' 0 = 320x240x256 1 = 256x256x256',13,10 + db ' 2 = 320x240x256(VESA2) 3 = 320x240x16b(VESA2) ',13,10 + db ' 4 = 640x480x256(VESA2) 5 = 640x480x16b(VESA2) ',13,10 + db ' 6 = 512x384x256(VESA2) 7 = 512x384x16b(VESA2) ',13,10 + db ' 8 = 640x480x16b(VESA1.2) 9 = 320x480x256(VESA2) ',13,10 + db ' 10 = 320x480x65536(VESA2)',13,10 + db ' -w Enable VSync',13,10 + db 'Press any key to continue.',0 +.noparms3 db 13,' -y Enable EAGLE (640x480x256 only) or Interpolation (640x480x65536 only)',13,10 + db ' -z Enable Stereo Sound',13,10 + db '',13,10 + db ' File Formats Supported by GUI : .SMC,.SFC,.SWC,.FIG,.058,.078,.1,.USA,.JAP',13,10 + db '',13,10,0 + +SECTION .text + +NEWSYM obtaindir + cmp byte[cfgloadsdir],1 + je .nosdriveb + mov ebx,SRAMDir + mov edx,SRAMDrive + call Get_Dir +.nosdriveb + cmp byte[cfgloadgdir],1 + je .noldriveb + mov ebx,LoadDir + mov edx,LoadDrive + call Get_Dir +.noldriveb + ret + +NEWSYM preparedir +;Function 47h - Get current directory +;------------------------------------ +; +; AH = 47h +; DL = drive number (0 = default, 1 = A: etc.) +; DS:ESI -> 64 byte buffer to receive ASCIZ pathname +; get current drive, ah = 19h, al = A=0,B=1, etc. + + cmp byte[cfgloadsdir],0 + je near .nosdrivec + ; verify sram drive/directory exists + ; change dir to SRAMDrive/SRAMDir + mov dl,[SRAMDrive] + mov ebx,SRAMDir + call Change_Dir + jc .sramerror + jmp .yessdrive +.sramerror + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + + mov byte[cfgloadsdir],0 + ; Get drive/dir + mov ebx,SRAMDir + mov edx,SRAMDrive + call Get_Dir + + mov edx,.sramerrorm + call PrintStr + call WaitForKey + cmp al,27 + jne .noesc + jmp DosExit +.noesc + mov edx,.enter + call PrintStr + jmp .nosdrivec + +.yessdrive + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir +.nosdrivec + ret + +SECTION .data +.sramerrorm db 'Invalid SRAM Directory in ZSNES.CFG!',13,10,13,10 + db 'Press any key to continue.',0 +.enter db 13,10,0 + +NEWSYM InitDrive, db 2 +NEWSYM InitDir, times 512 db 0 +NEWSYM SRAMDrive, db 2 +NEWSYM SRAMDir, times 512 db 0 +NEWSYM LoadDrive, db 2 +NEWSYM LoadDir, times 512 db 0 + +NEWSYM gotoroot, db '\',0 + +SECTION .text + + +NEWSYM DosExit ; Terminate Program + jmp .nodeallocate + + mov ebx,memfreearray +.nextdeallocate + mov eax,[ebx] + or eax,eax + jz .nodeallocate + push ebx + push eax + call free + pop eax + pop ebx + add ebx,4 + jmp .nextdeallocate +.nodeallocate + call init18_2hz + mov ax,4c00h ;terminate + int 21h + + \ No newline at end of file diff --git a/zsnes/src/vcache.asm b/zsnes/src/vcache.asm new file mode 100644 index 00000000..c792808b --- /dev/null +++ b/zsnes/src/vcache.asm @@ -0,0 +1,3765 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM MessageOn,MsgCount,Msgptr,Voice0Disable,Voice0Status,Voice1Disable +EXTSYM Voice1Status,Voice2Disable,Voice2Status,Voice3Disable,Voice3Status +EXTSYM Voice4Disable,Voice4Status,Voice5Disable,Voice5Status,Voice6Disable +EXTSYM Voice6Status,Voice7Disable,Voice7Status,bgcmsung,bgmode,cbackofsaddr +EXTSYM cbitmode,cgmod,debuggeron,disableeffects,frameskip,frskipper,newgfxerror2 +EXTSYM maxbr,modeused,mousexloc,mouseyloc,newengen,newgfx16b,newgfxerror +EXTSYM nextdrawallng,oamaddr,pal16b,pal16bxcl,pressed,prevbright,prevpal +EXTSYM scaddsngb,scaddtngb,scaddtngbx,scfbl,scrndis,snesmouse,sprprdrn +EXTSYM t1cc,vidbright,vidbuffer,vidbufferm,vidbufferofsa,vidbufferofsb +EXTSYM vidmemch2,statefileloc,fnamest,GUIClick,MousePRClick,ngmsdraw,cvidmode +EXTSYM KeyDisableSC0,KeyDisableSC1,KeyDisableSC2,KeyDisableSC3,KeyDisableSC4 +EXTSYM KeyDisableSC5,KeyDisableSC6,KeyDisableSC7,KeyFastFrwrd,SRAMSave5Sec +EXTSYM KeyBGDisble0,KeyBGDisble1,KeyBGDisble2,KeyBGDisble3,KeySprDisble +EXTSYM KeyResetAll,KeyExtraEnab,KeyWinDisble,KeyNewGfxSwt,KeyOffsetMSw +EXTSYM KeyStateSlc0,KeyStateSlc1,KeyStateSlc2,KeyStateSlc3,KeyStateSlc4 +EXTSYM KeyStateSlc5,KeyStateSlc6,KeyStateSlc7,KeyStateSlc8,KeyStateSlc9 +EXTSYM maxskip,DSPMem,SprValAdd,dsp1ptr,dsp1array,FastFwdToggle,SaveSramData +EXTSYM ngextbg,Mode7HiRes,Check60hz,Get_MouseData,Get_MousePositionDisplacement +EXTSYM WindowDisables,scanlines,romispal +EXTSYM MusicRelVol,MusicVol,WDSPReg0C,WDSPReg1C +EXTSYM DSPOp02,Op02AAS,Op02AZS,Op02CX,Op02CY,Op02FX,Op02FY +EXTSYM Op02FZ,Op02LES,Op02LFE,Op02VOF,Op02VVA +EXTSYM CurRecv +EXTSYM CNetType +EXTSYM KeySlowDown +EXTSYM chaton +EXTSYM genfulladdtab +EXTSYM KeyFRateDown,KeyFRateUp,KeyVolUp,KeyVolDown,FPSOn +EXTSYM bg1ptr,bg2ptr,bg3ptr,bg4ptr,cachebg1,resolutn +EXTSYM curypos,oamram,objhipr,objptr,objptrn,objsize1,objsize2 +EXTSYM spritetablea,sprleftpr,sprlefttot,vcache4b +EXTSYM objadds1,objadds2,objmovs1,objmovs2,tltype4b,vidmemch4,vram +EXTSYM bgptr,bgptrc,bgptrd,curtileptr,vcache2b +EXTSYM vcache8b,vidmemch8 +EXTSYM offsetmshl +EXTSYM tltype2b +EXTSYM tltype8b + + + + + + +; Process stuff & Cache sprites + +NEWSYM fskipped, db 0 +NEWSYM objvramadder, dd 0 +NEWSYM pobjvram, dw 0 +NEWSYM sprprifix, db 1 + +ALIGN32 +NEWSYM OMBGTestVal, dd 0 +NEWSYM ngptrdat2, dd 0 +NEWSYM ofshvaladd, dd 0 +NEWSYM ofsmtptrs, dd 0 +NEWSYM ofsmcptr2, dd 0 +NEWSYM sramb4save, dd 0 +NEWSYM mode7hiresen, dd 1 +NEWSYM hiresstuff, dd 0 +NEWSYM cmovietimeint, dd 0 +NEWSYM overalltimer, dd 0 + +mousecheck db 0 + + + +%macro stateselcomp 3 + mov eax,[%1] + test byte[pressed+eax],1 + je %%nostsl + mov byte[pressed+eax],2 + mov byte[sselm+11],%2 + mov eax,[statefileloc] + mov byte[fnamest+eax],%3 + mov dword[Msgptr],sselm + mov eax,[MsgCount] + mov [MessageOn],eax +%%nostsl +%endmacro + +%macro soundselcomp 4 + mov eax,[%1] + test byte[pressed+eax],1 + je %%nosdis + xor byte[%2],01h + mov byte[%3],0 + mov byte[pressed+eax],2 + mov byte[sndchena+9],%4 + mov byte[sndchdis+9],%4 + mov dword[Msgptr],sndchena + test byte[%2],01h + jnz %%sen + mov dword[Msgptr],sndchdis +%%sen + mov eax,[MsgCount] + mov [MessageOn],eax +%%nosdis +%endmacro + + +UpdateVolume: + pushad + xor eax,eax + xor edx,edx + mov al,[MusicRelVol] + shl eax,7 + mov ebx,100 + div ebx + cmp al,127 + jb .noof + mov al,127 +.noof + mov [MusicVol],al + + mov al,[DSPMem+0Ch] + call WDSPReg0C + mov al,[DSPMem+1Ch] + call WDSPReg1C + + mov dword[vollv+14],20202020h + mov edx,vollv+15 + mov al,[MusicRelVol] + cmp al,100 + jne .no100 + mov byte[edx],49 + mov byte[edx+1],48 + sub al,100 + add edx,2 +.no100 + xor ah,ah + mov bl,10 + div bl + cmp al,0 + je .no10 + add al,48 + mov [edx],al + inc edx +.no10 + add ah,48 + mov [edx],ah + mov dword[Msgptr],vollv + mov eax,[MsgCount] + mov [MessageOn],eax + popad + ret + +ClockCounter: + inc dword[overalltimer] + cmp byte[romispal],0 + jne .dopal + cmp dword[overalltimer],60 + jne .notimer + inc dword[cmovietimeint] + sub dword[overalltimer],60 + jmp .notimer +.dopal + cmp dword[overalltimer],50 + jne .notimer + inc dword[cmovietimeint] + sub dword[overalltimer],50 +.notimer + test byte[pressed+2Eh],1 + jz .noclear + mov dword[cmovietimeint],0 + mov dword[overalltimer],0 +.noclear + ret + + +NEWSYM dsp1teststuff + ; ///////////////////////////// + mov dword[dsp1ptr],0 + push eax + push ecx + mov ecx,4096 + mov eax,dsp1array +.cvloop + mov byte[eax],0 + inc eax + loop .cvloop + pop ecx + pop eax + ret + mov eax,dsp1array + add eax,[dsp1ptr] + push ebx + mov byte[eax],02h + mov bx,[Op02FX] + mov [eax+1],bx + mov bx,[Op02FY] + mov [eax+3],bx + mov bx,[Op02FZ] + mov [eax+5],bx + mov bx,[Op02LFE] + mov [eax+7],bx + mov bx,[Op02LES] + mov [eax+9],bx + mov bx,[Op02AAS] + mov [eax+11],bx + mov bx,[Op02AZS] + mov [eax+13],bx + mov bx,[Op02VOF] + mov [eax+15],bx + mov bx,[Op02VVA] + mov [eax+17],bx + mov bx,[Op02CX] + mov [eax+19],bx + mov bx,[Op02CY] + mov [eax+21],bx + pop ebx + add dword[dsp1ptr],23 + pop ecx + pop eax + ; ///////////////////////////// + ret + +FastForwardLock db 0 +SlowDownLock db 0 +FastForwardLockp db 0 +SaveRamSaved db 'SAVED SRAM DATA',0 +NEWSYM CSprWinPtr, dd 0 + +NEWSYM cachevideo + mov dword[CSprWinPtr],0 + mov byte[pressed],0 + mov dword[objvramadder],0 + mov dword[bgcmsung],0 + mov dword[modeused],0 + mov dword[modeused+4],0 + mov dword[scaddsngb],0 + mov dword[scaddtngb],0 + mov dword[sprprdrn],0 + mov dword[ngmsdraw],0 + mov dword[ngextbg],0 + mov dword[scaddtngbx],0FFFFFFFFh + mov byte[hiresstuff],0 + mov byte[Mode7HiRes],0 + cmp dword[WindowDisables],0 + je .nowindis + dec dword[WindowDisables] +.nowindis + + cmp byte[CurRecv],1 + je near .fskipall + + call ClockCounter + + cmp byte[mode7hiresen],0 + je .nohires + cmp byte[scanlines],1 + je .nohires + cmp byte[cvidmode],9 + je .yeshires + cmp byte[cvidmode],4 + jne .nohires +.yeshires + mov byte[Mode7HiRes],1 +.nohires + mov dword[scfbl],1 + mov al,[vidbright] + mov [maxbr],al + mov byte[cgmod],1 + xor al,al + mov [curblank],al + cmp byte[debuggeron],0 + je .nodebugger + mov byte[curblank],40h + mov al,40h + jmp .nofrskip +.nodebugger + + cmp dword[sramb4save],0 + je .nofocussave + cmp byte[SRAMSave5Sec],0 + je .nofocussaveb + dec dword[sramb4save] + cmp dword[sramb4save],0 + jne .nofocussave + pushad + call SaveSramData + popad +; mov dword[Msgptr],SaveRamSaved +; mov eax,[MsgCount] +; mov [MessageOn],eax + jmp .nofocussave +.nofocussaveb + mov dword[sramb4save],0 +.nofocussave + + cmp byte[CNetType],20 + je near .sdskip + + cmp byte[FastFwdToggle],0 + jne .ffmode2 + mov eax,[KeyFastFrwrd] + test byte[pressed+eax],1 + jnz near .fastfor + jmp .ffskip +.ffmode2 + mov eax,[KeyFastFrwrd] + test byte[pressed+eax],1 + je .nofastfor + mov byte[pressed+eax],2 + xor byte[FastForwardLock],1 + jmp .ff +.nofastfor +.ff + cmp byte[FastForwardLock],1 + je near .fastfor +.ffskip + + cmp byte[FastFwdToggle],0 + jne .sdmode2 + mov eax,[KeySlowDown] + test byte[pressed+eax],1 + jnz near .slowdwn + jmp .sdskip +.sdmode2 + mov eax,[KeySlowDown] + test byte[pressed+eax],1 + je .noslowdwn + mov byte[pressed+eax],2 + xor byte[SlowDownLock],1 +.noslowdwn + cmp byte[SlowDownLock],1 + je near .slowdwn + jmp .sdskip +.slowdwn + mov ax,2 + jmp .skipnoslowdown +.sdskip + mov ax,1 +.skipnoslowdown + + cmp byte[frameskip],0 + jne near .frameskip + cmp word[t1cc],ax + jae .skipt1ccc +.noskip + push eax + call Check60hz + pop eax + cmp word[t1cc],ax + jb .noskip +.skipt1ccc + sub word[t1cc],ax + cmp word[t1cc],ax + jb .noskip2 + mov byte[curblank],40h + inc byte[fskipped] + mov al,40h + mov cl,[maxskip] + cmp byte[fskipped],cl + jbe near .nofrskip + mov word[t1cc],0 + mov byte[curblank],0 + mov byte[fskipped],0 + jmp .nofrskip +.noskip2 + mov byte[fskipped],0 + jmp .nofrskip +.fastfor + inc byte[frskipper] + push ebx + mov bl,10 + jmp .fastforb +.frameskip + inc byte[frskipper] + push ebx + mov bl,byte[frameskip] +.fastforb + cmp byte[frskipper],bl + pop ebx + jae .nofrskip +.fskipall + mov byte[curblank],40h + mov al,40h + jmp .frskip +.nofrskip + mov byte[frskipper],0 +.frskip + push ebx + push esi + push edi + push edx + inc byte[mousecheck] + and byte[mousecheck],07h + cmp byte[mousecheck],0 + jne .noclick + cmp byte[GUIClick],0 + je .noclick + cmp byte[snesmouse],0 + jne .noclick + call Get_MouseData + test bx,02h + jz .norclick + cmp byte[MousePRClick],0 + jne .noclick + mov byte[pressed+1],1 +.norclick + mov byte[MousePRClick],0 +.noclick + mov ax,[oamaddr] + mov cl,[bgmode] + mov al,01h + shl al,cl + mov [cachedmode],al + ; disable all necessary backgrounds + cmp byte[chaton],1 + je near .finishchatskip + mov eax,[KeyBGDisble0] + test byte[pressed+eax],1 + je .nodis1 + xor byte[scrndis],01h + mov byte[pressed+eax],2 + mov dword[Msgptr],bg1layena + test byte[scrndis],01h + jz .en1 + mov dword[Msgptr],bg1laydis +.en1 + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis1 + mov eax,[KeyBGDisble1] + test byte[pressed+eax],1 + je .nodis2 + xor byte[scrndis],02h + mov byte[pressed+eax],2 + mov dword[Msgptr],bg2layena + test byte[scrndis],02h + jz .en2 + mov dword[Msgptr],bg2laydis +.en2 + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis2 + mov eax,[KeyBGDisble2] + test byte[pressed+eax],1 + je .nodis3 + xor byte[scrndis],04h + mov byte[pressed+eax],2 + mov dword[Msgptr],bg3layena + test byte[scrndis],04h + jz .en3 + mov dword[Msgptr],bg3laydis +.en3 + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis3 + mov eax,[KeyBGDisble3] + test byte[pressed+eax],1 + je .nodis4 + xor byte[scrndis],08h + mov byte[pressed+eax],2 + mov dword[Msgptr],bg4layena + test byte[scrndis],08h + jz .en4 + mov dword[Msgptr],bg4laydis +.en4 + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis4 + mov eax,[KeySprDisble] + test byte[pressed+eax],1 + je .nodis5 + xor byte[scrndis],10h + mov byte[pressed+eax],2 + mov dword[Msgptr],sprlayena + test byte[scrndis],10h + jz .en5 + mov dword[Msgptr],sprlaydis +.en5 + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis5 + mov eax,[KeyResetAll] + test byte[pressed+eax],1 + je .nodis6 + mov byte[pressed+eax],2 + mov byte[Voice0Disable],01h + mov byte[Voice1Disable],01h + mov byte[Voice2Disable],01h + mov byte[Voice3Disable],01h + mov byte[Voice4Disable],01h + mov byte[Voice5Disable],01h + mov byte[Voice6Disable],01h + mov byte[Voice7Disable],01h + mov byte[scrndis],00h + mov byte[snesmouse],0 + mov dword[Msgptr],panickeyp + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis6 + mov eax,[KeyExtraEnab] + test byte[pressed+eax],1 + je near .nodis7 + mov byte[pressed+eax],2 + inc byte[snesmouse] + cmp byte[snesmouse],5 + jne .mousewrap + mov byte[snesmouse],0 +.mousewrap + mov dword[Msgptr],snesle + cmp byte[snesmouse],0 + jne .nom0 + mov dword[Msgptr],snesmousep0 +.nom0 + cmp byte[snesmouse],1 + jne .nom1 + mov dword[Msgptr],snesmousep1 +.nom1 + cmp byte[snesmouse],2 + jne .nom2 + mov dword[Msgptr],snesmousep2 +.nom2 + cmp byte[snesmouse],3 + jne .nom3 + mov dword[Msgptr],snesss + mov word[mousexloc],128 + mov word[mouseyloc],112 +.nom3 + mov eax,[MsgCount] + mov [MessageOn],eax + call Get_MousePositionDisplacement +.nodis7 + cmp byte[CNetType],20 + jne .nonet + cmp byte[snesmouse],0 + je .nonet + mov byte[snesmouse],0 + mov dword[MessageOn],0 +.nonet + mov eax,[KeyNewGfxSwt] + test byte[pressed+eax],1 + je near .nodis8 + mov byte[pressed+eax],2 + cmp byte[cbitmode],1 + jne .no16bng + cmp byte[newgfx16b],1 + je .no16bng + jmp .no16bng + mov dword[Msgptr],newgfxerror +.msgstuff + mov eax,[MsgCount] + mov [MessageOn],eax + cmp byte[newengen],0 + je near .nodis8 + mov byte[newengen],0 + jmp .disng +.nores + mov dword[Msgptr],newgfxerror2 + jmp .msgstuff +.no16bng + mov byte[prevbright],16 + xor byte[newengen],1 + mov dword[Msgptr],ngena + cmp byte[newengen],1 + je .disng + mov dword[Msgptr],ngdis +.disng + mov eax,[MsgCount] + mov [MessageOn],eax + mov dword[nextdrawallng],1 + mov edi,vidmemch2 + mov ecx,1024*3 + mov eax,01010101h + rep stosd + mov edi,pal16b + mov ecx,256 + xor eax,eax + rep stosd + mov edi,prevpal + mov ecx,128 + rep stosd + mov eax,0FFFFh + cmp byte[newengen],1 + jne .noneweng + mov eax,0FFFFFFFFh +.noneweng + mov edi,pal16bxcl + mov ecx,256 + rep stosd + pushad + call genfulladdtab + popad +.yesng +.disng2 +.nodis8 + mov eax,[KeyWinDisble] + test byte[pressed+eax],1 + je .nodis9 + mov byte[pressed+eax],2 + xor byte[disableeffects],1 + mov dword[Msgptr],windissw + cmp byte[disableeffects],1 + je .disablew + mov dword[Msgptr],winenasw +.disablew + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis9 + mov eax,[KeyOffsetMSw] + test byte[pressed+eax],1 + je .nodis10 + mov byte[pressed+eax],2 + xor byte[osm2dis],1 + mov dword[Msgptr],ofsdissw + cmp byte[osm2dis],1 + je .disableom + mov dword[Msgptr],ofsenasw +.disableom + mov eax,[MsgCount] + mov [MessageOn],eax +.nodis10 + mov eax,[KeyVolUp] + test byte[pressed+eax],1 + je .novolup + cmp byte[MusicRelVol],100 + jae .novolup + inc byte[MusicRelVol] + call UpdateVolume +.novolup + mov eax,[KeyVolDown] + test byte[pressed+eax],1 + je .novoldown + cmp byte[MusicRelVol],0 + je .novoldown + dec byte[MusicRelVol] + call UpdateVolume +.novoldown + mov eax,[KeyFRateUp] + test byte[pressed+eax],1 + je .nofrup + mov byte[pressed+eax],2 + cmp byte[frameskip],10 + je .nofrup + mov byte[FPSOn],0 + inc byte[frameskip] + mov al,[frameskip] + add al,47 + mov [frlev+18],al + mov dword[Msgptr],frlev + mov eax,[MsgCount] + mov [MessageOn],eax +.nofrup + mov eax,[KeyFRateDown] + test byte[pressed+eax],1 + je .nofrdown + mov byte[pressed+eax],2 + cmp byte[frameskip],0 + je .nofrdown + dec byte[frameskip] + cmp byte[frameskip],0 + je .min + mov al,[frameskip] + add al,47 + mov [frlev+18],al + mov dword[Msgptr],frlev + jmp .nomin +.min + mov dword[Msgptr],frlv0 + mov word[t1cc],0 +.nomin + mov eax,[MsgCount] + mov [MessageOn],eax +.nofrdown + ; do state selects + stateselcomp KeyStateSlc0,'0','T' + stateselcomp KeyStateSlc1,'1','1' + stateselcomp KeyStateSlc2,'2','2' + stateselcomp KeyStateSlc3,'3','3' + stateselcomp KeyStateSlc4,'4','4' + stateselcomp KeyStateSlc5,'5','5' + stateselcomp KeyStateSlc6,'6','6' + stateselcomp KeyStateSlc7,'7','7' + stateselcomp KeyStateSlc8,'8','8' + stateselcomp KeyStateSlc9,'9','9' + mov eax,[KeyStateSlc0] + test byte[pressed+eax],1 + je .nostsl0 + mov byte[pressed+eax],2 + mov byte[sselm+11],'0' + mov dword[Msgptr],sselm + mov eax,[MsgCount] + mov [MessageOn],eax +.nostsl0 + ; do sound disables + soundselcomp KeyDisableSC0,Voice0Disable,Voice0Status,'1' + soundselcomp KeyDisableSC1,Voice1Disable,Voice1Status,'2' + soundselcomp KeyDisableSC2,Voice2Disable,Voice2Status,'3' + soundselcomp KeyDisableSC3,Voice3Disable,Voice3Status,'4' + soundselcomp KeyDisableSC4,Voice4Disable,Voice4Status,'5' + soundselcomp KeyDisableSC5,Voice5Disable,Voice5Status,'6' + soundselcomp KeyDisableSC6,Voice6Disable,Voice6Status,'7' + soundselcomp KeyDisableSC7,Voice7Disable,Voice7Status,'8' +.finishchatskip + cmp byte[curblank],0h + jne near yesblank + ; Swap video addresses +; mov ebx,[vidbuffer] +; cmp ebx,[vidbufferofsa] +; je .useb + mov ebx,[vidbufferofsa] + mov [vidbuffer],ebx + add ebx,75036+16 + mov [cbackofsaddr],ebx + mov ebx,[vidbufferofsb] + mov [vidbufferm],ebx +; jmp .nouseb +;.useb +; mov ebx,[vidbufferofsb] +; mov [vidbuffer],ebx +; add ebx,75036+16 +; mov [cbackofsaddr],ebx +; mov ebx,[vidbufferofsa] +; mov [vidbufferm],ebx +;.nouseb + +NEWSYM docache + xor ebx,ebx + mov bl,[bgmode] + shl bl,2 + add ebx,colormodedef + mov [colormodeofs],ebx + xor ebx,ebx + mov bl,[bgmode] + mov al,[colormodedef+ebx*4] + mov [curcolbg1],al + mov ah,[colormodedef+ebx*4+1] + mov [curcolbg2],ah + mov al,[colormodedef+ebx*4] + mov [curcolbg3],al + mov ah,[colormodedef+ebx*4+1] + mov [curcolbg4],ah + mov ax,[bg1ptr] + mov [curbgofs1],ax + mov ax,[bg2ptr] + mov [curbgofs2],ax + mov ax,[bg3ptr] + mov [curbgofs3],ax + mov ax,[bg4ptr] + mov [curbgofs4],ax + push es + mov ax,ds + mov es,ax + ; clear # of sprites & bg cache + mov edi,cachebg1 + mov ecx,64*5+16*4 + xor eax,eax + rep stosd +; cmp byte[sprprifix],0 +; je .nosprfix +; mov edi,sprlefttotb +; mov ecx,64*3 +; xor eax,eax +; rep stosd +;.nosprfix + ; do sprites +; test word[scrnon],1010h +; jz .nosprites + test byte[scrndis],10h + jnz .nosprites + call cachesprites + call processsprites +; mov byte[sprprncache],0 +; cmp byte[sprprifix],0 +; je .nosprites +; call processspritesb + +.nosprites + ; fill background with 0's unless 16-bit/new graphics engine mode is on + jmp .skipbgclear + cmp byte[cbitmode],1 + je .skipbgclear + cmp byte[newengen],1 + jne .skipbgclear +; cmp byte[FPUCopy],1 +; je near ClearBGFPUCopy + mov edi,[vidbuffer] + xor eax,eax + add edi,16 + mov dl,[resolutn] +.loopa + mov ecx,64 + rep stosd + add edi,32 + dec dl + jnz .loopa +.skipbgclear + xor ecx,ecx + pop es +NEWSYM yesblank + pop edx + pop edi + pop esi + pop ebx + ret + +NEWSYM ClearBGFPUCopy + mov edi,[vidbuffer] + xor eax,eax + add edi,16 + mov dl,[resolutn] +.loopa + mov ecx,16 +.TopOfLoop + FLDZ + FLDZ + FISTP QWORD [EDI] + FISTP QWORD [EDI+8] + ADD EDI,16 + DEC ECX + JNZ .TopOfLoop + add edi,32 + dec dl + jnz .loopa +.skipbgclear + xor ecx,ecx + pop es + pop edx + pop edi + pop esi + pop ebx + ret + +.Zero dd 0,0 +.Zero2 dd 0,0 + +NEWSYM osm2dis, db 0 +NEWSYM cachedmode, db 0 +NEWSYM tempfname, db 'vram.bin',0 +NEWSYM scrnsizebyte, dw 1024,2048,2048,4096 +NEWSYM colormodedef, db 1,1,1,1, 2,2,1,0, 2,2,0,0, 3,2,0,0, + db 3,1,0,0, 2,1,0,0, 2,0,0,0, 0,0,0,0 +NEWSYM colormoded2, db 4,4,4,4, 5,5,4,0, 5,5,0,0, 6,5,0,0, + db 6,4,0,0, 5,4,0,0, 5,0,0,0, 0,0,0,0 +NEWSYM colormodeofs, dd 0 +NEWSYM curblank, db 80h ; current blank state (40h = skip fill) +NEWSYM addr2add, dd 0 +;cachebg1 times 64 db 0 +;cachebg2 times 64 db 0 +;cachebg3 times 64 db 0 +;cachebg4 times 64 db 0 +;sprlefttot times 256 db 0 ; total sprites left +;sprleftpr times 256 db 0 ; sprites left for priority 0 +;sprleftpr1 times 256 db 0 ; sprites left for priority 1 +;sprleftpr2 times 256 db 0 ; sprites left for priority 2 +;sprleftpr3 times 256 db 0 ; sprites left for priority 3 +;spritetable times 256*512 db 0 ; sprite table (flip/pal/xloc/vbufptr)38*7 +NEWSYM curbgofs1, dw 0 +NEWSYM curbgofs2, dw 0 +NEWSYM curbgofs3, dw 0 +NEWSYM curbgofs4, dw 0 +NEWSYM curcolbg1, db 0 +NEWSYM curcolbg2, db 0 +NEWSYM curcolbg3, db 0 +NEWSYM curcolbg4, db 0 +NEWSYM panickeyp, db 'ALL SWITCHES NORMAL',0 +NEWSYM snesmousep0, db 'MOUSE/SUPER SCOPE DISABLED',0 +NEWSYM snesmousep1, db 'MOUSE ENABLED IN PORT 1',0 +NEWSYM snesmousep2, db 'MOUSE ENABLED IN PORT 2',0 +NEWSYM snesss, db 'SUPER SCOPE ENABLED',0 +NEWSYM snesle, db 'LETHAL ENFORCER GUN ENABLED',0 +NEWSYM windissw, db 'WINDOWING DISABLED',0 +NEWSYM winenasw, db 'WINDOWING ENABLED',0 +NEWSYM ofsdissw, db 'OFFSET MODE DISABLED',0 +NEWSYM ofsenasw, db 'OFFSET MODE ENABLED',0 +NEWSYM ngena, db 'NEW GFX ENGINE ENABLED',0 +NEWSYM ngdis, db 'NEW GFX ENGINE DISABLED',0 +NEWSYM sselm, db 'STATE SLOT 0 SELECTED',0 +NEWSYM vollv, db 'VOLUME LEVEL : ',0 +NEWSYM frlev, db 'FRAME SKIP SET TO ',0 +NEWSYM frlv0, db 'AUTO FRAMERATE ENABLED',0 +sndchena db 'SOUND CH ENABLED',0 +sndchdis db 'SOUND CH DISABLED',0 +bg1layena db 'BG1 LAYER ENABLED',0 +bg2layena db 'BG2 LAYER ENABLED',0 +bg3layena db 'BG3 LAYER ENABLED',0 +bg4layena db 'BG4 LAYER ENABLED',0 +sprlayena db 'SPRITE LAYER ENABLED',0 +bg1laydis db 'BG1 LAYER DISABLED',0 +bg2laydis db 'BG2 LAYER DISABLED',0 +bg3laydis db 'BG3 LAYER DISABLED',0 +bg4laydis db 'BG4 LAYER DISABLED',0 +sprlaydis db 'SPRITE LAYER DISABLED',0 + +;******************************************************* +; Process Sprites +;******************************************************* +; Use oamram for object table +NEWSYM processsprites +; cmp byte[cbitmode],1 +; je .skipnewspr +; cmp byte[newengen],1 +; je .skipnewspr + cmp byte[sprprifix],0 + jne near processspritesb +.skipnewspr + ; set obj pointers + cmp byte[objsize1],1 + jne .16dot1 + mov ebx,.process8x8sprite + mov [.size1ptr],ebx + jmp .fin1 +.16dot1 + cmp byte[objsize1],4 + jne .32dot1 + mov ebx,.process16x16sprite + mov [.size1ptr],ebx + jmp .fin1 +.32dot1 + cmp byte[objsize1],16 + jne .64dot1 + mov ebx,.process32x32sprite + mov [.size1ptr],ebx + jmp .fin1 +.64dot1 + mov ebx,.process64x64sprite + mov [.size1ptr],ebx +.fin1 + cmp byte[objsize2],1 + jne .16dot2 + mov ebx,.process8x8sprite + mov [.size2ptr],ebx + jmp .fin2 +.16dot2 + cmp byte[objsize2],4 + jne .32dot2 + mov ebx,.process16x16sprite + mov [.size2ptr],ebx + jmp .fin2 +.32dot2 + cmp byte[objsize2],16 + jne .64dot2 + mov ebx,.process32x32sprite + mov [.size2ptr],ebx + jmp .fin2 +.64dot2 + mov ebx,.process64x64sprite + mov [.size2ptr],ebx +.fin2 + ; set pointer adder + xor eax,eax + xor ebx,ebx + mov al,[objhipr] + shl ax,2 + mov ebx,eax + sub bx,4 + and bx,01FCh + mov dword[addr2add],0 + mov byte[.prileft],4 + mov byte[.curpri],0 + ; do 1st priority + mov ecx,[objptr] + shl ecx,1 + mov [.objvramloc],ecx + mov ecx,[objptrn] + sub ecx,[objptr] + shl ecx,1 + mov [.objvramloc2],ecx + push ebp + mov ebp,[spritetablea] +.startobject + mov byte[.objleft],128 +.objloop + xor ecx,ecx + mov cx,[oamram+ebx+2] + mov dl,ch + shr dl,4 + and dl,03h + cmp dl,[.curpri] + jne near .nextobj + ; get object information + push ebx + mov dl,[oamram+ebx+1] ; y + inc dl + ; set up pointer to esi + mov dh,ch + and ch,01h + shr dh,1 + shl ecx,6 + add ecx,[.objvramloc] + test byte[oamram+ebx+3],01h + jz .noloc2 + add ecx,[.objvramloc2] +.noloc2 + and ecx,01FFFFh + add ecx,[vcache4b] + mov esi,ecx + ; get x + mov al,[oamram+ebx] ; x + ; get double bits + mov cl,bl + shr ebx,4 ; /16 + shr cl,1 + and cl,06h + mov ah,[oamram+ebx+512] + shr ah,cl + and ah,03h + mov ch,ah + and ch,01h + mov cl,al + ; process object + ; esi = pointer to 8-bit object, dh = stats (1 shifted to right) + ; cx = x position, dl = y position + cmp cx,384 + jb .noadder + add cx,65535-511 +.noadder + cmp cx,256 + jge .returnfromptr + cmp cx,-64 + jle .returnfromptr + test ah,02h + jz .size1 + jmp dword near [.size2ptr] +.size1 + jmp dword near [.size1ptr] +.returnfromptr + pop ebx + ; next object +.nextobj + sub bx,4 + and bx,01FCh + dec byte[.objleft] + jnz near .objloop + add dword[addr2add],256 + inc byte[.curpri] + dec byte[.prileft] + jnz near .startobject + pop ebp + ret + +.objvramloc dd 0 +.objvramloc2 dd 0 +.curpri dd 0 +.trypri dd 0 +.objleft dd 0 +.prileft dd 0 +.size1ptr dd 0 +.size2ptr dd 0 + +.reprocesssprite + cmp cx,-8 + jle .next + cmp cx,256 + jge .next + add cx,8 +.reprocessspriteb + cmp dl,[resolutn] + jae .overflow + xor ebx,ebx + mov bl,dl + xor eax,eax + cmp bx,[curypos] + jb .overflow + mov al,byte[sprlefttot+ebx] + cmp al,37 + ja near .overflow + inc byte[sprlefttot+ebx] + add ebx,[addr2add] + inc byte[sprleftpr+ebx] + sub ebx,[addr2add] + shl ebx,9 + shl eax,3 + add ebx,eax + mov [ebp+ebx],cx + mov [ebp+ebx+2],esi + mov al,[.statusbit] + mov byte[ebp+ebx+6],dh + mov byte[ebp+ebx+7],al +.overflow + inc dl + add esi,8 + dec byte[.numleft2do] + jnz .reprocessspriteb + sub cx,8 + ret +.next + add dl,8 + add esi,64 + ret + +.reprocessspriteflipy + cmp cx,-8 + jle .nextb + cmp cx,256 + jge .nextb + add cx,8 +.reprocessspriteflipyb + cmp dl,[resolutn] + jae .overflow2 + xor ebx,ebx + xor eax,eax + mov bl,dl + cmp bx,[curypos] + jb .overflow2 + mov al,byte[sprlefttot+ebx] + cmp al,37 + ja near .overflow2 + inc byte[sprlefttot+ebx] + add ebx,[addr2add] + inc byte[sprleftpr+ebx] + sub ebx,[addr2add] + shl ebx,9 + shl eax,3 + add ebx,eax + mov [ebp+ebx],cx + mov [ebp+ebx+2],esi + mov al,[.statusbit] + mov byte[ebp+ebx+6],dh + mov byte[ebp+ebx+7],al +.overflow2 + inc dl + sub esi,8 + dec byte[.numleft2do] + jnz .reprocessspriteflipyb + sub cx,8 + ret +.nextb + add dl,8 + sub esi,64 + ret + +.statusbit db 0 + +.process8x8sprite: + test dh,40h + jnz .8x8flipy + mov [.statusbit],dh + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + jmp .returnfromptr +.8x8flipy + mov [.statusbit],dh + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add esi,56 + call .reprocessspriteflipy + jmp .returnfromptr +.numleft2do db 0 + +.process16x16sprite: + mov [.statusbit],dh + test dh,20h + jnz near .16x16flipx + test dh,40h + jnz .16x16flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + sub cx,8 + add esi,64*14 + mov byte[.numleft2do],8 + call .reprocesssprite + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + jmp .returnfromptr +.16x16flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add dl,8 + add esi,56 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + sub dl,16 + sub cx,8 + add esi,64*14 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + jmp .returnfromptr +.16x16flipx + test dh,40h + jnz .16x16flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,8 + call .reprocesssprite + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + add esi,64*14 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + jmp .returnfromptr +.16x16flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,8 + add dl,8 + add esi,56 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + add esi,64*14 + sub dl,16 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + jmp .returnfromptr + +;******************************************************* +; Sprite increment/draw macros +;******************************************************* + +%macro nextsprite2right 0 + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite +%endmacro + +%macro nextsprite2rightflipy 0 + add esi,128 + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy +%endmacro + +%macro nextsprite2rightflipx 0 + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite +%endmacro + +%macro nextsprite2rightflipyx 0 + add esi,128 + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy +%endmacro + +;******************************************************* +; 32x32 sprites routines +;******************************************************* + +%macro nextline32x32 0 + sub cx,24 + add esi,64*12 + mov byte[.numleft2do],8 + call .reprocesssprite + nextsprite2right + nextsprite2right + nextsprite2right +%endmacro + +.process32x32sprite: + mov [.statusbit],dh + test dh,20h + jnz near .32x32flipx + test dh,40h + jnz near .32x32flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + nextsprite2right + nextsprite2right + nextsprite2right + nextline32x32 + nextline32x32 + nextline32x32 + jmp .returnfromptr + +%macro nextline32x32flipy 0 + sub cx,24 + add esi,64*12+128 + sub dl,16 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy +%endmacro + +.32x32flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add dl,24 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextline32x32flipy + nextline32x32flipy + nextline32x32flipy + jmp .returnfromptr + +%macro nextline32x32flipx 0 + add cx,24 + add esi,64*12 + mov byte[.numleft2do],8 + call .reprocesssprite + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx +%endmacro + +.32x32flipx + test dh,40h + jnz near .32x32flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,24 + call .reprocesssprite + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextline32x32flipx + nextline32x32flipx + nextline32x32flipx + jmp .returnfromptr + +%macro nextline32x32flipyx 0 + add cx,24 + add esi,64*12+128 + sub dl,16 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx +%endmacro + +.32x32flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,24 + add dl,24 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextline32x32flipyx + nextline32x32flipyx + nextline32x32flipyx + jmp .returnfromptr + +;******************************************************* +; 64x64 sprites routines +;******************************************************* + +%macro nextline64x64 0 + sub cx,56 + add esi,64*8 + mov byte[.numleft2do],8 + call .reprocesssprite + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right +%endmacro + +.process64x64sprite: + mov [.statusbit],dh + test dh,20h + jnz near .64x64flipx + test dh,40h + jnz near .64x64flipy + mov [.statusbit],dh + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + jmp .returnfromptr + +%macro nextline64x64flipy 0 + sub cx,56 + add esi,64*8+128 + sub dl,16 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy +%endmacro + +.64x64flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add dl,56 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + jmp .returnfromptr + +%macro nextline64x64flipx 0 + add cx,56 + add esi,64*8 + mov byte[.numleft2do],8 + call .reprocesssprite + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx +%endmacro + +.64x64flipx + test dh,40h + jnz near .64x64flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,56 + call .reprocesssprite + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + jmp .returnfromptr + +%macro nextline64x64flipyx 0 + add cx,56 + add esi,64*8+128 + sub dl,16 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx +%endmacro + +.64x64flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,56 + add dl,56 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + jmp .returnfromptr + +;******************************************************* +; Process Sprites B - Process +;******************************************************* +; Use oamram for object table + +NEWSYM processspritesb + ; set obj pointers + cmp byte[objsize1],1 + jne .16dot1 + mov ebx,.process8x8sprite + mov [.size1ptr],ebx + jmp .fin1 +.16dot1 + cmp byte[objsize1],4 + jne .32dot1 + mov ebx,.process16x16sprite + mov [.size1ptr],ebx + jmp .fin1 +.32dot1 + cmp byte[objsize1],16 + jne .64dot1 + mov ebx,.process32x32sprite + mov [.size1ptr],ebx + jmp .fin1 +.64dot1 + mov ebx,.process64x64sprite + mov [.size1ptr],ebx +.fin1 + cmp byte[objsize2],1 + jne .16dot2 + mov ebx,.process8x8sprite + mov [.size2ptr],ebx + jmp .fin2 +.16dot2 + cmp byte[objsize2],4 + jne .32dot2 + mov ebx,.process16x16sprite + mov [.size2ptr],ebx + jmp .fin2 +.32dot2 + cmp byte[objsize2],16 + jne .64dot2 + mov ebx,.process32x32sprite + mov [.size2ptr],ebx + jmp .fin2 +.64dot2 + mov ebx,.process64x64sprite + mov [.size2ptr],ebx +.fin2 + ; set pointer adder + xor eax,eax + xor ebx,ebx + mov al,[objhipr] + shl ax,2 + mov ebx,eax + and bx,01FCh + mov dword[addr2add],0 + ; do 1st priority + mov ecx,[objptr] + shl ecx,1 + mov [.objvramloc],ecx + mov ecx,[objptrn] + sub ecx,[objptr] + shl ecx,1 + mov [.objvramloc2],ecx + push ebp + mov ebp,[spritetablea] +.startobject + mov byte[.objleft],128 +.objloop + xor ecx,ecx + mov cx,[oamram+ebx+2] + mov dl,ch + shr dl,4 + and edx,03h + mov [.cpri],dl + ; get object information + push ebx + mov dl,[oamram+ebx+1] ; y + inc dl + ; set up pointer to esi + mov dh,ch + and ch,01h + shr dh,1 + shl ecx,6 + add ecx,[.objvramloc] + test byte[oamram+ebx+3],01h + jz .noloc2 + add ecx,[.objvramloc2] +.noloc2 + and ecx,01FFFFh + add ecx,[vcache4b] + mov esi,ecx + ; get x + mov al,[oamram+ebx] ; x + ; get double bits + mov cl,bl + shr ebx,4 ; /16 + shr cl,1 + and cl,06h + mov ah,[oamram+ebx+512] + shr ah,cl + and ah,03h + mov ch,ah + and ch,01h + mov cl,al + ; process object + ; esi = pointer to 8-bit object, dh = stats (1 shifted to right) + ; cx = x position, dl = y position + cmp cx,384 + jb .noadder + add cx,65535-511 +.noadder + cmp cx,256 + jge .returnfromptr + cmp cx,-64 + jle .returnfromptr + test ah,02h + jz .size1 + jmp dword near [.size2ptr] +.size1 + jmp dword near [.size1ptr] +.returnfromptr + pop ebx + ; next object +.nextobj + add bx,4 + and bx,01FCh + dec byte[.objleft] + jnz near .objloop + pop ebp + ret + +.objvramloc dd 0 +.objvramloc2 dd 0 +.curpri dd 0 +.trypri dd 0 +.objleft dd 0 +.prileft dd 0 +.size1ptr dd 0 +.size2ptr dd 0 +.cpri dd 0 + +.reprocesssprite + cmp cx,-8 + jle near .next + cmp cx,256 + jge .next + add cx,8 +.reprocessspriteb + cmp dl,[resolutn] + jae .overflow + xor ebx,ebx + xor eax,eax + mov bl,dl + cmp bx,[curypos] + jb .overflow + mov al,byte[sprlefttot+ebx] + cmp al,37 + ja near .overflow + inc byte[sprlefttot+ebx] + mov edi,[.cpri] + mov byte[sprleftpr+ebx*4+edi],1 + shl ebx,9 + shl eax,3 + add ebx,eax + mov [ebp+ebx],cx + mov [ebp+ebx+2],esi + mov al,[.statusbit] + and al,0F8h + or al,[.cpri] + mov byte[ebp+ebx+6],dh + mov byte[ebp+ebx+7],al +.overflow + inc dl + add esi,8 + dec byte[.numleft2do] + jnz .reprocessspriteb + sub cx,8 + ret +.next + add dl,8 + add esi,64 + ret + +.reprocessspriteflipy + cmp cx,-8 + jle near .nextb + cmp cx,256 + jge .nextb + add cx,8 +.reprocessspriteflipyb + cmp dl,[resolutn] + jae .overflow2 + xor ebx,ebx + xor eax,eax + mov bl,dl + cmp bx,[curypos] + jb .overflow + mov al,byte[sprlefttot+ebx] + cmp al,37 + ja near .overflow2 + inc byte[sprlefttot+ebx] + mov edi,[.cpri] + mov byte[sprleftpr+ebx*4+edi],1 + shl ebx,9 + shl eax,3 + add ebx,eax + mov [ebp+ebx],cx + mov [ebp+ebx+2],esi + mov al,[.statusbit] + and al,0F8h + or al,[.cpri] + mov byte[ebp+ebx+6],dh + mov byte[ebp+ebx+7],al +.overflow2 + inc dl + sub esi,8 + dec byte[.numleft2do] + jnz .reprocessspriteflipyb + sub cx,8 + ret +.nextb + add dl,8 + sub esi,64 + ret + +.statusbit db 0 + +.process8x8sprite: + test dh,40h + jnz .8x8flipy + mov [.statusbit],dh + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + jmp .returnfromptr +.8x8flipy + mov [.statusbit],dh + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add esi,56 + call .reprocessspriteflipy + jmp .returnfromptr +.numleft2do db 0 + +.process16x16sprite: + mov [.statusbit],dh + test dh,20h + jnz near .16x16flipx + test dh,40h + jnz .16x16flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + sub cx,8 + add esi,64*14 + mov byte[.numleft2do],8 + call .reprocesssprite + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + jmp .returnfromptr +.16x16flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add dl,8 + add esi,56 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + sub dl,16 + sub cx,8 + add esi,64*14 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + jmp .returnfromptr +.16x16flipx + test dh,40h + jnz .16x16flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,8 + call .reprocesssprite + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + add esi,64*14 + add cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocesssprite + jmp .returnfromptr +.16x16flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,8 + add dl,8 + add esi,56 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + add esi,64*14 + sub dl,16 + add cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + add esi,128 + sub dl,8 + sub cx,8 + mov byte[.numleft2do],8 + call .reprocessspriteflipy + jmp .returnfromptr + +;******************************************************* +; 32x32 sprites routines +;******************************************************* + +.process32x32sprite: + mov [.statusbit],dh + test dh,20h + jnz near .32x32flipx + test dh,40h + jnz near .32x32flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + nextsprite2right + nextsprite2right + nextsprite2right + nextline32x32 + nextline32x32 + nextline32x32 + jmp .returnfromptr + +.32x32flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add dl,24 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextline32x32flipy + nextline32x32flipy + nextline32x32flipy + jmp .returnfromptr + +.32x32flipx + test dh,40h + jnz near .32x32flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,24 + call .reprocesssprite + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextline32x32flipx + nextline32x32flipx + nextline32x32flipx + jmp .returnfromptr + +.32x32flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,24 + add dl,24 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextline32x32flipyx + nextline32x32flipyx + nextline32x32flipyx + jmp .returnfromptr + +;******************************************************* +; 64x64 sprites routines +;******************************************************* + +.process64x64sprite: + mov [.statusbit],dh + test dh,20h + jnz near .64x64flipx + test dh,40h + jnz near .64x64flipy + mov [.statusbit],dh + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + call .reprocesssprite + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextsprite2right + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + nextline64x64 + jmp .returnfromptr + +.64x64flipy + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add dl,56 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextsprite2rightflipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + nextline64x64flipy + jmp .returnfromptr + +.64x64flipx + test dh,40h + jnz near .64x64flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,56 + call .reprocesssprite + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextsprite2rightflipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + nextline64x64flipx + jmp .returnfromptr + +.64x64flipyx + and dh,07h + mov byte[.numleft2do],8 + shl dh,4 + add dh,128 + add cx,56 + add dl,56 + add esi,56 + call .reprocessspriteflipy + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextsprite2rightflipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + nextline64x64flipyx + jmp .returnfromptr + +;******************************************************* +; Cache Process Macros, info from Nerlaska! +;******************************************************* + +%macro processcache2b 1 + xor al,al + add ch,ch + adc al,al + add cl,cl + adc al,al + mov [edi+%1],al +%endmacro + +%macro processcache4b 1 + xor al,al + add dh,dh + adc al,al + add dl,dl + adc al,al + add ch,ch + adc al,al + add cl,cl + adc al,al + mov [edi+%1],al +%endmacro + +;******************************************************* +; Cache Sprites +;******************************************************* +; Use oamram for object table, copy from vram -> vcache4b +; 16x16 sprite, to move = 2, to add = 14, 32x32 = 4,12, 64x64 = 8,8 + +%macro processcache4bs 1 + xor al,al + add dh,dh + adc al,al + add dl,dl + adc al,al + add ch,ch + adc al,al + add cl,cl + adc al,al + mov [edi+%1],al + or al,al + jz %%zeroed + and byte[tiletypec],1 + jmp %%nozeroed +%%zeroed + and byte[tiletypec],2 +%%nozeroed +%endmacro + +NEWSYM cachesprites + ; initialize obj size cache + mov dword[.objptr],oamram + add dword[.objptr],512 + mov esi,dword[.objptr] + mov al,[esi] + mov [.curobjtype],al + mov byte[.objleftinbyte],4 + ; Initialize oamram pointer + mov esi,oamram + add esi,2 + + ; process pointers (.objptra = source, .objptrb = dest) +.trynextgroup + xor ebx,ebx + mov bx,[objptr] + mov ecx,ebx + shr ecx,4 + mov [.nbg],cx + mov edi,[vram] + add edi,ebx + mov [.objptra],edi + shl ebx,1 + add ebx,[vcache4b] + mov [.objptrb],ebx + + xor ebx,ebx + mov bx,[objptrn] + mov ecx,ebx + shr ecx,4 + mov [.nbg2],cx + mov edi,[vram] + add edi,ebx + mov [.objptra2],edi + shl ebx,1 + add ebx,[vcache4b] + mov [.objptrb2],ebx + + xor ebx,ebx + + ; process objects + mov dword[.sprnum],3 + mov byte[.objleft],128 +.nextobj + ; process sprite sizes + test byte[.curobjtype],02h + jz .dosprsize1 + mov al,[objsize2] + mov [.num2do],al + mov ax,[objadds2] + mov [.byte2add],ax + mov al,[objmovs2] + mov [.byte2move],al + mov [.byteb4add],al + jmp .exitsprsize +.dosprsize1 + mov al,[objsize1] + mov [.num2do],al + mov ax,[objadds1] + mov [.byte2add],ax + mov al,[objmovs1] + mov [.byte2move],al + mov [.byteb4add],al +.exitsprsize + shr byte[.curobjtype],2 + dec byte[.objleftinbyte] + jnz .skipobjproc + mov byte[.objleftinbyte],4 + inc dword[.objptr] + mov ebx,[.objptr] + mov al,[ebx] + mov [.curobjtype],al +.skipobjproc + mov bx,[esi] + and bh,1h + mov [.curobj],bx +.nextobject + mov ebx,[.sprnum] + mov cl,[oamram+ebx-2] + mov ch,[curypos] + dec ch + cmp cl,ch + jb near .nocache + test byte[oamram+ebx],01h + jnz .namebase + xor ebx,ebx + mov bx,[.curobj] + mov cx,bx + add bx,bx + add bx,[.nbg] + and bx,4095 + test word[vidmemch4+ebx],0101h + jz near .nocache + mov word[vidmemch4+ebx],0000h + mov [.sprfillpl],ebx + push esi + shl bx,4 + mov esi,[vram] + add esi,ebx + add ebx,ebx + mov edi,[vcache4b] + add edi,ebx + jmp .nonamebase +.namebase + xor ebx,ebx + mov bx,[.curobj] + mov cx,bx + shl bx,1 + add bx,[.nbg2] + and bx,4095 + test word[vidmemch4+ebx],0101h + jz near .nocache + mov word[vidmemch4+ebx],0000h + mov [.sprfillpl],ebx + push esi + shl bx,4 + mov esi,[vram] + add esi,ebx + add ebx,ebx + mov edi,[vcache4b] + add edi,ebx +.nonamebase + ; convert from [esi] to [edi] + mov byte[.rowleft],8 + mov byte[tiletypec],3 +.donext + + mov cx,[esi] + mov dx,[esi+16] + + processcache4bs 0 + processcache4bs 1 + processcache4bs 2 + processcache4bs 3 + processcache4bs 4 + processcache4bs 5 + processcache4bs 6 + processcache4bs 7 + + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + mov ebx,[.sprfillpl] + mov al,[tiletypec] + shr ebx,1 + pop esi + mov byte[tltype4b+ebx],al +.nocache + inc word[.curobj] + dec byte[.byteb4add] + jnz .skipbyteadd + mov ax,[.byte2add] + add word[.curobj],ax + mov al,[.byte2move] + mov byte[.byteb4add],al +.skipbyteadd + dec byte[.num2do] + jnz near .nextobject + add esi,4 + add dword[.sprnum],4 + dec byte[.objleft] + jnz near .nextobj + ret + +.objptra dd 0 +.objptrb dd 0 +.nbg dd 0 +.objptra2 dd 0 +.objptrb2 dd 0 +.nbg2 dd 0 +.objleft db 0 +.rowleft db 0 +.a dd 0 +.objptr dd 0 +.objleftinbyte dd 0 +.curobjtype dd 0 +.num2do dd 1 +.curobj dd 0 +.byteb4add dd 2 +.byte2move dd 0 +.byte2add dd 0 +.sprnum dd 0 +.sprcheck dd 0 +.sprfillpl dd 0 + +;******************************************************* +; Cache 2-Bit +;******************************************************* +NEWSYM cachetile2b + ; Keep high word ecx 0 + push eax + xor ecx,ecx + push edx + mov byte[.nextar],1 + push ebx + ; get tile info location + test al,20h + jnz .highptr + shl eax,6 ; x 64 for each line + add ax,[bgptr] + jmp .loptr +.highptr + and al,1Fh + shl eax,6 ; x 64 for each line + add ax,[bgptrc] +.loptr + add eax,[vram] + mov bx,[curtileptr] + shr bx,4 + mov byte[.count],32 + mov [.nbg],bx + ; do loop +.cacheloop + mov si,[eax] + and esi,03FFh + add si,[.nbg] + and esi,4095 + test byte[vidmemch2+esi],01h + jz near .nocache + mov byte[vidmemch2+esi],00h + mov edi,esi + shl esi,4 + shl edi,6 + add esi,[vram] + add edi,[vcache2b] + push eax + mov byte[.rowleft],8 +.donext + mov cx,[esi] + processcache2b 0 + processcache2b 1 + processcache2b 2 + processcache2b 3 + processcache2b 4 + processcache2b 5 + processcache2b 6 + processcache2b 7 + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + pop eax +.nocache + add eax,2 + dec byte[.count] + jnz near .cacheloop + + cmp byte[.nextar],0 + je .skipall + mov bx,[bgptrc] + cmp [bgptrd],bx + je .skipall + add eax,2048-64 + mov byte[.count],32 + mov byte[.nextar],0 + jmp .cacheloop +.skipall + pop ebx + pop edx + pop eax + ret + +.nbg dw 0 +.count db 0 +.a db 0 +.rowleft db 0 +.nextar db 0 + +NEWSYM cache2bit + ret + +;******************************************************* +; Cache 4-Bit +;******************************************************* + +; esi = pointer to tile location vram +; edi = pointer to graphics data (cache & non-cache) +; ebx = external pointer +; tile value : bit 15 = flipy, bit 14 = flipx, bit 10-12 = palette, 0-9=tile# + +NEWSYM cachetile4b + ; Keep high word ecx 0 + push eax + xor ecx,ecx + push edx + mov byte[.nextar],1 + push ebx + ; get tile info location + test al,20h + jnz .highptr + shl eax,6 ; x 64 for each line + add ax,[bgptr] + jmp .loptr +.highptr + and al,1Fh + shl eax,6 ; x 64 for each line + add ax,[bgptrc] +.loptr + add eax,[vram] + mov bx,[curtileptr] + shr bx,5 + mov byte[.count],32 + mov [.nbg],bx + + ; do loop +.cacheloop + mov si,[eax] + and esi,03FFh + add si,[.nbg] + shl esi,1 + and esi,4095 + test word[vidmemch4+esi],0101h + jz near .nocache + mov word[vidmemch4+esi],0000h + mov edi,esi + shl esi,4 + shl edi,5 + add esi,[vram] + add edi,[vcache4b] + push eax + mov byte[.rowleft],8 +.donext + + mov cx,[esi] + mov dx,[esi+16] + processcache4b 0 + processcache4b 1 + processcache4b 2 + processcache4b 3 + processcache4b 4 + processcache4b 5 + processcache4b 6 + processcache4b 7 + + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + pop eax +.nocache + add eax,2 + dec byte[.count] + jnz near .cacheloop + + cmp byte[.nextar],0 + je .skipall + mov bx,[bgptrc] + cmp [bgptrd],bx + je .skipall + add eax,2048-64 + mov byte[.count],32 + mov byte[.nextar],0 + jmp .cacheloop +.skipall + pop ebx + pop edx + pop eax + ret + +.nbg dw 0 +.count db 0 +.rowleft db 0 +.nextar db 0 + +NEWSYM cache4bit + ret +;******************************************************* +; Cache 8-Bit +;******************************************************* +; tile value : bit 15 = flipy, bit 14 = flipx, bit 10-12 = palette, 0-9=tile# +NEWSYM cachetile8b + ; Keep high word ecx 0 + push eax + xor ecx,ecx + push edx + mov byte[.nextar],1 + push ebx + ; get tile info location + test al,20h + jnz .highptr + shl eax,6 ; x 64 for each line + add ax,[bgptr] + jmp .loptr +.highptr + and al,1Fh + shl eax,6 ; x 64 for each line + add ax,[bgptrc] +.loptr + add eax,[vram] + mov bx,[curtileptr] + shr bx,6 + mov byte[.count],32 + mov [.nbg],bx + + ; do loop +.cacheloop + mov si,[eax] + and esi,03FFh + add si,[.nbg] + shl esi,2 + and esi,4095 + test dword[vidmemch8+esi],01010101h + jz near .nocache + mov dword[vidmemch8+esi],00000000h + mov edi,esi + shl esi,4 + shl edi,4 + add esi,[vram] + add edi,[vcache8b] + push eax + mov byte[.rowleft],8 +.donext + xor ah,ah + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov byte[.a],0 + + mov al,[esi] ; bitplane 0 + cmp al,0 + je .skipconva + test al,01h + jz .skipa0 + or ah,01h +.skipa0 + test al,02h + jz .skipa1 + or bl,01h +.skipa1 + test al,04h + jz .skipa2 + or bh,01h +.skipa2 + test al,08h + jz .skipa3 + or cl,01h +.skipa3 + test al,10h + jz .skipa4 + or ch,01h +.skipa4 + test al,20h + jz .skipa5 + or dl,01h +.skipa5 + test al,40h + jz .skipa6 + or dh,01h +.skipa6 + test al,80h + jz .skipa7 + or byte[.a],01h +.skipa7 +.skipconva + + mov al,[esi+1] ; bitplane 1 + cmp al,0 + je .skipconvb + test al,01h + jz .skipb0 + or ah,02h +.skipb0 + test al,02h + jz .skipb1 + or bl,02h +.skipb1 + test al,04h + jz .skipb2 + or bh,02h +.skipb2 + test al,08h + jz .skipb3 + or cl,02h +.skipb3 + test al,10h + jz .skipb4 + or ch,02h +.skipb4 + test al,20h + jz .skipb5 + or dl,02h +.skipb5 + test al,40h + jz .skipb6 + or dh,02h +.skipb6 + test al,80h + jz .skipb7 + or byte[.a],02h +.skipb7 +.skipconvb + + mov al,[esi+16] ; bitplane 2 + cmp al,0 + je .skipconvc + test al,01h + jz .skipc0 + or ah,04h +.skipc0 + test al,02h + jz .skipc1 + or bl,04h +.skipc1 + test al,04h + jz .skipc2 + or bh,04h +.skipc2 + test al,08h + jz .skipc3 + or cl,04h +.skipc3 + test al,10h + jz .skipc4 + or ch,04h +.skipc4 + test al,20h + jz .skipc5 + or dl,04h +.skipc5 + test al,40h + jz .skipc6 + or dh,04h +.skipc6 + test al,80h + jz .skipc7 + or byte[.a],04h +.skipc7 +.skipconvc + + mov al,[esi+17] ; bitplane 3 + cmp al,0 + je .skipconvd + test al,01h + jz .skipd0 + or ah,08h +.skipd0 + test al,02h + jz .skipd1 + or bl,08h +.skipd1 + test al,04h + jz .skipd2 + or bh,08h +.skipd2 + test al,08h + jz .skipd3 + or cl,08h +.skipd3 + test al,10h + jz .skipd4 + or ch,08h +.skipd4 + test al,20h + jz .skipd5 + or dl,08h +.skipd5 + test al,40h + jz .skipd6 + or dh,08h +.skipd6 + test al,80h + jz .skipd7 + or byte[.a],08h +.skipd7 +.skipconvd + + mov al,[esi+32] ; bitplane 4 + cmp al,0 + je .skipconve + test al,01h + jz .skipe0 + or ah,10h +.skipe0 + test al,02h + jz .skipe1 + or bl,10h +.skipe1 + test al,04h + jz .skipe2 + or bh,10h +.skipe2 + test al,08h + jz .skipe3 + or cl,10h +.skipe3 + test al,10h + jz .skipe4 + or ch,10h +.skipe4 + test al,20h + jz .skipe5 + or dl,10h +.skipe5 + test al,40h + jz .skipe6 + or dh,10h +.skipe6 + test al,80h + jz .skipe7 + or byte[.a],10h +.skipe7 +.skipconve + + mov al,[esi+33] ; bitplane 5 + cmp al,0 + je .skipconvf + test al,01h + jz .skipf0 + or ah,20h +.skipf0 + test al,02h + jz .skipf1 + or bl,20h +.skipf1 + test al,04h + jz .skipf2 + or bh,20h +.skipf2 + test al,08h + jz .skipf3 + or cl,20h +.skipf3 + test al,10h + jz .skipf4 + or ch,20h +.skipf4 + test al,20h + jz .skipf5 + or dl,20h +.skipf5 + test al,40h + jz .skipf6 + or dh,20h +.skipf6 + test al,80h + jz .skipf7 + or byte[.a],20h +.skipf7 +.skipconvf + + mov al,[esi+48] ; bitplane 6 + cmp al,0 + je .skipconvg + test al,01h + jz .skipg0 + or ah,40h +.skipg0 + test al,02h + jz .skipg1 + or bl,40h +.skipg1 + test al,04h + jz .skipg2 + or bh,40h +.skipg2 + test al,08h + jz .skipg3 + or cl,40h +.skipg3 + test al,10h + jz .skipg4 + or ch,40h +.skipg4 + test al,20h + jz .skipg5 + or dl,40h +.skipg5 + test al,40h + jz .skipg6 + or dh,40h +.skipg6 + test al,80h + jz .skipg7 + or byte[.a],40h +.skipg7 +.skipconvg + + mov al,[esi+49] ; bitplane 7 + cmp al,0 + je .skipconvh + test al,01h + jz .skiph0 + or ah,80h +.skiph0 + test al,02h + jz .skiph1 + or bl,80h +.skiph1 + test al,04h + jz .skiph2 + or bh,80h +.skiph2 + test al,08h + jz .skiph3 + or cl,80h +.skiph3 + test al,10h + jz .skiph4 + or ch,80h +.skiph4 + test al,20h + jz .skiph5 + or dl,80h +.skiph5 + test al,40h + jz .skiph6 + or dh,80h +.skiph6 + test al,80h + jz .skiph7 + or byte[.a],80h +.skiph7 +.skipconvh + + ; move all bytes into [edi] + mov [edi+7],ah + mov [edi+6],bl + mov [edi+5],bh + mov [edi+4],cl + mov [edi+3],ch + mov [edi+2],dl + mov [edi+1],dh + mov al,[.a] + mov [edi],al + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + pop eax +.nocache + add eax,2 + dec byte[.count] + jnz near .cacheloop + + cmp byte[.nextar],0 + je .skipall + mov bx,[bgptrc] + cmp [bgptrd],bx + je .skipall + add eax,2048-64 + mov byte[.count],32 + mov byte[.nextar],0 + jmp .cacheloop +.skipall + pop ebx + pop edx + pop eax + ret + +.nbg dw 0 +.count db 0 +.a db 0 +.rowleft db 0 +.nextar db 0 + +NEWSYM cache8bit + ret + +;******************************************************* +; Cache 2-Bit 16x16 tiles +;******************************************************* + +NEWSYM cachetile2b16x16 + ; Keep high word ecx 0 + push eax + xor ecx,ecx + push edx + mov byte[.nextar],1 + push ebx + ; get tile info location + test al,20h + jnz .highptr + shl eax,6 ; x 64 for each line + add ax,[bgptr] + jmp .loptr +.highptr + and al,1Fh + shl eax,6 ; x 64 for each line + add ax,[bgptrc] +.loptr + add eax,[vram] + mov bx,[curtileptr] + shr bx,4 + mov byte[.count],32 + mov [.nbg],bx + ; do loop +.cacheloop + mov si,[eax] + and esi,03FFh + add si,[.nbg] + mov byte[.tileleft],4 +.nextof4 + and esi,4095 + test byte[vidmemch2+esi],01h + jz near .nocache + mov byte[vidmemch2+esi],00h + push esi + mov edi,esi + shl esi,4 + shl edi,6 + add esi,[vram] + add edi,[vcache2b] + push eax + mov byte[.rowleft],8 +.donext + mov cx,[esi] + processcache2b 0 + processcache2b 1 + processcache2b 2 + processcache2b 3 + processcache2b 4 + processcache2b 5 + processcache2b 6 + processcache2b 7 + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + pop eax + pop esi +.nocache + inc esi + cmp byte[.tileleft],3 + jne .noadd + add esi,14 +.noadd + dec byte[.tileleft] + jnz near .nextof4 + add eax,2 + dec byte[.count] + jnz near .cacheloop + + cmp byte[.nextar],0 + je .skipall + mov bx,[bgptrc] + cmp [bgptrd],bx + je .skipall + add eax,2048-64 + mov byte[.count],32 + mov byte[.nextar],0 + jmp .cacheloop +.skipall + pop ebx + pop edx + pop eax + ret + +.nbg dw 0 +.count db 0 +.a db 0 +.rowleft db 0 +.nextar db 0 +.tileleft db 0 + +NEWSYM cache2bit16x16 + ret + +;******************************************************* +; Cache 4-Bit 16x16 tiles +;******************************************************* + +NEWSYM cachetile4b16x16 + ; Keep high word ecx 0 + push eax + xor ecx,ecx + push edx + mov byte[.nextar],1 + push ebx + ; get tile info location + test al,20h + jnz .highptr + shl eax,6 ; x 64 for each line + add ax,[bgptr] + jmp .loptr +.highptr + and al,1Fh + shl eax,6 ; x 64 for each line + add ax,[bgptrc] +.loptr + add eax,[vram] + mov bx,[curtileptr] + shr bx,5 + mov byte[.count],32 + mov [.nbg],bx + + ; do loop +.cacheloop + mov si,[eax] + and esi,03FFh + add si,[.nbg] + shl esi,1 + mov byte[.tileleft],4 +.nextof4 + and esi,4095 + test word[vidmemch4+esi],0101h + jz near .nocache + mov word[vidmemch4+esi],0000h + push esi + mov edi,esi + shl esi,4 + shl edi,5 + add esi,[vram] + add edi,[vcache4b] + push eax + mov byte[.rowleft],8 +.donext + mov cx,[esi] + mov dx,[esi+16] + + processcache4b 0 + processcache4b 1 + processcache4b 2 + processcache4b 3 + processcache4b 4 + processcache4b 5 + processcache4b 6 + processcache4b 7 + + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + pop eax + pop esi +.nocache + add esi,2 + cmp byte[.tileleft],3 + jne .noadd + add esi,28 +.noadd + dec byte[.tileleft] + jnz near .nextof4 + add eax,2 + dec byte[.count] + jnz near .cacheloop + + cmp byte[.nextar],0 + je .skipall + mov bx,[bgptrc] + cmp [bgptrd],bx + je .skipall + add eax,2048-64 + mov byte[.count],32 + mov byte[.nextar],0 + jmp .cacheloop +.skipall + pop ebx + pop edx + pop eax + ret + +.nbg dw 0 +.count db 0 +.rowleft db 0 +.nextar db 0 +.tileleft db 0 + +NEWSYM cache4bit16x16 + ret + +;******************************************************* +; Cache 8-Bit 16x16 tiles +;******************************************************* + +NEWSYM cachetile8b16x16 + ; Keep high word ecx 0 + push eax + xor ecx,ecx + push edx + mov byte[.nextar],1 + push ebx + ; get tile info location + test al,20h + jnz .highptr + shl eax,6 ; x 64 for each line + add ax,[bgptr] + jmp .loptr +.highptr + and al,1Fh + shl eax,6 ; x 64 for each line + add ax,[bgptrc] +.loptr + add eax,[vram] + mov bx,[curtileptr] + shr bx,6 + mov byte[.count],32 + mov [.nbg],bx + + ; do loop +.cacheloop + mov si,[eax] + and esi,03FFh + add si,[.nbg] + shl esi,2 + mov byte[.tileleft],4 +.nextof4 + and esi,4095 + test dword[vidmemch8+esi],01010101h + jz near .nocache + mov dword[vidmemch8+esi],00000000h + push esi + mov edi,esi + shl esi,4 + shl edi,4 + add esi,[vram] + add edi,[vcache8b] + push eax + mov byte[.rowleft],8 +.donext + xor ah,ah + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov byte[.a],0 + + mov al,[esi] ; bitplane 0 + cmp al,0 + je .skipconva + test al,01h + jz .skipa0 + or ah,01h +.skipa0 + test al,02h + jz .skipa1 + or bl,01h +.skipa1 + test al,04h + jz .skipa2 + or bh,01h +.skipa2 + test al,08h + jz .skipa3 + or cl,01h +.skipa3 + test al,10h + jz .skipa4 + or ch,01h +.skipa4 + test al,20h + jz .skipa5 + or dl,01h +.skipa5 + test al,40h + jz .skipa6 + or dh,01h +.skipa6 + test al,80h + jz .skipa7 + or byte[.a],01h +.skipa7 +.skipconva + + mov al,[esi+1] ; bitplane 1 + cmp al,0 + je .skipconvb + test al,01h + jz .skipb0 + or ah,02h +.skipb0 + test al,02h + jz .skipb1 + or bl,02h +.skipb1 + test al,04h + jz .skipb2 + or bh,02h +.skipb2 + test al,08h + jz .skipb3 + or cl,02h +.skipb3 + test al,10h + jz .skipb4 + or ch,02h +.skipb4 + test al,20h + jz .skipb5 + or dl,02h +.skipb5 + test al,40h + jz .skipb6 + or dh,02h +.skipb6 + test al,80h + jz .skipb7 + or byte[.a],02h +.skipb7 +.skipconvb + + mov al,[esi+16] ; bitplane 2 + cmp al,0 + je .skipconvc + test al,01h + jz .skipc0 + or ah,04h +.skipc0 + test al,02h + jz .skipc1 + or bl,04h +.skipc1 + test al,04h + jz .skipc2 + or bh,04h +.skipc2 + test al,08h + jz .skipc3 + or cl,04h +.skipc3 + test al,10h + jz .skipc4 + or ch,04h +.skipc4 + test al,20h + jz .skipc5 + or dl,04h +.skipc5 + test al,40h + jz .skipc6 + or dh,04h +.skipc6 + test al,80h + jz .skipc7 + or byte[.a],04h +.skipc7 +.skipconvc + + mov al,[esi+17] ; bitplane 3 + cmp al,0 + je .skipconvd + test al,01h + jz .skipd0 + or ah,08h +.skipd0 + test al,02h + jz .skipd1 + or bl,08h +.skipd1 + test al,04h + jz .skipd2 + or bh,08h +.skipd2 + test al,08h + jz .skipd3 + or cl,08h +.skipd3 + test al,10h + jz .skipd4 + or ch,08h +.skipd4 + test al,20h + jz .skipd5 + or dl,08h +.skipd5 + test al,40h + jz .skipd6 + or dh,08h +.skipd6 + test al,80h + jz .skipd7 + or byte[.a],08h +.skipd7 +.skipconvd + + mov al,[esi+32] ; bitplane 4 + cmp al,0 + je .skipconve + test al,01h + jz .skipe0 + or ah,10h +.skipe0 + test al,02h + jz .skipe1 + or bl,10h +.skipe1 + test al,04h + jz .skipe2 + or bh,10h +.skipe2 + test al,08h + jz .skipe3 + or cl,10h +.skipe3 + test al,10h + jz .skipe4 + or ch,10h +.skipe4 + test al,20h + jz .skipe5 + or dl,10h +.skipe5 + test al,40h + jz .skipe6 + or dh,10h +.skipe6 + test al,80h + jz .skipe7 + or byte[.a],10h +.skipe7 +.skipconve + + mov al,[esi+33] ; bitplane 5 + cmp al,0 + je .skipconvf + test al,01h + jz .skipf0 + or ah,20h +.skipf0 + test al,02h + jz .skipf1 + or bl,20h +.skipf1 + test al,04h + jz .skipf2 + or bh,20h +.skipf2 + test al,08h + jz .skipf3 + or cl,20h +.skipf3 + test al,10h + jz .skipf4 + or ch,20h +.skipf4 + test al,20h + jz .skipf5 + or dl,20h +.skipf5 + test al,40h + jz .skipf6 + or dh,20h +.skipf6 + test al,80h + jz .skipf7 + or byte[.a],20h +.skipf7 +.skipconvf + + mov al,[esi+48] ; bitplane 6 + cmp al,0 + je .skipconvg + test al,01h + jz .skipg0 + or ah,40h +.skipg0 + test al,02h + jz .skipg1 + or bl,40h +.skipg1 + test al,04h + jz .skipg2 + or bh,40h +.skipg2 + test al,08h + jz .skipg3 + or cl,40h +.skipg3 + test al,10h + jz .skipg4 + or ch,40h +.skipg4 + test al,20h + jz .skipg5 + or dl,40h +.skipg5 + test al,40h + jz .skipg6 + or dh,40h +.skipg6 + test al,80h + jz .skipg7 + or byte[.a],40h +.skipg7 +.skipconvg + + mov al,[esi+49] ; bitplane 7 + cmp al,0 + je .skipconvh + test al,01h + jz .skiph0 + or ah,80h +.skiph0 + test al,02h + jz .skiph1 + or bl,80h +.skiph1 + test al,04h + jz .skiph2 + or bh,80h +.skiph2 + test al,08h + jz .skiph3 + or cl,80h +.skiph3 + test al,10h + jz .skiph4 + or ch,80h +.skiph4 + test al,20h + jz .skiph5 + or dl,80h +.skiph5 + test al,40h + jz .skiph6 + or dh,80h +.skiph6 + test al,80h + jz .skiph7 + or byte[.a],80h +.skiph7 +.skipconvh + + ; move all bytes into [edi] + mov [edi+7],ah + mov [edi+6],bl + mov [edi+5],bh + mov [edi+4],cl + mov [edi+3],ch + mov [edi+2],dl + mov [edi+1],dh + mov al,[.a] + mov [edi],al + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + pop eax + pop esi +.nocache + add esi,4 + cmp byte[.tileleft],3 + jne .noadd + add esi,56 +.noadd + dec byte[.tileleft] + jnz near .nextof4 + add eax,2 + dec byte[.count] + jnz near .cacheloop + + cmp byte[.nextar],0 + je .skipall + mov bx,[bgptrc] + cmp [bgptrd],bx + je .skipall + add eax,2048-64 + mov byte[.count],32 + mov byte[.nextar],0 + jmp .cacheloop +.skipall + pop ebx + pop edx + pop eax + ret + +.nbg dw 0 +.count db 0 +.a db 0 +.rowleft db 0 +.nextar db 0 +.tileleft db 0 + +NEWSYM cache8bit16x16 + ret + +NEWSYM cachesingle + cmp byte[offsetmshl],1 + je near cachesingle4b + cmp byte[offsetmshl],2 + je near cachesingle2b + ret + +%macro processcache4b2 1 + xor al,al + add dh,dh + adc al,al + add dl,dl + adc al,al + add ch,ch + adc al,al + add cl,cl + adc al,al + mov [edi+%1],al +%endmacro + +NEWSYM cachesingle4b + mov word[ebx],0 + sub ebx,vidmemch4 + push edi + mov edi,ebx + shl edi,5 ; cached ram + shl ebx,4 ; vram + add edi,[vcache4b] + add ebx,[vram] + push eax + push edx + mov byte[scacheloop],8 +.nextline + mov cx,[ebx] + mov dx,[ebx+16] + processcache4b2 0 + processcache4b2 1 + processcache4b2 2 + processcache4b2 3 + processcache4b2 4 + processcache4b2 5 + processcache4b2 6 + processcache4b2 7 + add ebx,2 + add edi,8 + dec byte[scacheloop] + jnz near .nextline + pop edx + pop eax + pop edi + ret + +NEWSYM cachesingle2b + ret + +NEWSYM scacheloop, db 0 +NEWSYM tiletypec, db 0 + +%macro processcache4b3 1 + xor al,al + add dh,dh + adc al,al + add dl,dl + adc al,al + add bh,bh + adc al,al + add bl,bl + adc al,al + mov [edi+%1],al + or al,al + jz %%zeroed + and byte[tiletypec],1 + jmp %%nozeroed +%%zeroed + and byte[tiletypec],2 +%%nozeroed +%endmacro + +NEWSYM cachesingle4bng + mov word[vidmemch4+ecx*2],0 + mov byte[tiletypec],3 + push edi + push eax + push ecx + push ebx + push edx + mov edi,ecx + shl edi,6 ; cached ram + shl ecx,5 ; vram + add edi,[vcache4b] + add ecx,[vram] + mov byte[scacheloop],8 +.nextline + mov bx,[ecx] + mov dx,[ecx+16] + processcache4b3 0 + processcache4b3 1 + processcache4b3 2 + processcache4b3 3 + processcache4b3 4 + processcache4b3 5 + processcache4b3 6 + processcache4b3 7 + add ecx,2 + add edi,8 + dec byte[scacheloop] + jnz near .nextline + pop edx + pop ebx + pop ecx + mov al,[tiletypec] + mov [tltype4b+ecx],al + pop eax + pop edi + ret + +%macro processcache2b3 1 + xor al,al + add bh,bh + adc al,al + add bl,bl + adc al,al + mov [edi+%1],al + or al,al + jz %%zeroed + and byte[tiletypec],1 + jmp %%nozeroed +%%zeroed + and byte[tiletypec],2 +%%nozeroed +%endmacro + +NEWSYM cachesingle2bng + mov byte[vidmemch2+ecx],0 + mov byte[tiletypec],3 + push edi + push eax + push ecx + push ebx + push edx + mov edi,ecx + shl edi,6 ; cached ram + shl ecx,4 ; vram + add edi,[vcache2b] + add ecx,[vram] + mov byte[scacheloop],8 +.nextline + mov bx,[ecx] + processcache2b3 0 + processcache2b3 1 + processcache2b3 2 + processcache2b3 3 + processcache2b3 4 + processcache2b3 5 + processcache2b3 6 + processcache2b3 7 + add ecx,2 + add edi,8 + dec byte[scacheloop] + jnz near .nextline + pop edx + pop ebx + pop ecx + mov al,[tiletypec] + mov [tltype2b+ecx],al + pop eax + pop edi + ret + +%macro processcache8b3 1 + xor esi,esi + add ch,ch + adc esi,esi + add cl,cl + adc esi,esi + add dh,dh + adc esi,esi + add dl,dl + adc esi,esi + add ah,ah + adc esi,esi + add al,al + adc esi,esi + add bh,bh + adc esi,esi + add bl,bl + adc esi,esi + push eax + mov eax,esi + mov [edi+%1],al + or al,al + jz %%zeroed + and byte[tiletypec],1 + jmp %%nozeroed +%%zeroed + and byte[tiletypec],2 +%%nozeroed + pop eax +%endmacro + +NEWSYM cachesingle8bng + mov dword[vidmemch8+ecx*4],0 + mov byte[tiletypec],3 + push esi + push edi + push eax + push ecx + push ebx + push edx + mov edi,ecx + shl edi,6 ; cached ram + shl ecx,6 ; vram + add edi,[vcache8b] + add ecx,[vram] + mov byte[scacheloop],8 +.nextline + mov bx,[ecx] + mov ax,[ecx+16] + mov dx,[ecx+32] + push ecx + mov cx,[ecx+48] + processcache8b3 0 + processcache8b3 1 + processcache8b3 2 + processcache8b3 3 + processcache8b3 4 + processcache8b3 5 + processcache8b3 6 + processcache8b3 7 + pop ecx + add ecx,2 + add edi,8 + dec byte[scacheloop] + jnz near .nextline + pop edx + pop ebx + pop ecx + mov al,[tiletypec] + mov [tltype8b+ecx],al + pop eax + pop edi + pop esi + ret + \ No newline at end of file diff --git a/zsnes/src/video/2xsai.cpp b/zsnes/src/video/2xsai.cpp new file mode 100644 index 00000000..8e5276ec --- /dev/null +++ b/zsnes/src/video/2xsai.cpp @@ -0,0 +1,289 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +//#define MMX + + +#define uint32 unsigned long +#define uint16 unsigned short +#define uint8 unsigned char + + + +static uint32 colorMask = 0xF7DEF7DE; +static uint32 lowPixelMask = 0x08210821; +static uint32 qcolorMask = 0xE79CE79C; +static uint32 qlowpixelMask = 0x18631863; +static uint32 redblueMask = 0xF81F; +static uint32 greenMask = 0x7E0; + + + +extern "C" void Init_2xSaI(uint32 BitFormat) +{ + + + if (BitFormat == 565) + { + colorMask = 0xF7DEF7DE; + lowPixelMask = 0x08210821; + qcolorMask = 0xE79CE79C; + qlowpixelMask = 0x18631863; + redblueMask = 0xF81F; + greenMask = 0x7E0; + } + else + if (BitFormat == 555) + { + colorMask = 0x7BDE7BDE; + lowPixelMask = 0x04210421; + qcolorMask = 0x739C739C; + qlowpixelMask = 0x0C630C63; + redblueMask = 0x7C1F; + greenMask = 0x3E0; + } + else + { + return; + } +#ifdef MMX + Init_2xSaIMMX(BitFormat); +#endif + return; +} + + +static inline int GetResult1(uint32 A, uint32 B, uint32 C, uint32 D, uint32 E) +{ + int x = 0; + int y = 0; + int r = 0; + if (A == C) x+=1; else if (B == C) y+=1; + if (A == D) x+=1; else if (B == D) y+=1; + if (x <= 1) r+=1; + if (y <= 1) r-=1; + return r; +} + +static inline int GetResult2(uint32 A, uint32 B, uint32 C, uint32 D, uint32 E) +{ + int x = 0; + int y = 0; + int r = 0; + if (A == C) x+=1; else if (B == C) y+=1; + if (A == D) x+=1; else if (B == D) y+=1; + if (x <= 1) r-=1; + if (y <= 1) r+=1; + return r; +} + + +static inline int GetResult(uint32 A, uint32 B, uint32 C, uint32 D) +{ + int x = 0; + int y = 0; + int r = 0; + if (A == C) x+=1; else if (B == C) y+=1; + if (A == D) x+=1; else if (B == D) y+=1; + if (x <= 1) r+=1; + if (y <= 1) r-=1; + return r; +} + + +static inline uint32 INTERPOLATE(uint32 A, uint32 B) +{ + if (A !=B) + { + return ( ((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask) ); + } + else return A; +} + + +static inline uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D) +{ + register uint32 x = ((A & qcolorMask) >> 2) + + ((B & qcolorMask) >> 2) + + ((C & qcolorMask) >> 2) + + ((D & qcolorMask) >> 2); + register uint32 y = (A & qlowpixelMask) + + (B & qlowpixelMask) + + (C & qlowpixelMask) + + (D & qlowpixelMask); + y = (y>>2) & qlowpixelMask; + return x+y; +} + + +#define BLUE_MASK565 0x001F001F +#define RED_MASK565 0xF800F800 +#define GREEN_MASK565 0x07E007E0 + +#define BLUE_MASK555 0x001F001F +#define RED_MASK555 0x7C007C00 +#define GREEN_MASK555 0x03E003E0 + + +//srcPtr equ 8 +//deltaPtr equ 12 +//srcPitch equ 16 +//width equ 20 +//dstOffset equ 24 +//dstPitch equ 28 +//dstSegment equ 32 + +extern "C" void Super2xSaI(uint8 *srcPtr, uint8 *deltaPtr, uint32 srcPitch, + int width, uint8 *dstPtr , uint32 dstPitch) +{ + uint16 *dP; + uint16 *bP; + uint32 inc_bP; + int height = 1; + uint32 dPitch = dstPitch >> 1; + uint32 Nextline = srcPitch >> 1; + + { + inc_bP = 1; + +// for (height; height; height-=1) + { + bP = (uint16 *) srcPtr; + dP = (uint16 *) dstPtr; + for (uint32 finish = width; finish; finish -= inc_bP ) + { + uint32 color4, color5, color6; + uint32 color1, color2, color3; + uint32 colorA0, colorA1, colorA2, colorA3, + colorB0, colorB1, colorB2, colorB3, + colorS1, colorS2; + uint32 product1a, product1b, + product2a, product2b; + +//--------------------------------------- B1 B2 +// 4 5 6 S2 +// 1 2 3 S1 +// A1 A2 + + colorB0 = *(bP- Nextline - 1); + colorB1 = *(bP- Nextline); + colorB2 = *(bP- Nextline + 1); + colorB3 = *(bP- Nextline + 2); + + color4 = *(bP - 1); + color5 = *(bP); + color6 = *(bP + 1); + colorS2 = *(bP + 2); + + color1 = *(bP + Nextline - 1); + color2 = *(bP + Nextline); + color3 = *(bP + Nextline + 1); + colorS1 = *(bP + Nextline + 2); + + colorA0 = *(bP + Nextline + Nextline - 1); + colorA1 = *(bP + Nextline + Nextline); + colorA2 = *(bP + Nextline + Nextline + 1); + colorA3 = *(bP + Nextline + Nextline + 2); + + +//-------------------------------------- + if (color2 == color6 && color5 != color3) + { + product2b = product1b = color2; + } + else + if (color5 == color3 && color2 != color6) + { + product2b = product1b = color5; + } + else + if (color5 == color3 && color2 == color6) + { + register int r = 0; + + r += GetResult (color6, color5, color1, colorA1); + r += GetResult (color6, color5, color4, colorB1); + r += GetResult (color6, color5, colorA2, colorS1); + r += GetResult (color6, color5, colorB2, colorS2); + + if (r > 0) + product2b = product1b = color6; + else + if (r < 0) + product2b = product1b = color5; + else + { + product2b = product1b = INTERPOLATE (color5, color6); + } + + } + else + { + + if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0) + product2b = Q_INTERPOLATE (color3, color3, color3, color2); + else + if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3) + product2b = Q_INTERPOLATE (color2, color2, color2, color3); + else + product2b = INTERPOLATE (color2, color3); + + if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0) + product1b = Q_INTERPOLATE (color6, color6, color6, color5); + else + if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3) + product1b = Q_INTERPOLATE (color6, color5, color5, color5); + else + product1b = INTERPOLATE (color5, color6); + } + + if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2) + product2a = INTERPOLATE (color2, color5); + else + if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0) + product2a = INTERPOLATE(color2, color5); + else + product2a = color2; + + if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2) + product1a = INTERPOLATE (color2, color5); + else + if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0) + product1a = INTERPOLATE(color2, color5); + else + product1a = color5; + + + product1a = product1a | (product1b << 16); + product2a = product2a | (product2b << 16); + + *dP = product1a; + *(dP + 1) = product1b; + *(dP + dPitch) = product2a; + *(dP + dPitch + 1) = product2b; + + bP ++; + dP += 2; + }//end of for ( finish= width etc..) + + srcPtr += srcPitch; + deltaPtr += srcPitch << 1; + }; //endof: for (height; height; height--) + } +} + \ No newline at end of file diff --git a/zsnes/src/video/2xsaimmx.inc b/zsnes/src/video/2xsaimmx.inc new file mode 100644 index 00000000..43525f98 --- /dev/null +++ b/zsnes/src/video/2xsaimmx.inc @@ -0,0 +1,1358 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +;/*---------------------------------------------------------------------* +; * The following (piece of) code, (part of) the 2xSaI engine, * +; * copyright (c) 1999 by Derek Liauw Kie Fa. * +; * Non-Commercial use of the engine is allowed and is encouraged, * +; * provided that appropriate credit be given and that this copyright * +; * notice will not be removed under any circumstance. * +; * You may freely modify this code, but I request * +; * that any improvements to the engine be submitted to me, so * +; * that I can implement these improvements in newer versions of * +; * the engine. * +; * If you need more information, have any comments or suggestions, * +; * you can e-mail me. My e-mail: derek-liauw@usa.net. * +; *---------------------------------------------------------------------*/ + +;---------------------- +; 2xSaI version 0.59 WIP, soon to become version 0.60 +;---------------------- + + BITS 32 +%ifdef __DJGPP__ +; GLOBAL __2xSaILine +; GLOBAL __2xSaISuperEagleLine +; GLOBAL _Init_2xSaIMMX +%else + GLOBAL _2xSaILine + GLOBAL _2xSaISuperEagleLine + GLOBAL Init_2xSaIMMX +%endif + SECTION .text ALIGN = 32 + +%ifdef __DJGPP__ +;EXTERN_C void __2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width, +; uint8 *dstPtr, uint32 dstPitch, uint16 dstSegment); +%else +;EXTERN_C void _2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width, +; uint8 *dstPtr, uint32 dstPitch); +%endif + +srcPtr equ 8 +deltaPtr equ 12 +srcPitch equ 16 +width equ 20 +dstOffset equ 24 +dstPitch equ 28 +dstSegment equ 32 + + +colorB0 equ -2 +colorB1 equ 0 +colorB2 equ 2 +colorB3 equ 4 + +color7 equ -2 +color8 equ 0 +color9 equ 2 + +color4 equ -2 +color5 equ 0 +color6 equ 2 +colorS2 equ 4 + +color1 equ -2 +color2 equ 0 +color3 equ 2 +colorS1 equ 4 + +colorA0 equ -2 +colorA1 equ 0 +colorA2 equ 2 +colorA3 equ 4 + + + +NEWSYM _2xSaISuperEagleLine +; Store some stuff + push ebp + mov ebp, esp + pushad + +; Prepare the destination +%ifdef __DJGPP__ + ; Set the selector + mov eax, [ebp+dstSegment] + mov fs, ax +%endif + mov edx, [ebp+dstOffset] ; edx points to the screen +; Prepare the source + ; eax points to colorA + mov eax, [ebp+srcPtr] + mov ebx, [ebp+srcPitch] + mov ecx, [ebp+width] + ; eax now points to colorB1 + sub eax, ebx + +; Main Loop +.Loop: push ecx + + ;-----Check Delta------------------ + mov ecx, [ebp+deltaPtr] + + movq mm0, [eax+colorB0] + movq mm1, [eax+colorB3] + movq mm2, [eax+ebx+color4] + movq mm3, [eax+ebx+colorS2] + movq mm4, [eax+ebx+ebx+color1] + movq mm5, [eax+ebx+ebx+colorS1] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorA0] + movq mm7, [eax+ebx+ebx+colorA3] + pop eax + + pcmpeqw mm0, [ecx+2+colorB0] + pcmpeqw mm1, [ecx+2+colorB3] + pcmpeqw mm2, [ecx+ebx+2+color4] + pcmpeqw mm3, [ecx+ebx+2+colorS2] + pcmpeqw mm4, [ecx+ebx+ebx+2+color1] + pcmpeqw mm5, [ecx+ebx+ebx+2+colorS1] + add ecx, ebx + pcmpeqw mm6, [ecx+ebx+ebx+2+colorA0] + pcmpeqw mm7, [ecx+ebx+ebx+2+colorA3] + sub ecx, ebx + + + pand mm0, mm1 + pand mm2, mm3 + pand mm4, mm5 + pand mm6, mm7 + pand mm0, mm2 + pand mm4, mm6 + pxor mm7, mm7 + pand mm0, mm4 + movq mm6, [eax+colorB0] + pcmpeqw mm7, mm0 + + movq [ecx+2+colorB0], mm6 + + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_PROCESS + + ;End Delta + + ;--------------------------------- + movq mm0, [eax+ebx+color5] + movq mm1, [eax+ebx+color6] + movq mm2, mm0 + movq mm3, mm1 + movq mm4, mm0 + movq mm5, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + movq [I56Pixel], mm0 + movq mm7, mm0 + + ;------------------- + movq mm0, mm7 + movq mm1, mm4 ;5,5,5,6 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + movq [product1a], mm0 + ;-------------------- + + movq mm0, mm7 + movq mm1, mm5 ;6,6,6,5 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product1b], mm0 + + ;------------------------- + ;------------------------- + movq mm0, [eax+ebx+ebx+color2] + movq mm1, [eax+ebx+ebx+color3] + movq mm2, mm0 + movq mm3, mm1 + movq mm4, mm0 + movq mm5, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [I23Pixel], mm0 + movq mm7, mm0 + + ;--------------------- + movq mm0, mm7 + movq mm1, mm4 ;2,2,2,3 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product2a], mm0 + + ;---------------------- + movq mm0, mm7 + movq mm1, mm5 ;3,3,3,2 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product2b], mm0 + + + ;//////////////////////////////// + ; Decide which "branch" to take + ;-------------------------------- + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + movq mm6, [eax+ebx+ebx+color3] + movq mm7, [eax+ebx+ebx+color2] + + pxor mm3, mm3 + movq mm0, mm4 + movq mm1, mm5 + + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pcmpeqw mm1, mm3 + pand mm0, mm1 + movq [Mask35], mm0 + + movq mm0, [eax+ebx+ebx+colorS1] + movq mm1, [eax+ebx+color4] + push eax + add eax, ebx + movq mm2, [eax+ebx+ebx+colorA2] + pop eax + movq mm3, [eax+colorB1] + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm4 + pcmpeqw mm3, mm4 + pand mm0, mm1 + pand mm2, mm3 + por mm0, mm2 + pand mm0, [Mask35] + movq [Mask35b], mm0 + + ;----------- + pxor mm3, mm3 + movq mm0, mm4 + movq mm1, mm5 + + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pcmpeqw mm0, mm3 + pand mm0, mm1 + movq [Mask26], mm0 + + movq mm0, [eax+ebx+ebx+color1] + movq mm1, [eax+ebx+colorS2] + push eax + add eax, ebx + movq mm2, [eax+ebx+ebx+colorA1] + pop eax + movq mm3, [eax+colorB2] + pcmpeqw mm0, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm1 + pand mm2, mm3 + por mm0, mm2 + pand mm0, [Mask26] + movq [Mask26b], mm0 + + ;-------------------- + movq mm0, mm4 + movq mm1, mm5 + movq mm2, mm0 + + pcmpeqw mm2, mm1 + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pand mm0, mm1 + pand mm2, mm0 + pxor mm0, mm2 + movq mm7, mm0 + + ;------------------ + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_GUESS + +;--------------------------------------------- +; Map of the pixels: I|E F|J +; G|A B|K +; H|C D|L +; M|N O|P + movq mm6, mm0 + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + pxor mm7, mm7 + pand mm6, [ONE] + + movq mm0, [eax+colorB1] + movq mm1, [eax+ebx+color4] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+colorB2] + movq mm1, [eax+ebx+colorS2] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + push eax + add eax, ebx + movq mm0, [eax+ebx+color1] + movq mm1, [eax+ebx+ebx+colorA1] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+ebx+colorS1] + movq mm1, [eax+ebx+ebx+colorA2] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + pop eax + movq mm1, mm7 + pxor mm0, mm0 + pcmpgtw mm7, mm0 + pcmpgtw mm0, mm1 + + por mm7, [Mask35] + por mm1, [Mask26] + movq [Mask35], mm7 + movq [Mask26], mm1 + +.SKIP_GUESS: + ;Start the ASSEMBLY !!! + + movq mm4, [Mask35] + movq mm5, [Mask26] + movq mm6, [Mask35b] + movq mm7, [Mask26b] + + movq mm0, [eax+ebx+color5] + movq mm1, [eax+ebx+color6] + movq mm2, [eax+ebx+ebx+color2] + movq mm3, [eax+ebx+ebx+color3] + pcmpeqw mm0, mm2 + pcmpeqw mm1, mm3 + movq mm2, mm4 + movq mm3, mm5 + por mm0, mm1 + por mm2, mm3 + pand mm2, mm0 + pxor mm0, mm2 + movq mm3, mm0 + + movq mm2, mm0 + pxor mm0, mm0 + por mm2, mm4 + pxor mm4, mm6 + por mm2, mm5 + pxor mm5, mm7 + pcmpeqw mm2, mm0 + ;---------------- + + movq mm0, [eax+ebx+color5] + movq mm1, mm3 + por mm1, mm4 + por mm1, mm6 + pand mm0, mm1 + movq mm1, mm5 + pand mm1, [I56Pixel] + por mm0, mm1 + movq mm1, mm7 + pand mm1, [product1b] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product1a] + por mm0, mm1 + movq [final1a], mm0 + + movq mm0, [eax+ebx+color6] + movq mm1, mm3 + por mm1, mm5 + por mm1, mm7 + pand mm0, mm1 + movq mm1, mm4 + pand mm1, [I56Pixel] + por mm0, mm1 + movq mm1, mm6 + pand mm1, [product1a] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product1b] + por mm0, mm1 + movq [final1b], mm0 + + movq mm0, [eax+ebx+ebx+color2] + movq mm1, mm3 + por mm1, mm5 + por mm1, mm7 + pand mm0, mm1 + movq mm1, mm4 + pand mm1, [I23Pixel] + por mm0, mm1 + movq mm1, mm6 + pand mm1, [product2b] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product2a] + por mm0, mm1 + movq [final2a], mm0 + + movq mm0, [eax+ebx+ebx+color3] + movq mm1, mm3 + por mm1, mm4 + por mm1, mm6 + pand mm0, mm1 + movq mm1, mm5 + pand mm1, [I23Pixel] + por mm0, mm1 + movq mm1, mm7 + pand mm1, [product2a] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product2b] + por mm0, mm1 + movq [final2b], mm0 + + + movq mm0, [final1a] + movq mm2, [final1b] + movq mm1, mm0 + movq mm4, [final2a] + movq mm6, [final2b] + movq mm5, mm4 + punpcklwd mm0, mm2 + punpckhwd mm1, mm2 + punpcklwd mm4, mm6 + punpckhwd mm5, mm6 + + + + +%ifdef __DJGPP__ + movq [fs:edx], mm0 + movq [fs:edx+8], mm1 + push edx + add edx, [ebp+dstPitch] + movq [fs:edx], mm4 + movq [fs:edx+8], mm5 + pop edx +%else + movq [es:edx], mm0 + movq [es:edx+8], mm1 + push edx + add edx, [ebp+dstPitch] + movq [es:edx], mm4 + movq [es:edx+8], mm5 + pop edx +%endif +.SKIP_PROCESS: + mov ecx, [ebp+deltaPtr] + add ecx, 8 + mov [ebp+deltaPtr], ecx + add edx, 16 + add eax, 8 + + pop ecx + sub ecx, 4 + cmp ecx, 0 + jg near .Loop + +; Restore some stuff + popad + mov esp, ebp + pop ebp + emms + ret + + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + + +;This is version 0.50 +colorI equ -2 +colorE equ 0 +colorF equ 2 +colorJ equ 4 + +colorG equ -2 +colorA equ 0 +colorB equ 2 +colorK equ 4 + +colorH equ -2 +colorC equ 0 +colorD equ 2 +colorL equ 4 + +colorM equ -2 +colorN equ 0 +colorO equ 2 +colorP equ 4 + +NEWSYM _2xSaILine +; Store some stuff + push ebp + mov ebp, esp + pushad + +; Prepare the destination +%ifdef __DJGPP__ + ; Set the selector + mov eax, [ebp+dstSegment] + mov fs, ax +%endif + mov edx, [ebp+dstOffset] ; edx points to the screen +; Prepare the source + ; eax points to colorA + mov eax, [ebp+srcPtr] + mov ebx, [ebp+srcPitch] + mov ecx, [ebp+width] + ; eax now points to colorE + sub eax, ebx + + +; Main Loop +.Loop: push ecx + + ;-----Check Delta------------------ + mov ecx, [ebp+deltaPtr] + + movq mm0, [eax+colorI] + movq mm1, [eax+colorJ] + movq mm2, [eax+ebx+colorG] + movq mm3, [eax+ebx+colorK] + movq mm4, [eax+ebx+ebx+colorH] + movq mm5, [eax+ebx+ebx+colorL] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorM] + movq mm7, [eax+ebx+ebx+colorP] + pop eax + + pcmpeqw mm0, [ecx+2+colorI] + pcmpeqw mm1, [ecx+2+colorK] + pcmpeqw mm2, [ecx+ebx+2+colorG] + pcmpeqw mm3, [ecx+ebx+2+colorK] + pcmpeqw mm4, [ecx+ebx+ebx+2+colorH] + pcmpeqw mm5, [ecx+ebx+ebx+2+colorL] + add ecx, ebx + pcmpeqw mm6, [ecx+ebx+ebx+2+colorM] + pcmpeqw mm7, [ecx+ebx+ebx+2+colorP] + sub ecx, ebx + + + pand mm0, mm1 + pand mm2, mm3 + pand mm4, mm5 + pand mm6, mm7 + pand mm0, mm2 + pand mm4, mm6 + pxor mm7, mm7 + pand mm0, mm4 + movq mm6, [eax+colorI] + pcmpeqw mm7, mm0 + + movq [ecx+2+colorI], mm6 + + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_PROCESS + + ;End Delta + + ;--------------------------------- + + +;1 + ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorE) && (colorB == colorL) + movq mm0, [eax+ebx+colorA] ;mm0 and mm1 contain colorA + movq mm2, [eax+ebx+colorB] ;mm2 and mm3 contain colorB + + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+ebx+colorD] + pcmpeqw mm1, [eax+colorE] + pcmpeqw mm2, [eax+ebx+ebx+colorL] + pcmpeqw mm3, [eax+ebx+ebx+colorC] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorA == colorC) && (colorB != colorE) && (colorA == colorF) && (colorB == colorJ) + movq mm4, [eax+ebx+colorA] ;mm4 and mm5 contain colorA + movq mm6, [eax+ebx+colorB] ;mm6 and mm7 contain colorB + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorC] + pcmpeqw mm5, [eax+colorF] + pcmpeqw mm6, [eax+colorJ] + pcmpeqw mm7, [eax+colorE] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask1], mm0 + + ;-------------------------------------------- + +;2 + ;if ((colorB == colorC) && (colorA != colorD) && (colorB == colorF) && (colorA == colorH) + movq mm0, [eax+ebx+colorB] ;mm0 and mm1 contain colorB + movq mm2, [eax+ebx+colorA] ;mm2 and mm3 contain colorA + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+ebx+colorC] + pcmpeqw mm1, [eax+colorF] + pcmpeqw mm2, [eax+ebx+ebx+colorH] + pcmpeqw mm3, [eax+ebx+ebx+colorD] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI) + movq mm4, [eax+ebx+colorB] ;mm4 and mm5 contain colorB + movq mm6, [eax+ebx+colorA] ;mm6 and mm7 contain colorA + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorD] + pcmpeqw mm5, [eax+colorE] + pcmpeqw mm6, [eax+colorI] + pcmpeqw mm7, [eax+colorF] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask2], mm0 + + +;interpolate colorA and colorB + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + + ;assemble the pixels + movq mm1, [eax+ebx+colorA] + movq mm2, [eax+ebx+colorB] + + movq mm3, [Mask1] + movq mm5, mm1 + movq mm4, [Mask2] + movq mm6, mm1 + + pand mm1, mm3 + por mm3, mm4 + pxor mm7, mm7 + pand mm2, mm4 + + pcmpeqw mm3, mm7 + por mm1, mm2 + pand mm0, mm3 + + por mm0, mm1 + + punpcklwd mm5, mm0 + punpckhwd mm6, mm0 + +%ifdef __DJGPP__ + movq [fs:edx], mm5 + movq [fs:edx+8], mm6 +%else + movq [es:edx], mm5 + movq [es:edx+8], mm6 +%endif + +;------------------------------------------------ +; Create the Nextline +;------------------------------------------------ +;3 ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorG) && (colorC == colorO) + movq mm0, [eax+ebx+colorA] ;mm0 and mm1 contain colorA + movq mm2, [eax+ebx+ebx+colorC] ;mm2 and mm3 contain colorC + movq mm1, mm0 + movq mm3, mm2 + + push eax + add eax, ebx + pcmpeqw mm0, [eax+ebx+colorD] + pcmpeqw mm1, [eax+colorG] + pcmpeqw mm2, [eax+ebx+ebx+colorO] + pcmpeqw mm3, [eax+colorB] + pop eax + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorA == colorB) && (colorG != colorC) && (colorA == colorH) && (colorC == colorM) + movq mm4, [eax+ebx+colorA] ;mm4 and mm5 contain colorA + movq mm6, [eax+ebx+ebx+colorC] ;mm6 and mm7 contain colorC + movq mm5, mm4 + movq mm7, mm6 + + push eax + add eax, ebx + pcmpeqw mm4, [eax+ebx+colorH] + pcmpeqw mm5, [eax+colorB] + pcmpeqw mm6, [eax+ebx+ebx+colorM] + pcmpeqw mm7, [eax+colorG] + pop eax + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask1], mm0 + ;-------------------------------------------- + +;4 + ;if ((colorB == colorC) && (colorA != colorD) && (colorC == colorH) && (colorA == colorF) + movq mm0, [eax+ebx+ebx+colorC] ;mm0 and mm1 contain colorC + movq mm2, [eax+ebx+colorA] ;mm2 and mm3 contain colorA + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+colorB] + pcmpeqw mm1, [eax+ebx+ebx+colorH] + pcmpeqw mm2, [eax+colorF] + pcmpeqw mm3, [eax+ebx+ebx+colorD] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI) + movq mm4, [eax+ebx+ebx+colorC] ;mm4 and mm5 contain colorC + movq mm6, [eax+ebx+colorA] ;mm6 and mm7 contain colorA + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorD] + pcmpeqw mm5, [eax+ebx+colorG] + pcmpeqw mm6, [eax+colorI] + pcmpeqw mm7, [eax+ebx+ebx+colorH] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask2], mm0 + ;---------------------------------------------- + +;interpolate colorA and colorC + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+ebx+colorC] + + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + ;------------- + + ;assemble the pixels + movq mm1, [eax+ebx+colorA] + movq mm2, [eax+ebx+ebx+colorC] + + movq mm3, [Mask1] + movq mm4, [Mask2] + + pand mm1, mm3 + pand mm2, mm4 + + por mm3, mm4 + pxor mm7, mm7 + por mm1, mm2 + + pcmpeqw mm3, mm7 + pand mm0, mm3 + por mm0, mm1 + movq [ACPixel], mm0 + +;//////////////////////////////// +; Decide which "branch" to take +;-------------------------------- + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + movq mm6, mm0 + movq mm7, mm1 + pcmpeqw mm0, [eax+ebx+ebx+colorD] + pcmpeqw mm1, [eax+ebx+ebx+colorC] + pcmpeqw mm6, mm7 + + movq mm2, mm0 + movq mm3, mm0 + + pand mm0, mm1 ;colorA == colorD && colorB == colorC + pxor mm7, mm7 + + pcmpeqw mm2, mm7 + pand mm6, mm0 + pand mm2, mm1 ;colorA != colorD && colorB == colorC + + pcmpeqw mm1, mm7 + + pand mm1, mm3 ;colorA == colorD && colorB != colorC + pxor mm0, mm6 + por mm1, mm6 + movq mm7, mm0 + movq [Mask2], mm2 + packsswb mm7, mm7 + movq [Mask1], mm1 + + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_GUESS +;--------------------------------------------- +; Map of the pixels: I|E F|J +; G|A B|K +; H|C D|L +; M|N O|P + movq mm6, mm0 + movq mm4, [eax+ebx+colorA] + movq mm5, [eax+ebx+colorB] + pxor mm7, mm7 + pand mm6, [ONE] + + movq mm0, [eax+colorE] + movq mm1, [eax+ebx+colorG] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+colorF] + movq mm1, [eax+ebx+colorK] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + push eax + add eax, ebx + movq mm0, [eax+ebx+colorH] + movq mm1, [eax+ebx+ebx+colorN] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+ebx+colorL] + movq mm1, [eax+ebx+ebx+colorO] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + pop eax + movq mm1, mm7 + pxor mm0, mm0 + pcmpgtw mm7, mm0 + pcmpgtw mm0, mm1 + + por mm7, [Mask1] + por mm1, [Mask2] + movq [Mask1], mm7 + movq [Mask2], mm1 + +.SKIP_GUESS: + ;---------------------------- + ;interpolate A, B, C and D + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + movq mm4, mm0 + movq mm2, [eax+ebx+ebx+colorC] + movq mm5, mm1 + movq mm3, [qcolorMask] + movq mm6, mm2 + movq mm7, [qlowpixelMask] + + pand mm0, mm3 + pand mm1, mm3 + pand mm2, mm3 + pand mm3, [eax+ebx+ebx+colorD] + + psrlw mm0, 2 + pand mm4, mm7 + psrlw mm1, 2 + pand mm5, mm7 + psrlw mm2, 2 + pand mm6, mm7 + psrlw mm3, 2 + pand mm7, [eax+ebx+ebx+colorD] + + paddw mm0, mm1 + paddw mm2, mm3 + + paddw mm4, mm5 + paddw mm6, mm7 + + paddw mm4, mm6 + paddw mm0, mm2 + psrlw mm4, 2 + pand mm4, [qlowpixelMask] + paddw mm0, mm4 ;mm0 contains the interpolated value of A, B, C and D + +;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ + ;assemble the pixels + movq mm1, [Mask1] + movq mm2, [Mask2] + movq mm4, [eax+ebx+colorA] + movq mm5, [eax+ebx+colorB] + pand mm4, mm1 + pand mm5, mm2 + + pxor mm7, mm7 + por mm1, mm2 + por mm4, mm5 + pcmpeqw mm1, mm7 + pand mm0, mm1 + por mm4, mm0 ;mm4 contains the diagonal pixels + + movq mm0, [ACPixel] + movq mm1, mm0 + punpcklwd mm0, mm4 + punpckhwd mm1, mm4 + + push edx + add edx, [ebp+dstPitch] + +%ifdef __DJGPP__ + movq [fs:edx], mm0 + movq [fs:edx+8], mm1 +%else + movq [es:edx], mm0 + movq [es:edx+8], mm1 +%endif + pop edx + +.SKIP_PROCESS: + mov ecx, [ebp+deltaPtr] + add ecx, 8 + mov [ebp+deltaPtr], ecx + add edx, 16 + add eax, 8 + + pop ecx + sub ecx, 4 + cmp ecx, 0 + jg near .Loop + +; Restore some stuff + popad + mov esp, ebp + pop ebp + emms + ret + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + +NEWSYM Init_2xSaIMMX +; Store some stuff + push ebp + mov ebp, esp + push edx + + +;Damn thing doesn't work +; mov eax,1 +; cpuid +; test edx, 0x00800000 ;test bit 23 +; jz end2 ;bit not set => no MMX detected + + mov eax, [ebp+8] ;PixelFormat + cmp eax, 555 + jz Bits555 + cmp eax, 565 + jz Bits565 +end2: + mov eax, 1 + jmp end +Bits555: + mov edx, 0x7BDE7BDE + mov eax, colorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x04210421 + mov eax, lowPixelMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x739C739C + mov eax, qcolorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x0C630C63 + mov eax, qlowpixelMask + mov [eax], edx + mov [eax+4], edx + mov eax, 0 + jmp end +Bits565: + mov edx, 0xF7DEF7DE + mov eax, colorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x08210821 + mov eax, lowPixelMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0xE79CE79C + mov eax, qcolorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x18631863 + mov eax, qlowpixelMask + mov [eax], edx + mov [eax+4], edx + mov eax, 0 + jmp end +end: + pop edx + mov esp, ebp + pop ebp + ret + + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + + SECTION .data ALIGN = 32 +;Some constants +colorMask dd 0xF7DEF7DE, 0xF7DEF7DE +lowPixelMask dd 0x08210821, 0x08210821 + +qcolorMask dd 0xE79CE79C, 0xE79CE79C +qlowpixelMask dd 0x18631863, 0x18631863 + +FALSE dd 0x00000000, 0x00000000 +TRUE dd 0xffffffff, 0xffffffff +ONE dd 0x00010001, 0x00010001 + +ACPixel times 8 db 0 +Mask1 times 8 db 0 +Mask2 times 8 db 0 + +I56Pixel times 8 db 0 +I23Pixel times 8 db 0 +Mask26 times 8 db 0 +Mask35 times 8 db 0 +Mask26b times 8 db 0 +Mask35b times 8 db 0 +product1a times 8 db 0 +product1b times 8 db 0 +product2a times 8 db 0 +product2b times 8 db 0 +final1a times 8 db 0 +final1b times 8 db 0 +final2a times 8 db 0 +final2b times 8 db 0 + \ No newline at end of file diff --git a/zsnes/src/video/2xsaiw.asm b/zsnes/src/video/2xsaiw.asm new file mode 100644 index 00000000..4077dc7f --- /dev/null +++ b/zsnes/src/video/2xsaiw.asm @@ -0,0 +1,1345 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + + +;/*---------------------------------------------------------------------* +; * The following (piece of) code, (part of) the 2xSaI engine, * +; * copyright (c) 1999 by Derek Liauw Kie Fa. * +; * Non-Commercial use of the engine is allowed and is encouraged, * +; * provided that appropriate credit be given and that this copyright * +; * notice will not be removed under any circumstance. * +; * You may freely modify this code, but I request * +; * that any improvements to the engine be submitted to me, so * +; * that I can implement these improvements in newer versions of * +; * the engine. * +; * If you need more information, have any comments or suggestions, * +; * you can e-mail me. My e-mail: derek-liauw@usa.net. * +; *---------------------------------------------------------------------*/ + +;---------------------- +; 2xSaI version 0.59 WIP, soon to become version 0.60 +;---------------------- + + BITS 32 + + SECTION .text ALIGN = 32 + +srcPtr equ 8 +deltaPtr equ 12 +srcPitch equ 16 +width equ 20 +dstOffset equ 24 +dstPitch equ 28 +dstSegment equ 32 + + +colorB0 equ -2 +colorB1 equ 0 +colorB2 equ 2 +colorB3 equ 4 + +color7 equ -2 +color8 equ 0 +color9 equ 2 + +color4 equ -2 +color5 equ 0 +color6 equ 2 +colorS2 equ 4 + +color1 equ -2 +color2 equ 0 +color3 equ 2 +colorS1 equ 4 + +colorA0 equ -2 +colorA1 equ 0 +colorA2 equ 2 +colorA3 equ 4 + + + +NEWSYM _2xSaISuperEagleLineW + +; Store some stuff + push ebp + mov ebp, esp + pushad + +; Prepare the destination +%ifdef __DJGPP__ + ; Set the selector + mov eax, [ebp+dstSegment] + mov fs, ax +%endif + mov edx, [ebp+dstOffset] ; edx points to the screen +; Prepare the source + ; eax points to colorA + mov eax, [ebp+srcPtr] + mov ebx, [ebp+srcPitch] + mov ecx, [ebp+width] + ; eax now points to colorB1 + sub eax, ebx + +; Main Loop +.Loop: push ecx + + ;-----Check Delta------------------ + mov ecx, [ebp+deltaPtr] + + movq mm0, [eax+colorB0] + movq mm1, [eax+colorB3] + movq mm2, [eax+ebx+color4] + movq mm3, [eax+ebx+colorS2] + movq mm4, [eax+ebx+ebx+color1] + movq mm5, [eax+ebx+ebx+colorS1] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorA0] + movq mm7, [eax+ebx+ebx+colorA3] + pop eax + + pcmpeqw mm0, [ecx+2+colorB0] + pcmpeqw mm1, [ecx+2+colorB3] + pcmpeqw mm2, [ecx+ebx+2+color4] + pcmpeqw mm3, [ecx+ebx+2+colorS2] + pcmpeqw mm4, [ecx+ebx+ebx+2+color1] + pcmpeqw mm5, [ecx+ebx+ebx+2+colorS1] + add ecx, ebx + pcmpeqw mm6, [ecx+ebx+ebx+2+colorA0] + pcmpeqw mm7, [ecx+ebx+ebx+2+colorA3] + sub ecx, ebx + + + pand mm0, mm1 + pand mm2, mm3 + pand mm4, mm5 + pand mm6, mm7 + pand mm0, mm2 + pand mm4, mm6 + pxor mm7, mm7 + pand mm0, mm4 + movq mm6, [eax+colorB0] + pcmpeqw mm7, mm0 + + movq [ecx+2+colorB0], mm6 + + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_PROCESS + + ;End Delta + + ;--------------------------------- + movq mm0, [eax+ebx+color5] + movq mm1, [eax+ebx+color6] + movq mm2, mm0 + movq mm3, mm1 + movq mm4, mm0 + movq mm5, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + movq [I56Pixel], mm0 + movq mm7, mm0 + + ;------------------- + movq mm0, mm7 + movq mm1, mm4 ;5,5,5,6 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + movq [product1a], mm0 + ;-------------------- + + movq mm0, mm7 + movq mm1, mm5 ;6,6,6,5 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product1b], mm0 + + ;------------------------- + ;------------------------- + movq mm0, [eax+ebx+ebx+color2] + movq mm1, [eax+ebx+ebx+color3] + movq mm2, mm0 + movq mm3, mm1 + movq mm4, mm0 + movq mm5, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [I23Pixel], mm0 + movq mm7, mm0 + + ;--------------------- + movq mm0, mm7 + movq mm1, mm4 ;2,2,2,3 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product2a], mm0 + + ;---------------------- + movq mm0, mm7 + movq mm1, mm5 ;3,3,3,2 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product2b], mm0 + + + ;//////////////////////////////// + ; Decide which "branch" to take + ;-------------------------------- + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + movq mm6, [eax+ebx+ebx+color3] + movq mm7, [eax+ebx+ebx+color2] + + pxor mm3, mm3 + movq mm0, mm4 + movq mm1, mm5 + + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pcmpeqw mm1, mm3 + pand mm0, mm1 + movq [Mask35], mm0 + + movq mm0, [eax+ebx+ebx+colorS1] + movq mm1, [eax+ebx+color4] + push eax + add eax, ebx + movq mm2, [eax+ebx+ebx+colorA2] + pop eax + movq mm3, [eax+colorB1] + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm4 + pcmpeqw mm3, mm4 + pand mm0, mm1 + pand mm2, mm3 + por mm0, mm2 + pand mm0, [Mask35] + movq [Mask35b], mm0 + + ;----------- + pxor mm3, mm3 + movq mm0, mm4 + movq mm1, mm5 + + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pcmpeqw mm0, mm3 + pand mm0, mm1 + movq [Mask26], mm0 + + movq mm0, [eax+ebx+ebx+color1] + movq mm1, [eax+ebx+colorS2] + push eax + add eax, ebx + movq mm2, [eax+ebx+ebx+colorA1] + pop eax + movq mm3, [eax+colorB2] + pcmpeqw mm0, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm1 + pand mm2, mm3 + por mm0, mm2 + pand mm0, [Mask26] + movq [Mask26b], mm0 + + ;-------------------- + movq mm0, mm4 + movq mm1, mm5 + movq mm2, mm0 + + pcmpeqw mm2, mm1 + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pand mm0, mm1 + pand mm2, mm0 + pxor mm0, mm2 + movq mm7, mm0 + + ;------------------ + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_GUESS + +;--------------------------------------------- +; Map of the pixels: I|E F|J +; G|A B|K +; H|C D|L +; M|N O|P + movq mm6, mm0 + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + pxor mm7, mm7 + pand mm6, [ONE] + + movq mm0, [eax+colorB1] + movq mm1, [eax+ebx+color4] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+colorB2] + movq mm1, [eax+ebx+colorS2] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + push eax + add eax, ebx + movq mm0, [eax+ebx+color1] + movq mm1, [eax+ebx+ebx+colorA1] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+ebx+colorS1] + movq mm1, [eax+ebx+ebx+colorA2] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + pop eax + movq mm1, mm7 + pxor mm0, mm0 + pcmpgtw mm7, mm0 + pcmpgtw mm0, mm1 + + por mm7, [Mask35] + por mm1, [Mask26] + movq [Mask35], mm7 + movq [Mask26], mm1 + +.SKIP_GUESS: + ;Start the ASSEMBLY !!! + + movq mm4, [Mask35] + movq mm5, [Mask26] + movq mm6, [Mask35b] + movq mm7, [Mask26b] + + movq mm0, [eax+ebx+color5] + movq mm1, [eax+ebx+color6] + movq mm2, [eax+ebx+ebx+color2] + movq mm3, [eax+ebx+ebx+color3] + pcmpeqw mm0, mm2 + pcmpeqw mm1, mm3 + movq mm2, mm4 + movq mm3, mm5 + por mm0, mm1 + por mm2, mm3 + pand mm2, mm0 + pxor mm0, mm2 + movq mm3, mm0 + + movq mm2, mm0 + pxor mm0, mm0 + por mm2, mm4 + pxor mm4, mm6 + por mm2, mm5 + pxor mm5, mm7 + pcmpeqw mm2, mm0 + ;---------------- + + movq mm0, [eax+ebx+color5] + movq mm1, mm3 + por mm1, mm4 + por mm1, mm6 + pand mm0, mm1 + movq mm1, mm5 + pand mm1, [I56Pixel] + por mm0, mm1 + movq mm1, mm7 + pand mm1, [product1b] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product1a] + por mm0, mm1 + movq [final1a], mm0 + + movq mm0, [eax+ebx+color6] + movq mm1, mm3 + por mm1, mm5 + por mm1, mm7 + pand mm0, mm1 + movq mm1, mm4 + pand mm1, [I56Pixel] + por mm0, mm1 + movq mm1, mm6 + pand mm1, [product1a] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product1b] + por mm0, mm1 + movq [final1b], mm0 + + movq mm0, [eax+ebx+ebx+color2] + movq mm1, mm3 + por mm1, mm5 + por mm1, mm7 + pand mm0, mm1 + movq mm1, mm4 + pand mm1, [I23Pixel] + por mm0, mm1 + movq mm1, mm6 + pand mm1, [product2b] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product2a] + por mm0, mm1 + movq [final2a], mm0 + + movq mm0, [eax+ebx+ebx+color3] + movq mm1, mm3 + por mm1, mm4 + por mm1, mm6 + pand mm0, mm1 + movq mm1, mm5 + pand mm1, [I23Pixel] + por mm0, mm1 + movq mm1, mm7 + pand mm1, [product2a] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product2b] + por mm0, mm1 + movq [final2b], mm0 + + + movq mm0, [final1a] + movq mm2, [final1b] + movq mm1, mm0 + movq mm4, [final2a] + movq mm6, [final2b] + movq mm5, mm4 + punpcklwd mm0, mm2 + punpckhwd mm1, mm2 + punpcklwd mm4, mm6 + punpckhwd mm5, mm6 + + + + +%ifdef __DJGPP__ + movq [fs:edx], mm0 + movq [fs:edx+8], mm1 + push edx + add edx, [ebp+dstPitch] + movq [fs:edx], mm4 + movq [fs:edx+8], mm5 + pop edx +%else + movq [edx], mm0 + movq [edx+8], mm1 + push edx + add edx, [ebp+dstPitch] + movq [edx], mm4 + movq [edx+8], mm5 + pop edx +%endif +.SKIP_PROCESS: + mov ecx, [ebp+deltaPtr] + add ecx, 8 + mov [ebp+deltaPtr], ecx + add edx, 16 + add eax, 8 + + pop ecx + sub ecx, 4 + cmp ecx, 0 + jg near .Loop + +; Restore some stuff + popad + mov esp, ebp + pop ebp + emms + ret + + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + + +;This is version 0.50 +colorI equ -2 +colorE equ 0 +colorF equ 2 +colorJ equ 4 + +colorG equ -2 +colorA equ 0 +colorB equ 2 +colorK equ 4 + +colorH equ -2 +colorC equ 0 +colorD equ 2 +colorL equ 4 + +colorM equ -2 +colorN equ 0 +colorO equ 2 +colorP equ 4 + +NEWSYM _2xSaILineW +; Store some stuff + push ebp + mov ebp, esp + pushad + +; Prepare the destination +%ifdef __DJGPP__ + ; Set the selector + mov eax, [ebp+dstSegment] + mov fs, ax +%endif + mov edx, [ebp+dstOffset] ; edx points to the screen +; Prepare the source + ; eax points to colorA + mov eax, [ebp+srcPtr] + mov ebx, [ebp+srcPitch] + mov ecx, [ebp+width] + ; eax now points to colorE + sub eax, ebx + + +; Main Loop +.Loop: push ecx + + ;-----Check Delta------------------ + mov ecx, [ebp+deltaPtr] + + movq mm0, [eax+colorI] + movq mm1, [eax+colorJ] + movq mm2, [eax+ebx+colorG] + movq mm3, [eax+ebx+colorK] + movq mm4, [eax+ebx+ebx+colorH] + movq mm5, [eax+ebx+ebx+colorL] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorM] + movq mm7, [eax+ebx+ebx+colorP] + pop eax + + pcmpeqw mm0, [ecx+2+colorI] + pcmpeqw mm1, [ecx+2+colorK] + pcmpeqw mm2, [ecx+ebx+2+colorG] + pcmpeqw mm3, [ecx+ebx+2+colorK] + pcmpeqw mm4, [ecx+ebx+ebx+2+colorH] + pcmpeqw mm5, [ecx+ebx+ebx+2+colorL] + add ecx, ebx + pcmpeqw mm6, [ecx+ebx+ebx+2+colorM] + pcmpeqw mm7, [ecx+ebx+ebx+2+colorP] + sub ecx, ebx + + + pand mm0, mm1 + pand mm2, mm3 + pand mm4, mm5 + pand mm6, mm7 + pand mm0, mm2 + pand mm4, mm6 + pxor mm7, mm7 + pand mm0, mm4 + movq mm6, [eax+colorI] + pcmpeqw mm7, mm0 + + movq [ecx+2+colorI], mm6 + + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_PROCESS + + ;End Delta + + ;--------------------------------- + + +;1 + ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorE) && (colorB == colorL) + movq mm0, [eax+ebx+colorA] ;mm0 and mm1 contain colorA + movq mm2, [eax+ebx+colorB] ;mm2 and mm3 contain colorB + + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+ebx+colorD] + pcmpeqw mm1, [eax+colorE] + pcmpeqw mm2, [eax+ebx+ebx+colorL] + pcmpeqw mm3, [eax+ebx+ebx+colorC] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorA == colorC) && (colorB != colorE) && (colorA == colorF) && (colorB == colorJ) + movq mm4, [eax+ebx+colorA] ;mm4 and mm5 contain colorA + movq mm6, [eax+ebx+colorB] ;mm6 and mm7 contain colorB + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorC] + pcmpeqw mm5, [eax+colorF] + pcmpeqw mm6, [eax+colorJ] + pcmpeqw mm7, [eax+colorE] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask1], mm0 + + ;-------------------------------------------- + +;2 + ;if ((colorB == colorC) && (colorA != colorD) && (colorB == colorF) && (colorA == colorH) + movq mm0, [eax+ebx+colorB] ;mm0 and mm1 contain colorB + movq mm2, [eax+ebx+colorA] ;mm2 and mm3 contain colorA + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+ebx+colorC] + pcmpeqw mm1, [eax+colorF] + pcmpeqw mm2, [eax+ebx+ebx+colorH] + pcmpeqw mm3, [eax+ebx+ebx+colorD] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI) + movq mm4, [eax+ebx+colorB] ;mm4 and mm5 contain colorB + movq mm6, [eax+ebx+colorA] ;mm6 and mm7 contain colorA + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorD] + pcmpeqw mm5, [eax+colorE] + pcmpeqw mm6, [eax+colorI] + pcmpeqw mm7, [eax+colorF] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask2], mm0 + + +;interpolate colorA and colorB + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + + ;assemble the pixels + movq mm1, [eax+ebx+colorA] + movq mm2, [eax+ebx+colorB] + + movq mm3, [Mask1] + movq mm5, mm1 + movq mm4, [Mask2] + movq mm6, mm1 + + pand mm1, mm3 + por mm3, mm4 + pxor mm7, mm7 + pand mm2, mm4 + + pcmpeqw mm3, mm7 + por mm1, mm2 + pand mm0, mm3 + + por mm0, mm1 + + punpcklwd mm5, mm0 + punpckhwd mm6, mm0 + +%ifdef __DJGPP__ + movq [fs:edx], mm5 + movq [fs:edx+8], mm6 +%else + movq [edx], mm5 + movq [edx+8], mm6 +%endif + +;------------------------------------------------ +; Create the Nextline +;------------------------------------------------ +;3 ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorG) && (colorC == colorO) + movq mm0, [eax+ebx+colorA] ;mm0 and mm1 contain colorA + movq mm2, [eax+ebx+ebx+colorC] ;mm2 and mm3 contain colorC + movq mm1, mm0 + movq mm3, mm2 + + push eax + add eax, ebx + pcmpeqw mm0, [eax+ebx+colorD] + pcmpeqw mm1, [eax+colorG] + pcmpeqw mm2, [eax+ebx+ebx+colorO] + pcmpeqw mm3, [eax+colorB] + pop eax + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorA == colorB) && (colorG != colorC) && (colorA == colorH) && (colorC == colorM) + movq mm4, [eax+ebx+colorA] ;mm4 and mm5 contain colorA + movq mm6, [eax+ebx+ebx+colorC] ;mm6 and mm7 contain colorC + movq mm5, mm4 + movq mm7, mm6 + + push eax + add eax, ebx + pcmpeqw mm4, [eax+ebx+colorH] + pcmpeqw mm5, [eax+colorB] + pcmpeqw mm6, [eax+ebx+ebx+colorM] + pcmpeqw mm7, [eax+colorG] + pop eax + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask1], mm0 + ;-------------------------------------------- + +;4 + ;if ((colorB == colorC) && (colorA != colorD) && (colorC == colorH) && (colorA == colorF) + movq mm0, [eax+ebx+ebx+colorC] ;mm0 and mm1 contain colorC + movq mm2, [eax+ebx+colorA] ;mm2 and mm3 contain colorA + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+colorB] + pcmpeqw mm1, [eax+ebx+ebx+colorH] + pcmpeqw mm2, [eax+colorF] + pcmpeqw mm3, [eax+ebx+ebx+colorD] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI) + movq mm4, [eax+ebx+ebx+colorC] ;mm4 and mm5 contain colorC + movq mm6, [eax+ebx+colorA] ;mm6 and mm7 contain colorA + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorD] + pcmpeqw mm5, [eax+ebx+colorG] + pcmpeqw mm6, [eax+colorI] + pcmpeqw mm7, [eax+ebx+ebx+colorH] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask2], mm0 + ;---------------------------------------------- + +;interpolate colorA and colorC + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+ebx+colorC] + + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + ;------------- + + ;assemble the pixels + movq mm1, [eax+ebx+colorA] + movq mm2, [eax+ebx+ebx+colorC] + + movq mm3, [Mask1] + movq mm4, [Mask2] + + pand mm1, mm3 + pand mm2, mm4 + + por mm3, mm4 + pxor mm7, mm7 + por mm1, mm2 + + pcmpeqw mm3, mm7 + pand mm0, mm3 + por mm0, mm1 + movq [ACPixel], mm0 + +;//////////////////////////////// +; Decide which "branch" to take +;-------------------------------- + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + movq mm6, mm0 + movq mm7, mm1 + pcmpeqw mm0, [eax+ebx+ebx+colorD] + pcmpeqw mm1, [eax+ebx+ebx+colorC] + pcmpeqw mm6, mm7 + + movq mm2, mm0 + movq mm3, mm0 + + pand mm0, mm1 ;colorA == colorD && colorB == colorC + pxor mm7, mm7 + + pcmpeqw mm2, mm7 + pand mm6, mm0 + pand mm2, mm1 ;colorA != colorD && colorB == colorC + + pcmpeqw mm1, mm7 + + pand mm1, mm3 ;colorA == colorD && colorB != colorC + pxor mm0, mm6 + por mm1, mm6 + movq mm7, mm0 + movq [Mask2], mm2 + packsswb mm7, mm7 + movq [Mask1], mm1 + + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_GUESS +;--------------------------------------------- +; Map of the pixels: I|E F|J +; G|A B|K +; H|C D|L +; M|N O|P + movq mm6, mm0 + movq mm4, [eax+ebx+colorA] + movq mm5, [eax+ebx+colorB] + pxor mm7, mm7 + pand mm6, [ONE] + + movq mm0, [eax+colorE] + movq mm1, [eax+ebx+colorG] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+colorF] + movq mm1, [eax+ebx+colorK] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + push eax + add eax, ebx + movq mm0, [eax+ebx+colorH] + movq mm1, [eax+ebx+ebx+colorN] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+ebx+colorL] + movq mm1, [eax+ebx+ebx+colorO] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + pop eax + movq mm1, mm7 + pxor mm0, mm0 + pcmpgtw mm7, mm0 + pcmpgtw mm0, mm1 + + por mm7, [Mask1] + por mm1, [Mask2] + movq [Mask1], mm7 + movq [Mask2], mm1 + +.SKIP_GUESS: + ;---------------------------- + ;interpolate A, B, C and D + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + movq mm4, mm0 + movq mm2, [eax+ebx+ebx+colorC] + movq mm5, mm1 + movq mm3, [qcolorMask] + movq mm6, mm2 + movq mm7, [qlowpixelMask] + + pand mm0, mm3 + pand mm1, mm3 + pand mm2, mm3 + pand mm3, [eax+ebx+ebx+colorD] + + psrlw mm0, 2 + pand mm4, mm7 + psrlw mm1, 2 + pand mm5, mm7 + psrlw mm2, 2 + pand mm6, mm7 + psrlw mm3, 2 + pand mm7, [eax+ebx+ebx+colorD] + + paddw mm0, mm1 + paddw mm2, mm3 + + paddw mm4, mm5 + paddw mm6, mm7 + + paddw mm4, mm6 + paddw mm0, mm2 + psrlw mm4, 2 + pand mm4, [qlowpixelMask] + paddw mm0, mm4 ;mm0 contains the interpolated value of A, B, C and D + +;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ + ;assemble the pixels + movq mm1, [Mask1] + movq mm2, [Mask2] + movq mm4, [eax+ebx+colorA] + movq mm5, [eax+ebx+colorB] + pand mm4, mm1 + pand mm5, mm2 + + pxor mm7, mm7 + por mm1, mm2 + por mm4, mm5 + pcmpeqw mm1, mm7 + pand mm0, mm1 + por mm4, mm0 ;mm4 contains the diagonal pixels + + movq mm0, [ACPixel] + movq mm1, mm0 + punpcklwd mm0, mm4 + punpckhwd mm1, mm4 + + push edx + add edx, [ebp+dstPitch] + +%ifdef __DJGPP__ + movq [fs:edx], mm0 + movq [fs:edx+8], mm1 +%else + movq [edx], mm0 + movq [edx+8], mm1 +%endif + pop edx + +.SKIP_PROCESS: + mov ecx, [ebp+deltaPtr] + add ecx, 8 + mov [ebp+deltaPtr], ecx + add edx, 16 + add eax, 8 + + pop ecx + sub ecx, 4 + cmp ecx, 0 + jg near .Loop + +; Restore some stuff + popad + mov esp, ebp + pop ebp + emms + ret + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + +NEWSYM Init_2xSaIMMXW +; Store some stuff + push ebp + mov ebp, esp + push edx + + +;Damn thing doesn't work +; mov eax,1 +; cpuid +; test edx, 0x00800000 ;test bit 23 +; jz end2 ;bit not set => no MMX detected + + mov eax, [ebp+8] ;PixelFormat + cmp eax, 555 + jz Bits555 + cmp eax, 565 + jz Bits565 +end2: + mov eax, 1 + jmp end +Bits555: + mov edx, 0x7BDE7BDE + mov eax, colorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x04210421 + mov eax, lowPixelMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x739C739C + mov eax, qcolorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x0C630C63 + mov eax, qlowpixelMask + mov [eax], edx + mov [eax+4], edx + mov eax, 0 + jmp end +Bits565: + mov edx, 0xF7DEF7DE + mov eax, colorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x08210821 + mov eax, lowPixelMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0xE79CE79C + mov eax, qcolorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x18631863 + mov eax, qlowpixelMask + mov [eax], edx + mov [eax+4], edx + mov eax, 0 + jmp end +end: + pop edx + mov esp, ebp + pop ebp + ret + + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + + SECTION .data ALIGN = 32 +;Some constants +colorMask dd 0xF7DEF7DE, 0xF7DEF7DE +lowPixelMask dd 0x08210821, 0x08210821 + +qcolorMask dd 0xE79CE79C, 0xE79CE79C +qlowpixelMask dd 0x18631863, 0x18631863 + +FALSE dd 0x00000000, 0x00000000 +TRUE dd 0xffffffff, 0xffffffff +ONE dd 0x00010001, 0x00010001 + +ACPixel times 8 db 0 +Mask1 times 8 db 0 +Mask2 times 8 db 0 + +I56Pixel times 8 db 0 +I23Pixel times 8 db 0 +Mask26 times 8 db 0 +Mask35 times 8 db 0 +Mask26b times 8 db 0 +Mask35b times 8 db 0 +product1a times 8 db 0 +product1b times 8 db 0 +product2a times 8 db 0 +product2b times 8 db 0 +final1a times 8 db 0 +final1b times 8 db 0 +final2a times 8 db 0 +final2b times 8 db 0 + \ No newline at end of file diff --git a/zsnes/src/video/2xsaiw.inc b/zsnes/src/video/2xsaiw.inc new file mode 100644 index 00000000..7aa8408c --- /dev/null +++ b/zsnes/src/video/2xsaiw.inc @@ -0,0 +1,1375 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +;/*---------------------------------------------------------------------* +; * The following (piece of) code, (part of) the 2xSaI engine, * +; * copyright (c) 1999 by Derek Liauw Kie Fa. * +; * Non-Commercial use of the engine is allowed and is encouraged, * +; * provided that appropriate credit be given and that this copyright * +; * notice will not be removed under any circumstance. * +; * You may freely modify this code, but I request * +; * that any improvements to the engine be submitted to me, so * +; * that I can implement these improvements in newer versions of * +; * the engine. * +; * If you need more information, have any comments or suggestions, * +; * you can e-mail me. My e-mail: derek-liauw@usa.net. * +; *---------------------------------------------------------------------*/ + +;---------------------- +; 2xSaI version 0.59 WIP, soon to become version 0.60 +;---------------------- + + BITS 32 +%ifdef __DJGPP__ + GLOBAL __2xSaILineW + GLOBAL __2xSaISuperEagleLineW + GLOBAL _Init_2xSaIMMX +%else + GLOBAL _2xSaILineW + GLOBAL _2xSaISuperEagleLineW + GLOBAL Init_2xSaIMMX +%endif + SECTION .text ALIGN = 32 + +%ifdef __DJGPP__ +;EXTERN_C void __2xSaILineW (uint8 *srcPtr, uint32 srcPitch, uint32 width, +; uint8 *dstPtr, uint32 dstPitch, uint16 dstSegment); +%else +;EXTERN_C void _2xSaILineW (uint8 *srcPtr, uint32 srcPitch, uint32 width, +; uint8 *dstPtr, uint32 dstPitch); +%endif + +srcPtr equ 8 +deltaPtr equ 12 +srcPitch equ 16 +width equ 20 +dstOffset equ 24 +dstPitch equ 28 +dstSegment equ 32 + + +colorB0 equ -2 +colorB1 equ 0 +colorB2 equ 2 +colorB3 equ 4 + +color7 equ -2 +color8 equ 0 +color9 equ 2 + +color4 equ -2 +color5 equ 0 +color6 equ 2 +colorS2 equ 4 + +color1 equ -2 +color2 equ 0 +color3 equ 2 +colorS1 equ 4 + +colorA0 equ -2 +colorA1 equ 0 +colorA2 equ 2 +colorA3 equ 4 + + +%ifdef __DJGPP__ +__2xSaISuperEagleLineW: +%else +_2xSaISuperEagleLineW: +%endif +; Store some stuff + push ebp + mov ebp, esp + pushad + +; Prepare the destination +%ifdef __DJGPP__ + ; Set the selector + mov eax, [ebp+dstSegment] + mov fs, ax +%endif + mov edx, [ebp+dstOffset] ; edx points to the screen +; Prepare the source + ; eax points to colorA + mov eax, [ebp+srcPtr] + mov ebx, [ebp+srcPitch] + mov ecx, [ebp+width] + ; eax now points to colorB1 + sub eax, ebx + +; Main Loop +.Loop: push ecx + + ;-----Check Delta------------------ + mov ecx, [ebp+deltaPtr] + + movq mm0, [eax+colorB0] + movq mm1, [eax+colorB3] + movq mm2, [eax+ebx+color4] + movq mm3, [eax+ebx+colorS2] + movq mm4, [eax+ebx+ebx+color1] + movq mm5, [eax+ebx+ebx+colorS1] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorA0] + movq mm7, [eax+ebx+ebx+colorA3] + pop eax + + pcmpeqw mm0, [ecx+2+colorB0] + pcmpeqw mm1, [ecx+2+colorB3] + pcmpeqw mm2, [ecx+ebx+2+color4] + pcmpeqw mm3, [ecx+ebx+2+colorS2] + pcmpeqw mm4, [ecx+ebx+ebx+2+color1] + pcmpeqw mm5, [ecx+ebx+ebx+2+colorS1] + add ecx, ebx + pcmpeqw mm6, [ecx+ebx+ebx+2+colorA0] + pcmpeqw mm7, [ecx+ebx+ebx+2+colorA3] + sub ecx, ebx + + + pand mm0, mm1 + pand mm2, mm3 + pand mm4, mm5 + pand mm6, mm7 + pand mm0, mm2 + pand mm4, mm6 + pxor mm7, mm7 + pand mm0, mm4 + movq mm6, [eax+colorB0] + pcmpeqw mm7, mm0 + + movq [ecx+2+colorB0], mm6 + + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_PROCESS + + ;End Delta + + ;--------------------------------- + movq mm0, [eax+ebx+color5] + movq mm1, [eax+ebx+color6] + movq mm2, mm0 + movq mm3, mm1 + movq mm4, mm0 + movq mm5, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + movq [I56Pixel], mm0 + movq mm7, mm0 + + ;------------------- + movq mm0, mm7 + movq mm1, mm4 ;5,5,5,6 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + movq [product1a], mm0 + ;-------------------- + + movq mm0, mm7 + movq mm1, mm5 ;6,6,6,5 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product1b], mm0 + + ;------------------------- + ;------------------------- + movq mm0, [eax+ebx+ebx+color2] + movq mm1, [eax+ebx+ebx+color3] + movq mm2, mm0 + movq mm3, mm1 + movq mm4, mm0 + movq mm5, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [I23Pixel], mm0 + movq mm7, mm0 + + ;--------------------- + movq mm0, mm7 + movq mm1, mm4 ;2,2,2,3 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product2a], mm0 + + ;---------------------- + movq mm0, mm7 + movq mm1, mm5 ;3,3,3,2 + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 + movq [product2b], mm0 + + + ;//////////////////////////////// + ; Decide which "branch" to take + ;-------------------------------- + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + movq mm6, [eax+ebx+ebx+color3] + movq mm7, [eax+ebx+ebx+color2] + + pxor mm3, mm3 + movq mm0, mm4 + movq mm1, mm5 + + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pcmpeqw mm1, mm3 + pand mm0, mm1 + movq [Mask35], mm0 + + movq mm0, [eax+ebx+ebx+colorS1] + movq mm1, [eax+ebx+color4] + push eax + add eax, ebx + movq mm2, [eax+ebx+ebx+colorA2] + pop eax + movq mm3, [eax+colorB1] + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm4 + pcmpeqw mm3, mm4 + pand mm0, mm1 + pand mm2, mm3 + por mm0, mm2 + pand mm0, [Mask35] + movq [Mask35b], mm0 + + ;----------- + pxor mm3, mm3 + movq mm0, mm4 + movq mm1, mm5 + + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pcmpeqw mm0, mm3 + pand mm0, mm1 + movq [Mask26], mm0 + + movq mm0, [eax+ebx+ebx+color1] + movq mm1, [eax+ebx+colorS2] + push eax + add eax, ebx + movq mm2, [eax+ebx+ebx+colorA1] + pop eax + movq mm3, [eax+colorB2] + pcmpeqw mm0, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm1 + pand mm2, mm3 + por mm0, mm2 + pand mm0, [Mask26] + movq [Mask26b], mm0 + + ;-------------------- + movq mm0, mm4 + movq mm1, mm5 + movq mm2, mm0 + + pcmpeqw mm2, mm1 + pcmpeqw mm0, mm6 + pcmpeqw mm1, mm7 + pand mm0, mm1 + pand mm2, mm0 + pxor mm0, mm2 + movq mm7, mm0 + + ;------------------ + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_GUESS + +;--------------------------------------------- +; Map of the pixels: I|E F|J +; G|A B|K +; H|C D|L +; M|N O|P + movq mm6, mm0 + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + pxor mm7, mm7 + pand mm6, [ONE] + + movq mm0, [eax+colorB1] + movq mm1, [eax+ebx+color4] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+colorB2] + movq mm1, [eax+ebx+colorS2] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + push eax + add eax, ebx + movq mm0, [eax+ebx+color1] + movq mm1, [eax+ebx+ebx+colorA1] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+ebx+colorS1] + movq mm1, [eax+ebx+ebx+colorA2] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + pop eax + movq mm1, mm7 + pxor mm0, mm0 + pcmpgtw mm7, mm0 + pcmpgtw mm0, mm1 + + por mm7, [Mask35] + por mm1, [Mask26] + movq [Mask35], mm7 + movq [Mask26], mm1 + +.SKIP_GUESS: + ;Start the ASSEMBLY !!! + + movq mm4, [Mask35] + movq mm5, [Mask26] + movq mm6, [Mask35b] + movq mm7, [Mask26b] + + movq mm0, [eax+ebx+color5] + movq mm1, [eax+ebx+color6] + movq mm2, [eax+ebx+ebx+color2] + movq mm3, [eax+ebx+ebx+color3] + pcmpeqw mm0, mm2 + pcmpeqw mm1, mm3 + movq mm2, mm4 + movq mm3, mm5 + por mm0, mm1 + por mm2, mm3 + pand mm2, mm0 + pxor mm0, mm2 + movq mm3, mm0 + + movq mm2, mm0 + pxor mm0, mm0 + por mm2, mm4 + pxor mm4, mm6 + por mm2, mm5 + pxor mm5, mm7 + pcmpeqw mm2, mm0 + ;---------------- + + movq mm0, [eax+ebx+color5] + movq mm1, mm3 + por mm1, mm4 + por mm1, mm6 + pand mm0, mm1 + movq mm1, mm5 + pand mm1, [I56Pixel] + por mm0, mm1 + movq mm1, mm7 + pand mm1, [product1b] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product1a] + por mm0, mm1 + movq [final1a], mm0 + + movq mm0, [eax+ebx+color6] + movq mm1, mm3 + por mm1, mm5 + por mm1, mm7 + pand mm0, mm1 + movq mm1, mm4 + pand mm1, [I56Pixel] + por mm0, mm1 + movq mm1, mm6 + pand mm1, [product1a] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product1b] + por mm0, mm1 + movq [final1b], mm0 + + movq mm0, [eax+ebx+ebx+color2] + movq mm1, mm3 + por mm1, mm5 + por mm1, mm7 + pand mm0, mm1 + movq mm1, mm4 + pand mm1, [I23Pixel] + por mm0, mm1 + movq mm1, mm6 + pand mm1, [product2b] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product2a] + por mm0, mm1 + movq [final2a], mm0 + + movq mm0, [eax+ebx+ebx+color3] + movq mm1, mm3 + por mm1, mm4 + por mm1, mm6 + pand mm0, mm1 + movq mm1, mm5 + pand mm1, [I23Pixel] + por mm0, mm1 + movq mm1, mm7 + pand mm1, [product2a] + por mm0, mm1 + movq mm1, mm2 + pand mm1, [product2b] + por mm0, mm1 + movq [final2b], mm0 + + + movq mm0, [final1a] + movq mm2, [final1b] + movq mm1, mm0 + movq mm4, [final2a] + movq mm6, [final2b] + movq mm5, mm4 + punpcklwd mm0, mm2 + punpckhwd mm1, mm2 + punpcklwd mm4, mm6 + punpckhwd mm5, mm6 + + + + +%ifdef __DJGPP__ + movq [fs:edx], mm0 + movq [fs:edx+8], mm1 + push edx + add edx, [ebp+dstPitch] + movq [fs:edx], mm4 + movq [fs:edx+8], mm5 + pop edx +%else + movq [edx], mm0 + movq [edx+8], mm1 + push edx + add edx, [ebp+dstPitch] + movq [edx], mm4 + movq [edx+8], mm5 + pop edx +%endif +.SKIP_PROCESS: + mov ecx, [ebp+deltaPtr] + add ecx, 8 + mov [ebp+deltaPtr], ecx + add edx, 16 + add eax, 8 + + pop ecx + sub ecx, 4 + cmp ecx, 0 + jg near .Loop + +; Restore some stuff + popad + mov esp, ebp + pop ebp + emms + ret + + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + + +;This is version 0.50 +colorI equ -2 +colorE equ 0 +colorF equ 2 +colorJ equ 4 + +colorG equ -2 +colorA equ 0 +colorB equ 2 +colorK equ 4 + +colorH equ -2 +colorC equ 0 +colorD equ 2 +colorL equ 4 + +colorM equ -2 +colorN equ 0 +colorO equ 2 +colorP equ 4 + +%ifdef __DJGPP__ +__2xSaILineW: +%else +_2xSaILineW: +%endif +; Store some stuff + push ebp + mov ebp, esp + pushad + +; Prepare the destination +%ifdef __DJGPP__ + ; Set the selector + mov eax, [ebp+dstSegment] + mov fs, ax +%endif + mov edx, [ebp+dstOffset] ; edx points to the screen +; Prepare the source + ; eax points to colorA + mov eax, [ebp+srcPtr] + mov ebx, [ebp+srcPitch] + mov ecx, [ebp+width] + ; eax now points to colorE + sub eax, ebx + + +; Main Loop +.Loop: push ecx + + ;-----Check Delta------------------ + mov ecx, [ebp+deltaPtr] + + movq mm0, [eax+colorI] + movq mm1, [eax+colorJ] + movq mm2, [eax+ebx+colorG] + movq mm3, [eax+ebx+colorK] + movq mm4, [eax+ebx+ebx+colorH] + movq mm5, [eax+ebx+ebx+colorL] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorM] + movq mm7, [eax+ebx+ebx+colorP] + pop eax + + pcmpeqw mm0, [ecx+2+colorI] + pcmpeqw mm1, [ecx+2+colorK] + pcmpeqw mm2, [ecx+ebx+2+colorG] + pcmpeqw mm3, [ecx+ebx+2+colorK] + pcmpeqw mm4, [ecx+ebx+ebx+2+colorH] + pcmpeqw mm5, [ecx+ebx+ebx+2+colorL] + add ecx, ebx + pcmpeqw mm6, [ecx+ebx+ebx+2+colorM] + pcmpeqw mm7, [ecx+ebx+ebx+2+colorP] + sub ecx, ebx + + + pand mm0, mm1 + pand mm2, mm3 + pand mm4, mm5 + pand mm6, mm7 + pand mm0, mm2 + pand mm4, mm6 + pxor mm7, mm7 + pand mm0, mm4 + movq mm6, [eax+colorI] + pcmpeqw mm7, mm0 + + movq [ecx+2+colorI], mm6 + + packsswb mm7, mm7 + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_PROCESS + + ;End Delta + + ;--------------------------------- + + +;1 + ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorE) && (colorB == colorL) + movq mm0, [eax+ebx+colorA] ;mm0 and mm1 contain colorA + movq mm2, [eax+ebx+colorB] ;mm2 and mm3 contain colorB + + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+ebx+colorD] + pcmpeqw mm1, [eax+colorE] + pcmpeqw mm2, [eax+ebx+ebx+colorL] + pcmpeqw mm3, [eax+ebx+ebx+colorC] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorA == colorC) && (colorB != colorE) && (colorA == colorF) && (colorB == colorJ) + movq mm4, [eax+ebx+colorA] ;mm4 and mm5 contain colorA + movq mm6, [eax+ebx+colorB] ;mm6 and mm7 contain colorB + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorC] + pcmpeqw mm5, [eax+colorF] + pcmpeqw mm6, [eax+colorJ] + pcmpeqw mm7, [eax+colorE] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask1], mm0 + + ;-------------------------------------------- + +;2 + ;if ((colorB == colorC) && (colorA != colorD) && (colorB == colorF) && (colorA == colorH) + movq mm0, [eax+ebx+colorB] ;mm0 and mm1 contain colorB + movq mm2, [eax+ebx+colorA] ;mm2 and mm3 contain colorA + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+ebx+colorC] + pcmpeqw mm1, [eax+colorF] + pcmpeqw mm2, [eax+ebx+ebx+colorH] + pcmpeqw mm3, [eax+ebx+ebx+colorD] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI) + movq mm4, [eax+ebx+colorB] ;mm4 and mm5 contain colorB + movq mm6, [eax+ebx+colorA] ;mm6 and mm7 contain colorA + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorD] + pcmpeqw mm5, [eax+colorE] + pcmpeqw mm6, [eax+colorI] + pcmpeqw mm7, [eax+colorF] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask2], mm0 + + +;interpolate colorA and colorB + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + + ;assemble the pixels + movq mm1, [eax+ebx+colorA] + movq mm2, [eax+ebx+colorB] + + movq mm3, [Mask1] + movq mm5, mm1 + movq mm4, [Mask2] + movq mm6, mm1 + + pand mm1, mm3 + por mm3, mm4 + pxor mm7, mm7 + pand mm2, mm4 + + pcmpeqw mm3, mm7 + por mm1, mm2 + pand mm0, mm3 + + por mm0, mm1 + + punpcklwd mm5, mm0 + punpckhwd mm6, mm0 + +%ifdef __DJGPP__ + movq [fs:edx], mm5 + movq [fs:edx+8], mm6 +%else + movq [edx], mm5 + movq [edx+8], mm6 +%endif + +;------------------------------------------------ +; Create the Nextline +;------------------------------------------------ +;3 ;if ((colorA == colorD) && (colorB != colorC) && (colorA == colorG) && (colorC == colorO) + movq mm0, [eax+ebx+colorA] ;mm0 and mm1 contain colorA + movq mm2, [eax+ebx+ebx+colorC] ;mm2 and mm3 contain colorC + movq mm1, mm0 + movq mm3, mm2 + + push eax + add eax, ebx + pcmpeqw mm0, [eax+ebx+colorD] + pcmpeqw mm1, [eax+colorG] + pcmpeqw mm2, [eax+ebx+ebx+colorO] + pcmpeqw mm3, [eax+colorB] + pop eax + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorA == colorB) && (colorG != colorC) && (colorA == colorH) && (colorC == colorM) + movq mm4, [eax+ebx+colorA] ;mm4 and mm5 contain colorA + movq mm6, [eax+ebx+ebx+colorC] ;mm6 and mm7 contain colorC + movq mm5, mm4 + movq mm7, mm6 + + push eax + add eax, ebx + pcmpeqw mm4, [eax+ebx+colorH] + pcmpeqw mm5, [eax+colorB] + pcmpeqw mm6, [eax+ebx+ebx+colorM] + pcmpeqw mm7, [eax+colorG] + pop eax + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask1], mm0 + ;-------------------------------------------- + +;4 + ;if ((colorB == colorC) && (colorA != colorD) && (colorC == colorH) && (colorA == colorF) + movq mm0, [eax+ebx+ebx+colorC] ;mm0 and mm1 contain colorC + movq mm2, [eax+ebx+colorA] ;mm2 and mm3 contain colorA + movq mm1, mm0 + movq mm3, mm2 + + pcmpeqw mm0, [eax+ebx+colorB] + pcmpeqw mm1, [eax+ebx+ebx+colorH] + pcmpeqw mm2, [eax+colorF] + pcmpeqw mm3, [eax+ebx+ebx+colorD] + + pand mm0, mm1 + pxor mm1, mm1 + pand mm0, mm2 + pcmpeqw mm3, mm1 + pand mm0, mm3 ;result in mm0 + + ;if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI) + movq mm4, [eax+ebx+ebx+colorC] ;mm4 and mm5 contain colorC + movq mm6, [eax+ebx+colorA] ;mm6 and mm7 contain colorA + movq mm5, mm4 + movq mm7, mm6 + + pcmpeqw mm4, [eax+ebx+ebx+colorD] + pcmpeqw mm5, [eax+ebx+colorG] + pcmpeqw mm6, [eax+colorI] + pcmpeqw mm7, [eax+ebx+ebx+colorH] + + pand mm4, mm5 + pxor mm5, mm5 + pand mm4, mm6 + pcmpeqw mm7, mm5 + pand mm4, mm7 ;result in mm4 + + por mm0, mm4 ;combine the masks + movq [Mask2], mm0 + ;---------------------------------------------- + +;interpolate colorA and colorC + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+ebx+colorC] + + movq mm2, mm0 + movq mm3, mm1 + + pand mm0, [colorMask] + pand mm1, [colorMask] + + psrlw mm0, 1 + psrlw mm1, 1 + + pand mm3, [lowPixelMask] + paddw mm0, mm1 + + pand mm3, mm2 + paddw mm0, mm3 ;mm0 contains the interpolated values + ;------------- + + ;assemble the pixels + movq mm1, [eax+ebx+colorA] + movq mm2, [eax+ebx+ebx+colorC] + + movq mm3, [Mask1] + movq mm4, [Mask2] + + pand mm1, mm3 + pand mm2, mm4 + + por mm3, mm4 + pxor mm7, mm7 + por mm1, mm2 + + pcmpeqw mm3, mm7 + pand mm0, mm3 + por mm0, mm1 + movq [ACPixel], mm0 + +;//////////////////////////////// +; Decide which "branch" to take +;-------------------------------- + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + movq mm6, mm0 + movq mm7, mm1 + pcmpeqw mm0, [eax+ebx+ebx+colorD] + pcmpeqw mm1, [eax+ebx+ebx+colorC] + pcmpeqw mm6, mm7 + + movq mm2, mm0 + movq mm3, mm0 + + pand mm0, mm1 ;colorA == colorD && colorB == colorC + pxor mm7, mm7 + + pcmpeqw mm2, mm7 + pand mm6, mm0 + pand mm2, mm1 ;colorA != colorD && colorB == colorC + + pcmpeqw mm1, mm7 + + pand mm1, mm3 ;colorA == colorD && colorB != colorC + pxor mm0, mm6 + por mm1, mm6 + movq mm7, mm0 + movq [Mask2], mm2 + packsswb mm7, mm7 + movq [Mask1], mm1 + + movd ecx, mm7 + test ecx, ecx + jz near .SKIP_GUESS +;--------------------------------------------- +; Map of the pixels: I|E F|J +; G|A B|K +; H|C D|L +; M|N O|P + movq mm6, mm0 + movq mm4, [eax+ebx+colorA] + movq mm5, [eax+ebx+colorB] + pxor mm7, mm7 + pand mm6, [ONE] + + movq mm0, [eax+colorE] + movq mm1, [eax+ebx+colorG] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+colorF] + movq mm1, [eax+ebx+colorK] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + push eax + add eax, ebx + movq mm0, [eax+ebx+colorH] + movq mm1, [eax+ebx+ebx+colorN] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + movq mm0, [eax+ebx+colorL] + movq mm1, [eax+ebx+ebx+colorO] + movq mm2, mm0 + movq mm3, mm1 + pcmpeqw mm0, mm4 + pcmpeqw mm1, mm4 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm0, mm6 + pand mm1, mm6 + pand mm2, mm6 + pand mm3, mm6 + paddw mm0, mm1 + paddw mm2, mm3 + + pxor mm3, mm3 + pcmpgtw mm0, mm6 + pcmpgtw mm2, mm6 + pcmpeqw mm0, mm3 + pcmpeqw mm2, mm3 + pand mm0, mm6 + pand mm2, mm6 + paddw mm7, mm0 + psubw mm7, mm2 + + pop eax + movq mm1, mm7 + pxor mm0, mm0 + pcmpgtw mm7, mm0 + pcmpgtw mm0, mm1 + + por mm7, [Mask1] + por mm1, [Mask2] + movq [Mask1], mm7 + movq [Mask2], mm1 + +.SKIP_GUESS: + ;---------------------------- + ;interpolate A, B, C and D + movq mm0, [eax+ebx+colorA] + movq mm1, [eax+ebx+colorB] + movq mm4, mm0 + movq mm2, [eax+ebx+ebx+colorC] + movq mm5, mm1 + movq mm3, [qcolorMask] + movq mm6, mm2 + movq mm7, [qlowpixelMask] + + pand mm0, mm3 + pand mm1, mm3 + pand mm2, mm3 + pand mm3, [eax+ebx+ebx+colorD] + + psrlw mm0, 2 + pand mm4, mm7 + psrlw mm1, 2 + pand mm5, mm7 + psrlw mm2, 2 + pand mm6, mm7 + psrlw mm3, 2 + pand mm7, [eax+ebx+ebx+colorD] + + paddw mm0, mm1 + paddw mm2, mm3 + + paddw mm4, mm5 + paddw mm6, mm7 + + paddw mm4, mm6 + paddw mm0, mm2 + psrlw mm4, 2 + pand mm4, [qlowpixelMask] + paddw mm0, mm4 ;mm0 contains the interpolated value of A, B, C and D + +;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ + ;assemble the pixels + movq mm1, [Mask1] + movq mm2, [Mask2] + movq mm4, [eax+ebx+colorA] + movq mm5, [eax+ebx+colorB] + pand mm4, mm1 + pand mm5, mm2 + + pxor mm7, mm7 + por mm1, mm2 + por mm4, mm5 + pcmpeqw mm1, mm7 + pand mm0, mm1 + por mm4, mm0 ;mm4 contains the diagonal pixels + + movq mm0, [ACPixel] + movq mm1, mm0 + punpcklwd mm0, mm4 + punpckhwd mm1, mm4 + + push edx + add edx, [ebp+dstPitch] + +%ifdef __DJGPP__ + movq [fs:edx], mm0 + movq [fs:edx+8], mm1 +%else + movq [edx], mm0 + movq [edx+8], mm1 +%endif + pop edx + +.SKIP_PROCESS: + mov ecx, [ebp+deltaPtr] + add ecx, 8 + mov [ebp+deltaPtr], ecx + add edx, 16 + add eax, 8 + + pop ecx + sub ecx, 4 + cmp ecx, 0 + jg near .Loop + +; Restore some stuff + popad + mov esp, ebp + pop ebp + emms + ret + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + +%ifdef __DJGPP__ +_Init_2xSaIMMX: +%else +Init_2xSaIMMX: +%endif +; Store some stuff + push ebp + mov ebp, esp + push edx + + +;Damn thing doesn't work +; mov eax,1 +; cpuid +; test edx, 0x00800000 ;test bit 23 +; jz end2 ;bit not set => no MMX detected + + mov eax, [ebp+8] ;PixelFormat + cmp eax, 555 + jz Bits555 + cmp eax, 565 + jz Bits565 +end2: + mov eax, 1 + jmp end +Bits555: + mov edx, 0x7BDE7BDE + mov eax, colorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x04210421 + mov eax, lowPixelMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x739C739C + mov eax, qcolorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x0C630C63 + mov eax, qlowpixelMask + mov [eax], edx + mov [eax+4], edx + mov eax, 0 + jmp end +Bits565: + mov edx, 0xF7DEF7DE + mov eax, colorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x08210821 + mov eax, lowPixelMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0xE79CE79C + mov eax, qcolorMask + mov [eax], edx + mov [eax+4], edx + mov edx, 0x18631863 + mov eax, qlowpixelMask + mov [eax], edx + mov [eax+4], edx + mov eax, 0 + jmp end +end: + pop edx + mov esp, ebp + pop ebp + ret + + +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- +;------------------------------------------------------------------------- + + SECTION .data ALIGN = 32 +;Some constants +colorMask dd 0xF7DEF7DE, 0xF7DEF7DE +lowPixelMask dd 0x08210821, 0x08210821 + +qcolorMask dd 0xE79CE79C, 0xE79CE79C +qlowpixelMask dd 0x18631863, 0x18631863 + +FALSE dd 0x00000000, 0x00000000 +TRUE dd 0xffffffff, 0xffffffff +ONE dd 0x00010001, 0x00010001 + +ACPixel times 8 db 0 +Mask1 times 8 db 0 +Mask2 times 8 db 0 + +I56Pixel times 8 db 0 +I23Pixel times 8 db 0 +Mask26 times 8 db 0 +Mask35 times 8 db 0 +Mask26b times 8 db 0 +Mask35b times 8 db 0 +product1a times 8 db 0 +product1b times 8 db 0 +product2a times 8 db 0 +product2b times 8 db 0 +final1a times 8 db 0 +final1b times 8 db 0 +final2a times 8 db 0 +final2b times 8 db 0 + \ No newline at end of file diff --git a/zsnes/src/video/copyvid.inc b/zsnes/src/video/copyvid.inc new file mode 100644 index 00000000..aee9e5f7 --- /dev/null +++ b/zsnes/src/video/copyvid.inc @@ -0,0 +1,5698 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM GUIOn,HalfTrans +EXTSYM ClearScreen +EXTSYM Mode7HiRes,mosenng,mosszng,intrlng,mode7hr ;,VESAAddr +EXTSYM GUICPC, newgfx16b +EXTSYM vesa2_clbitng,vesa2_clbitng2,vesa2_clbitng3 +EXTSYM granadd +EXTSYM SpecialLine +EXTSYM vidbufferofsb +EXTSYM Super2xSaI +EXTSYM HalfTransB,HalfTransC + + +%include "video/2xSaImmx.inc" + + + + + +SECTION .text + +%macro FlipCheck 0 + cmp byte[FlipWait],0 + je %%noflip + mov dx,3DAh ;VGA status port + in al,dx + test al,8 + jz %%noflip + mov ax,4F07h + mov bh,00h + mov bl,00h + xor cx,cx + mov dx,[NextLineStart] + mov [LastLineStart],dx + int 10h + mov byte[FlipWait],0 +%%noflip +%endmacro + +NEWSYM ResetTripleBuf + mov byte[FlipWait],0 + mov dword[VidStartDraw],0 + mov byte[CVidStartAd],0 + ret + +GUITripleBuffer: + cmp byte[TriplebufTech],0 + je near .tech2 + cmp byte[ApplyStart],0 + je .notstartedb + mov byte[ApplyStart],0 + cmp word[LastLineStart],0 + je .notstartedb + mov ax,4F07h + mov bh,00h + mov bl,00h + xor ecx,ecx + xor edx,edx + int 10h +.notstartedb + mov byte[FlipWait],0 + mov dword[VidStartDraw],0 + mov byte[CVidStartAd],0 + mov dword[LastLineStart],0 + ret + +.tech2 + xor ecx,ecx + mov cl,[cvidmode] + cmp byte[VidModeComp+ecx],0 + je .notbuf + cmp byte[Triplebufen],0 + je .notbuf + jmp .yestbuf +.notbuf + ret +.yestbuf + cmp byte[ApplyStart],0 + je .notstarted + mov ax,4F07h + mov bh,00h + mov bl,02h + xor ecx,ecx + xor edx,edx + int 10h + cmp byte[ApplyStart],4 + jne .nocheck + cmp al,4Fh + jne .failed + cmp ah,0 + ja .failed +.nocheck + mov dword[VidStartDraw],0 + mov byte[CVidStartAd],0 + mov byte[ApplyStart],0 +.notstarted + ret +.failed + mov byte[TriplebufTech],1 + ret + +PostTripleBuffer: + xor ecx,ecx + mov cl,[cvidmode] + cmp byte[VidModeComp+ecx],0 + je .notbuf + cmp byte[Triplebufen],0 + je .notbuf + jmp .yestbuf +.notbuf + ret +.yestbuf + xor ecx,ecx + cmp byte[CVidStartAd],2 + je .nooffset0 + mov cl,[cvidmode] + mov ecx,[VidModeSize+ecx*4] + cmp byte[CVidStartAd],0 + je .nooffset0 + add ecx,ecx +.nooffset0 + mov [VidStartDraw],ecx + inc byte[CVidStartAd] + cmp byte[CVidStartAd],3 + jne .notof + mov byte[CVidStartAd],0 +.notof + ret + +PreTripleBuffer2: + cmp byte[TriplebufTech],0 + je near PreTripleBuffer + xor ecx,ecx + mov cl,[cvidmode] + cmp byte[VidModeComp+ecx],0 + je .notbuf + cmp byte[Triplebufen],0 + jne .yestbuf +.notbuf + ret +.yestbuf + cmp byte[FlipWait],0 + je .noflip + mov dx,3DAh ;VGA status port +.loop + in al,dx + test al,8 + jz .loop + mov ax,4F07h + mov bh,00h + mov bl,00h + xor cx,cx + mov dx,[NextLineStart] + mov [LastLineStart],dx + int 10h + mov byte[FlipWait],0 +.noflip + xor ecx,ecx + cmp byte[CVidStartAd],2 + je .nooffset0 + mov cl,[cvidmode] + mov ecx,[VidModeLine+ecx*4] + cmp byte[CVidStartAd],0 + je .nooffset0 + add ecx,ecx +.nooffset0 + mov [NextLineStart],ecx + mov byte[ApplyStart],1 + mov byte[FlipWait],1 + ret + +PreTripleBuffer: + xor ecx,ecx + mov cl,[cvidmode] + cmp byte[VidModeComp+ecx],0 + je .notbuf + cmp byte[Triplebufen],0 + jne .yestbuf +.notbuf + ret +.yestbuf + cmp byte[ApplyStart],2 + jne .noflip +.notflipped +; *** I have no idea why this code doesn't work (freezes on NVidia cards) +; mov ax,4F07h +; mov bx,04h +; int 10h +; or ah,ah +; jnz .noflip +; or cx,cx +; jz .notflipped +.noflip + mov ax,4F07h + mov bh,00h + mov bl,02h + xor ecx,ecx + cmp byte[CVidStartAd],0 + je .nooffset0 + mov cl,[cvidmode] + mov ecx,[VidModeSize+ecx*4] + cmp byte[CVidStartAd],1 + je .nooffset0 + add ecx,ecx +.nooffset0 + xor edx,edx + int 10h + cmp byte[ApplyStart],4 + jne .nocheck + cmp al,4Fh + jne .failed + cmp ah,0 + ja .failed + mov byte[ApplyStart],0 +.nocheck + cmp byte[ApplyStart],2 + je .skipcheckb + inc byte[ApplyStart] +.skipcheckb + ret +.failed + mov byte[Triplebufen],0 + ret + +VidModeSize dd 0,0,320*240,320*240*2,640*480,640*480*2,512*384,512*384*2 + dd 0,320*480,320*480*2 +VidModeLine dd 0,0,240,240,480,480,384,384 + dd 0,480,480 +NEWSYM VidStartDraw, dd 0 +VidModeComp db 0,0,1,1,1,1,1,1,0,1,1 +CVidStartAd db 0 +ApplyStart db 4 +NEWSYM NextLineStart, dd 0 +NEWSYM LastLineStart, dd 0 +NEWSYM FlipWait, db 0 +NEWSYM TriplebufTech, db 0 + +NEWSYM DosDrawScreen + cmp byte[curblank],40h + je .nocopy + call PreTripleBuffer2 + call PostTripleBuffer +.nocopy + call ScreenShow + FlipCheck + ret + +NEWSYM DosDrawScreenB + cmp byte[curblank],40h + je .nocopy + call GUITripleBuffer +.nocopy + call ScreenShow + ret + +ScreenShow: + cmp byte[debugdisble],0 + je .debug + cmp byte[cvidmode],1 + je near copymodeq +.debug + cmp byte[cvidmode],2 + je near copyvesa2320x240x8b + cmp byte[cvidmode],3 + je near copyvesa2320x240x16b + cmp byte[cvidmode],4 + je near copyvesa2640x480x8b + cmp byte[cvidmode],5 + je near copyvesa2640x480x16b + cmp byte[cvidmode],6 + je near copyvesa2512x384x8b + cmp byte[cvidmode],7 + je near copyvesa2512x384x16b + cmp byte[cvidmode],8 + je near copyvesa12640x480x16b + cmp byte[cvidmode],9 + je near copyvesa2320x480x8b + cmp byte[cvidmode],10 + je near copyvesa2320x480x16b + cmp byte[cvidmode],0 + je near copymodex + cmp byte[curblank],40h + je .startcopy + inc byte[curfps2] +; call sounddisplay + call hextestoutput +.startcopy + jmp copymodeq + +NEWSYM dosvidpastecopyscr + cmp byte[curblank],40h + je .nocopy + call GUITripleBuffer +.nocopy + call ScreenShowGUI + ret + +ScreenShowGUI: + cmp byte[cvidmode],1 + je near copymodeq + cmp byte[cvidmode],2 + je near copyvesa2320x240x8b + cmp byte[cvidmode],3 + je near copyvesa2320x240x16bgui + cmp byte[cvidmode],4 + je near copyvesa2640x480x8bgui + cmp byte[cvidmode],5 + je near copyvesa2640x480x16bgui + cmp byte[cvidmode],6 + je near copyvesa2512x384x8b + cmp byte[cvidmode],7 + je near copyvesa2512x384x16bgui + cmp byte[cvidmode],8 + je near copyvesa12640x480x16bgui + cmp byte[cvidmode],9 + je near copyvesa2320x480x8bgui + cmp byte[cvidmode],10 + je near copyvesa2320x480x16bgui + cmp byte[cvidmode],0 + je near copymodex + jmp copymodeq + + + +;******************************************************* +; CopyModeX Copies buffer into unchained 320x240 +;******************************************************* + +NEWSYM copymodex + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + ; select plane 1 + mov dx,03C4h + mov ax,0102h ; set as plane 1 + out dx,ax + push es + mov ax,[selcA000] + mov es,ax + + mov esi,[vidbuffer] + mov edi,8 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*80+8 +.res239 + add esi,16+256+32 + cmp byte[whichpage],0 + jne .pageb + add edi,19200 +.pageb + mov [.startesi],esi + mov [.startedi],edi + mov dl,[resolutn] + dec dl + dec dl +.loopa + mov ecx,16 +.loopb + mov ah,[esi+12] + mov al,[esi+8] + shl eax,16 + mov ah,[esi+4] + mov al,[esi+0] + mov [es:edi],eax + add esi,16 + add edi,4 + dec ecx + jnz .loopb + add esi,32 + add edi,16 + dec dl + jnz .loopa + mov dx,03C4h + mov ax,0202h ; set as plane 2 + out dx,ax + mov esi,[.startesi] + inc esi + mov edi,[.startedi] + mov dl,[resolutn] + dec dl + dec dl +.loopa2 + mov ecx,16 +.loopb2 + mov ah,[esi+12] + mov al,[esi+8] + shl eax,16 + mov ah,[esi+4] + mov al,[esi+0] + mov [es:edi],eax + add esi,16 + add edi,4 + dec ecx + jnz .loopb2 + add esi,32 + add edi,16 + dec dl + jnz .loopa2 + mov dx,03C4h + mov ax,0402h ; set as plane 3 + out dx,ax + mov esi,[.startesi] + add esi,2 + mov edi,[.startedi] + mov dl,[resolutn] + dec dl + dec dl +.loopa3 + mov ecx,16 +.loopb3 + mov ah,[esi+12] + mov al,[esi+8] + shl eax,16 + mov ah,[esi+4] + mov al,[esi+0] + mov [es:edi],eax + add esi,16 + add edi,4 + dec ecx + jnz .loopb3 + add esi,32 + add edi,16 + dec dl + jnz .loopa3 + mov dx,03C4h + mov ax,0802h ; set as plane 4 + out dx,ax + mov esi,[.startesi] + add esi,3 + mov edi,[.startedi] + mov dl,[resolutn] + dec dl + dec dl +.loopa4 + mov ecx,16 +.loopb4 + mov ah,[esi+12] + mov al,[esi+8] + shl eax,16 + mov ah,[esi+4] + mov al,[esi+0] + mov [es:edi],eax + add esi,16 + add edi,4 + dec ecx + jnz .loopb4 + add esi,32 + add edi,16 + dec dl + jnz .loopa4 + pop es + cmp byte[whichpage],0 + jne .setpageb + mov dx,03D4h + mov al,0Ch + out dx,al + inc dx + mov al,75 + out dx,al + dec dx + mov al,0Dh + out dx,al + inc dx + xor al,al + out dx,al + mov byte[whichpage],1 + ret +.setpageb + mov dx,03D4h + mov al,0Ch + out dx,al + inc dx + xor al,al + out dx,al + dec dx + mov al,0Dh + out dx,al + inc dx + xor al,al + out dx,al + mov byte[whichpage],0 + ret +.startesi dd 0 +.startedi dd 0 + +NEWSYM whichpage, db 0 ; active page and visual page locations + +;******************************************************* +; CopyModeQ Copies buffer into chained 256x256 +;******************************************************* + +NEWSYM copymodeq + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[selcA000] + mov es,ax + mov esi,[vidbuffer] + mov ebp,[vidbufferm] + mov edi,9*256 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,17*256 +.res239 + add esi,16+256+32 + add ebp,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[FPUCopy],2 + je near .loopc +.loopa + mov ecx,64 + rep movsd + add esi,32 + dec dl + jnz .loopa + pop es + ret + +.loopc + mov ecx,16 + MMXStuff + add esi,32 + dec dl + jnz .loopc + emms + pop es + ret + +;******************************************************* +; Copy VESA2 320x240x8b Copies buffer to 320x240x8bVBE2 +;******************************************************* +; Input: AX = 4F07h VBE Set/Get Display Start Control +; BH = 00h Reserved and must be 00h +; BL = 00h Set Display Start +; = 01h Get Display Start +; = 80h Set Display Start during Vertical +; Retrace +; CX = First Displayed Pixel In Scan Line +; (Set Display Start only) +; DX = First Displayed Scan Line (Set Display Start +; only) + +NEWSYM copyvesa2320x240x8b + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + cmp byte[ScreenScale],1 + je near .scalescreen + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320+32 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[FPUCopy],1 + je .loopb + cmp byte[FPUCopy],2 + je near .loopc +.loopa + mov ecx,64 + rep movsd + add esi,32 + add edi,64 + dec dl + jnz .loopa + pop es + ret +.loopb + CopyFPU + add esi,32 + add edi,64 + dec dl + jnz near .loopa + pop es + ret +.loopc + mov ecx,16 + MMXStuff + add esi,32 + add edi,64 + dec dl + jnz .loopc + emms + pop es + ret + +.scalescreen + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + xor edi,edi + cmp word[resolutn],224 + jne .res239b + mov edi,8*320 +.res239b + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl +.loopab + mov ecx,64 +.loopbbb + mov eax,[esi] + mov [es:edi],al + mov [es:edi+1],eax + add esi,4 + add edi,5 + dec ecx + jnz .loopbbb + add esi,32 + dec dl + jnz .loopab + pop es + ret + +;******************************************************* +; Copy VESA2 320x480x8b Copies buffer to 320x480x8bVBE2 +;******************************************************* + +NEWSYM copyvesa2320x480x8bgui + mov byte[CurrentGUIOn],1 + jmp copyvesa2320x480x8b.nogui +NEWSYM copyvesa2320x480x8b + mov byte[CurrentGUIOn],0 +.nogui + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320+32 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near copyvesa2320x480x8bs + cmp byte[CurrentGUIOn],1 + je .loopa + cmp byte[f3menuen],1 + je .loopa + cmp byte[ForceNewGfxOff],0 + jne .loopa + cmp byte[newengen],0 + jne near copyvesa2320x480x8ng +.loopa + mov ecx,64 +.a + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a + mov ecx,64 + add edi,64 + sub esi,256 +.a2r + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a2r +.returnloop + add esi,32 + add edi,64 + dec dl + jnz .loopa + pop es + ret + + +copyvesa2320x480x8bs +.loopa + mov ecx,64 +.a + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a +.returnloop + add esi,32 + add edi,64+320 + dec dl + jnz .loopa + pop es + ret + +copyvesa2320x480x8ng: + mov ebx,1 +.loopa + cmp dword[ignor512],0 + je .ignore + test byte[intrlng+ebx],01h + jnz near .interlaced +.ignore + cmp byte[Mode7HiRes],0 + je .nomode7hires + test byte[mosenng+ebx],1 + jz .yesmode7hires + cmp byte[mosszng+ebx],0 + jne .nomode7hires +.yesmode7hires + test byte[intrlng+ebx],40h + jnz .nomode7hires + cmp byte[BGMA+ebx],7 + jne .nomode7hires + cmp byte[BGMA+ebx+1],7 + je near .mode7hires +.nomode7hires + + mov ecx,64 +.a + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a + mov ecx,64 + add edi,64 + sub esi,256 +.a2r + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a2r +.returnloop + add esi,32 + add edi,64 + inc ebx + dec dl + jnz near .loopa + pop es + ret + +.mode7hires + mov ecx,64 +.a7 + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a7 + mov ecx,64 + add edi,64 + add esi,75036-256 +.a2r7 + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a2r7 + sub esi,75036 + jmp .returnloop + +.interlaced + test byte[cfield],1 + jz .b + add edi,320 +.b + mov ecx,64 +.ai + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .ai + test byte[cfield],1 + jnz .bi + add edi,320 +.bi + jmp .returnloop + +;******************************************************* +; Copy VESA2 640x480x8b Copies buffer to 640x480x8bVBE2 +;******************************************************* + +ALIGN32 +NEWSYM EagleHold, dd 0 +NEWSYM smallscreenon, dd 0 +NEWSYM smallscreence, dd 0 +NEWSYM CurrentGUIOn, dd 0 +vesavaland dd 0,0 +mmxvalanda dd 11111111110000001111111111000000b,11111111110000001111111111000000b +mmxvalandb dd 00000000000111110000000000011111b,00000000000111110000000000011111b + +NEWSYM copyvesa2640x480x8bgui + mov byte[CurrentGUIOn],1 + cmp byte[smallscreenon],1 + je near smallscreen640x480x8b + cmp byte[ScreenScale],1 + je near smallscreen640x480x8b.fullscreen + cmp byte[antienab],1 + je near proceagle + cmp byte[scanlines],1 + je near copyvesa2640x480x8bs + mov byte[res640],1 + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + jmp copyvesa2640x480x8b.startcopy2 + +NEWSYM copyvesa2640x480x8b + mov byte[CurrentGUIOn],0 + cmp byte[smallscreenon],1 + je near smallscreen640x480x8b + cmp byte[ScreenScale],1 + je near smallscreen640x480x8b.fullscreen + cmp byte[antienab],1 + je near proceagle + cmp byte[scanlines],1 + je near copyvesa2640x480x8bs + mov byte[res640],1 + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + cmp byte[f3menuen],1 + je .startcopy2 + cmp byte[ForceNewGfxOff],0 + jne .startcopy2 + cmp byte[newengen],0 + jne near copyvesa2640x480x8ng +.startcopy2 + mov dword[ignor512],0 + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl +.loopa + cmp byte[Triplebufen],1 + je .ignorehr + cmp byte[ebx],1 + je near .yeshires +.ignorehr + mov ecx,128 +.a + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + mov ecx,128 + add edi,64*2 + sub esi,256 +.a2r + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2r +.returnloop + add esi,32 + add edi,64*2 + inc ebx + dec dl + jnz .loopa + pop es + cmp byte[Triplebufen],1 + je .ignorehr2 + xor byte[res512switch],1 +.ignorehr2 + ret +.yeshires + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightside + mov ecx,256 +.b + mov al,[esi] + mov [es:edi],al + mov [es:edi+640],al + inc esi + add edi,2 + dec ecx + jnz .b + add edi,640 + jmp .returnloop +.rightside + mov ecx,256 +.b2 + mov al,[esi] + mov [es:edi+1],al + mov [es:edi+641],al + inc esi + add edi,2 + dec ecx + jnz .b2 + add edi,640 + jmp .returnloop + +NEWSYM copyvesa2640x480x8ng + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov ebx,1 + mov dl,[resolutn] + dec dl + dec dl +.loopa + mov ecx,256 + cmp dword[ignor512],0 + je .ignore + test byte[intrlng+ebx],01h + jnz near .interlaced + cmp byte[BGMA+ebx],5 + je near .hires + cmp byte[BGMA+ebx],6 + je near .hires + cmp byte[Mode7HiRes],0 + je .nomode7hires + test byte[mosenng+ebx],1 + jz .yesmode7hires + cmp byte[mosszng+ebx],0 + jne .nomode7hires +.yesmode7hires + test byte[intrlng+ebx],40h + jnz .nomode7hires + cmp byte[BGMA+ebx],7 + jne .nomode7hires + cmp byte[BGMA+ebx+1],7 + je near .mode7hires +.nomode7hires +.ignore + mov ecx,128 +.a + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + mov ecx,128 + add edi,64*2 + sub esi,256 +.a2r + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2r +.returnloop + add esi,32 + add edi,64*2 ;+640 + inc ebx + dec dl + jnz near .loopa + mov dword[ignor512],0 + pop es + ret +.hires + mov ecx,128 +.a3 + mov al,[esi+1] + mov ah,[esi+75037] + shl eax,16 + mov al,[esi] + mov ah,[esi+75036] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a3 + add edi,64*2 + sub esi,256 + mov ecx,128 +.a6 + mov al,[esi+1] + mov ah,[esi+75037] + shl eax,16 + mov al,[esi] + mov ah,[esi+75036] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a6 + jmp .returnloop + +.interlaced + mov ecx,128 + cmp byte[BGMA+ebx],5 + je .hiresi + cmp byte[BGMA+ebx],6 + je .hiresi + test byte[cfield],1 + jz .b + add edi,640 +.b +.a2 + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 + test byte[cfield],1 + jnz .bi + add edi,640 +.bi + jmp .returnloop + +.hiresi + test byte[cfield],1 + jz .b2 + add edi,640 +.b2 +.a4 + mov al,[esi+1] + mov ah,[esi+75037] + shl eax,16 + mov al,[esi] + mov ah,[esi+75036] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a4 + test byte[cfield],1 + jnz .bi2 + add edi,640 +.bi2 + jmp .returnloop + +.mode7hires + cmp byte[mode7hr+ebx],1 + je near .mode7hiresb + mov ecx,128 +.a7 + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a7 + mov ecx,128 + add edi,64*2 + add esi,75036-256 +.a7r + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a7r + sub esi,75036 + jmp .returnloop + +.mode7hiresb + mov ecx,64 +.a7hr + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a7hr + mov ecx,64 + add esi,75036*2-256 +.a7hrb + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a7hrb + sub esi,75036*2 + add edi,64*2 + add esi,75036-256 + mov ecx,64 +.a7hrr + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a7hrr + mov ecx,64 + add esi,75036*2-256 +.a7hrbr + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .a7hrbr + sub esi,75036*3 + jmp .returnloop + +NEWSYM smallscreen640x480x8b + mov byte[res640],0 + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640+32*2 +.res239 + add edi,[VidStartDraw] + add edi,128+120*640 + add esi,16+256+32 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl +.loopa + mov ecx,64 + rep movsd + add esi,32 + add edi,640-256 + inc ebx + dec dl + jnz .loopa + pop es + ret + +.fullscreen + cmp byte[curblank],40h + jne .startcopy2 + ret +.startcopy2 + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + xor edi,edi + cmp word[resolutn],224 + jne .res239b + mov edi,8*640 +.res239b + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines +.loopa3 + mov ecx,128 +.loopa2 + mov al,[esi] + mov [es:edi],al + mov [es:edi+1],al + mov [es:edi+640],al + mov [es:edi+641],al + mov al,[esi+1] + mov [es:edi+2],al + mov [es:edi+3],al + mov [es:edi+4],al + mov [es:edi+642],al + mov [es:edi+643],al + mov [es:edi+644],al + add esi,2 + add edi,5 + dec ecx + jnz .loopa2 + add esi,32 + add edi,640 + inc ebx + dec dl + jnz .loopa3 + pop es + ret + +.scanlines +.loopa5 + mov ecx,128 +.loopa4 + mov al,[esi] + mov [es:edi],al + mov [es:edi+1],al + mov al,[esi+1] + mov [es:edi+2],al + mov [es:edi+3],al + mov [es:edi+4],al + add esi,2 + add edi,5 + dec ecx + jnz .loopa4 + add esi,32 + add edi,640 + inc ebx + dec dl + jnz .loopa5 + pop es + ret + +NEWSYM copyvesa2640x480x8bs + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + mov byte[res640],2 + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl + cmp byte[CurrentGUIOn],1 + je .loopa + cmp byte[ForceNewGfxOff],0 + jne .loopa + cmp byte[newengen],0 + jne near copyvesa2640x480x8bsng +.loopa + cmp byte[Triplebufen],1 + je .ignorehr + cmp byte[ebx],1 + je .yeshires +.ignorehr + mov ecx,256 +.a + mov al,[esi] + mov [es:edi],al + mov [es:edi+1],al + inc esi + add edi,2 + dec ecx + jnz .a +.returnloop + add esi,32 + add edi,64*2+640 + inc ebx + dec dl + jnz .loopa + pop es + cmp byte[Triplebufen],1 + je .ignorehr2 + xor byte[res512switch],1 +.ignorehr2 + ret +.yeshires + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightside + mov ecx,256 +.b + mov al,[esi] + mov [es:edi],al + inc esi + add edi,2 + dec ecx + jnz .b + jmp .returnloop +.rightside + mov ecx,256 +.b2 + mov al,[esi] + mov [es:edi+1],al + inc esi + add edi,2 + dec ecx + jnz .b2 + jmp .returnloop + +copyvesa2640x480x8bsng: + xor ebx,ebx +.loopa + cmp byte[BGMA+ebx],5 + je near .hires + cmp byte[BGMA+ebx],6 + je near .hires + mov ecx,128 +.a + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a +.returnloop + add esi,32 + add edi,64*2+640 + inc ebx + dec dl + jnz .loopa + pop es + xor byte[res512switch],1 + ret +.hires + mov ecx,128 +.a2 + mov al,[esi+1] + mov ah,[esi+75037] + shl eax,16 + mov al,[esi] + mov ah,[esi+75036] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 + jmp .returnloop + +NEWSYM proceagle + mov byte[res640],0 + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + add esi,16+256+32 + mov dl,237 + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640+32*2 + add edi,[VidStartDraw] + mov dl,222 +.res239 + call draweagle + pop es + ret + +NEWSYM draweagle + ; copies a buffer from esi to es:edi with dl # of lines + ; This only works under vesa 2 640x480x8b mode + mov [lineleft],dl + + ; copy the first line directly + mov ecx,128 +.drawnext + mov al,[esi] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .drawnext + + dec byte[lineleft] + add edi,128 ; 512 + 128 = 640 + add esi,32 ; There are 32 extra pixels in the buffer used + ; for clipping + + xor eax,eax + xor ebx,ebx + mov edx,[spritetablea] +.drawloop + ; process EAGLE on the bottom line + ; process the first pixel + ; copy to the left pixel + mov al,[esi] + mov [edx],al + ; draw the right pixel depending on the pixels right & below + mov al,[esi+1] + mov ah,al + mov bx,[esi+288] + cmp ebx,eax + je .matchf + mov al,[esi] +.matchf + mov [edx+1],al + inc esi + add edx,2 + + ; Start drawing the in-between pixels + mov ecx,256-2 + mov bx,[esi+287] +.lineloopd + ; draw the left pixel depending on the pixels left & below + mov al,[esi-1] + mov ah,al + cmp ebx,eax + je .matchlp + mov al,[esi] +.matchlp + mov [edx],al + + ; draw the right pixel depending on the pixels right & below + mov al,[esi+1] + mov ah,al + mov bx,[esi+288] + cmp ebx,eax + je .matchrp + mov al,[esi] +.matchrp + mov [edx+1],al + ;increment the addresses + add edx,2 + inc esi + dec ecx + jnz .lineloopd + + ; process the last pixel + ; draw the left pixel depending on the pixels left & below + mov al,[esi-1] + mov ah,al + mov bx,[esi+287] + cmp ebx,eax + je .matchl + mov al,[esi] +.matchl + mov [edx],al + ; copy to the right pixel + mov al,[esi] + mov [edx+1],al + inc esi + + sub edx,510 + mov ecx,128 +.copyloop + mov eax,[edx] + mov [es:edi],eax + add edx,4 + add edi,4 + loop .copyloop + xor eax,eax + + ; process EAGLE on the upper line + add edi,128 + add esi,32 + + mov edx,[spritetablea] + ; process the first pixel + ; copy to the left pixel + mov al,[esi] + mov [edx],al + ; draw the right pixel depending on the pixels right & above + mov al,[esi+1] + mov ah,al + mov bx,[esi-288] + cmp ebx,eax + je .matchf2 + mov al,[esi] +.matchf2 + mov [edx+1],al + inc esi + add edx,2 + + ; Start drawing the in-between pixels + mov ecx,256-2 + mov bx,[esi-289] + +.lineloopd2 + ; draw the left pixel depending on the pixels left & above + mov al,[esi-1] + mov ah,al + cmp ebx,eax + je .matchlp2 + mov al,[esi] +.matchlp2 + mov [edx],al + ; draw the right pixel depending on the pixels right & below + mov al,[esi+1] + mov ah,al + mov bx,[esi-288] + cmp ebx,eax + je .matchrp2 + mov al,[esi] +.matchrp2 + mov [edx+1],al + ;increment the addresses + add edx,2 + inc esi + dec ecx + jnz .lineloopd2 + + ; process the last pixel + ; draw the left pixel depending on the pixels left & above + mov al,[esi-1] + mov ah,al + mov bx,[esi-289] + cmp ebx,eax + je .matchl2 + mov al,[esi] +.matchl2 + mov [edx],al + ; copy to the right pixel + mov al,[esi] + mov [edx+1],al + inc esi + + sub edx,510 + mov ecx,128 +.copyloop2 + mov eax,[edx] + mov [es:edi],eax + add edx,4 + add edi,4 + loop .copyloop2 + xor eax,eax + + sub esi,256 ; move esi back to left side of the line + add edi,128 + dec byte[lineleft] + jnz near .drawloop + + ; copy the last line directly + mov ecx,128 +.drawlast + mov al,[esi] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .drawlast + ret + +;******************************************************* +; Copy VESA2 512x384x8b Copies buffer to 512x384x8bVBE2 +;******************************************************* + +NEWSYM copyvesa2512x384x8b + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + cmp byte[ForceNewGfxOff],0 + jne .nong16b + cmp byte[newengen],0 + jne near copyvesa2512x384x8ng +.nong16b + mov dword[ignor512],0 + push es + mov byte[.lastrep],0 + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov byte[.scratio],61 ; 60.6695 + cmp word[resolutn],224 + jne .res239 + mov byte[.scratio],72 ; 72.4286 +.res239 + mov edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl + xor dh,dh +.loopa + mov al,[ebx] + mov [.p512],al + cmp byte[Triplebufen],1 + je .ignorehr + cmp al,1 + je .yeshires +.ignorehr + mov ecx,128 +.a + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a +.returnloop + cmp byte[.lastrep],1 + je .no2 + sub dh,[.scratio] + jnc .no2 + add dh,100 + sub esi,256 + mov al,[.p512] + mov [ebx],al + inc dl + dec ebx + mov byte[.lastrep],1 + jmp .yes2 +.no2 + mov byte[.lastrep],0 + add esi,32 +.yes2 + inc ebx + dec dl + jnz .loopa + pop es + cmp byte[Triplebufen],1 + je .ignorehr2 + xor byte[res512switch],1 +.ignorehr2 + ret +.yeshires + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightside + mov ecx,256 +.b + mov al,[esi] + mov [es:edi],al + inc esi + add edi,2 + dec ecx + jnz .b + jmp .returnloop +.rightside + mov ecx,256 +.b2 + mov al,[esi] + mov [es:edi+1],al + inc esi + add edi,2 + dec ecx + jnz .b2 + jmp .returnloop + +.scratio db 0 +.lastrep db 0 +.p512 db 0 + +NEWSYM copyvesa2512x384x8ng + push es + mov byte[.lastrep],0 + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov byte[.scratio],61 ; 60.6695 + cmp word[resolutn],224 + jne .res239 + mov byte[.scratio],72 ; 72.4286 +.res239 + mov edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov ebx,1 + mov dl,[resolutn] + dec dl + dec dl + xor dh,dh +.loopa + cmp dword[ignor512],0 + je .a2 + cmp byte[BGMA+ebx],5 + je near .hires + cmp byte[BGMA+ebx],6 + je near .hires +.a2 + mov ecx,128 +.a + mov al,[esi+1] + mov ah,al + shl eax,16 + mov al,[esi] + mov ah,al + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a +.returnloop + cmp byte[.lastrep],1 + je .no2 + sub dh,[.scratio] + jnc .no2 + add dh,100 + sub esi,256 + mov al,[.p512] + mov [ebx],al + inc dl + dec ebx + mov byte[.lastrep],1 + jmp .yes2 +.no2 + mov byte[.lastrep],0 + add esi,32 +.yes2 + inc ebx + dec dl + jnz near .loopa + pop es + mov dword[ignor512],0 + ret +.hires + mov ecx,256 +.b + mov al,[esi] + mov ah,[esi+75036] + mov [es:edi],ax + inc esi + add edi,2 + dec ecx + jnz .b + jmp .returnloop + +.scratio db 0 +.lastrep db 0 +.p512 db 0 + +;******************************************************* +; Copy VESA2 320x240x16b Copies buffer to 320x240x16bVB2 +;******************************************************* + + +copyvesa2320x240x16bgui: + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + cmp byte[ScreenScale],1 + je near .scalescreen + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl +.loopa + mov ecx,256 + xor eax,eax +.loopa2 + mov al,[esi] + inc esi + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + add edi,2 + dec ecx + jnz .loopa2 + add esi,32 + add edi,128 + dec dl + jnz .loopa + pop es + ret +.scalescreen + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + xor edi,edi + cmp word[resolutn],224 + jne .res239b + mov edi,8*320*2 +.res239b + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl +.loopab + mov ecx,64 + xor eax,eax +.loopbb + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + mov al,[esi+1] + mov bx,[GUICPC+eax*2] + mov [es:edi+4],bx + mov al,[esi+2] + mov bx,[GUICPC+eax*2] + mov [es:edi+6],bx + mov al,[esi+3] + mov bx,[GUICPC+eax*2] + mov [es:edi+8],bx + add esi,4 + add edi,10 + dec ecx + jnz .loopbb + add esi,32 + dec dl + jnz .loopab + pop es + ret + +NEWSYM copyvesa2320x240x16b + cmp byte[vesa2red10],1 + jne .notbr + call ConvertToAFormat +.notbr +; je near copyvesa2320x240x16br + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + cmp byte[ScreenScale],1 + je near .scalescreen + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov ebp,[vidbufferm] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16*2+256*2+32*2 + add ebp,16*2+256*2+32*2 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[FPUCopy],1 + je .loopb + cmp byte[FPUCopy],2 + je near .loopc +.loopa + mov ecx,128 + rep movsd + add esi,64 + add edi,128 + dec dl + jnz .loopa + pop es + ret +.loopb + CopyFPU + CopyFPU + add esi,64 + add edi,128 + dec dl + jnz near .loopb + pop es + ret +.loopc + mov ecx,32 + MMXStuff + add esi,64 + add edi,128 + dec dl + jnz .loopc + emms + pop es + ret +.scalescreen + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + xor edi,edi + cmp word[resolutn],224 + jne .res239b + mov edi,8*320*2 +.res239b + add edi,[VidStartDraw] + add esi,16*2+256*2+32*2 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl +.loopab + mov ecx,64 +.loopbb + mov eax,[esi] + mov [es:edi],ax + mov [es:edi+2],eax + mov eax,[esi+4] + mov [es:edi+6],eax + add esi,8 + add edi,10 + dec ecx + jnz .loopbb + add esi,64 + dec dl + jnz .loopab + pop es + ret + +NEWSYM palresvalng, dd 0,0 +NEWSYM palresvalngb, dd 0,0 + +%macro copya320x240 0 + mov [es:edi],dx +%endmacro + +%macro copyb320x240 0 + mov [es:edi+2],dx +%endmacro + +ALIGN32 +NEWSYM rescompareng, dd 0 +NEWSYM nextdrawallng, dd 0 +NEWSYM prevcol0ng, dd 0 +NEWSYM numbytelng, dd 0 +NEWSYM lineleft, dd 0 +NEWSYM lineleft2, dd 0 +bankpos dd 0 + +;******************************************************* +; Copy VESA2 320x480x16b Copies buffer to 320x480x16bVB2 +;******************************************************* + +NEWSYM copyvesa2320x480x16bgui + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quarterscanlines + cmp byte[scanlines],1 + je near .scanlines +.loopa + mov ecx,256 + xor eax,eax +.a + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .a + sub esi,256 + add edi,64*2 + mov ecx,256 + xor eax,eax +.a2 + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .a2 + add esi,32 + add edi,64*2 + dec dl + jnz .loopa + pop es + ret + +.scanlines +.loopab + mov ecx,256 + xor eax,eax +.ab + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .ab +.returnb + add esi,32 + add edi,64*2+320*2 + dec dl + jnz .loopab + pop es + ret + +.halfscanlines +.loopabh + mov ecx,256 + xor eax,eax +.abh + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .abh + add edi,64*2 + mov ecx,128 + sub esi,256 +.abh2 + mov al,[esi+1] + mov bx,[GUICPC+eax*2] + mov al,[esi] + shl ebx,16 + mov bx,[GUICPC+eax*2] + and ebx,[vesa2_clbitng2] + shr ebx,1 + mov [es:edi],ebx + add esi,2 + add edi,4 + dec ecx + jnz .abh2 + add esi,32 + add edi,64*2 + dec dl + jnz .loopabh + pop es + ret + +.quarterscanlines +.loopabhq + mov ecx,256 + xor eax,eax +.abhq + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .abhq + add edi,64*2 + mov ecx,128 + sub esi,256 +.abh2q + mov al,[esi+1] + mov bx,[GUICPC+eax*2] + mov al,[esi] + shl ebx,16 + mov bx,[GUICPC+eax*2] + and ebx,[vesa2_clbitng2] + shr ebx,1 + mov eax,ebx + and eax,[vesa2_clbitng2] + shr eax,1 + add ebx,eax + mov [es:edi],ebx + xor eax,eax + add esi,2 + add edi,4 + dec ecx + jnz .abh2q + add esi,32 + add edi,64*2 + dec dl + jnz .loopabhq + pop es + ret + + +NEWSYM ConvertToAFormat + cmp byte[GUIOn],1 + je .nonewgfx + cmp byte[newengen],0 + je .nonewgfx + ret +.nonewgfx + mov eax,[vesa2_clbitng2] + mov ebx,eax + and eax,11111111110000001111111111000000b + and ebx,00000000000111110000000000011111b + or eax,ebx + mov [vesavaland],eax + mov [vesavaland+4],eax + mov esi,[vidbuffer] + add esi,16*2+256*2+32*2 + mov dl,[resolutn] + dec dl + dec dl + cmp byte[FPUCopy],2 + je near .mmxconv +.crgbloop + mov ecx,128 +.crgbloop2 + mov eax,[esi] + mov ebx,eax + and eax,11111111110000001111111111000000b + and ebx,00000000000111110000000000011111b + shr eax,1 + or ebx,eax + mov [esi],ebx + add esi,4 + loop .crgbloop2 + add esi,64 + dec dl + jnz .crgbloop + jmp .nocopyvesa2r +.mmxconv +.crgbloopm + mov ecx,64 + movq mm6,[mmxvalanda] + movq mm7,[mmxvalandb] +.crgbloop2m + movq mm0,[esi] + movq mm1,mm0 + pand mm0,mm6 + pand mm1,mm7 + psrlw mm0,1 + por mm0,mm1 + movq [esi],mm0 + add esi,8 + loop .crgbloop2m + add esi,64 + dec dl + jnz .crgbloopm + emms +.nocopyvesa2r + ret + +NEWSYM UnConvertToAFormat + mov esi,[vidbuffer] + add esi,16*2+256*2+32*2 + mov dl,[resolutn] + dec dl + dec dl +.crgbloop + mov ecx,128 +.crgbloop2 + mov eax,[esi] + mov ebx,eax + and eax,01111111111000000111111111100000b + and ebx,00000000000111110000000000011111b + shl eax,1 + or ebx,eax + mov [esi],ebx + add esi,4 + loop .crgbloop2 + add esi,64 + dec dl + jnz .crgbloop + ret + +NEWSYM copyvesa2320x480x16b + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + mov eax,[vesa2_clbitng2] + mov [vesavaland],eax + mov [vesavaland+4],eax + cmp byte[vesa2red10],1 + jne .nocopyvesa2r + call ConvertToAFormat +.nocopyvesa2r + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2+32*2 +.res239 + add edi,[VidStartDraw] + add esi,16*2+256*2+32*2 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quartscanlines +.loopa + mov ecx,128 + cmp byte[FPUCopy],2 + je near .mmx + rep movsd + sub esi,256*2 + add edi,64*2 + mov ecx,128 + rep movsd +.return + add esi,64 + add edi,64*2 + inc ebx + dec dl + jnz .loopa + pop es + cmp byte[FPUCopy],2 + je .mmx2 + ret +.mmx2 + emms + ret +.mmx + mov ecx,32 +.mmxr + movq mm0,[esi] + movq mm1,[esi+8] + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxr + sub esi,16*32 + add edi,64*2 + mov ecx,32 +.mmxr2 + movq mm0,[esi] + movq mm1,[esi+8] + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxr2 + jmp .return + +.scanlines +.loopab + mov ecx,128 + cmp byte[FPUCopy],2 + je near .mmxsl +.ab + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .ab +.returnb + add esi,64 + add edi,64*2+320*2 + inc ebx + dec dl + jnz .loopab + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxsl + mov ecx,32 +.mmxrsl + movq mm0,[esi] + movq mm1,[esi+8] + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxrsl + jmp .returnb + +.halfscanlines +.loopabh + cmp byte[FPUCopy],2 + je near .mmxslh + mov ecx,128 +.abh + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .abh + mov ecx,128 + sub esi,512 + add edi,64*2 +.abhs + mov eax,[esi] + and eax,[vesavaland] + shr eax,1 + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .abhs +.returnbh + add esi,64 + add edi,64*2 + inc ebx + dec dl + jnz .loopabh + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxslh + mov ecx,32 + add eax,512 +.mmxrslh + movq mm0,[esi] + movq mm1,[esi+8] + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxrslh + mov ecx,16 + sub esi,512 + add eax,512 + add edi,64*2 + movq mm4,[vesavaland] +.mmxr2h + movq mm0,[esi] + movq mm1,[esi+8] + movq mm2,[esi+16] + movq mm3,[esi+24] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + movq [es:edi+16],mm2 + movq [es:edi+24],mm3 + add esi,32 + add edi,32 + dec ecx + jnz .mmxr2h + jmp .returnbh + +.quartscanlines + mov [lineleft],dl +.loopabh2 + cmp byte[FPUCopy],2 + je near .mmxslh2 + mov ecx,128 +.abh2 + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .abh2 + mov ecx,128 + sub esi,512 + add edi,64*2 +.abhs2 + mov eax,[esi] + and eax,[vesavaland] + shr eax,1 + mov edx,eax + and edx,[vesavaland] + shr edx,1 + add eax,edx + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .abhs2 +.returnbh2 + add esi,64 + add edi,64*2 + inc ebx + dec byte[lineleft] + jnz near .loopabh2 + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxslh2 + mov ecx,32 + add eax,512 +.mmxrslh2 + movq mm0,[esi] + movq mm1,[esi+8] + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxrslh2 + mov ecx,32 + sub esi,512 + add edi,64*2 + movq mm4,[vesavaland] +.mmxr2h2 + movq mm0,[esi] + movq mm1,[esi+8] + pand mm0,mm4 + pand mm1,mm4 + psrlw mm0,1 + psrlw mm1,1 + movq mm2,mm0 + movq mm3,mm1 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm2 + paddd mm1,mm3 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxr2h2 + jmp .returnbh2 + +;******************************************************* +; Copy VESA2 640x480x16b Copies buffer to 640x480x16bVB2 +;******************************************************* + +%macro copya640x480 0 + mov [es:edi],dx + mov [es:edi+2],dx + mov [es:edi+640*2],dx + mov [es:edi+640*2+2],dx +%endmacro + +%macro copyb640x480 0 + mov [es:edi+4],dx + mov [es:edi+6],dx + mov [es:edi+640*2+4],dx + mov [es:edi+640*2+6],dx +%endmacro + +%macro copya640x480sl 0 + mov [es:edi],dx + mov [es:edi+2],dx +%endmacro + +%macro copyb640x480sl 0 + mov [es:edi+4],dx + mov [es:edi+6],dx +%endmacro + +%macro precheckvesa12 1 + cmp edx,%1 + ja %%a + mov ecx,edx +%%a +%endmacro + +%macro postcheckvesa12 4 + cmp edx,%3 + ja %%a + call VESA12Bankswitch + mov ecx,%3 + sub ecx,edx + add edx,%4 + or ecx,ecx + jz %%a + jmp %1 +%%a + sub edx,%3 + sub edx,%2 + jg %%nobankswitch + add edx,%4 + call VESA12Bankswitch +%%nobankswitch +%endmacro + +NEWSYM copyvesa12640x480x16bgui + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov word[bankpos],0 + call VESA12Bankswitch + mov ax,[selcA000] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2*2+32*2*2 +.res239 + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + mov [lineleft],dl + mov edx,65536 + sub edx,edi + shr edx,2 + cmp byte[smallscreenon],1 + je near .smallscreen + cmp byte[scanlines],1 + je near .scanlines +.loopa + mov ecx,256 + xor eax,eax + precheckvesa12 256 +.a + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .a + postcheckvesa12 .a,64,256,16384 + sub esi,256 + add edi,128*2 + mov ecx,256 + xor eax,eax + precheckvesa12 256 +.a2 + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .a2 + postcheckvesa12 .a2,64,256,16384 + add esi,32 + add edi,128*2 + dec byte[lineleft] + jnz near .loopa + pop es + ret + +.scanlines +.loopa2 + mov ecx,256 + xor eax,eax + precheckvesa12 256 +.ab + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .ab + postcheckvesa12 .ab,64+320,256,16384 + add esi,32 + add edi,128*2+640*2 + dec byte[lineleft] + jnz near .loopa2 + pop es + ret + +.smallscreen + add edx,edx +.loopa3 + mov ecx,256 + xor eax,eax + precheckvesa12 256 +.ac + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .ac + postcheckvesa12 .ac,128+256,256,32768 + add esi,32 + add edi,128*2+256*2 + dec byte[lineleft] + jnz near .loopa3 + pop es + ret + + +VESA12Bankswitch: + pushad + mov ax,4F05h + mov bx,0 + mov dx,[bankpos] + int 10h + mov ax,[granadd] + add word[bankpos],ax + popad + sub edi,65536 + ret + +NEWSYM copyvesa2640x480x16bgui + je near smallscreen640x480x16bgui.fullscreen + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2*2+32*2*2 +.res239 + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quarterscanlines + cmp byte[scanlines],1 + je near .scanlines +.loopa + mov ecx,256 + xor eax,eax +.a + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .a + sub esi,256 + add edi,128*2 + mov ecx,256 + xor eax,eax +.a2 + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .a2 + add esi,32 + add edi,128*2 + dec dl + jnz .loopa + pop es + ret + +.scanlines +.loopab + mov ecx,256 + xor eax,eax +.ab + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .ab +.returnb + add esi,32 + add edi,128*2+640*2 + dec dl + jnz .loopab + pop es + ret + +.halfscanlines +.loopabh + mov ecx,256 + xor eax,eax +.abh + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .abh + add edi,128*2 + mov ecx,256 + sub esi,256 +.abh2 + mov al,[esi] + mov bx,[GUICPC+eax*2] + shl ebx,16 + mov bx,[GUICPC+eax*2] + and ebx,[vesa2_clbitng2] + shr ebx,1 + mov [es:edi],ebx + inc esi + add edi,4 + dec ecx + jnz .abh2 + add esi,32 + add edi,128*2 + dec dl + jnz .loopabh + pop es + ret + +.quarterscanlines +.loopabhq + mov ecx,256 + xor eax,eax +.abhq + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .abhq + add edi,128*2 + mov ecx,256 + sub esi,256 +.abh2q + mov al,[esi] + mov bx,[GUICPC+eax*2] + shl ebx,16 + mov bx,[GUICPC+eax*2] + and ebx,[vesa2_clbitng2] + shr ebx,1 + mov eax,ebx + and eax,[vesa2_clbitng2] + shr eax,1 + add ebx,eax + mov [es:edi],ebx + xor eax,eax + inc esi + add edi,4 + dec ecx + jnz .abh2q + add esi,32 + add edi,128*2 + dec dl + jnz .loopabhq + pop es + ret + +NEWSYM smallscreen640x480x16bgui + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640*2+32*2*2 +.res239 + add edi,[VidStartDraw] + add edi,128*2+120*640*2 + add esi,16+256+32 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl +.loopa + mov ecx,256 + xor eax,eax +.a3 + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + inc esi + add edi,2 + dec ecx + jnz .a3 + add esi,32 + add edi,640*2-256*2 + inc ebx + dec dl + jnz .loopa + pop es + ret + +.fullscreen + cmp byte[curblank],40h + jne .startcopy2 + ret +.startcopy2 + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + xor edi,edi + cmp word[resolutn],224 + jne .res239b + mov edi,8*320*2*2 +.res239b + add edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines +.loopa2 + mov ecx,128 + xor eax,eax +.a + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + mov al,[esi+1] + mov bx,[GUICPC+eax*2] + mov [es:edi+4],bx + mov [es:edi+6],bx + mov [es:edi+8],bx + add esi,2 + add edi,10 + dec ecx + jnz .a + sub esi,256 + mov ecx,128 +.a2 + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + mov al,[esi+1] + mov bx,[GUICPC+eax*2] + mov [es:edi+4],bx + mov [es:edi+6],bx + mov [es:edi+8],bx + add esi,2 + add edi,10 + dec ecx + jnz .a2 + add esi,32 + dec dl + jnz near .loopa2 + pop es + ret + +.scanlines +.loopab + mov ecx,128 + xor eax,eax +.ab + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + mov al,[esi+1] + mov bx,[GUICPC+eax*2] + mov [es:edi+4],bx + mov [es:edi+6],bx + mov [es:edi+8],bx + add esi,2 + add edi,10 + dec ecx + jnz .ab + add esi,32 + add edi,640*2 + dec dl + jnz .loopab + pop es + ret + +NEWSYM copyvesa2640x480x16b +; cmp byte[vesa2red10],1 +; je near copyvesa2640x480x16br + cmp byte[vesa2red10],1 + jne .notbr + call ConvertToAFormat +; call UnConvertToAFormat +.notbr + cmp byte[smallscreenon],1 + je near smallscreen640x480x16b + cmp byte[ScreenScale],1 + je near smallscreen640x480x16b.fullscreen + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2*2+32*2*2 +.res239 + add edi,[VidStartDraw] + add esi,16*2+256*2+32*2 + xor eax,eax + ; Check if interpolation mode + cmp byte[GUIOn],1 + je .nointerp + cmp byte[FPUCopy],2 + jne .nommx + cmp byte[newgfx16b],0 + je .nommx + cmp byte[En2xSaI],0 + jne near Process2xSaI +.nommx + cmp byte[antienab],1 + je near interpolate640x480x16b +.nointerp + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quartscanlines + mov ebx,hirestiledat+1 + cmp byte[newengen],0 + je .loopa + mov ebx,SpecialLine+1 +.loopa + mov ecx,256 + cmp byte[Triplebufen],1 + je .ignorehr + cmp byte[ebx],1 + je near .yeshires + cmp byte[GUIOn],1 + je .ignorehr + cmp byte[ebx],1 + ja near .yeshiresng +.ignorehr + cmp byte[FPUCopy],2 + je near .mmx +.a + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + sub esi,256*2 + add edi,128*2 + mov ecx,256 +.a2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 +.return + add esi,64 + add edi,128*2 + inc ebx + dec dl + jnz near .loopa + pop es + cmp byte[Triplebufen],1 + je .ignorehr2 + xor byte[res512switch],1 +.ignorehr2 + cmp byte[FPUCopy],2 + je .mmx2 + ret +.mmx2 + emms + ret +.yeshires + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightside +.b + mov ax,[esi] + mov [es:edi],ax + mov [es:edi+1280],ax + add esi,2 + add edi,4 + dec ecx + jnz .b + add edi,640*2 + jmp .return +.rightside +.c + mov ax,[esi] + mov [es:edi+2],ax + mov [es:edi+1282],ax + add esi,2 + add edi,4 + dec ecx + jnz .c + add edi,640*2 + jmp .return +.mmx + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.mmxr + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + movq [es:edi],mm0 + punpckhwd mm1,mm1 + movq [es:edi+8],mm1 + movq [eax],mm0 + movq [eax+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxr +.nextmmx + mov eax,[spritetablea] + mov ecx,32 + add eax,512 + add edi,128*2 +.mmxr2 + movq mm0,[eax] + movq [es:edi],mm0 + movq mm1,[eax+8] + movq [es:edi+8],mm1 + movq mm2,[eax+16] + movq [es:edi+16],mm2 + movq mm3,[eax+24] + movq [es:edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2 + jmp .return +.yeshiresng + call HighResProc + jmp .return + +.scanlines + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopab + cmp byte[newengen],0 + je .loopab + mov ebx,SpecialLine+1 +.loopab + mov ecx,256 + cmp byte[Triplebufen],1 + je .ignorehrb + cmp byte[ebx],1 + je .yeshiresb + cmp byte[ebx],1 + jbe .ignorehrb + call HighResProc + jmp .returnb +.ignorehrb + cmp byte[FPUCopy],2 + je near .mmxsl +.ab + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .ab +.returnb + add esi,64 + add edi,128*2+640*2 + inc ebx + dec dl + jnz .loopab + pop es + cmp byte[Triplebufen],1 + je .ignorehr2b + xor byte[res512switch],1 +.ignorehr2b + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.yeshiresb + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightsideb +.bb + mov ax,[esi] + mov [es:edi],ax + add esi,2 + add edi,4 + dec ecx + jnz .bb + jmp .returnb +.rightsideb +.cb + mov ax,[esi] + mov [es:edi+2],ax + add esi,2 + add edi,4 + dec ecx + jnz .cb + jmp .returnb +.mmxsl + mov ecx,64 +.mmxrsl + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + punpckhwd mm1,mm1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrsl + jmp .returnb + +.halfscanlines + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabh + cmp byte[newengen],0 + je .loopabh + mov ebx,SpecialLine+1 +.loopabh + cmp byte[ebx],1 + jbe .ignorehrbh + call HighResProc + jmp .returnbh +.ignorehrbh + cmp byte[FPUCopy],2 + je near .mmxslh + mov ecx,256 +.abh + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abh + mov ecx,256 + sub esi,512 + add edi,128*2 +.abhs + mov ax,[esi] + shl eax,16 + mov ax,[esi] + and eax,[vesa2_clbitng2] + shr eax,1 + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs +.returnbh + add esi,64 + add edi,128*2 + inc ebx + dec dl + jnz near .loopabh + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxslh + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.mmxrslh + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + punpckhwd mm1,mm1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + movq [eax],mm0 + movq [eax+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrslh + mov eax,[spritetablea] + mov ecx,32 + add eax,512 + add edi,128*2 + movq mm4,[vesa2_clbitng2] +.mmxr2h + movq mm0,[eax] + movq mm1,[eax+8] + movq mm2,[eax+16] + movq mm3,[eax+24] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + movq [es:edi+16],mm2 + movq [es:edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2h + jmp .returnbh + +.quartscanlines + mov [lineleft],dl + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabh2 + cmp byte[newengen],0 + je .loopabh2 + mov ebx,SpecialLine+1 +.loopabh2 + cmp byte[ebx],1 + jbe .ignorehrbh2 + call HighResProc + jmp .returnbh2 +.ignorehrbh2 + cmp byte[FPUCopy],2 + je near .mmxslh2 + mov ecx,256 +.abh2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abh2 + mov ecx,256 + sub esi,512 + add edi,128*2 +.abhs2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + and eax,[vesa2_clbitng2] + shr eax,1 + mov edx,eax + and edx,[vesa2_clbitng2] + shr edx,1 + add eax,edx + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs2 +.returnbh2 + add esi,64 + add edi,128*2 + inc ebx + dec byte[lineleft] + jnz near .loopabh2 + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxslh2 + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.mmxrslh2 + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + punpckhwd mm1,mm1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + movq [eax],mm0 + movq [eax+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrslh2 + mov eax,[spritetablea] + mov ecx,64 + add eax,512 + add edi,128*2 + movq mm4,[vesa2_clbitng2] +.mmxr2h2 + movq mm0,[eax] + movq mm1,[eax+8] + pand mm0,mm4 + pand mm1,mm4 + psrlw mm0,1 + psrlw mm1,1 + movq mm2,mm0 + movq mm3,mm1 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm2 + paddd mm1,mm3 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add eax,16 + add edi,16 + dec ecx + jnz .mmxr2h2 + jmp .returnbh2 + +HighResProc: + mov ecx,256 + cmp byte[ebx],3 + je near .hiresmode7 + cmp byte[ebx],7 + je near .hiresmode7 + test byte[ebx],4 + jz .nofield + cmp byte[scanlines],0 + jne .nofield + test byte[cfield],1 + jz .nofield + add edi,640*2 +.nofield + test byte[ebx],3 + jnz near .hires +.a + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + cmp byte[scanlines],0 + jne .nofield + test byte[cfield],1 + jnz .nofielde + add edi,640*2 +.nofielde + ret +.hiresmode7 + cmp byte[FPUCopy],2 + je .yeshiresngmmxmode7 +.a2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 + add edi,128*2 + sub esi,512 + mov ecx,256 + add esi,75036*4 +.a2b + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2b + sub esi,75036*4 + ret +.yeshiresngmmxmode7 + mov ecx,64 +.mmxr + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + movq [es:edi],mm0 + punpckhwd mm1,mm1 + movq [es:edi+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxr + add edi,128*2 + sub esi,512 + add esi,75036*4 + mov ecx,64 +.mmxrb + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + movq [es:edi],mm0 + punpckhwd mm1,mm1 + movq [es:edi+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrb + sub esi,75036*4 + ret +.hires + cmp byte[FPUCopy],2 + je near .yeshiresngmmx +.bng + mov eax,[esi+75036*4-2] + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .bng + test byte[ebx],4 + jz .nofieldb + cmp byte[scanlines],0 + jne .nofieldb + test byte[cfield],1 + jnz .lowerfield + add edi,640*2 +.lowerfield + ret +.nofieldb + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quartscanlines + add edi,128*2 + sub esi,256*2 + mov ecx,256 +.bngb + mov eax,[esi+75036*4-2] + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .bngb + ret +.scanlines + ret +.yeshiresngmmx + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.ngal + movq mm0,[esi] + movq mm1,[esi+75036*4] + movq mm2,mm0 + punpcklwd mm0,mm1 + movq [es:edi],mm0 + punpckhwd mm2,mm1 + movq [es:edi+8],mm2 + movq [eax],mm0 + movq [eax+8],mm2 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .ngal + test byte[ebx],4 + jz .nofieldc + cmp byte[scanlines],0 + jne .nofieldc + test byte[cfield],1 + jnz .lowerfieldb + add edi,640*2 +.lowerfieldb + ret +.nofieldc + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlinesmmx + cmp byte[scanlines],2 + je near .quartscanlinesmmx + test byte[ebx+1],3 + jz .noaa + cmp byte[En2xSaI],0 + jne near .antialias + cmp byte[antienab],0 + jne near .antialias +.noaa + add edi,128*2 + mov eax,[spritetablea] + mov ecx,32 + add eax,512 +.mmxr2 + movq mm0,[eax] + movq [es:edi],mm0 + movq mm1,[eax+8] + movq [es:edi+8],mm1 + movq mm2,[eax+16] + movq [es:edi+16],mm2 + movq mm3,[eax+24] + movq [es:edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2 + ret +.antialias + add edi,128*2 + mov eax,[spritetablea] + mov ecx,64 + add eax,512 + movq mm4,[vesa2_clbitng2] + sub esi,256*2 +.mmxr2aa + movq mm0,[esi+288*2] + movq mm1,[esi+288*2+75036*4] + movq mm2,mm0 + punpcklwd mm0,mm1 + punpckhwd mm2,mm1 + movq mm1,[eax] + movq mm3,[eax+8] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm1 + paddd mm2,mm3 + movq [es:edi],mm0 + movq [es:edi+8],mm2 + add eax,16 + add edi,16 + add esi,8 + dec ecx + jnz .mmxr2aa + ret +.halfscanlines + add edi,128*2 + sub esi,256*2 + mov ecx,256 +.abhs + mov eax,[esi+75036*4-2] + mov ax,[esi] + and eax,[vesa2_clbitng2] + shr eax,1 + mov edx,eax + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs + ret +.quartscanlines + add edi,128*2 + sub esi,256*2 + mov ecx,256 +.abhs2 + mov eax,[esi+75036*4-2] + mov ax,[esi] + and eax,[vesa2_clbitng2] + shr eax,1 + mov edx,eax + and edx,[vesa2_clbitng2] + shr edx,1 + add eax,edx + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs2 + ret +.halfscanlinesmmx + mov eax,[spritetablea] + mov ecx,32 + add eax,512 + add edi,128*2 + movq mm4,[vesa2_clbitng2] +.mmxr2h + movq mm0,[eax] + movq mm1,[eax+8] + movq mm2,[eax+16] + movq mm3,[eax+24] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + movq [es:edi+16],mm2 + movq [es:edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2h + ret +.quartscanlinesmmx + mov eax,[spritetablea] + mov ecx,64 + add eax,512 + add edi,128*2 + movq mm4,[HalfTransC] +.mmxr2h2 + movq mm0,[eax] + movq mm1,[eax+8] + pand mm0,mm4 + pand mm1,mm4 + psrlw mm0,1 + psrlw mm1,1 + movq mm2,mm0 + movq mm3,mm1 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm2 + paddd mm1,mm3 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add eax,16 + add edi,16 + dec ecx + jnz .mmxr2h2 + ret + +Process2xSaI: + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabi + cmp byte[newengen],0 + je .loopabi + mov ebx,SpecialLine+1 +.loopabi + mov [InterPtr],ebx + +; add edi,[VESAAddr] + mov dl,[resolutn] + sub dl,2 ; Compensate for top/bottom line + 2 lines in 2xSaI + mov byte[lineleft],dl + mov dword[esi+512],0 + mov dword[esi+512+576*2],0 + mov ebx,[vidbufferofsb] + add ebx,288*2 + +.next + mov dword[esi+512+576*3],0 + + mov eax,[InterPtr] + cmp byte[eax],1 + jbe .ignorehr + push ebx + mov ebx,[InterPtr] + call HighResProc + pop ebx + push ebx + mov ecx,144 +.nextb + mov dword[ebx],0FFFFFFFFh + add ebx,4 + loop .nextb + pop ebx + jmp .returninterp +.ignorehr + +;srcPtr equ 8 +;deltaPtr equ 12 +;srcPitch equ 16 +;width equ 20 +;dstOffset equ 24 +;dstPitch equ 28 +;dstSegment equ 32 + + + cmp byte[En2xSaI],3 + je .super2xsai + mov eax,1280 ; destination pitch + push eax + mov eax,edi ; destination offset + push eax + mov eax,256 ; width + push eax + mov eax,576 ; source pitch + push eax + push ebx + mov eax,esi ; source pointer + push eax + cmp byte[En2xSaI],2 + je .supereagle + call _2xSaILine + jmp .normal +.supereagle + call _2xSaISuperEagleLine + jmp .normal +.super2xsai + pushad + mov eax,1280 ; destination pitch + push eax + mov eax,[spritetablea] ; destination offset + add eax,512 + push eax + mov eax,256 ; width + push eax + mov eax,576 ; source pitch + push eax + push ebx + mov eax,esi ; source pointer + push eax + call Super2xSaI + add esp,24 + popad + ; blit to screen + mov eax,edi + mov edx,[spritetablea] + add edx,512 + mov ecx,128 +.s2xsailoop + movq mm0,[edx] + movq [es:eax],mm0 + add edx,8 + add eax,8 + loop .s2xsailoop + mov edx,[spritetablea] + add edx,512+1280 + add eax,128*2 + mov ecx,128 +.s2xsailoop2 + movq mm0,[edx] + movq [es:eax],mm0 + add edx,8 + add eax,8 + loop .s2xsailoop2 + jmp .dones2xsai +.normal + add esp,24 +.dones2xsai + add esi,576 + inc dword[InterPtr] + add edi,1280*2 + add ebx,576 + dec dword[lineleft] + jnz near .next + mov ecx,256 + sub edi,640*2 +.loop + mov dword[es:edi],0 + add edi,4 + loop .loop + emms + pop es + ret +.returninterp + add esi,64 + inc dword[InterPtr] + add edi,128*2 + dec byte[lineleft] + jnz near .next + emms + pop es + ret + +NEWSYM smallscreen640x480x16b + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*640*2+32*2*2 +.res239 + add edi,[VidStartDraw] + add edi,128*2+120*640*2 + add esi,16*2+256*2+32*2 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl +.loopa + mov ecx,128 + rep movsd + add esi,32*2 + add edi,640*2-256*2 + inc ebx + dec dl + jnz .loopa + pop es + ret + +.fullscreen + cmp byte[curblank],40h + jne .startcopy2 + ret +.startcopy2 + cmp byte[GUIOn],1 + je .nointerpolat + cmp byte[antienab],1 + jne .nointerpolat + cmp byte[FPUCopy],2 + je near MMXInterpolFS +.nointerpolat + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + xor edi,edi + cmp word[resolutn],224 + jne .res239b + mov edi,8*320*2*2 +.res239b + add edi,[VidStartDraw] + add esi,16*2+256*2+32*2 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines +.loopa2 + mov ecx,128 +.a + mov ax,[esi] + mov [es:edi],ax + mov [es:edi+2],ax + mov ax,[esi+2] + mov [es:edi+4],ax + mov [es:edi+6],ax + mov [es:edi+8],ax + add esi,4 + add edi,10 + dec ecx + jnz .a + sub esi,256*2 + mov ecx,128 +.a2 + mov ax,[esi] + mov [es:edi],ax + mov [es:edi+2],ax + mov ax,[esi+2] + mov [es:edi+4],ax + mov [es:edi+6],ax + mov [es:edi+8],ax + add esi,4 + add edi,10 + dec ecx + jnz .a2 + add esi,64 + inc ebx + dec dl + jnz .loopa2 + pop es + ret + +.scanlines +.loopab + mov ecx,128 +.ab + mov ax,[esi] + mov [es:edi],ax + mov [es:edi+2],ax + mov ax,[esi+2] + mov [es:edi+4],ax + mov [es:edi+6],ax + mov [es:edi+8],ax + add esi,4 + add edi,10 + dec ecx + jnz .ab + add esi,64 + add edi,640*2 + inc ebx + dec dl + jnz .loopab + pop es + ret + +MMXInterpolFS: + push es + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + add esi,16*2+256*2+32*2 + xor edi,edi + add edi,[VidStartDraw] + mov dword[lineleft2],0FFFFh + cmp word[resolutn],224 + jne .res239 + mov dword[lineleft2],14 +.res239 + mov dl,[resolutn] + dec dl + dec dl + dec dl + movq mm2,[HalfTrans] + mov [lineleft],dl + mov edx,[spritetablea] + mov ecx,64 + mov eax,[esi+510] + add edx,512 + mov [esi+512],eax +.a2 + movq mm0,[esi] + movq mm4,mm0 + movq mm1,[esi+2] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 +; movq [es:edi],mm4 +; movq [es:edi+8],mm5 + movq [edx],mm4 + movq [edx+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .a2 + add esi,64 + add edi,128*2 +.a5 + mov eax,[esi+510] + mov ecx,32 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 + ; Process next line +.a3 + ; aaaa/abbb/bbcc/cccd/dddd/ + ; aaaa/bbbA/ccBb/dCcc/Dddd/ + ; a / a >> 48, b << 16 / b >> 48, b >> 32 & 0xFFFF0000, c << 32 / + ; c >> 32, c >> 16 & 0xFFFF00000000, d << 48 / d >> 16, d &0xFFFF000000000000 + movq mm0,[esi] + movq mm4,mm0 + movq mm1,[esi+2] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq mm6,[edx] + movq mm7,[edx+8] + movq [edx],mm4 + movq [edx+8],mm5 + pand mm6,mm2 + pand mm7,mm2 + pand mm4,mm2 + pand mm5,mm2 + psrlw mm6,1 + psrlw mm7,1 + psrlw mm4,1 + psrlw mm5,1 + paddd mm4,mm6 + paddd mm5,mm7 + movq [es:edi],mm4 + movq [.interpspad],mm4 + movq [.interpspad+8],mm5 + movq mm4,[.interpspad+6] + movq [es:edi+8],mm4 + movq [.interpspad+6],mm5 + + movq mm0,[esi+8] + movq mm4,mm0 + movq mm1,[esi+10] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq mm6,[edx+16] + movq mm7,[edx+24] + movq [edx+16],mm4 + movq [edx+24],mm5 + pand mm6,mm2 + pand mm7,mm2 + pand mm4,mm2 + pand mm5,mm2 + psrlw mm6,1 + psrlw mm7,1 + psrlw mm4,1 + psrlw mm5,1 + paddd mm4,mm6 + paddd mm5,mm7 + movq [.interpspad+16],mm4 + movq mm7,[.interpspad+12] + movq [es:edi+16],mm7 + movq [.interpspad+14],mm4 + movq [.interpspad+24],mm5 + movq mm7,[.interpspad+18] + movq [es:edi+24],mm7 + movq [.interpspad+22],mm5 + movq mm7,[.interpspad+24] + movq [es:edi+32],mm7 + + add esi,16 + add edi,40 + add edx,32 + dec ecx + jnz near .a3 +; add edi,128*2 + + mov edx,[spritetablea] + add edx,512 + mov ecx,32 +.a4 + movq mm4,[edx] + movq mm5,[edx+8] + movq [es:edi],mm4 + movq [.interpspad],mm4 + movq [.interpspad+8],mm5 + movq mm4,[.interpspad+6] + movq [es:edi+8],mm4 + movq [.interpspad+6],mm5 + movq mm4,[edx+16] + movq mm5,[edx+24] + movq [.interpspad+16],mm4 + movq mm7,[.interpspad+12] + movq [es:edi+16],mm7 + movq [.interpspad+14],mm4 + movq [.interpspad+24],mm5 + movq mm7,[.interpspad+18] + movq [es:edi+24],mm7 + movq [.interpspad+22],mm5 + movq mm7,[.interpspad+24] + movq [es:edi+32],mm7 + add edi,40 + add edx,32 + dec ecx + jnz near .a4 + + add esi,64 +; add edi,128*2 + + dec dword[lineleft2] + cmp dword[lineleft2],0 + jne near .norepeat + mov dword[lineleft2],14 + mov edx,[spritetablea] + add edx,512 + mov ecx,32 +.a6 + movq mm4,[edx] + movq mm5,[edx+8] + movq [es:edi],mm4 + movq [.interpspad],mm4 + movq [.interpspad+8],mm5 + movq mm4,[.interpspad+6] + movq [es:edi+8],mm4 + movq [.interpspad+6],mm5 + movq mm4,[edx+16] + movq mm5,[edx+24] + movq [.interpspad+16],mm4 + movq mm7,[.interpspad+12] + movq [es:edi+16],mm7 + movq [.interpspad+14],mm4 + movq [.interpspad+24],mm5 + movq mm7,[.interpspad+18] + movq [es:edi+24],mm7 + movq [.interpspad+22],mm5 + movq mm7,[.interpspad+24] + movq [es:edi+32],mm7 + add edi,40 + add edx,32 + dec ecx + jnz near .a6 +; add edi,128*2 +.norepeat + + dec byte[lineleft] + jnz near .a5 + emms + pop es + ret + +ALIGN32 +.interpspad dd 0,0,0,0,0,0,0,0 + + +MMXInterpol: + mov dl,[resolutn] + dec dl + dec dl + dec dl + movq mm2,[HalfTransC] + + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopab + cmp byte[newengen],0 + je .loopab + mov ebx,SpecialLine+1 +.loopab + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],2 + je near .scanlinesquart + cmp byte[scanlines],3 + je near .scanlineshalf + inc ebx + mov [lineleft],dl + ; do scanlines + mov edx,[spritetablea] + mov ecx,64 + mov eax,[esi+510] + add edx,512 + mov [esi+512],eax +.a2 + movq mm0,[esi] + movq mm3,mm0 + movq mm4,mm0 + movq mm1,[esi+2] + pand mm3,mm1 + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + pand mm3,[HalfTransB] + paddw mm0,mm3 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [es:edi],mm4 + movq [es:edi+8],mm5 + movq [edx],mm4 + movq [edx+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .a2 + add esi,64 + add edi,128*2 +.a5 + cmp byte[ebx],1 + jbe .ignorehr + call HighResProc + movq mm2,[HalfTransC] +.nothrcopy + jmp .returninterp +.ignorehr + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 + ; Process next line +.a3 + movq mm0,[esi] + movq mm3,mm0 + movq mm4,mm0 + movq mm1,[esi+2] + pand mm3,mm1 + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + pand mm3,[HalfTransB] + paddw mm0,mm3 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + movq mm6,[edx] + movq mm7,[edx+8] + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edx],mm4 + movq [edx+8],mm5 + pand mm0,mm4 + movq mm0,mm6 + pand mm4,mm2 + pand mm6,mm2 + psrlw mm4,1 + psrlw mm6,1 + pand mm0,[HalfTransB] + paddd mm4,mm6 + paddw mm4,mm0 + movq mm0,mm5 + pand mm0,mm7 + pand mm5,mm2 + pand mm7,mm2 + psrlw mm5,1 + pand mm0,[HalfTransB] + psrlw mm7,1 + paddd mm5,mm7 + paddw mm5,mm0 + movq [es:edi],mm4 + movq [es:edi+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz near .a3 + add edi,128*2 + mov edx,[spritetablea] + add edx,512 + mov ecx,64 +.a4 + movq mm0,[edx] + movq mm1,[edx+8] + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add edi,16 + add edx,16 + dec ecx + jnz .a4 +.returninterp + add esi,64 + add edi,128*2 + inc ebx + dec byte[lineleft] + jnz near .a5 + emms + pop es + ret +.blank dd 0,0 + +.scanlines + inc dl + mov [lineleft],dl + ; do scanlines + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax +.asl + cmp byte[ebx],1 + jbe .ignorehrs + call HighResProc + movq mm2,[HalfTrans] + jmp .returninterps +.ignorehrs +.a + movq mm0,[esi] + movq mm4,mm0 + movq mm1,[esi+2] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [es:edi],mm4 + movq [es:edi+8],mm5 + add esi,8 + add edi,16 + dec ecx + jnz .a + mov eax,[esi+510+64] + mov [esi+512+64],eax +.returninterps + add esi,64 + add edi,128*2 + add edi,640*2 + inc ebx + mov ecx,64 + dec byte[lineleft] + jnz near .asl + emms + pop es + ret + +.scanlineshalf + inc dl + mov [lineleft],dl + ; do scanlines +.ahb + cmp byte[ebx],1 + jbe .ignorehrhs + call HighResProc + movq mm2,[HalfTrans] + jmp .returninterphs +.ignorehrhs + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 +.ah + movq mm0,[esi] + movq mm4,mm0 + movq mm1,[esi+2] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edx],mm4 + movq [edx+8],mm5 + movq [es:edi],mm4 + movq [es:edi+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .ah + add edi,128*2 + sub edx,16*64 + mov ecx,64 +.ahc + movq mm0,[edx] + movq mm1,[edx+8] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add edi,16 + add edx,16 + dec ecx + jnz .ahc +.returninterphs + add edi,128*2 + add esi,64 + inc ebx + dec byte[lineleft] + jnz near .ahb + emms + pop es + ret + +.scanlinesquart + inc dl + mov [lineleft],dl + ; do scanlines +.ahb2 + cmp byte[ebx],1 + jbe .ignorehrqs + call HighResProc + movq mm2,[HalfTransC] + jmp .returninterpqs +.ignorehrqs + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 +.ah2 + movq mm0,[esi] + movq mm3,mm0 + movq mm4,mm0 + movq mm1,[esi+2] + pand mm3,mm1 + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + pand mm3,[HalfTransB] + paddw mm0,mm3 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edx],mm4 + movq [edx+8],mm5 + movq [es:edi],mm4 + movq [es:edi+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .ah2 + add edi,128*2 + sub edx,16*64 + mov ecx,64 +.ahc2 + movq mm0,[edx] + movq mm1,[edx+8] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + movq mm4,mm0 + movq mm5,mm1 + pand mm4,mm2 + pand mm5,mm2 + psrlw mm4,1 + psrlw mm5,1 + paddd mm0,mm4 + paddd mm1,mm5 + movq [es:edi],mm0 + movq [es:edi+8],mm1 + add edi,16 + add edx,16 + dec ecx + jnz .ahc2 +.returninterpqs + add esi,64 + add edi,128*2 + inc ebx + dec byte[lineleft] + jnz near .ahb2 + emms + pop es + ret + +ALIGN32 +NEWSYM InterPtr, dd 0 + +NEWSYM interpolate640x480x16b + cmp byte[FPUCopy],2 + je near MMXInterpol + mov byte[FPUCopy],0 + + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabi + cmp byte[newengen],0 + je .loopabi + mov ebx,SpecialLine+1 +.loopabi + mov [InterPtr],ebx + + mov dl,[resolutn] + dec dl + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],2 + je near .scanlinesquart + cmp byte[scanlines],3 + je near .scanlineshalf + inc dword[InterPtr] + mov [lineleft],dl + ; do first line + mov ecx,255 + mov edx,[spritetablea] +.a + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [es:edi],ebx + mov [edx],ebx + add esi,2 + add edi,4 + add edx,4 + loop .a + add esi,66 + add edi,130*2 +.loopb + mov ebx,[InterPtr] + cmp byte[ebx],1 + jbe .ignorehr + call HighResProc + jmp .returninterp +.ignorehr + mov ecx,255 + mov edx,[spritetablea] +.c + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov eax,[edx] + mov bx,[esi] + and eax,[HalfTrans] + mov [edx],ebx + and ebx,[HalfTrans] + shr eax,1 + shr ebx,1 + add eax,ebx + mov [es:edi],eax + add esi,2 + add edi,4 + add edx,4 + loop .c + add edi,130*2 + mov edx,[spritetablea] + mov ecx,255 +.d + mov eax,[edx] + mov [es:edi],eax + add edx,4 + add edi,4 + loop .d + inc dword[InterPtr] + add esi,66 + add edi,130*2 + dec byte[lineleft] + jnz near .loopb + pop es + ret +.returninterp + inc dword[InterPtr] + add esi,64 + add edi,128*2 + dec byte[lineleft] + jnz near .loopb + pop es + ret + +.scanlines + xor eax,eax + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabis + cmp byte[newengen],0 + je .loopabis + mov ebx,SpecialLine+1 +.loopabis +.loopab + mov ecx,255 + cmp byte[Triplebufen],1 + je .ignorehrb + cmp byte[ebx],1 + jbe .ignorehrs + call HighResProc + jmp .returninterps +.ignorehrs + cmp byte[ebx],1 + je .yeshiresb +.ignorehrb + push ebx +.ab + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [es:edi],ebx + add esi,2 + add edi,4 + dec ecx + jnz .ab + pop ebx +.returnb + add esi,66 + add edi,130*2+640*2 + inc ebx + dec dl + jnz .loopab + pop es + cmp byte[Triplebufen],1 + je .ignorehr2b + xor byte[res512switch],1 +.ignorehr2b + ret +.yeshiresb + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightsideb +.bb + mov ax,[esi] + mov [es:edi],ax + add esi,2 + add edi,4 + dec ecx + jnz .bb + jmp .returnb +.rightsideb +.cb + mov ax,[esi] + mov [es:edi+2],ax + add esi,2 + add edi,4 + dec ecx + jnz .cb + jmp .returnb +.returninterps + add esi,64 + inc dword[InterPtr] + add edi,128*2+640*2 + inc ebx + dec byte[lineleft] + jnz near .loopab + pop es + ret + +.scanlineshalf + xor eax,eax + mov [lineleft],dl +.loopab2 + mov ebx,[InterPtr] + cmp byte[ebx],1 + jbe .ignorehrhs + call HighResProc + jmp .returninterphs +.ignorehrhs + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab2 + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [edx],ebx + mov [es:edi],ebx + add esi,2 + add edi,4 + add edx,4 + dec ecx + jnz .ab2 + add edi,130*2 + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab2b + mov eax,[edx] + and eax,[HalfTrans] + shr eax,1 + mov [es:edi],eax + add edi,4 + add edx,4 + dec ecx + jnz .ab2b + inc dword[InterPtr] + add esi,66 + add edi,130*2 + dec byte[lineleft] + jnz near .loopab2 + pop es + ret +.returninterphs + add esi,64 + inc dword[InterPtr] + add edi,128*2 + dec byte[lineleft] + jnz near .loopab2 + pop es + ret + +.scanlinesquart + xor eax,eax + mov [lineleft],dl +.loopab3 + mov ebx,[InterPtr] + cmp byte[ebx],1 + jbe .ignorehrqs + call HighResProc + jmp .returninterpqs +.ignorehrqs + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab3 + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [edx],ebx + mov [es:edi],ebx + add esi,2 + add edi,4 + add edx,4 + dec ecx + jnz .ab3 + add edi,130*2 + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab3b + mov eax,[edx] + and eax,[HalfTrans] + shr eax,1 + mov ebx,eax + and ebx,[HalfTrans] + shr ebx,1 + add eax,ebx + mov [es:edi],eax + add edi,4 + add edx,4 + dec ecx + jnz .ab3b + inc dword[InterPtr] + add esi,66 + add edi,130*2 + dec byte[lineleft] + jnz near .loopab3 + pop es + ret +.returninterpqs + add esi,64 + inc dword[InterPtr] + add edi,128*2 + dec byte[lineleft] + jnz near .loopab2 + pop es + ret + +;******************************************************* +; Copy VESA2 640x480x16b, bit setting 1:5:5:5 +;******************************************************* + +ALIGN32 +.interpspad dd 0,0,0,0,0,0,0,0 + +;******************************************************* +; Copy VESA2 512x384x16b Copies buffer to 512x384x16bV2 +;******************************************************* + +NEWSYM copyvesa2512x384x16bgui + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov byte[.lastrep],0 + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov byte[.scratio],61 ; 60.6695 + cmp word[resolutn],224 + jne .res239 + mov byte[.scratio],72 ; 72.4286 +.res239 + mov edi,[VidStartDraw] + add esi,16+256+32 + xor eax,eax + mov dl,[resolutn] + dec dl + dec dl + xor dh,dh +.loopa + mov ecx,256 + xor eax,eax +.a + mov al,[esi] + mov bx,[GUICPC+eax*2] + mov [es:edi],bx + mov [es:edi+2],bx + inc esi + add edi,4 + dec ecx + jnz .a + cmp byte[.lastrep],1 + je .no2 + sub dh,[.scratio] + jnc .no2 + add dh,100 + sub esi,256 + inc dl + dec ebx + mov byte[.lastrep],1 + jmp .yes2 +.no2 + mov byte[.lastrep],0 + add esi,32 +.yes2 + dec dl + jnz .loopa + pop es + ret + +.scratio db 0 +.lastrep db 0 + +NEWSYM copyvesa2512x384x16b + cmp byte[vesa2red10],1 + jne .noconvertr + call ConvertToAFormat +.noconvertr + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov byte[.lastrep],0 + mov ax,[vesa2selec] + mov es,ax + mov esi,[vidbuffer] + mov byte[.scratio],61 ; 60.6695 + cmp word[resolutn],224 + jne .res239 + mov byte[.scratio],72 ; 72.4286 +.res239 + mov edi,[VidStartDraw] + add esi,16*2+256*2+32*2 + xor eax,eax + mov ebx,hirestiledat+1 + mov dl,[resolutn] + dec dl + dec dl + xor dh,dh +.loopa + mov al,[ebx] + mov [.p512],al + cmp byte[Triplebufen],1 + je .ignorehr + cmp al,1 + je .yeshires +.ignorehr + mov ecx,256 +.a + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a +.returnloop + cmp byte[.lastrep],1 + je .no2 + sub dh,[.scratio] + jnc .no2 + add dh,100 + sub esi,512 + inc dl + mov al,[.p512] + mov [ebx],al + dec ebx + mov byte[.lastrep],1 + jmp .yes2 +.no2 + mov byte[.lastrep],0 + add esi,64 +.yes2 + inc ebx + dec dl + jnz .loopa + pop es + cmp byte[Triplebufen],1 + je .ignorehr2 + xor byte[res512switch],1 +.ignorehr2 + ret +.yeshires + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightside + mov ecx,256 +.b + mov ax,[esi] + mov [es:edi],ax + add esi,2 + add edi,4 + dec ecx + jnz .b + jmp .returnloop +.rightside + mov ecx,256 +.b2 + mov ax,[esi] + mov [es:edi+2],ax + add esi,2 + add edi,4 + dec ecx + jnz .b2 + jmp .returnloop + +.scratio db 0 +.lastrep db 0 +.p512 db 0 + +; Temporary + +NEWSYM tempcopy + cmp byte[pressed+12],1 + jne .nocolch + mov byte[pressed+12],2 + add byte[.cocol],16 +.nocolch + cmp byte[pressed+13],1 + jne .nocolch2 + mov byte[pressed+13],2 + add dword[.startbuf],512*64 + cmp dword[.startbuf],512*64*4 + jne .nores + mov dword[.startbuf],0 +.nores +.nocolch2 + ; cache all sprites + call allcache + pusha + ; copy [vcache4b]+bg1objptr*2 into + xor ebx,ebx + mov bx,[objptr] + shl ebx,1 + add ebx,[vcache4b] + add ebx,[.startbuf] + mov edi,[vidbuffer] + add edi,16 + mov esi,edi + mov dh,16 +.loopd + mov dl,32 +.loopc + mov ch,8 +.loopb + mov cl,8 +.loopa + mov al,[ebx] + add al,[.cocol] + mov [edi],al + inc edi + inc ebx + dec cl + jnz .loopa + add edi,248+32 + dec ch + jnz .loopb + add esi,8 + mov edi,esi + dec dl + jnz .loopc + add esi,288*8-32*8 + mov edi,esi + dec dh + jnz .loopd + popa + ret + +.cocol db 0 +.startbuf dd 0 + +NEWSYM allcache + pushad + mov esi,[vram] + mov edi,[vcache4b] + mov ecx,2048 +.nextcache + ; convert from [esi] to [edi] + ; use ah = color 0, bl = color 1, bh = color 2, cl = color 3 + ; ch = color 4, dl = color 5, dh = color 6, .a = color 7 + push edi + push esi + push ecx + + mov byte[.rowleft],8 +.donext + xor ah,ah + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov byte[.a],0 + mov al,[esi] ; bitplane 0 + cmp al,0 + je .skipconva + test al,01h + jz .skipa0 + or ah,01h +.skipa0 + test al,02h + jz .skipa1 + or bl,01h +.skipa1 + test al,04h + jz .skipa2 + or bh,01h +.skipa2 + test al,08h + jz .skipa3 + or cl,01h +.skipa3 + test al,10h + jz .skipa4 + or ch,01h +.skipa4 + test al,20h + jz .skipa5 + or dl,01h +.skipa5 + test al,40h + jz .skipa6 + or dh,01h +.skipa6 + test al,80h + jz .skipa7 + or byte[.a],01h +.skipa7 +.skipconva + + mov al,[esi+1] ; bitplane 1 + cmp al,0 + je .skipconvb + test al,01h + jz .skipb0 + or ah,02h +.skipb0 + test al,02h + jz .skipb1 + or bl,02h +.skipb1 + test al,04h + jz .skipb2 + or bh,02h +.skipb2 + test al,08h + jz .skipb3 + or cl,02h +.skipb3 + test al,10h + jz .skipb4 + or ch,02h +.skipb4 + test al,20h + jz .skipb5 + or dl,02h +.skipb5 + test al,40h + jz .skipb6 + or dh,02h +.skipb6 + test al,80h + jz .skipb7 + or byte[.a],02h +.skipb7 +.skipconvb + + mov al,[esi+16] ; bitplane 2 + cmp al,0 + je .skipconvc + test al,01h + jz .skipc0 + or ah,04h +.skipc0 + test al,02h + jz .skipc1 + or bl,04h +.skipc1 + test al,04h + jz .skipc2 + or bh,04h +.skipc2 + test al,08h + jz .skipc3 + or cl,04h +.skipc3 + test al,10h + jz .skipc4 + or ch,04h +.skipc4 + test al,20h + jz .skipc5 + or dl,04h +.skipc5 + test al,40h + jz .skipc6 + or dh,04h +.skipc6 + test al,80h + jz .skipc7 + or byte[.a],04h +.skipc7 +.skipconvc + + mov al,[esi+17] ; bitplane 3 + cmp al,0 + je .skipconvd + test al,01h + jz .skipd0 + or ah,08h +.skipd0 + test al,02h + jz .skipd1 + or bl,08h +.skipd1 + test al,04h + jz .skipd2 + or bh,08h +.skipd2 + test al,08h + jz .skipd3 + or cl,08h +.skipd3 + test al,10h + jz .skipd4 + or ch,08h +.skipd4 + test al,20h + jz .skipd5 + or dl,08h +.skipd5 + test al,40h + jz .skipd6 + or dh,08h +.skipd6 + test al,80h + jz .skipd7 + or byte[.a],08h +.skipd7 +.skipconvd + + ; move all bytes into [edi] + mov [edi+7],ah + mov [edi+6],bl + mov [edi+5],bh + mov [edi+4],cl + mov [edi+3],ch + mov [edi+2],dl + mov [edi+1],dh + mov al,[.a] + mov [edi],al + add edi,8 + add esi,2 + dec byte[.rowleft] + jnz near .donext + + pop ecx + pop esi + pop edi + + add esi,32 + add edi,64 + dec cx + jnz near .nextcache + popad + ret + +.nbg dw 0 +.a db 0 +.rowleft db 0 + +;******************************************************* +; Copy VESA1.2 640x480x16b +;******************************************************* + +NEWSYM copyvesa12640x480x16b + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + cmp byte[vesa2red10],1 + jne .nocopyvesa2r + call ConvertToAFormat +.nocopyvesa2r + push es + mov word[bankpos],0 + call VESA12Bankswitch + mov ax,[selcA000] + mov es,ax + mov esi,[vidbuffer] + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2*2+32*2*2 +.res239 + add esi,16*2+256*2+32*2 + xor eax,eax + ; Check if interpolation mode +.nommx + mov dl,[resolutn] + dec dl + dec dl + mov [lineleft],dl + mov edx,65536 + sub edx,edi + shr edx,2 + cmp byte[smallscreenon],1 + je near .smallscreen + cmp byte[scanlines],1 + je near .scanlines +.loopa + mov ecx,256 + precheckvesa12 256 +.a + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + postcheckvesa12 .a,64,256,16384 + sub esi,256*2 + add edi,128*2 + mov ecx,256 + precheckvesa12 256 +.a2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 + postcheckvesa12 .a2,64,256,16384 + add esi,64 + add edi,128*2 + inc ebx + dec byte[lineleft] + jnz near .loopa + pop es + ret + +.scanlines +.loopab + mov ecx,256 + precheckvesa12 256 +.ab + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [es:edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .ab + postcheckvesa12 .ab,64+320,256,16384 + mov ecx,256 + add esi,64 + add edi,128*2+640*2 + inc ebx + dec byte[lineleft] + jnz near .loopab + pop es + ret + +.smallscreen +.loopac + mov ecx,128 + precheckvesa12 128 +.ac + mov eax,[esi] + mov [es:edi],eax + add esi,4 + add edi,4 + dec ecx + jnz .ac + postcheckvesa12 .ac,64+128,128,16384 + mov ecx,128 + add esi,64 + add edi,128*2+256*2 + inc ebx + dec byte[lineleft] + jnz near .loopac + pop es + ret + +;******************************************************* +; Clear Screen +;******************************************************* + +NEWSYM DOSClearScreen + cmp byte[cvidmode],1 + je near cscopymodeq + cmp byte[cvidmode],2 + je near cscopyvesa2320x240x8b + cmp byte[cvidmode],3 + je near cscopyvesa2320x240x16b + cmp byte[cvidmode],4 + je near cscopyvesa2640x480x8b + cmp byte[cvidmode],5 + je near cscopyvesa2640x480x16b + cmp byte[cvidmode],6 + je near cscopyvesa2512x384x8b + cmp byte[cvidmode],7 + je near cscopyvesa2512x384x16b + cmp byte[cvidmode],8 + je near cscopyvesa12640x480x16b + cmp byte[cvidmode],9 + je near cscopyvesa2320x480x8b + cmp byte[cvidmode],10 + je near cscopyvesa2320x480x16b + cmp byte[cvidmode],0 + je near cscopymodex + ret + +%macro TripleBufferClear 0 + cmp byte[Triplebufen],0 + je %%noclear + push ebx + mov ebx,ecx + add ecx,ebx + add ecx,ebx + pop ebx +%%noclear +%endmacro + +NEWSYM cscopymodeq + push es + mov ax,[selcA000] + mov es,ax + xor eax,eax + mov ecx,16384 + xor edi,edi + rep stosd + pop es + ret + +NEWSYM cscopymodex + ; select all planes + mov dx,03C4h + mov ax,0F02h + out dx,ax + push es + mov ax,[selcA000] + mov es,ax + xor edi,edi + mov ecx,65536/4 + xor eax,eax + rep stosd + pop es + ret + +NEWSYM cscopyvesa2320x240x8b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,320*240 + TripleBufferClear +.loop + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loop + pop es + ret + +NEWSYM cscopyvesa2320x240x16b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,320*240*2 + TripleBufferClear +.loop + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loop + pop es + ret + +NEWSYM cscopyvesa2640x480x8b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,640*480 + TripleBufferClear +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + +NEWSYM cscopyvesa2640x480x16b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,640*480*2 + TripleBufferClear +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + +NEWSYM cscopyvesa2320x480x8b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,320*480 + TripleBufferClear +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + +NEWSYM cscopyvesa2320x480x16b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,320*480*2 + TripleBufferClear +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + +NEWSYM cscopyvesa2512x384x8b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,512*384 + TripleBufferClear +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + +NEWSYM cscopyvesa2512x384x16b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,[VidStartDraw] + mov ecx,512*384*2 + TripleBufferClear +.loopb + mov byte[es:edi],0 + inc edi + dec ecx + jnz .loopb + pop es + ret + + +NEWSYM GetScreen + cmp byte[OSPort],1 + jbe .getscreen + ret +.getscreen + cmp byte[cvidmode],3 + je near getcopyvesa2320x240x16b + cmp byte[cvidmode],5 +; je near getcopyvesa2640x480x16b + cmp byte[cvidmode],7 +; je near getcopyvesa2512x384x16b + ret + +NEWSYM getcopyvesa2320x240x16b + push es + mov ax,[vesa2selec] + mov es,ax + mov edi,32*2 ; Draw @ Y from 9 to 247 + cmp word[resolutn],224 + jne .res239 + mov edi,8*320*2+32*2 +.res239 + add edi,[VidStartDraw] + xor ebx,ebx + mov bx,word[resolutn] + mov esi,[vidbuffer] + add esi,32+288*2 + mov ecx,256 +.loop + mov ax,[es:edi] + mov [esi],ax + add edi,2 + add esi,2 + loop .loop + add edi,128 + add esi,64 + mov ecx,256 + dec ebx + jnz .loop + pop es + cmp byte[vesa2red10],0 + jne .redvalue + ret +.redvalue + call ConvertImageDatared10 + ret + +ConvertImageDatared10: + xor ebx,ebx + mov bx,word[resolutn] + mov esi,[vidbuffer] + add esi,32+288*2 + mov ecx,256 +.loop + mov ax,[esi] + mov dx,ax + and ax,0000000000011111b + and dx,0111111111100000b + shl dx,1 + or ax,dx + mov [esi],ax + add esi,2 + loop .loop + add esi,64 + mov ecx,256 + dec ebx + jnz .loop + ret + +NEWSYM cscopyvesa12640x480x16b + push es + mov word[bankpos],0 + call VESA12Bankswitch + mov ax,[selcA000] + mov es,ax + mov edi,32*2*2 ; Draw @ Y from 9 to 247 + xor eax,eax + mov dl,239 + dec dl + dec dl + mov [lineleft],dl + mov edx,65536 + sub edx,edi + shr edx,2 +.loopa + mov ecx,256 + precheckvesa12 256 + xor eax,eax +.a + mov [es:edi],eax + add edi,4 + dec ecx + jnz .a + postcheckvesa12 .a,64,256,16384 + add edi,128*2 + mov ecx,256 + precheckvesa12 256 + xor eax,eax +.a2 + mov [es:edi],eax + add edi,4 + dec ecx + jnz .a2 + postcheckvesa12 .a2,64,256,16384 + add edi,128*2 + inc ebx + dec byte[lineleft] + jnz near .loopa + pop es + ret + +NEWSYM Clear2xSaIBuffer + mov ebx,[vidbufferofsb] + add ebx,288*2 + mov ecx,144*239 +.nextb + mov dword[ebx],0FFFFFFFFh + add ebx,4 + loop .nextb + ret + \ No newline at end of file diff --git a/zsnes/src/video/m716text.asm b/zsnes/src/video/m716text.asm new file mode 100644 index 00000000..743e4362 --- /dev/null +++ b/zsnes/src/video/m716text.asm @@ -0,0 +1,994 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM coladdr,curmosaicsz,curvidoffset,domosaic16b,mode7A,drawmode7dcolor +EXTSYM mode7B,mode7C,mode7D,mode7X0,mode7Y0,mode7set,mode7tab +EXTSYM pal16b,pal16bcl,pal16bxcl,scaddtype,scrnon,transpbuf +EXTSYM vesa2_clbit,vram,vrama,winon,xtravbuf,winptrref,scaddset +EXTSYM fulladdtab +EXTSYM cwinptr + + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + +%macro mode7halfadd 0 + mov [esi+288*2],dl + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + mov ecx,[ebp] + mov ebx,[pal16bcl+edx*4] + cmp cx,0 + je %%noadd + and ebx,[vesa2_clbit] + and ecx,[vesa2_clbit] + add ebx,ecx + shr ebx,1 +%%noadd + mov [esi],bx + xor ecx,ecx +%%nodraw +%endmacro + +%macro mode7fulladd 0 + mov [esi+288*2],dl + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + mov ecx,[ebp] + mov ebx,[pal16bcl+edx*4] + and ecx,[vesa2_clbit] + add ebx,ecx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + mov [esi],bx +%%nodraw +%endmacro + +%macro mode7fullsub 0 + mov [esi+288*2],dl + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + mov ecx,[ebp] + mov ebx,[pal16bxcl+edx*4] + and ecx,[vesa2_clbit] + add ebx,ecx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + xor ebx,0FFFFh + mov [esi],bx +%%nodraw +%endmacro + +%macro mode7mainsub 0 + mov [esi+288*2],dl + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + mov ecx,[pal16b+edx*4] + mov [esi],cx + mov [ebp],cx +%%nodraw +%endmacro + +%macro mode7halfaddwinon 0 + mov [esi+288*2],dl + mov eax,[cwinptr] + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + test byte[eax],0FFh + jnz %%nodraw + mov ecx,[ebp] + mov ebx,[pal16bcl+edx*4] + cmp cx,0 + je %%noadd + and ebx,[vesa2_clbit] + and ecx,[vesa2_clbit] + add ebx,ecx + shr ebx,1 +%%noadd + mov [esi],bx + xor ecx,ecx +%%nodraw + inc dword[cwinptr] +%endmacro + +%macro mode7fulladdwinon 0 + mov [esi+288*2],dl + mov eax,[cwinptr] + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + test byte[eax],0FFh + jnz %%nodraw + mov ecx,[ebp] + mov ebx,[pal16bcl+edx*4] + and ecx,[vesa2_clbit] + add ebx,ecx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + mov [esi],bx +%%nodraw + inc dword[cwinptr] +%endmacro + +%macro mode7fullsubwinon 0 + mov [esi+288*2],dl + mov eax,[cwinptr] + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + test byte[eax],0FFh + jnz %%nodraw + mov ecx,[ebp] + mov ebx,[pal16bxcl+edx*4] + and ecx,[vesa2_clbit] + add ebx,ecx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + xor ebx,0FFFFh + mov [esi],bx +%%nodraw + inc dword[cwinptr] +%endmacro + +%macro mode7mainsubwinon 0 + mov [esi+288*2],dl + mov eax,[cwinptr] + test dl,80h + jnz %%nodraw + or dl,dl + jz %%nodraw + test byte[eax],0FFh + jnz %%nodraw + mov ecx,[pal16b+edx*4] + mov [esi],cx + mov [ebp],cx +%%nodraw + inc dword[cwinptr] +%endmacro + +%macro mode716tmacro 1 + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx ebx,word[.cyloc] + movsx eax,word[mode7C] + imul eax,ebx + neg eax + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx +; neg ax + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx ebx,word[.cxloc] + movsx eax,word[mode7B] + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + mov ebp,transpbuf+32 + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + mov byte[.temp],0 + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + mov edi,[vram] + + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + test byte[mode7set],80h + jnz near .norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextval + test byte[.mode7xrpos+1],08h + jnz near .rposoffx +.nextposx + test byte[.mode7yrpos+1],08h + jnz near .rposoffy +.nextposy + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[edi+edx] + sub [.mode7yrpos],eax + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextval + jmp .finishmode7 +.rposoffx + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposx +.rposoffy + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + and byte[.mode7ptr+1],7Fh + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposy +.finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +.norep2 + test byte[mode7set],40h + jnz .tilerep2 +.nextvalb2 + cmp byte[.mode7ypos+2],3 + ja .offscr2 + cmp byte[.mode7xpos+2],3 + jbe near .offscr3 +.offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextvalb2 + jmp .finishmode7 +.tilerep2 +.nextvalb3 + cmp byte[.mode7ypos+2],3 + ja .offscr2b + cmp byte[.mode7xpos+2],3 + jbe near .offscr3 +.offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextvalb3 + jmp .finishmode7 +.offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextvalr + test byte[.mode7xrpos+1],08h + jnz near .rposoffxr +.nextposxr + test byte[.mode7yrpos+1],08h + jnz near .rposoffyr +.nextposyr + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[edi+edx] + sub [.mode7yrpos],eax + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextvalr + jmp .finishmode7 +.rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + jz .roff + cmp byte[.mode7ptr],0FEh + je .roff +.roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposxr +.rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js .roff +.roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposyr +.roff + test byte[mode7set],40h + jnz .tilerep3 + jmp .finishmode7 +.tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .tilerep3 + jmp .finishmode7 + +;********************************************************** +; Mode 7, old routines +;********************************************************** + +.nextval3 + test byte[mode7set],80h + jnz near .norep +.nextval2 + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextval2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + ; Color repetition +.norep + test byte[mode7set],40h + jnz near .tilerep +.nextvalb + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscr + cmp byte[.mode7xpos+2],3 + ja near .offscr +.offscrb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextvalb + jmp .goon +.offscrc + cmp byte[.mode7ypos+2],3 + ja .offscr + cmp byte[.mode7xpos+2],3 + jbe near .offscrb +.offscr + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,2 + add ebp,2 + dec byte[.temp] + jnz .offscrc +.goon + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +.tilerep +.nextvalbtr + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscrtr + cmp byte[.mode7xpos+2],3 + ja near .offscrtr +.offscrtrb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .nextvalbtr + jmp .goon +.offscrtrc + cmp byte[.mode7ypos+2],3 + ja .offscrtr + cmp byte[.mode7xpos+2],3 + jbe near .offscrtrb +.offscrtr + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + add esi,2 + add ebp,2 + dec byte[.temp] + jnz near .offscrtrc + jmp .goon + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dd 0 ; cx location +.cyloc dd 0 ; cy location +%endmacro + +;******************************************************* +; Processes & Draws Mode 7 half Addition +;******************************************************* +NEWSYM drawmode716textbg +; test byte[scaddset],1 +; jnz near drawmode7dcolor + mov esi,[cwinptr] + mov [winptrref],esi + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near drawmode716twinonextbg +.domosaic + test byte[scaddtype],80h + jnz near drawmode716tsubextbg + test byte[scaddtype],40h + jz near drawmode716tfulladdextbg + cmp byte[scrnon+1],0 + je near drawmode716tfulladdextbg + cmp dword[coladdr],0 + jnz near drawmode716tfulladdextbg + mode716tmacro mode7halfadd + + +;******************************************************* +; Processes & Draws Mode 7 Full Addition +;******************************************************* +NEWSYM drawmode716tfulladdextbg + mode716tmacro mode7fulladd + +;********************************************************** +; Processes and draws Mode 7 subtract +;********************************************************** + +drawmode716tsubextbg: + mode716tmacro mode7fullsub + +;********************************************************** +; Mode 7, main & sub mode +;********************************************************** + +NEWSYM drawmode716tbextbg + mode716tmacro mode7mainsub + +;******************************************************* +; Processes & Draws Mode 7 half Addition, Window on +;******************************************************* +NEWSYM drawmode716twinonextbg + test byte[scaddtype],80h + jnz near drawmode716tsubwinonextbg + test byte[scaddtype],40h + jz near drawmode716tfulladdwinonextbg + cmp byte[scrnon+1],0 + je near drawmode716tfulladdwinonextbg + cmp dword[coladdr],0 + jnz near drawmode716tfulladdwinonextbg + mode716tmacro mode7halfaddwinon + + +;******************************************************* +; Processes & Draws Mode 7 Full Addition, Window on +;******************************************************* + +NEWSYM drawmode716tfulladdwinonextbg + mode716tmacro mode7fulladdwinon + +;********************************************************** +; Processes and draws Mode 7 subtract, Window on +;********************************************************** + +NEWSYM drawmode716tsubwinonextbg + mode716tmacro mode7fullsubwinon + +;********************************************************** +; Mode 7, main & sub mode, Window on +;********************************************************** + +NEWSYM drawmode716tbwinonextbg + mode716tmacro mode7mainsubwinon + + +NEWSYM drawmode716textbg2 + mov esi,[cwinptr] + mov [winptrref],esi + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + mov edi,transpbuf+32 + test byte[scaddtype],80h + jnz near extbg2sub + test byte[scaddtype],40h + jz near extbg2add + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawwin +.domosaic + mov ecx,256 + xor eax,eax +.loop + mov al,[esi+288*2] + test al,80h + jz .nopr2 + and al,7Fh + mov edx,[edi] + mov ebx,[pal16bcl+eax*4] + cmp dx,0 + je .noadd + and ebx,[vesa2_clbit] + and edx,[vesa2_clbit] + add ebx,edx + shr ebx,1 +.noadd + mov [esi],bx +.nopr2 + add esi,2 + add edi,2 + loop .loop + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret +.drawwin + mov ebp,[cwinptr] + mov byte[esi],cl +.nodrawbw + mov ecx,256 + xor eax,eax +.loop2 + mov al,[esi+288*2] + test byte[ebp],0FFh + jnz .nopr2b + test al,80h + jz .nopr2b + and al,7Fh + mov edx,[edi] + mov ebx,[pal16bcl+eax*4] + cmp dx,0 + je .noadd2 + and ebx,[vesa2_clbit] + and edx,[vesa2_clbit] + add ebx,edx + shr ebx,1 +.noadd2 + mov [esi],bx +.nopr2b + add esi,2 + add edi,2 + inc ebp + loop .loop2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +extbg2add: + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawwin +.domosaic + mov ecx,256 + xor eax,eax +.loop + mov al,[esi+288*2] + test al,80h + jz .nopr2 + and al,7Fh + mov edx,[edi] + mov ebx,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add ebx,edx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + mov [esi],bx +.nopr2 + add esi,2 + add edi,2 + loop .loop + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret +.drawwin + mov ebp,[cwinptr] + mov byte[esi],cl +.nodrawbw + mov ecx,256 + xor eax,eax +.loop2 + mov al,[esi+288*2] + test byte[ebp],0FFh + jnz .nopr2b + test al,80h + jz .nopr2b + and al,7Fh + mov edx,[edi] + mov ebx,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add ebx,edx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + mov [esi],bx +.nopr2b + add esi,2 + add edi,2 + inc ebp + loop .loop2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +extbg2sub: + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawwin +.domosaic + mov ecx,256 + xor eax,eax +.loop + mov al,[esi+288*2] + test al,80h + jz .nopr2 + and al,7Fh + mov edx,[edi] + mov ebx,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add ebx,edx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + xor ebx,0FFFFh + mov [esi],bx +.nopr2 + add esi,2 + add edi,2 + loop .loop + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret +.drawwin + mov ebp,[cwinptr] + mov byte[esi],cl +.nodrawbw + mov ecx,256 + xor eax,eax +.loop2 + mov al,[esi+288*2] + test byte[ebp],0FFh + jnz .nopr2b + test al,80h + jz .nopr2b + and al,7Fh + mov edx,[edi] + mov ebx,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add ebx,edx + shr ebx,1 + mov ebx,[fulladdtab+ebx*2] + xor ebx,0FFFFh + mov [esi],bx +.nopr2b + add esi,2 + add edi,2 + inc ebp + loop .loop2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + \ No newline at end of file diff --git a/zsnes/src/video/makev16b.asm b/zsnes/src/video/makev16b.asm new file mode 100644 index 00000000..68b3e233 --- /dev/null +++ b/zsnes/src/video/makev16b.asm @@ -0,0 +1,3085 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM cursprloc,curypos,scrndis,scrnon,winon,winonsp,drawmode716extbg,drawmode716extbg2,SA1Enable +EXTSYM alreadydrawn,bg1cachloc,bg1tdabloc,bg1tdatloc,bg1vbufloc,bg1xposloc +EXTSYM bg1yaddval,bgcoloradder,bgmode,bgtilesz,curbgnum,drawn,makewindow +EXTSYM winbg1en,winenabs +EXTSYM mosaicon,winenabm +EXTSYM vidbuffer +EXTSYM bg3high2,colormodedef,colormodeofs,curbgpr,curblank +EXTSYM currentobjptr,curvidoffset,cwinenabm,drawline16t,forceblnk +EXTSYM makewindowsp,maxbr,newengen,newengine16b,preparesprpr +EXTSYM procbackgrnd,scaddset,scaddtype,spritetablea,sprleftpr,ForceNewGfxOff +EXTSYM bg1scrolx,bg1scroly,drawmode716b,mode7set,mosaicsz,sprleftpr1 +EXTSYM sprleftpr2,sprleftpr3,sprlefttot,sprprifix,interlval +EXTSYM extbgdone +EXTSYM FPUZero,coladdb,coladdg,coladdr,pal16b,vesa2_bpos +EXTSYM V8Mode,doveg,pal16bcl,pal16bxcl,prevbright,prevpal,vesa2_clbit +EXTSYM vesa2_gpos,vesa2_rpos,vesa2_usbit,vidbright +EXTSYM cgmod,cgram,gammalevel16b +EXTSYM winspdata +EXTSYM csprbit,csprprlft,sprclprio,sprsingle,sprpriodata +EXTSYM bgofwptr,bgsubby,bshifter,curmosaicsz,cwinptr,osm2dis,temp +EXTSYM tempcach,temptile,winptrref,vcache2b,vcache4b,vcache8b +EXTSYM xtravbuf,yadder,yrevadder +EXTSYM vcache2ba,vcache4ba,vcache8ba +EXTSYM hirestiledat,res512switch +EXTSYM numwin,windowdata +EXTSYM bg1objptr,bg1ptr,bg1ptrc,bg3ptr,bg3scrolx,bg3scroly,cachesingle +EXTSYM colormoded2,offsetenab,offsetmclr,offsetmcol,offsetmodeptr +EXTSYM offsetmptr,offsetmshl,offsetmtst,offsetptra,offsetptrb,posyscroll +EXTSYM prevoffsetdat,prevtempcache,tempoffset,vidmemch2,vidmemch4 +EXTSYM vidmemch8,vram +EXTSYM ofsmcptr,ofsmady,ofsmadx,yposng,yposngom,flipyposng,flipyposngom +EXTSYM ofsmtptr,ofsmmptr,ofsmcyps,bgtxadd,bg1ptrx,bg1ptry +EXTSYM a16x16xinc,a16x16yinc + +%include "video/vidmacro.mac" + + + + + +;drawspritesprio + +NEWSYM tempstuff, dd 0 + +ALIGN16 +.stuff dd 0 +.stuff2 db 0,0 + +%macro procmode716bextbg 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz %%noflip + mov ax,261 + sub ax,[curypos] + dec ax +%%noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz %%nomos + mov bl,[mosaicsz] + cmp bl,0 + je %%nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +%%nomos + add ax,%1 + mov dx,%2 + call drawmode716extbg +%endmacro + +%macro procmode716bextbg2 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz %%nomos + mov bl,[mosaicsz] + cmp bl,0 + je %%nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +%%nomos + call drawmode716extbg2 +%endmacro + +NEWSYM procspritessub16b + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon+1],10h + jz .nosprites + test byte[scrnon],10h + jnz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + cmp cl,0 + je .nosprites + call drawsprites16b +.nosprites + ret + +NEWSYM procspritesmain16b + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon],10h + jz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + cmp cl,0 + je .nosprites + call drawsprites16b +.nosprites + ret + +NEWSYM drawbackgrndsub16b + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon+1],al + jz near .noback + test byte[scrnon],al + jnz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabs],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + mov bl,20h + mul bl + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x816b + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn + jmp .noback +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616b + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb +.noback + ret + +NEWSYM drawbackgrndmain16b + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon],al + jz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabm],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + mov bl,20h + mul bl + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x816b + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn + jmp .noback +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616b + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb +.noback + ret +NEWSYM blanker16b + ; calculate current video offset + push ebx + push esi + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,9 + shl ebx,6 + add esi,ebx + add esi,32 + add esi,[vidbuffer] + mov bl,128 +.next + mov dword[esi],0 + add esi,4 + dec bl + jnz .next + pop esi + pop ebx + ret + +NEWSYM drawline16b + cmp byte[ForceNewGfxOff],0 + jne .nonewgfx + cmp byte[newengen],1 + je near newengine16b +.nonewgfx + cmp byte[curblank],0 + jne near nodrawline16b + mov al,[vidbright] + cmp al,[maxbr] + jbe .nochange + mov [maxbr],al +.nochange + cmp byte[forceblnk],0 + jne blanker16b + mov byte[alreadydrawn],0 + push ebx + xor ebx,ebx + mov bl,[bgmode] + shl bl,2 + add ebx,colormodedef + mov [colormodeofs],ebx + pop ebx + + cmp byte[SA1Enable],0 + je .noscrnona + cmp word[scrnon],1317h + jne .noscrnona + cmp byte[scaddtype],0 + jne .noscrnona + mov word[scrnon],1317h + mov byte[scaddtype],44h + mov byte[scaddset],02h +.noscrnona + cmp word[scrnon],0117h + jne .notransph + cmp word[scaddset],8202h + jne .notransph + mov word[scrnon],0116h +.notransph + + test byte[scaddset],02h + jnz near drawline16t + cmp dword[coladdr],0 + je .nocoladd + test byte[scaddtype],3Fh + jnz near drawline16t +.nocoladd + cmp byte[bgmode],7 + je near processmode716b + push esi + push edi + push ebx + push edx + push ebp + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,9 + shl ebx,6 + add esi,ebx + add esi,32 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; do sprite windowing + call makewindowsp + ; set palette + call setpalette16b + ; clear back area w/ back color + call clearback16b + ; clear registers + xor eax,eax + xor ecx,ecx + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + mov dword[cursprloc],sprleftpr + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio +; process backgrounds +; do background 2 + mov byte[curbgnum],02h + mov ebp,01h + call procbackgrnd +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call procbackgrnd +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call procbackgrnd +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call procbackgrnd + + cmp byte[bgmode],1 + ja near priority216b + mov al,[winenabm] + mov [cwinenabm],al + mov byte[curbgpr],0h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndmain16b +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain16b + mov ebp,0 + call procspritesmain16b + mov byte[curbgpr],20h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndmain16b +; do background 3 + cmp byte[bg3high2],1 + je .bg3nothighb + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain16b +.bg3nothighb + mov ebp,1 + call procspritesmain16b +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16b +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16b + mov ebp,2 + call procspritesmain16b +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16b +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16b + mov ebp,3 + call procspritesmain16b + cmp byte[bg3high2],1 + jne .bg3highb +; do background 3 + mov byte[curbgpr],20h + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain16b +.bg3highb + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx +NEWSYM nodrawline16b + ret + +NEWSYM priority216b + mov al,[winenabm] + mov [cwinenabm],al +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16b + mov ebp,0 + call procspritesmain16b +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16b + mov ebp,1 + call procspritesmain16b +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16b + mov ebp,2 + call procspritesmain16b +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16b + mov ebp,3 + call procspritesmain16b + cmp byte[bg3high2],1 + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx + ret + + +NEWSYM processmode716b + mov al,[winenabm] + mov [cwinenabm],al + push esi + push edi + push ebx + push edx + push ebp + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,9 + shl ebx,6 + add esi,ebx + add esi,32 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; do sprite windowing + call makewindowsp + ; set palette + call setpalette16b + ; clear back area w/ back color + call clearback16b + ; clear registers + xor eax,eax + xor ecx,ecx + + mov byte[extbgdone],0 + ; mode 7 extbg + test byte[interlval],40h + jz near .noback0 + test byte[scrndis],02h + jnz near .noback0 + ; do background 1 + test word[scrnon],0202h + jz near .noback0 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin0 + test word[winenabm],0100h + jnz near .nobackwin0 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback0 +.nobackwin0 + mov byte[extbgdone],1 + procmode716bextbg [bg1scroly],[bg1scrolx],1 +.noback0 + + ; do objects + test byte[scrndis],10h + jnz near .nosprites1 + test word[scrnon],1010h + jz near .nosprites1 + cmp byte[winonsp],0FFh + je .nosprites1 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr+ebx] + cmp byte[sprprifix],0 + je .nosprprio2 + mov cl,[sprlefttot+ebx] +.nosprprio2 + cmp cl,0 + je .nosprites1 + mov ebp,0 + call drawsprites16b +.nosprites1 + + ; display mode7 + test byte[interlval],40h + jnz near .noback1 + test byte[scrndis],01h + jnz near .noback1 + ; do background 1 + test word[scrnon],0101h + jz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + procmode716b [bg1scroly],[bg1scrolx],1 +.noback1 + + ; do objects + test byte[scrndis],10h + jnz near .nosprites2 + test word[scrnon],1010h + jz near .nosprites2 + cmp byte[winonsp],0FFh + je .nosprites2 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr1+ebx] + cmp byte[sprprifix],0 + je .nosprprio3 + mov cl,[sprlefttot+ebx] +.nosprprio3 + cmp cl,0 + je .nosprites2 + mov ebp,1 + call drawsprites16b +.nosprites2 + + test byte[interlval],40h + jz near .noback0b + test byte[scrndis],01h + jnz near .noback0b + cmp byte[extbgdone],0 + jne near .noback0b + ; do background 1 + test word[scrnon],0101h + jz near .noback0b + mov byte[winon],0 + test word[winenabm],0002h + jz near .nobackwin0b + test word[winenabm],0200h + jnz near .nobackwin0b + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback0b +.nobackwin0b + mov byte[extbgdone],1 + procmode716bextbg [bg1scroly],[bg1scrolx],1 +.noback0b + + ; mode 7 extbg + test byte[interlval],40h + jz near .noback2 + cmp byte[extbgdone],0 + je near .noback2 + test byte[scrndis],01h + jnz near .noback2 + ; do background 1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin2 + test word[winenabm],0100h + jnz near .nobackwin2 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback2 +.nobackwin2 + procmode716bextbg2 [bg1scroly],[bg1scrolx],1 +.noback2 + + ; do objects + test byte[scrndis],10h + jnz near .nosprites3 + test word[scrnon],1010h + jz near .nosprites3 + cmp byte[winonsp],0FFh + je .nosprites3 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr2+ebx] + cmp byte[sprprifix],0 + je .nosprprio4 + mov cl,[sprlefttot+ebx] +.nosprprio4 + cmp cl,0 + je .nosprites3 + mov ebp,2 + call drawsprites16b +.nosprites3 + ; do objects + test byte[scrndis],10h + jnz near .nosprites4 + test word[scrnon],1010h + jz near .nosprites4 + cmp byte[winonsp],0FFh + je .nosprites4 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr3+ebx] + cmp byte[sprprifix],0 + je .nosprprio5 + mov cl,[sprlefttot+ebx] +.nosprprio5 + cmp cl,0 + je .nosprites4 + mov ebp,3 + call drawsprites16b +.nosprites4 + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx + ret + +;******************************************************* +; Clear Backarea, 16-bit mode +;******************************************************* +NEWSYM clearback16b + test byte[scaddtype],00100000b + jz near .noaddition + test byte[scaddtype],10000000b + jnz near .noaddition + mov dx,[cgram] + mov ax,dx + and ax,001Fh + add al,[coladdr] + cmp al,01Fh + jb .noadd + mov al,01Fh +.noadd + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + shl ax,cl + mov bx,ax + mov ax,dx + shr ax,5 + and ax,001Fh + add al,[coladdg] + cmp al,01Fh + jb .noaddb + mov al,01Fh +.noaddb + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and ax,001Fh + add al,[coladdb] + cmp al,01Fh + jb .noaddc + mov al,01Fh +.noaddc + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + mov ax,bx + shl eax,16 + mov ax,bx + mov edi,[curvidoffset] +; cmp byte[FPUCopy],1 +; je .dofpuclear + mov ecx,128 + rep stosd + xor eax,eax + ret +.noaddition + mov edi,[curvidoffset] + mov ax,[pal16b] + shl eax,16 + mov ax,[pal16b] +; cmp byte[FPUCopy],1 +; je .dofpuclear + mov ecx,128 + rep stosd + xor eax,eax + ret +.dofpuclear + mov ecx,32 + call FPUZero + xor eax,eax + ret + +;******************************************************* +; Set palette 16bit +;******************************************************* +NEWSYM setpalall + cmp byte[V8Mode],1 + jne .noveg + call doveg +.noveg + xor esi,esi + mov byte[colleft16b],0 +.loopa + mov dx,[cgram+esi] + mov [prevpal+esi],dx + mov ax,dx + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + xor bx,bx + shl ax,cl + add bx,ax + mov ax,dx + shr ax,5 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + cmp bx,0 + jne .col0 + cmp byte[vidbright],0 + je .col0 + or bx,0000000000100000b +.col0 + mov ax,bx + mov [pal16b+esi*2],bx + and bx,[vesa2_clbit] + mov [pal16bcl+esi*2],bx + xor ax,0FFFFh + and ax,[vesa2_clbit] + mov [pal16bxcl+esi*2],ax + add esi,2 + inc byte[colleft16b] + jnz near .loopa + mov al,[vidbright] + mov [prevbright],al + ret + +NEWSYM colleft16b, db 0 + +NEWSYM setpalette16b + cmp byte[gammalevel16b],0 + jne near setpalette16bgamma + cmp byte[V8Mode],1 + jne .noveg + call doveg +.noveg + mov al,[vidbright] + cmp al,[prevbright] + jne near setpalall + cmp byte[cgmod],0 + je near .skipall + mov byte[cgmod],0 + xor esi,esi + mov byte[colleft16b],0 +.loopa + mov dx,[cgram+esi] + cmp [prevpal+esi],dx + je near .skipa + mov [prevpal+esi],dx + mov ax,dx + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + xor bx,bx + shl ax,cl + add bx,ax + mov ax,dx + shr ax,5 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + cmp bx,0 + jne .col0 + cmp byte[vidbright],0 + je .col0 + or bx,0000000000100000b +.col0 + mov [pal16b+esi*2],bx + mov ax,bx + and bx,[vesa2_clbit] + mov [pal16bcl+esi*2],bx + xor ax,0FFFFh + and ax,[vesa2_clbit] + mov [pal16bxcl+esi*2],ax +.skipa + add esi,2 + inc byte[colleft16b] + jnz near .loopa +.skipall + ret + +;pal16b times 256 dw 0 +;pal16bcl times 256 dw 0 ; w/ cl bit +;pal16bclha times 256 dw 0 ; w/ cl bit +;pal16bxcl times 256 dw 0FFFFh ; xored w/ cl bit + +NEWSYM setpalallgamma + xor esi,esi + mov byte[colleft16b],0 +.loopa + mov dx,[cgram+esi] + mov [prevpal+esi],dx + mov ax,dx + and al,01Fh + add al,[gammalevel16b] + cmp al,31 + jbe .norr + mov al,31 +.norr + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + xor bx,bx + shl ax,cl + add bx,ax + mov ax,dx + shr ax,5 + and al,01Fh + add al,[gammalevel16b] + cmp al,31 + jbe .nogr + mov al,31 +.nogr + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and al,01Fh + add al,[gammalevel16b] + cmp al,31 + jbe .nobr + mov al,31 +.nobr + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + cmp bx,0 + jne .col0 + cmp byte[vidbright],0 + je .col0 + or bx,0000000000100000b +.col0 + mov ax,bx + mov [pal16b+esi*2],bx + and bx,[vesa2_clbit] + mov [pal16bcl+esi*2],bx + xor ax,0FFFFh + and ax,[vesa2_clbit] + mov [pal16bxcl+esi*2],ax + add esi,2 + inc byte[colleft16b] + jnz near .loopa + mov al,[vidbright] + mov [prevbright],al + ret + +NEWSYM setpalette16bgamma + mov al,[vidbright] + cmp al,[prevbright] + jne near setpalallgamma + cmp byte[cgmod],0 + je near .skipall + mov byte[cgmod],0 + xor esi,esi + mov byte[colleft16b],0 +.loopa + mov dx,[cgram+esi] + cmp [prevpal+esi],dx + je near .skipa + mov [prevpal+esi],dx + mov ax,dx + and al,01Fh + add al,[gammalevel16b] + cmp al,31 + jbe .norb + mov al,31 +.norb + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + xor bx,bx + shl ax,cl + add bx,ax + mov ax,dx + shr ax,5 + and al,01Fh + add al,[gammalevel16b] + cmp al,31 + jbe .norr + mov al,31 +.norr + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and al,01Fh + add al,[gammalevel16b] + cmp al,31 + jbe .norg + mov al,31 +.norg + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + cmp bx,0 + jne .col0 + cmp byte[vidbright],0 + je .col0 + or bx,0000000000100000b +.col0 + mov [pal16b+esi*2],bx + mov ax,bx + and bx,[vesa2_clbit] + mov [pal16bcl+esi*2],bx + xor ax,0FFFFh + and ax,[vesa2_clbit] + mov [pal16bxcl+esi*2],ax +.skipa + add esi,2 + inc byte[colleft16b] + jnz near .loopa +.skipall + ret + +;******************************************************* +; Processes & Draws 4-bit sprites +;******************************************************* + +NEWSYM drawsprites16b + cmp byte[sprprifix],1 + je near drawsprites16bprio + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near drawsprites16bwinon +.drawnowin + mov esi,[currentobjptr] + mov edi,[curvidoffset] + xor ebx,ebx + xor eax,eax +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + shl bx,1 + mov al,[esi] + test al,0Fh + jz .skipa + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-16],dx +.skipa + mov al,[esi+1] + test al,0Fh + jz .skipb + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-14],dx +.skipb + mov al,[esi+2] + test al,0Fh + jz .skipc + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-12],dx +.skipc + mov al,[esi+3] + test al,0Fh + jz .skipd + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-10],dx +.skipd + mov al,[esi+4] + test al,0Fh + jz .skipe + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-8],dx +.skipe + mov al,[esi+5] + test al,0Fh + jz .skipf + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-6],dx +.skipf + mov al,[esi+6] + test al,0Fh + jz .skipg + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-4],dx +.skipg + mov al,[esi+7] + test al,0Fh + jz .skiph + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-2],dx +.skiph + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + shl bx,1 + mov al,[esi+7] + test al,0Fh + jz .skipa2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-16],dx +.skipa2 + mov al,[esi+6] + test al,0Fh + jz .skipb2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-14],dx +.skipb2 + mov al,[esi+5] + test al,0Fh + jz .skipc2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-12],dx +.skipc2 + mov al,[esi+4] + test al,0Fh + jz .skipd2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-10],dx +.skipd2 + mov al,[esi+3] + test al,0Fh + jz .skipe2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-8],dx +.skipe2 + mov al,[esi+2] + test al,0Fh + jz .skipf2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-6],dx +.skipf2 + mov al,[esi+1] + test al,0Fh + jz .skipg2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-4],dx +.skipg2 + mov al,[esi] + test al,0Fh + jz .skiph2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-2],dx +.skiph2 + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawsprites16bwinon + mov esi,[currentobjptr] + mov edi,[curvidoffset] + xor ebx,ebx + xor eax,eax +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + mov al,[esi] + test al,0Fh + jz .skipa + cmp byte[winspdata+ebx-8+16],0 + jne .skipa + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-16],dx +.skipa + mov al,[esi+1] + test al,0Fh + jz .skipb + cmp byte[winspdata+ebx-7+16],0 + jne .skipb + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-14],dx +.skipb + mov al,[esi+2] + test al,0Fh + jz .skipc + cmp byte[winspdata+ebx-6+16],0 + jne .skipc + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-12],dx +.skipc + mov al,[esi+3] + test al,0Fh + jz .skipd + cmp byte[winspdata+ebx-5+16],0 + jne .skipd + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-10],dx +.skipd + mov al,[esi+4] + test al,0Fh + jz .skipe + cmp byte[winspdata+ebx-4+16],0 + jne .skipe + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-8],dx +.skipe + mov al,[esi+5] + test al,0Fh + jz .skipf + cmp byte[winspdata+ebx-3+16],0 + jne .skipf + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-6],dx +.skipf + mov al,[esi+6] + test al,0Fh + jz .skipg + cmp byte[winspdata+ebx-2+16],0 + jne .skipg + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-4],dx +.skipg + mov al,[esi+7] + test al,0Fh + jz .skiph + cmp byte[winspdata+ebx-1+16],0 + jne .skiph + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-2],dx +.skiph + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + mov al,[esi+7] + test al,0Fh + jz .skipa2 + cmp byte[winspdata+ebx-8+16],0 + jne .skipa2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-16],dx +.skipa2 + mov al,[esi+6] + test al,0Fh + jz .skipb2 + cmp byte[winspdata+ebx-7+16],0 + jne .skipb2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-14],dx +.skipb2 + mov al,[esi+5] + test al,0Fh + jz .skipc2 + cmp byte[winspdata+ebx-6+16],0 + jne .skipc2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-12],dx +.skipc2 + mov al,[esi+4] + test al,0Fh + jz .skipd2 + cmp byte[winspdata+ebx-5+16],0 + jne .skipd2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-10],dx +.skipd2 + mov al,[esi+3] + test al,0Fh + jz .skipe2 + cmp byte[winspdata+ebx-4+16],0 + jne .skipe2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-8],dx +.skipe2 + mov al,[esi+2] + test al,0Fh + jz .skipf2 + cmp byte[winspdata+ebx-3+16],0 + jne .skipf2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-6],dx +.skipf2 + mov al,[esi+1] + test al,0Fh + jz .skipg2 + cmp byte[winspdata+ebx-2+16],0 + jne .skipg2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-4],dx +.skipg2 + mov al,[esi] + test al,0Fh + jz .skiph2 + cmp byte[winspdata+ebx-1+16],0 + jne .skiph2 + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-2],dx +.skiph2 + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawsprites16bprio + cmp byte[sprclprio+ebp],0 + je near .endobj + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near drawspritesprio16bwinon +.drawnowin + cmp dword[sprsingle],1 + je near .drawsingle + mov [csprprlft],cl + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notprio + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b sprdrawpra16b + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notpriof + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b sprdrawpra16b + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + xor eax,eax + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa16b sprdrawprb16b + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf16b sprdrawprb16b + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret + +NEWSYM drawspritesprio16bwinon + cmp dword[sprsingle],1 + je near .drawsingle + mov [csprprlft],cl + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notprio + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b sprdrawpraw16b + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notpriof + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b sprdrawpraw16b + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + xor eax,eax + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa16b sprdrawprbw16b + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf16b sprdrawprbw16b + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret + + +NEWSYM draw8x816b + cmp byte[osm2dis],1 + je .osm2dis + cmp byte[bgmode],2 + je near draw8x816boffset +.osm2dis + cmp byte[bgmode],5 + je near draw16x816 + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x816bwinon +.domosaic + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + cmp dword[ebx],0 + je .loopd4 + Draw8x816bmacro 0 + Draw8x816bmacro 1 + Draw8x816bmacro 2 + Draw8x816bmacro 3 +.loopd4 + cmp dword[ebx+4],0 + je .loopd8 + Draw8x816bmacro 4 + Draw8x816bmacro 5 + Draw8x816bmacro 6 + Draw8x816bmacro 7 +.loopd8 +.hprior + add esi,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + cmp dword[ebx+4],0 + je .loopd4b + Draw8x816bflipmacro 0 + Draw8x816bflipmacro 1 + Draw8x816bflipmacro 2 + Draw8x816bflipmacro 3 +.loopd4b + cmp dword[ebx],0 + je .loopd8b + Draw8x816bflipmacro 4 + Draw8x816bflipmacro 5 + Draw8x816bflipmacro 6 + Draw8x816bflipmacro 7 +.loopd8b + add esi,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM tileleft16b, db 0 + +NEWSYM draw8x816bwinon + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] + mov ebp,[winptrref] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + cmp dword[ebx],0 + je .loopd4 + Draw8x816bwinmacro 0 + Draw8x816bwinmacro 1 + Draw8x816bwinmacro 2 + Draw8x816bwinmacro 3 +.loopd4 + cmp dword[ebx+4],0 + je .loopd8 + Draw8x816bwinmacro 4 + Draw8x816bwinmacro 5 + Draw8x816bwinmacro 6 + Draw8x816bwinmacro 7 +.loopd8 +.hprior + add esi,16 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + cmp dword[ebx+4],0 + je .loopd4b + Draw8x816bwinflipmacro 0 + Draw8x816bwinflipmacro 1 + Draw8x816bwinflipmacro 2 + Draw8x816bwinflipmacro 3 +.loopd4b + cmp dword[ebx],0 + je .loopd8b + Draw8x816bwinflipmacro 4 + Draw8x816bwinflipmacro 5 + Draw8x816bwinflipmacro 6 + Draw8x816bwinflipmacro 7 +.loopd8b + add esi,16 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw16x816 + push eax + xor eax,eax + mov al,[curypos] + mov byte[hirestiledat+eax],1 + pop eax + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x816bwinon +.domosaic + cmp byte[res512switch],0 + jne near draw16x816b + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8 0, .loopd1, 0 + drawpixel16b8x8 2, .loopd3, 2 + drawpixel16b8x8 4, .loopd5, 4 + drawpixel16b8x8 6, .loopd7, 6 + add ebx,64 + ; Start loop + drawpixel16b8x8 0, .loopd1c, 8 + drawpixel16b8x8 2, .loopd3c, 10 + drawpixel16b8x8 4, .loopd5c, 12 + drawpixel16b8x8 6, .loopd7c, 14 +.hprior + add esi,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + ; reversed loop +.rloop + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8 1, .loopd1b, 14 + drawpixel16b8x8 3, .loopd3b, 12 + drawpixel16b8x8 5, .loopd5b, 10 + drawpixel16b8x8 7, .loopd7b, 8 + add ebx,64 + ; Start loop + drawpixel16b8x8 1, .loopd1d, 6 + drawpixel16b8x8 3, .loopd3d, 4 + drawpixel16b8x8 5, .loopd5d, 2 + drawpixel16b8x8 7, .loopd7d, 0 + add esi,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw16x816b + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8 1, .loopd1, 0 + drawpixel16b8x8 3, .loopd3, 2 + drawpixel16b8x8 5, .loopd5, 4 + drawpixel16b8x8 7, .loopd7, 6 + add ebx,64 + ; Start loop + drawpixel16b8x8 1, .loopd1c, 8 + drawpixel16b8x8 3, .loopd3c, 10 + drawpixel16b8x8 5, .loopd5c, 12 + drawpixel16b8x8 7, .loopd7c, 14 +.hprior + add esi,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + ; reversed loop +.rloop + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8 0, .loopd1b, 14 + drawpixel16b8x8 2, .loopd3b, 12 + drawpixel16b8x8 4, .loopd5b, 10 + drawpixel16b8x8 6, .loopd7b, 8 + add ebx,64 + ; Start loop + drawpixel16b8x8 0, .loopd1d, 6 + drawpixel16b8x8 2, .loopd3d, 4 + drawpixel16b8x8 4, .loopd5d, 2 + drawpixel16b8x8 6, .loopd7d, 0 + add esi,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw16x816bwinon + cmp byte[res512switch],0 + jne near draw16x816winonb + mov ebp,[winptrref] + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8winon 0, .loopd1, 0, 0 + drawpixel16b8x8winon 2, .loopd3, 2, 1 + drawpixel16b8x8winon 4, .loopd5, 4, 2 + drawpixel16b8x8winon 6, .loopd7, 6, 3 + add ebx,64 + ; Start loop + drawpixel16b8x8winon 0, .loopd1c, 8, 4 + drawpixel16b8x8winon 2, .loopd3c, 10, 5 + drawpixel16b8x8winon 4, .loopd5c, 12, 6 + drawpixel16b8x8winon 6, .loopd7c, 14, 7 +.hprior + add esi,16 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + ; reversed loop +.rloop + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8winon 1, .loopd1b, 14, 0 + drawpixel16b8x8winon 3, .loopd3b, 12, 1 + drawpixel16b8x8winon 5, .loopd5b, 10, 2 + drawpixel16b8x8winon 7, .loopd7b, 8, 3 + add ebx,64 + ; Start loop + drawpixel16b8x8winon 1, .loopd1d, 6, 4 + drawpixel16b8x8winon 3, .loopd3d, 4, 5 + drawpixel16b8x8winon 5, .loopd5d, 2, 6 + drawpixel16b8x8winon 7, .loopd7d, 0, 7 + add esi,16 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw16x816winonb + mov ebp,[winptrref] + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8winon 1, .loopd1, 0, 0 + drawpixel16b8x8winon 3, .loopd3, 2, 1 + drawpixel16b8x8winon 5, .loopd5, 4, 2 + drawpixel16b8x8winon 7, .loopd7, 6, 3 + add ebx,64 + ; Start loop + drawpixel16b8x8winon 1, .loopd1c, 8, 4 + drawpixel16b8x8winon 3, .loopd3c, 10, 5 + drawpixel16b8x8winon 5, .loopd5c, 12, 6 + drawpixel16b8x8winon 7, .loopd7c, 14, 7 +.hprior + add esi,16 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + ; reversed loop +.rloop + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawpixel16b8x8winon 0, .loopd1b, 14, 0 + drawpixel16b8x8winon 2, .loopd3b, 12, 1 + drawpixel16b8x8winon 4, .loopd5b, 10, 2 + drawpixel16b8x8winon 6, .loopd7b, 8, 3 + add ebx,64 + ; Start loop + drawpixel16b8x8winon 0, .loopd1d, 6, 4 + drawpixel16b8x8winon 2, .loopd3d, 4, 5 + drawpixel16b8x8winon 4, .loopd5d, 2, 6 + drawpixel16b8x8winon 6, .loopd7d, 0, 7 + add esi,16 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM domosaic16b + mov esi,xtravbuf+32 + mov edi,[curvidoffset] + mov dl,dh + mov cl,0 + mov ax,[esi] + cmp byte[winon],0 + jne near domosaicwin16b + test ax,0FFFFh + jz .zeroloop +.loopm + mov [edi],ax + add esi,2 + add edi,2 + dec cl + jz .doneloop + dec dl + jnz .loopm + mov ax,[esi] + mov dl,dh + test ax,0FFFFh + jnz .loopm +.zeroloop + add esi,2 + add edi,2 + dec cl + jz .doneloop + dec dl + jnz .zeroloop + mov ax,[esi] + mov dl,dh + test ax,0FFFFh + jnz .loopm + jmp .zeroloop +.doneloop + ret + +NEWSYM domosaicwin16b + mov ebp,[winptrref] + test ax,0FFFFh + jz .zeroloop +.loopm + cmp byte[ebp],0 + jne .nozero + mov [edi],ax +.nozero + add esi,2 + add edi,2 + inc ebp + dec cl + jz .doneloop + dec dl + jnz .loopm + mov ax,[esi] + mov dl,dh + test ax,0FFFFh + jnz .loopm +.zeroloop + add esi,2 + add edi,2 + inc ebp + dec cl + jz .doneloop + dec dl + jnz .zeroloop + mov ax,[esi] + mov dl,dh + test ax,0FFFFh + jnz .loopm + jmp .zeroloop +.doneloop + ret + +NEWSYM dowindow16b + mov ebx,windowdata + mov esi,xtravbuf+32 + mov edi,[curvidoffset] + xor edx,edx + xor ch,ch +.getnext + mov cl,[ebx] + cmp dl,cl + je .procnext +.dorest + sub cl,dl + cmp ch,0 + ja .nodraw +.loopa + mov ax,[esi+edx*2] + test ax,0FFFFh + jz .nocopy + mov [edi+edx*2],ax +.nocopy + inc dl + dec cl + jnz .loopa +.procnext + add ch,[ebx+1] + add ebx,2 + test byte[numwin],0FFh + jz .finishwin + dec byte[numwin] + jnz .getnext + xor cl,cl + jmp .dorest +.nodraw + add dl,cl + jmp .procnext +.finishwin + xor eax,eax + ret + +;******************************************************* +; Processes & Draws 8x8 tiles, offset mode +;******************************************************* + +NEWSYM draw8x816boffset + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + initoffsetmode + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x816bwinonoffset +.domosaic + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + cmp dword[ebx],0 + je .loopd4 + Draw8x816bmacro 0 + Draw8x816bmacro 1 + Draw8x816bmacro 2 + Draw8x816bmacro 3 +.loopd4 + cmp dword[ebx+4],0 + je .loopd8 + Draw8x816bmacro 4 + Draw8x816bmacro 5 + Draw8x816bmacro 6 + Draw8x816bmacro 7 +.loopd8 +.hprior + procoffsetmode + add esi,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + cmp dword[ebx+4],0 + je .loopd4b + Draw8x816bflipmacro 0 + Draw8x816bflipmacro 1 + Draw8x816bflipmacro 2 + Draw8x816bflipmacro 3 +.loopd4b + cmp dword[ebx],0 + je .loopd8b + Draw8x816bflipmacro 4 + Draw8x816bflipmacro 5 + Draw8x816bflipmacro 6 + Draw8x816bflipmacro 7 +.loopd8b + procoffsetmode + add esi,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x816bwinonoffset + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] + mov ebp,[winptrref] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + cmp dword[ebx],0 + je .loopd4 + Draw8x816bwinmacro 0 + Draw8x816bwinmacro 1 + Draw8x816bwinmacro 2 + Draw8x816bwinmacro 3 +.loopd4 + cmp dword[ebx+4],0 + je .loopd8 + Draw8x816bwinmacro 4 + Draw8x816bwinmacro 5 + Draw8x816bwinmacro 6 + Draw8x816bwinmacro 7 +.loopd8 +.hprior + procoffsetmode + add esi,16 + add ebp,8 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + cmp dword[ebx+4],0 + je .loopd4b + Draw8x816bwinflipmacro 0 + Draw8x816bwinflipmacro 1 + Draw8x816bwinflipmacro 2 + Draw8x816bwinflipmacro 3 +.loopd4b + cmp dword[ebx],0 + je .loopd8b + Draw8x816bwinflipmacro 4 + Draw8x816bwinflipmacro 5 + Draw8x816bwinflipmacro 6 + Draw8x816bwinflipmacro 7 +.loopd8b + procoffsetmode + add esi,16 + add ebp,8 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + +NEWSYM draw16x1616b + mov byte[drawn],0 + mov [temp],eax + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + xor ebx,ebx + mov bl,[curypos] + mov [temptile],edx + ; set up y adders + test byte[a16x16yinc],01h + jz .noincrc + mov word[.yadd],16 + mov word[.yflipadd],0 + jmp .yesincrc +.noincrc + mov word[.yadd],0 + mov word[.yflipadd],16 +.yesincrc + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x1616bwinon +.domosaic + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[.yadd] + jmp .yesyflip +.noyflip + add ax,word[.yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + + ; Start loop + Draw16x1616b 0, 0 + Draw16x1616b 1, 2 + Draw16x1616b 2, 4 + Draw16x1616b 3, 6 + Draw16x1616b 4, 8 + Draw16x1616b 5, 10 + Draw16x1616b 6, 12 + Draw16x1616b 7, 14 +.hprior + add esi,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + Draw16x1616b 7, 0 + Draw16x1616b 6, 2 + Draw16x1616b 5, 4 + Draw16x1616b 4, 6 + Draw16x1616b 3, 8 + Draw16x1616b 2, 10 + Draw16x1616b 1, 12 + Draw16x1616b 0, 14 +.skiploop2b + add esi,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +.yadd dw 0 +.yflipadd dw 0 + +draw16x1616bwinon: + mov byte[tileleft16b],33 + mov dl,[temp] + mov ebp,[winptrref] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[draw16x1616b.yadd] + jmp .yesyflip +.noyflip + add ax,word[draw16x1616b.yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + + ; Start loop + Draw16x1616bwin 0, 0, 0 + Draw16x1616bwin 1, 2, 1 + Draw16x1616bwin 2, 4, 2 + Draw16x1616bwin 3, 6, 3 + Draw16x1616bwin 4, 8, 4 + Draw16x1616bwin 5, 10, 5 + Draw16x1616bwin 6, 12, 6 + Draw16x1616bwin 7, 14, 7 +.hprior + add esi,16 + add ebp,8 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + Draw16x1616bwin 7, 0, 0 + Draw16x1616bwin 6, 2, 1 + Draw16x1616bwin 5, 4, 2 + Draw16x1616bwin 4, 6, 3 + Draw16x1616bwin 3, 8, 4 + Draw16x1616bwin 2, 10, 5 + Draw16x1616bwin 1, 12, 6 + Draw16x1616bwin 0, 14, 7 +.skiploop2b + add esi,16 + add ebp,8 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + \ No newline at end of file diff --git a/zsnes/src/video/makev16t.asm b/zsnes/src/video/makev16t.asm new file mode 100644 index 00000000..d1184e1f --- /dev/null +++ b/zsnes/src/video/makev16t.asm @@ -0,0 +1,5313 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM cwinptr,dualstartprocess,dualwinbg,dualwinsp,dwinptrproc,pwinbgenab +EXTSYM pwinbgtype,pwinspenab,pwinsptype,winbgdata,winlogicb,winonbtype +EXTSYM winonstype,winspdata,interlval,FPUCopy +EXTSYM bg1scrolx,bg1scroly,curmosaicsz,curypos,drawmode716t,makewindow +EXTSYM mode7set,mosaicon,mosaicsz,scrnon,winbg1en,winenabm +EXTSYM drawmode716textbg,drawmode716textbg2 +EXTSYM extbgdone +EXTSYM drawmode716tb,drawmode716b,drawmode716extbg,drawmode716extbg2 +EXTSYM cursprloc,drawsprites16b,scrndis,sprprifix,winonsp,bgfixer,bgfixer2 +EXTSYM scaddtype +EXTSYM alreadydrawn,bg1cachloc,bg1tdabloc,bg1tdatloc,bg1vbufloc,bg1xposloc +EXTSYM bg1yaddval,bgcoloradder,bgmode,bgtilesz,colormodeofs,curbgnum +EXTSYM draw16x1616b,draw8x816b,drawn,winenabs +EXTSYM curbgpr,draw16x1616tms,draw8x816tms +EXTSYM bg3high2,currentobjptr,curvidoffset,cwinenabm,makewindowsp +EXTSYM preparesprpr,procbackgrnd,setpalette16b,spritetablea +EXTSYM sprleftpr,sprlefttot +EXTSYM numwin,scaddset,wincolen,windowdata,winl1,winl2 +EXTSYM winon,winr1,winr2 +EXTSYM vidbuffer +EXTSYM FPUZero,coladdb,coladdg,coladdr,vesa2_bpos,vesa2_gpos,vesa2_rpos +EXTSYM vidbright +EXTSYM winptrref +EXTSYM fulladdtab,pal16b,vesa2_clbit +EXTSYM csprbit +EXTSYM sprclprio +EXTSYM csprprlft,sprsingle,sprpriodata +EXTSYM pal16bcl,pal16bxcl +EXTSYM bgofwptr,bgsubby,bshifter,domosaic16b,temp,tempcach,temptile +EXTSYM tileleft16b,xtravbuf,yadder +EXTSYM yrevadder,vcache2b,vcache4b,vcache8b +EXTSYM vcache2ba,vcache4ba,vcache8ba,draw8x816boffset +EXTSYM osm2dis,draw16x816 +EXTSYM hirestiledat,res512switch +EXTSYM bg1objptr,bg1ptr,bg1ptrc,bg3ptr,bg3scrolx,bg3scroly,cachesingle +EXTSYM colormoded2,offsetenab,offsetmclr,offsetmcol,offsetmodeptr +EXTSYM offsetmptr,offsetmshl,offsetmtst,offsetptra,offsetptrb,posyscroll +EXTSYM prevoffsetdat,prevtempcache,tempoffset,vidmemch2,vidmemch4 +EXTSYM vidmemch8,vram +EXTSYM ofsmcptr,ofsmady,ofsmadx,yposng,yposngom,flipyposng,flipyposngom +EXTSYM ofsmtptr,ofsmmptr,ofsmcyps,bgtxadd,bg1ptrx,bg1ptry +EXTSYM a16x16xinc,a16x16yinc + +%include "video/vidmacro.mac" + + + + + +; clearback16bts clearback16bdual + +;******************************************************* +; DrawLine 16bit Transparent Draws the current line +;******************************************************* +; use curypos+bg1scroly for y location and bg1scrolx for x location +; use bg1ptr(b,c,d) for the pointer to the tile number contents +; use bg1objptr for the pointer to the object tile contents + +NEWSYM makedualwincol + mov dl,[winlogicb] + shr dl,2 + and dl,03h + mov cl,dl + mov byte[winon],1 + mov ebx,[winl1] + ; check if data matches previous sprite data + cmp cl,[dualwinsp] + jne .skipsprcheck + cmp al,[pwinspenab] + jne .skipsprcheck + cmp ebx,[pwinsptype] + jne .skipsprcheck + mov dword[cwinptr],winspdata+16 + mov al,[winonstype] + mov [winon],al + ret +.skipsprcheck + ; check if data matches previous data + cmp cl,[dualwinbg] + jne .skipenab3 + cmp al,[pwinbgenab] + jne .skipenab + cmp ebx,[pwinbgtype] + jne .skipenab2 + mov dword[cwinptr],winbgdata+16 + mov al,[winonbtype] + mov [winon],al + ret +.skipenab3 + mov [dualwinbg],cl +.skipenab + mov [pwinbgenab],al + mov ebx,[winl1] +.skipenab2 + mov [pwinbgtype],ebx + mov dword[dwinptrproc],winbgdata+16 + mov dword[cwinptr],winbgdata+16 + mov byte[winon],1 + mov byte[winonbtype],1 + jmp dualstartprocess + +NEWSYM procmode716tsub + test word[scrnon+1],01h + jz near .noback1 + test word[scrnon],01h + jnz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + call drawmode716t +.noback1 + ret + + + +NEWSYM procmode716tsubextbg + test word[scrnon+1],02h + jz near .noback1 + test word[scrnon],02h + jnz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + mov byte[extbgdone],1 + call drawmode716extbg +.noback1 + ret + +NEWSYM procmode716tsubextbgb + cmp byte[extbgdone],0 + jne near .noback1 + test word[scrnon+1],01h + jz near .noback1 + test word[scrnon],01h + jnz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + mov byte[extbgdone],1 + call drawmode716textbg +.noback1 + ret + +NEWSYM procmode716tsubextbg2 + cmp byte[extbgdone],0 + je near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + call drawmode716extbg2 +.noback1 + ret + +NEWSYM procmode716tmain + test word[scrnon],01h + jz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + test byte[scaddset],02h + jz .noscrnadd + test word[scrnon+1],01h + jnz near .mode7b +.noscrnadd + test byte[scaddtype],01h + jz .notransp + call drawmode716t +.noback1 + ret +.notransp + call drawmode716b + ret +.mode7b + call drawmode716tb + ret + +NEWSYM procmode716tmainextbg + test word[scrnon],02h + jz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + test byte[scaddtype],01h + jz .notransp + mov byte[extbgdone],1 + call drawmode716textbg +.noback1 + ret +.notransp + mov byte[extbgdone],1 + call drawmode716extbg + ret + +NEWSYM procmode716tmainextbgb + cmp byte[extbgdone],0 + jne near .noback1 + test word[scrnon],01h + jz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + test byte[scaddtype],01h + jz .notransp + mov byte[extbgdone],1 + call drawmode716textbg +.noback1 + ret +.notransp + mov byte[extbgdone],1 + call drawmode716extbg + ret + +NEWSYM procmode716tmainextbg2 + cmp byte[extbgdone],0 + je near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 +; procwindow [winbg1en] + mov al,[winbg1en] + mov ebp,0 + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],1 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,[bg1scroly] + mov dx,[bg1scrolx] + test byte[scaddtype],01h + jz .notransp + call drawmode716textbg2 +.noback1 + ret +.notransp + call drawmode716extbg2 + ret + +NEWSYM procspritessub16t + cmp byte[bgfixer],1 + je near procspritessub16tfix + cmp byte[bgfixer2],1 + je near procspritessub16tfix + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon+1],10h + jz .nosprites + test byte[scrnon],10h + jnz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + cmp cl,0 + je .nosprites + call drawsprites16b +.nosprites + ret + +NEWSYM procspritesmain16t + cmp byte[bgfixer],1 + je near procspritesmain16tfix + cmp byte[bgfixer2],1 + je near procspritesmain16tfix + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon],10h + jz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + cmp cl,0 + je .nosprites + test byte[scrnon+1],10h + jnz .spritesubmain + test byte[scaddtype],10h + jz .nospriteadd + call drawsprites16t +.nosprites + ret +.nospriteadd + call drawsprites16b + xor eax,eax + ret +.spritesubmain + call drawsprites16bt + ret + +NEWSYM drawbackgrndsub16t + cmp byte[bgfixer],1 + je near drawbackgrndsub16tfix + cmp byte[bgfixer2],1 + je near drawbackgrndsub16tfix + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon+1],al + jz near .noback + test byte[scrnon],al + jnz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabs],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + mov bl,20h + mul bl + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x816b + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn +.noback + ret +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616b + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb + ret + +NEWSYM drawbackgrndmain16t + cmp byte[bgfixer],1 + je near drawbackgrndmain16tfix + cmp byte[bgfixer2],1 + je near drawbackgrndmain16tfix + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon],al + jz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabm],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + shl eax,5 + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + cmp byte[curbgpr],0h + jne .test2 +; test byte[scaddtype],cl +; jnz .transp +.test2 + test byte[scaddset],02h + jz .noscrnadd + test byte[scrnon+1],cl + jnz near .mainandsub +.noscrnadd + test byte[scaddtype],cl + jnz .transp + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x816b + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn +.noback + ret +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616b + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb + ret +.transp + test byte[bgtilesz],cl + jnz .16x16b + mov ecx,[bg1yaddval+ebp*4] + call draw8x816t + cmp byte[drawn],33 + jne .notalldrawnc + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnc + ret +.16x16b + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616t + cmp byte[drawn],33 + jne .notalldrawnd + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnd + ret +.mainandsub + test byte[curbgpr],20h + jnz .firstpr + test byte[scaddtype],cl + jnz .transpb +.firstpr + test byte[bgtilesz],cl + jnz .16x16c + mov ecx,[bg1yaddval+ebp*4] + call draw8x816bt + cmp byte[drawn],33 + jne .notalldrawne + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawne + ret +.16x16c + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616bt + cmp byte[drawn],33 + jne .notalldrawnf + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnf + ret +.transpb + test byte[bgtilesz],cl + jnz .16x16d + mov ecx,[bg1yaddval+ebp*4] + call draw8x816tms + cmp byte[drawn],33 + jne .notalldrawng + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawng + ret +.16x16d + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616tms + cmp byte[drawn],33 + jne .notalldrawnh + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnh + ret + +NEWSYM procspritessub16tfix + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon+1],10h + jz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + cmp cl,0 + je .nosprites + call drawsprites16b +.nosprites + ret + +NEWSYM procspritesmain16tfix + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon],10h + jz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + cmp cl,0 + je .nosprites + test byte[scaddtype],10h + jz .nospriteadd + call drawsprites16t +.nosprites + ret +.nospriteadd + call drawsprites16b + xor eax,eax + ret + +NEWSYM drawbackgrndsub16tfix + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon+1],al + jz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabs],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + mov bl,20h + mul bl + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x816b + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn +.noback + ret +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616b + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb + ret + +NEWSYM drawbackgrndmain16tfix + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon],al + jz near .noback + test byte[alreadydrawn],al +; jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabm],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + shl eax,5 + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + cmp byte[curbgpr],0h + jne .test2 +; test byte[scaddtype],cl +; jnz .transp +.test2 + test byte[scaddtype],cl + jnz .transp + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x816b + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn +.noback + ret +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616b + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb + ret +.transp + test byte[bgtilesz],cl + jnz .16x16b + mov ecx,[bg1yaddval+ebp*4] + call draw8x816t + cmp byte[drawn],33 + jne .notalldrawnc + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnc + ret +.16x16b + mov ecx,[bg1yaddval+ebp*4] + call draw16x1616t + cmp byte[drawn],33 + jne .notalldrawnd + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnd + ret + +ALIGN32 + +NEWSYM transpbuf, times 576+16+288*2 db 0 ; Transparent buffer + + +NEWSYM drawline16t + cmp byte[bgmode],7 + je near processmode716t + mov al,[scrnon] + test [scrnon+1],al + jz .nomainsub + test byte[scrnon],10h + jnz .nomainsub + test byte[scrnon+1],10h + jz .nomainsub + mov al,[scrnon+1] + xor al,0FFh + and [scrnon],al +.nomainsub + push esi + push edi + push ebx + push edx + push ebp + ; current video offset + mov dword[curvidoffset],transpbuf+32 + ; set palette + call setpalette16b + ; clear back area w/ back color + procwindowback + call clearback16bts + ; do sprite windowing + call makewindowsp + ; clear registers + xor eax,eax + xor ecx,ecx + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + mov dword[cursprloc],sprleftpr + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio +; process backgrounds +; do background 2 + mov byte[curbgnum],02h + mov ebp,01h + call procbackgrnd +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call procbackgrnd +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call procbackgrnd +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call procbackgrnd + + cmp byte[bgmode],1 + ja near priority216t + test byte[scaddset],02h + jz near .noscrnadd +; draw backgrounds + mov byte[curbgpr],0h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndsub16t +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndsub16t + mov ebp,0 + call procspritessub16t +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndsub16t +; do background 3 + mov byte[curbgpr],20h + cmp byte[bg3high2],1 + je .bg3nothigh + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndsub16t +.bg3nothigh + mov ebp,1 + call procspritessub16t +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub16t + mov ebp,2 + call procspritessub16t +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub16t + mov ebp,3 + call procspritessub16t +; do background 3 + cmp byte[bg3high2],1 + jne .bg3high + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndsub16t +.bg3high +.noscrnadd + mov al,[winenabm] + mov [cwinenabm],al + +NEWSYM NextDrawLine16bt + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,9 + shl ebx,6 + add esi,ebx + add esi,32 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; clear back area w/ back color + call clearback16t + mov byte[curbgpr],0h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndmain16t +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain16t + mov ebp,0 + call procspritesmain16t +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndmain16t +; do background 3 + mov byte[curbgpr],20h + cmp byte[bg3high2],1 + je .bg3nothighb + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain16t +.bg3nothighb + mov ebp,1 + call procspritesmain16t +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16t + mov ebp,2 + call procspritesmain16t +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16t + mov ebp,3 + call procspritesmain16t + cmp byte[bg3high2],1 + jne .bg3highb +; do background 3 + mov byte[curbgpr],20h + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain16t +.bg3highb + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx + ret + +NEWSYM priority216t + test byte[scaddset],02h + jz near .noscrnadd +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub16t + mov ebp,0 + call procspritessub16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub16t + mov ebp,1 + call procspritessub16t +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub16t + mov ebp,2 + call procspritessub16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub16t + mov ebp,3 + call procspritessub16t +.noscrnadd + mov al,[winenabm] + mov [cwinenabm],al +NEWSYM Priority2NextDrawLine16bt + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,9 + shl ebx,6 + add esi,ebx + add esi,32 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; clear back area w/ back color + call clearback16t +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16t + mov ebp,0 + call procspritesmain16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16t + mov ebp,1 + call procspritesmain16t +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain16t + mov ebp,2 + call procspritesmain16t +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain16t + mov ebp,3 + call procspritesmain16t + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx + ret + +NEWSYM processmode716t + push esi + push edi + push ebx + push edx + push ebp + ; current video offset + mov dword[curvidoffset],transpbuf+32 + ; set palette + call setpalette16b + ; clear back area w/ back color + procwindowback + call clearback16bts + ; do sprite windowing + call makewindowsp + ; clear registers + xor eax,eax + xor ecx,ecx + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + mov dword[cursprloc],sprleftpr + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio + mov byte[extbgdone],0 + test byte[scaddset],02h + jz .nosubscr + test byte[interlval],40h + jz .noback0s + call procmode716tsubextbg +.noback0s + mov ebp,0 + call procspritessub16t + test byte[interlval],40h + jnz .noback1s + call procmode716tsub +.noback1s + mov ebp,1 + call procspritessub16t + test byte[interlval],40h + jz .noback2s + call procmode716tsubextbgb + call procmode716tsubextbg2 +.noback2s + mov ebp,2 + call procspritessub16t + mov ebp,3 + call procspritessub16t +.nosubscr + mov al,[winenabm] + mov [cwinenabm],al +NEWSYM processmode716t2 + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,9 + shl ebx,6 + add esi,ebx + add esi,32 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + mov dword[cursprloc],sprleftpr + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio + ; clear back area w/ back color + call clearback16t + ; clear registers + xor eax,eax + xor ecx,ecx + mov byte[extbgdone],0 + test byte[interlval],40h + jz .noback0m + call procmode716tmainextbg +.noback0m + mov ebp,0 + call procspritesmain16t + ; do background 1 + test byte[interlval],40h + jnz .noback1m + call procmode716tmain +.noback1m + mov ebp,1 + call procspritesmain16t + test byte[interlval],40h + jz .noback2m + call procmode716tmainextbgb + call procmode716tmainextbg2 +.noback2m + mov ebp,2 + call procspritesmain16t + mov ebp,3 + call procspritesmain16t + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx + ret + +;******************************************************* +; Clear Backarea, with 0s +;******************************************************* + +NEWSYM prevrgbcol, dd 0 +NEWSYM prevrgbpal, dd 0 + +NEWSYM clearback16bts + mov byte[DoTransp],0 + cmp dword[vesa2_rpos],0 + je near clearback16bts0.clear + cmp byte[winon],0 + je near clearback16bts0b + cmp byte[winon],2 + je near clearback16bts0 + cmp byte[winon],4 + je near clearback16bts0.clear +.noclear + mov bl,[scaddset] + and bl,30h + cmp bl,20h + jne .dontclear + cmp byte[winon],5 + je near clearback16bts0.clear +.dontclear + cmp byte[winon],5 + je near clearback16bts0b + cmp byte[winon],3 + je near clearback16bts0b + mov eax,[coladdr] + shl eax,8 + mov bx,[prevrgbpal] + mov al,[vidbright] + cmp eax,[prevrgbcol] + je .useprevpal + mov [prevrgbcol],eax + xor eax,eax + mov al,[coladdr] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + shl ax,cl + mov bx,ax + xor eax,eax + mov al,[coladdg] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + xor eax,eax + mov al,[coladdb] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + mov [prevrgbpal],bx +.useprevpal + mov ax,bx + cmp eax,0 + je .nowin + jmp dowindowback16b +.nowin + mov edi,[curvidoffset] + or eax,eax + jz near clearback16bts0.clearing + cmp byte[FPUCopy],2 + je .dommxclear + mov ecx,128 + rep stosd + xor eax,eax + ret +.dommxclear + mov [mmxtempdat],eax + mov [mmxtempdat+4],eax + mov ecx,32 + movq mm0,[mmxtempdat] +.mmxloop + movq [edi],mm0 + movq [edi+8],mm0 + add edi,16 + dec ecx + jnz .mmxloop + emms + xor eax,eax + ret + +mmxtempdat dd 0,0 + +NEWSYM clearback16bts0b + mov eax,[coladdr] + shl eax,8 + mov bx,[prevrgbpal] + mov al,[vidbright] + cmp eax,[prevrgbcol] + je .useprevpal2 + mov [prevrgbcol],eax + xor eax,eax + mov al,[coladdr] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_rpos] + shl ax,cl + mov bx,ax + xor eax,eax + mov al,[coladdg] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_gpos] + shl ax,cl + add bx,ax + xor eax,eax + mov al,[coladdb] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[vesa2_bpos] + shl ax,cl + add bx,ax + mov [prevrgbpal],bx +.useprevpal2 + mov ax,bx + shl eax,16 + mov ax,bx + cmp byte[winon],3 + je near clearback16bdual + mov edi,[curvidoffset] + or eax,eax + jz near clearback16bts0.clearing + cmp byte[FPUCopy],2 + je .dommxclear + mov ecx,128 + rep stosd + xor eax,eax + ret +.dommxclear + mov [mmxtempdat],eax + mov [mmxtempdat+4],eax + mov ecx,32 + movq mm0,[mmxtempdat] +.mmxloop + movq [edi],mm0 + movq [edi+8],mm0 + add edi,16 + dec ecx + jnz .mmxloop + emms + xor eax,eax + ret + +NEWSYM clearback16bts0 + mov bl,[scaddset] + and bl,30h + cmp bl,20h + je near clearback16bts0b +.clear + mov edi,[curvidoffset] + xor eax,eax +.clearing + test byte[scrnon+1],10h + jnz .notnotransp + mov byte[DoTransp],1 +.notnotransp + cmp byte[FPUCopy],2 + je .dommxclear + mov ecx,128 + rep stosd + ret +.dommxclear + mov [mmxtempdat],eax + mov [mmxtempdat+4],eax + mov ecx,32 + movq mm0,[mmxtempdat] +.mmxloop + movq [edi],mm0 + movq [edi+8],mm0 + add edi,16 + dec ecx + jnz .mmxloop + emms + ret + +NEWSYM dowindowback16b + test byte[scrnon+1],10h + jnz .notnotransp + mov byte[DoTransp],1 +.notnotransp + mov bl,[scaddset] + and bl,30h + cmp bl,20h + je near dowindowback16brev + mov ebx,windowdata + mov edi,[curvidoffset] + xor edx,edx + xor ch,ch +.getnext + mov cl,[ebx] + cmp dl,cl + je .procnext +.dorest + sub cl,dl + cmp ch,0 + ja .nodraw + mov byte[DoTransp],0 +.loopa + mov word[edi+edx*2],ax + inc dl + dec cl + jnz .loopa +.procnext + add ch,[ebx+1] + add ebx,2 + test byte[numwin],0FFh + jz .finishwin + dec byte[numwin] + jnz .getnext + xor cl,cl + jmp .dorest +.nodraw +.loopb + mov word[edi+edx*2],0 + inc dl + dec cl + jnz .loopb + jmp .procnext +.finishwin + xor eax,eax + ret + +NEWSYM dowindowback16brev + mov ebx,windowdata + mov edi,[curvidoffset] + xor edx,edx + xor ch,ch +.getnext + mov cl,[ebx] + cmp dl,cl + je .procnext +.dorest + sub cl,dl + cmp ch,0 + ja .nodraw +.loopa + mov word[edi+edx*2],0 + inc dl + dec cl + jnz .loopa +.procnext + add ch,[ebx+1] + add ebx,2 + test byte[numwin],0FFh + jz .finishwin + dec byte[numwin] + jnz .getnext + xor cl,cl + jmp .dorest +.nodraw + mov byte[DoTransp],0 +.loopb + mov word[edi+edx*2],ax + inc dl + dec cl + jnz .loopb + jmp .procnext +.finishwin + xor eax,eax + ret + +NEWSYM clearback16bdual + cmp byte[bgmode],7 + jne .notmode7 + test byte[scrnon+1],10h + jnz .notmode7 + jmp clearback16bdualb2 +.notmode7 + + mov bl,[scaddset] + and bl,30h + cmp bl,10h + je near clearback16bdualrev + + mov edi,[curvidoffset] + mov esi,[cwinptr] + mov ecx,64 + cmp dword[esi],01010101h + je near .drawnone +.nextpart + cmp dword[esi],0 + jne .drawpart +.drawall + mov [edi],eax + mov [edi+4],eax + add edi,8 + add esi,4 + dec ecx + jnz .nextpart + jmp .findraw +.nextpartp + cmp dword[esi],01010101h + je near .drawnone + cmp dword[esi],0h + je .drawall +.drawpart + xor ebx,ebx + cmp byte[esi],1 + je .nodraw + mov ebx,eax +.nodraw + mov [edi],bx + xor ebx,ebx + cmp byte[esi+1],1 + je .nodraw1 + mov ebx,eax +.nodraw1 + mov [edi+2],bx + xor ebx,ebx + cmp byte[esi+2],1 + je .nodraw2 + mov ebx,eax +.nodraw2 + mov [edi+4],bx + xor ebx,ebx + cmp byte[esi+3],1 + je .nodraw3 + mov ebx,eax +.nodraw3 + mov [edi+6],bx + add edi,8 + add esi,4 + dec ecx + jnz near .nextpartp + jmp .findraw +.nextpartn + cmp dword[esi],01010101h + jne .drawpart +.drawnone + mov dword[edi],0 + mov dword[edi+4],0 + add edi,8 + add esi,4 + dec ecx + jnz .nextpartn +.findraw + ret + +NEWSYM clearback16bdualrev + +; xor eax,eax ;aaaaaaaaaaa +; ret + + mov edi,[curvidoffset] + mov esi,[winptrref] + mov esi,[cwinptr] + mov ecx,64 + cmp dword[esi],0 + je near .drawnone +.nextpart + cmp dword[esi],01010101h + jne .drawpart +.drawall + mov [edi],eax + mov [edi+4],eax + add edi,8 + add esi,4 + dec ecx + jnz .nextpart + jmp .findraw +.nextpartp + cmp dword[esi],0 + je near .drawnone + cmp dword[esi],01010101h + je .drawall +.drawpart + xor ebx,ebx + cmp byte[esi],1 + jne .nodraw + mov ebx,eax +.nodraw + mov [edi],bx + xor ebx,ebx + cmp byte[esi+1],1 + jne .nodraw1 + mov ebx,eax +.nodraw1 + mov [edi+2],bx + xor ebx,ebx + cmp byte[esi+2],1 + jne .nodraw2 + mov ebx,eax +.nodraw2 + mov [edi+4],bx + xor ebx,ebx + cmp byte[esi+3],1 + jne .nodraw3 + mov ebx,eax +.nodraw3 + mov [edi+6],bx + add edi,8 + add esi,4 + dec ecx + jnz near .nextpartp + jmp .findraw +.nextpartn + cmp dword[esi],0 + jne .drawpart +.drawnone + mov dword[edi],0 + mov dword[edi+4],0 + add edi,8 + add esi,4 + dec ecx + jnz .nextpartn +.findraw + ret + +NEWSYM clearback16bdualb2 + mov byte[DoTransp],1 + mov bl,[scaddset] + and bl,30h + cmp bl,10h + je near clearback16bdualrev2 + + mov edi,[curvidoffset] + mov esi,[cwinptr] + mov ecx,64 + cmp dword[esi],01010101h + je near .drawnone + mov byte[DoTransp],0 +.nextpart + cmp dword[esi],0 + jne .drawpart +.drawall + mov [edi],eax + mov [edi+4],eax + add edi,8 + add esi,4 + dec ecx + jnz .nextpart + jmp .findraw +.nextpartp + cmp dword[esi],01010101h + je near .drawnone + cmp dword[esi],0h + je .drawall +.drawpart + mov byte[DoTransp],0 + xor ebx,ebx + cmp byte[esi],1 + je .nodraw + mov ebx,eax +.nodraw + mov [edi],bx + xor ebx,ebx + cmp byte[esi+1],1 + je .nodraw1 + mov ebx,eax +.nodraw1 + mov [edi+2],bx + xor ebx,ebx + cmp byte[esi+2],1 + je .nodraw2 + mov ebx,eax +.nodraw2 + mov [edi+4],bx + xor ebx,ebx + cmp byte[esi+3],1 + je .nodraw3 + mov ebx,eax +.nodraw3 + mov [edi+6],bx + add edi,8 + add esi,4 + dec ecx + jnz near .nextpartp + jmp .findraw +.nextpartn + cmp dword[esi],01010101h + jne .drawpart +.drawnone + mov dword[edi],0 + mov dword[edi+4],0 + add edi,8 + add esi,4 + dec ecx + jnz .nextpartn +.findraw + ret + +NEWSYM clearback16bdualrev2 + mov edi,[curvidoffset] + mov esi,[winptrref] + mov esi,[cwinptr] + mov ecx,64 + cmp dword[esi],0 + je near .drawnone + mov byte[DoTransp],0 +.nextpart + cmp dword[esi],01010101h + jne .drawpart +.drawall + mov [edi],eax + mov [edi+4],eax + add edi,8 + add esi,4 + dec ecx + jnz .nextpart + jmp .findraw +.nextpartp + cmp dword[esi],0 + je near .drawnone + cmp dword[esi],01010101h + je .drawall +.drawpart + mov byte[DoTransp],0 + xor ebx,ebx + cmp byte[esi],1 + jne .nodraw + mov ebx,eax +.nodraw + mov [edi],bx + xor ebx,ebx + cmp byte[esi+1],1 + jne .nodraw1 + mov ebx,eax +.nodraw1 + mov [edi+2],bx + xor ebx,ebx + cmp byte[esi+2],1 + jne .nodraw2 + mov ebx,eax +.nodraw2 + mov [edi+4],bx + xor ebx,ebx + cmp byte[esi+3],1 + jne .nodraw3 + mov ebx,eax +.nodraw3 + mov [edi+6],bx + add edi,8 + add esi,4 + dec ecx + jnz near .nextpartp + jmp .findraw +.nextpartn + cmp dword[esi],0 + jne .drawpart +.drawnone + mov dword[edi],0 + mov dword[edi+4],0 + add edi,8 + add esi,4 + dec ecx + jnz .nextpartn +.findraw + ret + +NEWSYM DoTransp, db 0 + +;******************************************************* +; Clear Backarea, 16-bit mode w/ transparency +;******************************************************* +NEWSYM clearback16t + test byte[scaddtype],20h + jz near .backcopy + test byte[scaddtype],80h + jnz near clearback16ts + mov eax,[pal16b] + mov esi,[curvidoffset] + mov ebp,transpbuf+32 + mov dx,ax + and eax,[vesa2_clbit] + shr eax,1 + test byte[scaddtype],40h + jz .fulladd + cmp byte[scrnon+1],0 + je .fulladd + mov ecx,128 +.loopa + mov ebx,[ebp] + or bx,bx + jz .noadd + and bx,[vesa2_clbit] + shr bx,1 + add bx,ax + mov [esi],bx + jmp .skip +.noadd + mov [esi],dx +.skip + shr ebx,16 + or bx,bx + je .noadd2 + and bx,word[vesa2_clbit] + shr bx,1 + add bx,ax + mov [esi+2],bx + jmp .skip2 +.noadd2 + mov [esi+2],dx +.skip2 + add ebp,4 + add esi,4 + dec ecx + jnz .loopa + xor eax,eax + ret +.fulladd + cmp eax,0 + je .subcopy + mov ecx,256 + xor ebx,ebx +.loopc + mov ebx,[ebp] + and ebx,[vesa2_clbit] + shr ebx,1 + add ebx,eax + add ebp,2 + mov ebx,[fulladdtab+ebx*2] + mov [esi],bx + add esi,2 + dec ecx + jnz .loopc + xor eax,eax + ret +.subcopy + cmp byte[FPUCopy],2 + je .dommxcopy + mov ecx,128 + xor ebx,ebx + mov edi,esi + mov esi,ebp + rep movsd + xor eax,eax + ret +.dommxcopy + mov ecx,32 + xor ebx,ebx + mov edi,esi + mov esi,ebp +.mmxloop2 + movq mm0,[esi] + movq mm1,[esi+8] + movq [edi],mm0 + movq [edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz .mmxloop2 + emms + xor eax,eax + ret +.backcopy + mov edi,[curvidoffset] + mov ecx,128 + mov ax,[pal16b] + shl eax,16 + mov ax,[pal16b] + cmp byte[FPUCopy],2 + je .dommxclear + rep stosd + xor eax,eax + ret +.dommxclear + mov [mmxtempdat],eax + mov [mmxtempdat+4],eax + mov ecx,32 + movq mm0,[mmxtempdat] +.mmxloop + movq [edi],mm0 + movq [edi+8],mm0 + add edi,16 + dec ecx + jnz .mmxloop + emms + xor eax,eax + ret + +NEWSYM clearback16ts + mov eax,[pal16b] + mov esi,[curvidoffset] + mov ebp,transpbuf+32 + xor eax,0FFFFh + and eax,[vesa2_clbit] + shr eax,1 + mov ecx,256 + xor ebx,ebx +.loopc + mov ebx,[ebp] + and ebx,[vesa2_clbit] + shr ebx,1 + add ebx,eax + add ebp,2 + mov ebx,[fulladdtab+ebx*2] + xor ebx,0FFFFh + mov [esi],bx + add esi,2 + dec ecx + jnz .loopc + xor eax,eax + ret + +NEWSYM drawsprites16bt + cmp byte[sprprifix],1 + je near drawsprites16btprio + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near drawsprites16btwinon +.drawnowin + mov esi,[currentobjptr] + xor ebx,ebx + xor eax,eax +.loopobj + mov edi,[curvidoffset] + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + mov ebp,ebx + add edi,ebx + add ebp,transpbuf+32 + drawspr16bt 0, 16 + drawspr16bt 1, 14 + drawspr16bt 2, 12 + drawspr16bt 3, 10 + drawspr16bt 4, 8 + drawspr16bt 5, 6 + drawspr16bt 6, 4 + drawspr16bt 7, 2 + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + mov ebp,ebx + add edi,ebx + add ebp,transpbuf+32 + drawspr16bt 7, 16 + drawspr16bt 6, 14 + drawspr16bt 5, 12 + drawspr16bt 4, 10 + drawspr16bt 3, 8 + drawspr16bt 2, 6 + drawspr16bt 1, 4 + drawspr16bt 0, 2 + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawsprites16btwinon + mov esi,[currentobjptr] + xor ebx,ebx + xor eax,eax +.loopobj + mov edi,[curvidoffset] + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + mov ebp,ebx + add edi,ebx + shr ebx,1 + add ebp,transpbuf+32 + drawspr16btwo 0, 16, 0 + drawspr16btwo 1, 14, 1 + drawspr16btwo 2, 12, 2 + drawspr16btwo 3, 10, 3 + drawspr16btwo 4, 8, 4 + drawspr16btwo 5, 6, 5 + drawspr16btwo 6, 4, 6 + drawspr16btwo 7, 2, 7 + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + mov ebp,ebx + add edi,ebx + shr ebx,1 + add ebp,transpbuf+32 + drawspr16btwo 7, 16, 0 + drawspr16btwo 6, 14, 1 + drawspr16btwo 5, 12, 2 + drawspr16btwo 4, 10, 3 + drawspr16btwo 3, 8, 4 + drawspr16btwo 2, 6, 5 + drawspr16btwo 1, 4, 6 + drawspr16btwo 0, 2, 7 + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawsprites16btprio + sprpriorityinit drawsprites16btpriow + sprprioritydrawbt sprdrawpra16bt, sprdrawprb16bt + +NEWSYM drawsprites16btpriow + sprprioritydrawbt sprdrawpra16bt, sprdrawprb16bt + +NEWSYM drawsprites16t + cmp byte[sprprifix],1 + je near drawsprites16tprio + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near drawsprites16twinon +.drawnowin + test byte[scaddtype],40h + jz near drawspritesfulladd + cmp byte[scrnon+1],0 + je near drawspritesfulladd + test byte[scaddtype],80h + jnz near drawspritesfulladd + mov esi,[currentobjptr] + mov edi,[curvidoffset] + xor ebx,ebx + xor eax,eax +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobjnf + drawsprgrp drawspr16ta + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobj + drawsprgrpf drawspr16ta + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjnf + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrp drawspr16tb + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobj + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpf drawspr16tb + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +drawspritesfulladd: + mov esi,[currentobjptr] + mov edi,[curvidoffset] + xor ebx,ebx + xor eax,eax +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobjnf + drawsprgrp drawspr16ta + pop esi + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + shl bx,1 + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobj + drawsprgrpf drawspr16ta + pop esi + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjnf + test byte[scaddtype],80h + jnz near .transparentobjnfs + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrp drawspr16tc + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjnfs + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrp drawspr16td + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobj + test byte[scaddtype],80h + jnz near .transparentobjs + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpf drawspr16tc + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjs + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpf drawspr16td + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawsprites16twinon + test byte[scaddtype],40h + jz near drawspritesfulladdwinon + cmp byte[scrnon+1],0 + je near drawspritesfulladdwinon + test byte[scaddtype],80h + jnz near drawspritesfulladdwinon + mov esi,[currentobjptr] + mov edi,[curvidoffset] + xor ebx,ebx + xor eax,eax +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobjnf + drawsprgrpwin drawspr16tawinon + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobj + drawsprgrpfwin drawspr16tawinon + pop esi + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjnf + mov ebp,ebx + add edi,ebx + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpwin drawspr16tbwinon + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobj + mov ebp,ebx + add edi,ebx + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpfwin drawspr16tbwinon + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawspritesfulladdwinon + mov esi,[currentobjptr] + mov edi,[curvidoffset] + xor ebx,ebx + xor eax,eax +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobjnf + drawsprgrpwin drawspr16tawinon + pop esi + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + push esi + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transparentobj + drawsprgrpfwin drawspr16tawinon + pop esi + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjnf + test byte[scaddtype],80h + jnz near .transparentobjnfs + mov ebp,ebx + add edi,ebx + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpwin drawspr16tcwinon + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjnfs + mov ebp,ebx + add edi,ebx + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpwin drawspr16tdwinon + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobj + test byte[scaddtype],80h + jnz near .transparentobjs + mov ebp,ebx + add edi,ebx + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpfwin drawspr16tcwinon + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.transparentobjs + mov ebp,ebx + add edi,ebx + mov ebp,ebx + add edi,ebx + xor edx,edx + add ebp,transpbuf+32 + drawsprgrpfwin drawspr16tdwinon + pop esi + mov edi,[curvidoffset] + xor edx,edx + xor ebx,ebx + add esi,8 + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawsprites16tprio + test byte[scaddtype],40h + jz near drawspritesfulladdprio + cmp byte[scrnon+1],0 + je near drawspritesfulladdprio + test byte[scaddtype],80h + jnz near drawspritesfulladdprio + ; half add + sprpriorityinit drawsprites16tpriow + sprprioritydrawt16b sprdrawpra16bha, sprdrawprb16bha, sprdrawpra16b, sprdrawprb16b + +NEWSYM drawsprites16tpriow + sprprioritydrawt16b sprdrawpraw16bha, sprdrawprbw16bha, sprdrawpraw16b, sprdrawprbw16b + +NEWSYM drawspritesfulladdprio + test byte[scaddtype],80h + jnz near drawspritesfullsubprio + ; full add + sprpriorityinit drawspritesfulladdpriow + sprprioritydrawt16b sprdrawpra16bfa, sprdrawprb16bfa, sprdrawpra16b, sprdrawprb16b + +NEWSYM drawspritesfulladdpriow + sprprioritydrawt16b sprdrawpraw16bfa, sprdrawprbw16bfa, sprdrawpraw16b, sprdrawprbw16b + +NEWSYM drawspritesfullsubprio + ; full sub + sprpriorityinit drawspritesfullsubpriow + sprprioritydrawt16b sprdrawpra16bfs, sprdrawprb16bfs, sprdrawpra16b, sprdrawprb16b + +NEWSYM drawspritesfullsubpriow + sprprioritydrawt16b sprdrawpraw16bfs, sprdrawprbw16bfs, sprdrawpraw16b, sprdrawprbw16b + + +NEWSYM draw8x816bt + cmp byte[bgmode],2 + je near draw8x816boffset + cmp byte[bgmode],5 + je near draw16x816t + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x816btwinon +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + ; Start loop + drawtilegrp draw8x816bta +.hprior + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + drawtilegrpf draw8x816bta + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x816btwinon + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + mov byte[tileleft16b],33 + mov ecx,[winptrref] + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov eax,ecx + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + mov ecx,eax + xor eax,eax + ; Start loop + drawtilegrp draw8x816btawinon +.hprior + add esi,16 + add ecx,8 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov eax,ecx + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + mov ecx,eax + xor eax,eax + drawtilegrpf draw8x816btawinonb + add esi,16 + add ecx,8 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw8x816t + cmp byte[osm2dis],1 + je .osm2dis + cmp byte[bgmode],2 + je near draw8x816toffset +.osm2dis + cmp byte[bgmode],5 + je near draw16x816t + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x816twinon +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + + test byte[scaddtype],80h + jnz near draw8x816ts + test byte[scaddtype],40h + jz near draw8x8fulladd + cmp byte[scrnon+1],0 + jz near draw8x8fulladd + + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816ta +.hprior + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpf draw8x816ta + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x8fulladd + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tb +.hprior + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tb + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x816ts + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tc +.hprior + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tc + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +ALIGN32 +NEWSYM coadder16, dd 0 + +NEWSYM draw8x816twinon + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw8x816tswinon + test byte[scaddtype],40h + jz near draw8x8fulladdwinon + cmp byte[scrnon+1],0 + jz near draw8x8fulladdwinon + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test cl,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tawinon +.hprior + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpf draw8x816tawinonb + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw8x8fulladdwinon + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbwinon +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbwinonb + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw8x816tswinon + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcwinon +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcwinonb + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +;******************************************************* +; Processes & Draws 16x8 tiles +;******************************************************* + +%macro Process16x816t 2 + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +%%loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near %%hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb %%noclip + sub edi,[bgsubby] +%%noclip + test dh,80h + jz %%normadd + add edi,[yrevadder] + jmp %%skipadd +%%normadd + add edi,[yadder] +%%skipadd + test dh,40h + jnz near %%rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + %2 0+%1, 0 + %2 2+%1, 2 + %2 4+%1, 4 + %2 6+%1, 6 + add edi,64 + ; Start loop + %2 0+%1, 8 + %2 2+%1, 10 + %2 4+%1, 12 + %2 6+%1, 14 +%%hprior + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne %%loopc2 + mov edi,[temptile] +%%loopc2 + dec byte[tileleft16b] + jnz near %%loopa + cmp byte[drawn],0 + je %%nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +%%nodraw + ret + +%%rloop + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + %2 1-%1, 14 + %2 3-%1, 12 + %2 5-%1, 10 + %2 7-%1, 8 + add edi,64 + ; Start loop + %2 1-%1, 6 + %2 3-%1, 4 + %2 5-%1, 2 + %2 7-%1, 0 + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne %%loopc3 + mov edi,[temptile] +%%loopc3 + dec byte[tileleft16b] + jnz near %%loopa + cmp byte[drawn],0 + je %%nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +%%nodraw2 + ret +%endmacro + +%macro Process16x816twin 2 + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +%%loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near %%hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb %%noclip + sub edi,[bgsubby] +%%noclip + test cl,80h + jz %%normadd + add edi,[yrevadder] + jmp %%skipadd +%%normadd + add edi,[yadder] +%%skipadd + test cl,40h + jnz near %%rloop + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + %2 0+%1, 0, 0 + %2 2+%1, 2, 1 + %2 4+%1, 4, 2 + %2 6+%1, 6, 3 + add edi,64 + ; Start loop + %2 0+%1, 8, 4 + %2 2+%1, 10, 5 + %2 4+%1, 12, 6 + %2 6+%1, 14, 7 +%%hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne %%loopc2 + mov edi,[temptile] +%%loopc2 + dec byte[tileleft16b] + jnz near %%loopa + ret + +%%rloop + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + %2 1-%1, 14, 0 + %2 3-%1, 12, 1 + %2 5-%1, 10, 2 + %2 7-%1, 8, 3 + add edi,64 + ; Start loop + %2 1-%1, 6, 4 + %2 3-%1, 4, 5 + %2 5-%1, 2, 6 + %2 7-%1, 0, 7 + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne %%loopc3 + mov edi,[temptile] +%%loopc3 + dec byte[tileleft16b] + jnz near %%loopa + ret +%endmacro + +NEWSYM draw16x816t + push eax + xor eax,eax + mov al,[curypos] + mov byte[hirestiledat+eax],1 + pop eax + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + + test byte[scaddtype],80h + jnz near draw16x816ts + test byte[scaddtype],40h + jz near draw16x816tfa + cmp byte[scrnon+1],0 + jz near draw16x816tfa + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x816twinon +.domosaic + cmp byte[res512switch],0 + jne near draw16x816tb + Process16x816t 0, draw8x816ta2 + +NEWSYM draw16x816tb + Process16x816t 1, draw8x816ta2 + +NEWSYM draw16x816twinon + mov edx,[winptrref] + cmp byte[res512switch],0 + jne near draw16x816twinonb + Process16x816twin 0, draw8x816tawinon2 + +NEWSYM draw16x816twinonb + Process16x816twin 1, draw8x816tawinon2 + +draw16x816tfa: + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x816twinonfa +.domosaic + cmp byte[res512switch],0 + jne near draw16x816tbfa + Process16x816t 0, draw8x816tb +NEWSYM draw16x816tbfa + Process16x816t 1, draw8x816tb +NEWSYM draw16x816twinonfa + mov edx,[winptrref] + cmp byte[res512switch],0 + jne near draw16x816twinonbfa + Process16x816twin 0, draw8x816tbwinon2 +NEWSYM draw16x816twinonbfa + Process16x816twin 1, draw8x816tbwinon2 + +draw16x816ts: + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x816twinons +.domosaic + cmp byte[res512switch],0 + jne near draw16x816tbs + Process16x816t 0, draw8x816tc +NEWSYM draw16x816tbs + Process16x816t 1, draw8x816tc +NEWSYM draw16x816twinons + mov edx,[winptrref] + cmp byte[res512switch],0 + jne near draw16x816twinonbs + Process16x816twin 0, draw8x816tcwinon2 +NEWSYM draw16x816twinonbs + Process16x816twin 1, draw8x816tcwinon2 + +;******************************************************* +; Processes & Draws 8x8 tiles, offset mode +;******************************************************* + + +NEWSYM draw8x816toffset + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + initoffsetmode + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x816twinonoffset +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw8x816tsoffset + test byte[scaddtype],40h + jz near draw8x8fulladdoffset + cmp byte[scrnon+1],0 + jz near draw8x8fulladdoffset + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816ta +.hprior + procoffsetmode + add esi,16 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpf draw8x816ta + procoffsetmode + add esi,16 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x8fulladdoffset + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tb +.hprior + pop edi + procoffsetmode + add esi,16 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tb + pop edi + procoffsetmode + add esi,16 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x816tsoffset + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tc +.hprior + pop edi + procoffsetmode + add esi,16 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tc + pop edi + procoffsetmode + add esi,16 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + +NEWSYM draw8x816twinonoffset + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw8x816tswinonoffset + test byte[scaddtype],40h + jz near draw8x8fulladdwinonoffset + cmp byte[scrnon+1],0 + jz near draw8x8fulladdwinonoffset + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test cl,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tawinon +.hprior + procoffsetmode + add esi,16 + add edx,8 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpf draw8x816tawinonb + procoffsetmode + add esi,16 + add edx,8 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + +NEWSYM draw8x8fulladdwinonoffset + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbwinon +.hprior + pop edi + procoffsetmode + add esi,16 + add edx,8 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbwinonb + pop edi + procoffsetmode + add esi,16 + add edx,8 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + +NEWSYM draw8x816tswinonoffset + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcwinon +.hprior + pop edi + procoffsetmode + add esi,16 + add edx,8 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcwinonb + pop edi + procoffsetmode + add esi,16 + add edx,8 + add ebp,16 + dec byte[tileleft16b] + jnz near .loopa + xor eax,eax + ret + +;******************************************************* +; Processes & Draws 16x16 tiles in main and sub screen +;******************************************************* +NEWSYM draw16x1616bt + mov byte[drawn],0 + mov [temp],eax + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + xor ebx,ebx + mov bl,[curypos] + mov [temptile],edx + ; set up y adders + test byte[a16x16yinc],01h + jz .noincrc + mov word[yadd],16 + mov word[yflipadd],0 + jmp .yesincrc +.noincrc + mov word[yadd],0 + mov word[yflipadd],16 +.yesincrc + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x1616btwinon +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + + ; Start loop + drawtilegrp draw8x816bta +.hprior + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + drawtilegrpf draw8x816bta +.skiploop2b + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +NEWSYM draw16x1616btwinon + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + mov byte[tileleft16b],33 + mov ecx,[winptrref] + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov eax,ecx + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + mov ecx,eax + xor eax,eax + + ; Start loop + drawtilegrp draw8x816btawinon +.hprior + add esi,16 + add ecx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov eax,ecx + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + mov ecx,eax + xor eax,eax + drawtilegrpf draw8x816btawinon +.skiploop2b + add esi,16 + add ecx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +;******************************************************* +; Processes & Draws 16x16 tiles in 2, 4, & 8 bit mode +;******************************************************* + +NEWSYM draw16x1616t + mov byte[drawn],0 + mov [temp],eax + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + xor ebx,ebx + mov bl,[curypos] + mov [temptile],edx + ; set up y adders + test byte[a16x16yinc],01h + jz .noincrc + mov word[yadd],16 + mov word[yflipadd],0 + jmp .yesincrc +.noincrc + mov word[yadd],0 + mov word[yflipadd],16 +.yesincrc + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x1616twinon +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw16x1616ts + test byte[scaddtype],40h + jz near draw16x16fulladd + cmp byte[scrnon+1],0 + je near draw16x16fulladd + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816ta +.hprior + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpf draw8x816ta +.skiploop2b + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +NEWSYM yadd, dw 0 +NEWSYM yflipadd, dw 0 + +NEWSYM draw16x16fulladd + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + push edi + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tb +.hprior + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tb + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +NEWSYM draw16x1616ts + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + push edi + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tc +.hprior + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tc + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +NEWSYM draw16x1616twinon + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw16x1616tswinon + test byte[scaddtype],40h + jz near draw16x16fulladdwinon + cmp byte[scrnon+1],0 + je near draw16x16fulladdwinon + mov byte[tileleft16b],33 + mov edx,[winptrref] +.loopa + mov ax,[edi] + mov cl,ah + xor byte[a16x16xinc],1 + test cl,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + test cl,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test cl,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test cl,40h + jnz near .rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tawinon +.hprior + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc byte[temp] +.noincrb2 + cmp byte[temp],20h + jne .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpf draw8x816tawinonb +.skiploop2b + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc byte[temp] +.noincrb + cmp byte[temp],20h + jne near .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw16x16fulladdwinon + mov byte[tileleft16b],33 + mov edx,[winptrref] +.loopa + mov ax,[edi] + mov cl,ah + xor byte[a16x16xinc],1 + + test cl,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor cl,[curbgpr] + push edi + test cl,20h + jnz near .hprior + inc byte[drawn] + + test cl,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbwinon +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc byte[temp] +.noincrb2 + cmp byte[temp],20h + jne .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbwinonb + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc byte[temp] +.noincrb + cmp byte[temp],20h + jne near .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw16x1616tswinon + mov byte[tileleft16b],33 + mov edx,[winptrref] +.loopa + mov ax,[edi] + mov cl,ah + xor byte[a16x16xinc],1 + + test cl,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor cl,[curbgpr] + push edi + test cl,20h + jnz near .hprior + inc byte[drawn] + + test cl,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcwinon +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc byte[temp] +.noincrb2 + cmp byte[temp],20h + jne .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcwinonb + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc byte[temp] +.noincrb + cmp byte[temp],20h + jne near .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + \ No newline at end of file diff --git a/zsnes/src/video/makevid.asm b/zsnes/src/video/makevid.asm new file mode 100644 index 00000000..1a312574 --- /dev/null +++ b/zsnes/src/video/makevid.asm @@ -0,0 +1,4386 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM disableeffects,winl1,winl2,winbgdata,winr1,winr2,winspdata +EXTSYM winlogica +EXTSYM winenabm,winobjen +EXTSYM winlogicb +EXTSYM scrndis,scrnon +EXTSYM bgmode,bgtilesz,winbg1en,winenabs +EXTSYM bg1objptr,bg1ptr,bg1ptrb,bg1ptrc,bg1ptrd,bg1scrolx,bg1scroly +EXTSYM cachebg1,curbgofs1,curcolbg1,vcache2b,vcache4b,vcache8b +EXTSYM vcache2ba,vcache4ba,vcache8ba +EXTSYM vidbuffer +EXTSYM bg3highst,cbitmode,colormodedef,colormodeofs,drawline16b +EXTSYM forceblnk,newengine8b,preparesprpr,scaddset,spritetablea +EXTSYM sprleftpr,vidbright,ForceNewGfxOff +EXTSYM curypos,drawmode7,mode7set,mosaicon,mosaicsz,sprleftpr1,sprleftpr2 +EXTSYM sprleftpr3,sprlefttot,sprprifix,drawmode7extbg,interlval,drawmode7extbg2 +EXTSYM sprclprio,sprpriodata,sprsingle +EXTSYM cachetile2b,cachetile4b,cachetile8b,vram,CacheCheckSkip +EXTSYM cachetile2b16x16,cachetile4b16x16,cachetile8b16x16 +EXTSYM osm2dis,xtravbuf +EXTSYM bg3ptr,bg3scrolx,bg3scroly,cachesingle,colormoded2 +EXTSYM tempoffset,vidmemch2,vidmemch4,vidmemch8 +EXTSYM ofsmcptr,ofsmady,ofsmadx,yposng,yposngom,flipyposng,flipyposngom +EXTSYM ofsmtptr,ofsmmptr,ofsmcyps,bgtxadd,bg1ptrx,bg1ptry + +%include "video/vidmacro.mac" + + + + + +;drawspritesprio + +NEWSYM bgcoloradder, db 0 +NEWSYM res512switch, db 0 + +; mov cl,[bshifter] +;******************************************************* +; DrawLine Draws the current line +;******************************************************* +; use curypos+bg1scroly for y location and bg1scrolx for x location +; use bg1ptr(b,c,d) for the pointer to the tile number contents +; use bg1objptr for the pointer to the object tile contents + +%macro decideonmode 0 + cmp bl,2 + je .yes4bit + cmp bl,1 + je .yes2bit + mov byte[bshifter],6 + mov edx,[vcache8b] + jmp .skipbits +.yes4bit + mov byte[bshifter],2 + mov edx,[vcache4b] + shl eax,1 + jmp .skipbits +.yes2bit + mov byte[bshifter],0 + shl eax,2 + mov edx,[vcache2b] +.skipbits +%endmacro + +%macro procmode7 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz %%noflip + mov ax,261 + sub ax,[curypos] +%%noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz %%nomos + mov bl,[mosaicsz] + cmp bl,0 + je %%nomos + inc bl + mov [curmosaicsz],bl + xor edx,edx + xor bh,bh + div bx + xor edx,edx + mul bx + xor edx,edx + mov dl,[mosaicsz] + add ax,[MosaicYAdder+edx*2] +%%nomos + add ax,%1 + mov dx,%2 + call drawmode7 +%endmacro + +%macro procmode7extbg 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz %%noflip + mov ax,261 + sub ax,[curypos] +%%noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz %%nomos + mov bl,[mosaicsz] + cmp bl,0 + je %%nomos + inc bl + mov [curmosaicsz],bl + xor edx,edx + xor bh,bh + div bx + xor edx,edx + mul bx + xor edx,edx + mov dl,[mosaicsz] + add ax,[MosaicYAdder+edx*2] +%%nomos + add ax,%1 + mov dx,%2 + call drawmode7extbg +%endmacro + +%macro procmode7extbg2 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz %%noflip + mov ax,261 + sub ax,[curypos] +%%noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz %%nomos + mov bl,[mosaicsz] + cmp bl,0 + je %%nomos + inc bl + mov [curmosaicsz],bl + xor edx,edx + xor bh,bh + div bx + xor edx,edx + mul bx + xor edx,edx + mov dl,[mosaicsz] + add ax,[MosaicYAdder+edx*2] +%%nomos + add ax,%1 + mov dx,%2 + call drawmode7extbg2 +%endmacro + +NEWSYM MosaicYAdder, dw 0,0,0,1,0,2,1,0,0,4,2,2,3,1,0,7 + +NEWSYM pwinbgenab, db 0 +NEWSYM pwinbgtype, dd 0 +NEWSYM winonbtype, db 0 +NEWSYM dualwinbg, db 0 +NEWSYM pwinspenab, db 0 +NEWSYM pwinsptype, dd 0 +NEWSYM winonstype, db 0 +NEWSYM dualwinsp, db 0 +NEWSYM cwinptr, dd winbgdata +NEWSYM dwinptrproc, dd 0 + +; is this macro even used? +%macro ClearWindowData 0 + mov edi,winbgdata+16 + xor eax,eax + mov ecx,64 + rep stosd +%endmacro + +NEWSYM makewindow + ; upon entry, al = win enable bits + cmp byte[disableeffects],1 + je near .finishwin + mov bl,al + and bl,00001010b + cmp bl,00001010b + je near makedualwin + cmp bl,0 + je near .finishwin + mov byte[winon],1 + mov ebx,[winl1] + ; check if data matches previous sprite data + cmp al,[pwinspenab] + jne .skipsprcheck + cmp ebx,[pwinsptype] + jne .skipsprcheck + mov dword[cwinptr],winspdata+16 + mov al,[winonstype] + mov [winon],al + ret +.skipsprcheck + ; check if data matches previous data + cmp al,[pwinbgenab] + jne .skipenab + cmp ebx,[pwinbgtype] + jne .skipenab2 + mov dword[cwinptr],winbgdata+16 + mov al,[winonbtype] + mov [winon],al + ret +.skipenab + mov [pwinbgenab],al + mov ebx,[winl1] +.skipenab2 + mov [pwinbgtype],ebx + mov dl,[winl1] + mov dh,[winr1] + test al,00000010b + jnz .win1 + mov dl,[winl2] + mov dh,[winr2] + shr al,2 +.win1 + test al,01h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + mov byte[winon],0 + mov byte[winonbtype],0 + ret +.clip + mov edi,winbgdata+16 + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 +.nextdot + mov byte[edi+eax],0 + inc al + cmp al,dl + jb .nextdot ; blah +.nextdot2 + mov byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + mov byte[edi+eax],1 + cmp dh,255 + je .nextdot4 + ; start drawing 1's from right to 255 +.nextdot3 + mov byte[edi+eax],0 + inc al + jnz .nextdot3 +.nextdot4 + mov byte[winon],1 + mov byte[winonbtype],1 + mov dword[cwinptr],winbgdata+16 + ret +.outside + cmp dl,dh + jb .clip2 + mov byte[winon],0FFh + mov byte[winonbtype],0FFh + mov dword[cwinptr],winbgdata+16 + ret +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,winbgdata+16 + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + mov byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti +.nextdot2i + mov byte[edi+eax],0 + inc al + cmp al,dh + jb .nextdot2i + mov byte[edi+eax],0 + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + mov byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i + mov byte[winon],1 + mov byte[winonbtype],1 + mov dword[cwinptr],winbgdata+16 + ret +.finishwin + ret + +NEWSYM makedualwin + mov ecx,ebp + shl cl,1 + mov dl,[winlogica] + shr dl,cl + and dl,03h + mov cl,dl + mov byte[winon],1 + mov ebx,[winl1] + ; check if data matches previous sprite data + cmp cl,[dualwinsp] + jne .skipsprcheck + cmp al,[pwinspenab] + jne .skipsprcheck + cmp ebx,[pwinsptype] + jne .skipsprcheck + mov dword[cwinptr],winspdata+16 + mov al,[winonstype] + mov [winon],al + ret +.skipsprcheck + ; check if data matches previous data + cmp cl,[dualwinbg] + jne .skipenab3 + cmp al,[pwinbgenab] + jne .skipenab + cmp ebx,[pwinbgtype] + jne .skipenab2 + mov dword[cwinptr],winbgdata+16 + mov al,[winonbtype] + mov [winon],al + ret +.skipenab3 + mov [dualwinbg],cl +.skipenab + mov [pwinbgenab],al + mov ebx,[winl1] +.skipenab2 + mov [pwinbgtype],ebx + mov dword[dwinptrproc],winbgdata+16 + mov dword[cwinptr],winbgdata+16 + mov byte[winon],1 + mov byte[winonbtype],1 + +NEWSYM dualstartprocess + + mov dl,[winl1] + mov dh,[winr1] + + push eax + push ecx + test al,01h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + mov edi,[dwinptrproc] + xor eax,eax + mov ecx,64 + rep stosd + jmp .donextwin +.clip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 +.nextdot + mov byte[edi+eax],0 + inc al + cmp al,dl + jbe .nextdot +.nextdot2 + mov byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + mov byte[edi+eax],1 + cmp dh,255 + je .nextdot4 + ; start drawing 1's from right to 255 +.nextdot3 + mov byte[edi+eax],0 + inc al + jnz .nextdot3 +.nextdot4 + jmp .donextwin +.outside + cmp dl,dh + jb .clip2 + mov edi,[dwinptrproc] + mov eax,01010101h + mov ecx,64 + rep stosd + jmp .donextwin +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + mov byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti +.nextdot2i + mov byte[edi+eax],0 + inc al + cmp al,dh + jb .nextdot2i + mov byte[edi+eax],0 + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + mov byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i +.donextwin + pop ecx + pop eax + cmp cl,0 + je near dualwinor + cmp cl,2 + je near dualwinxor + cmp cl,3 + je near dualwinxnor + +NEWSYM dualwinand + mov dl,[winl2] + mov dh,[winr2] + test al,04h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + mov edi,[dwinptrproc] + xor eax,eax + mov ecx,64 + rep stosd + jmp .donextwin +.clip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 +.nextdot + mov byte[edi+eax],0 + inc al + cmp al,dl + jbe .nextdot +.nextdot2 + and byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + and byte[edi+eax],1 + cmp dh,255 + je .nextdot4 + ; start drawing 1's from right to 255 +.nextdot3 + mov byte[edi+eax],0 + inc al + jnz .nextdot3 +.nextdot4 + jmp .donextwin +.outside + cmp dl,dh + jb .clip2 + jmp .donextwin +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + and byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti +.nextdot2i + mov byte[edi+eax],0 + inc al + cmp al,dh + jb .nextdot2i + mov byte[edi+eax],0 + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + and byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i +.donextwin + ret + +NEWSYM dualwinor + mov dl,[winl2] + mov dh,[winr2] + test al,04h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + jmp .donextwin +.clip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 + mov al,dl + inc al +.nextdot2 + mov byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + mov byte[edi+eax],1 + jmp .donextwin +.outside + cmp dl,dh + jb .clip2 + mov edi,[dwinptrproc] + mov eax,01010101h + mov ecx,64 + rep stosd + jmp .donextwin +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + mov byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti + mov al,dh + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + mov byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i +.donextwin + ret + +NEWSYM dualwinxor + mov dl,[winl2] + mov dh,[winr2] + test al,04h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + jmp .donextwin +.clip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 + mov al,dl + inc al +.nextdot2 + xor byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + xor byte[edi+eax],1 + jmp .donextwin +.outside + cmp dl,dh + jb .clip2 + mov edi,[dwinptrproc] + mov ecx,64 +.loopxor + xor dword[edi],01010101h + add edi,4 + dec ecx + jnz .loopxor + jmp .donextwin +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + xor byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti + mov al,dh + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + xor byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i +.donextwin + ret + +NEWSYM dualwinxnor + mov dl,[winl2] + mov dh,[winr2] + test al,04h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + jmp .donextwin +.clip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 + mov al,dl + inc al +.nextdot2 + xor byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + xor byte[edi+eax],1 + jmp .donextwin +.outside + cmp dl,dh + jb .clip2 + mov edi,[dwinptrproc] + mov ecx,64 +.loopxor + xor dword[edi],01010101h + add edi,4 + dec ecx + jnz .loopxor + jmp .donextwin +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,[dwinptrproc] + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + xor byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti + mov al,dh + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + xor byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i +.donextwin + mov edi,[dwinptrproc] + mov ecx,64 +.loopxor2 + xor dword[edi],01010101h + add edi,4 + dec ecx + jnz .loopxor2 + ret + +;pwinspenab db 0 +;pwinsptype dd 0 +;winonstype db 0 +;dualwinsp db 0 +NEWSYM winonsp, db 0 + +NEWSYM makewindowsp + mov al,[winobjen] + mov byte[winonsp],0 + test dword[winenabm],1010h + jz near .finishwin + ; upon entry, al = win enable bits + cmp byte[disableeffects],1 + je near .finishwin + mov bl,al + and bl,00001010b + cmp bl,00001010b + je near makedualwinsp + cmp bl,0 + je near .finishwin + mov byte[winonsp],1 + ; check if data matches previous data + cmp al,[pwinspenab] + jne .skipenab + mov ebx,[winl1] + cmp ebx,[pwinsptype] + jne .skipenab2 + mov dword[cwinptr],winspdata+16 + mov al,[winonstype] + mov [winonsp],al + ret +.skipenab + mov [pwinspenab],al + mov ebx,[winl1] +.skipenab2 + mov [pwinsptype],ebx + mov dl,[winl1] + mov dh,[winr1] + test al,00000010b + jnz .win1 + mov dl,[winl2] + mov dh,[winr2] + shr al,2 +.win1 + test al,01h + jnz near .outside + cmp dl,254 + je .clipped + cmp dl,dh + jb .clip +.clipped + mov byte[winonsp],0 + mov byte[winonstype],0 + ret +.clip + mov edi,winspdata+16 + xor eax,eax + ; start drawing 1's from 0 to left + cmp dl,0 + je .nextdot2 +.nextdot + mov byte[edi+eax],0 + inc al + cmp al,dl + jbe .nextdot +.nextdot2 + mov byte[edi+eax],1 + inc al + cmp al,dh + jb .nextdot2 + mov byte[edi+eax],1 + cmp dh,255 + je .nextdot4 + ; start drawing 1's from right to 255 +.nextdot3 + mov byte[edi+eax],0 + inc al + jnz .nextdot3 +.nextdot4 + mov byte[winonsp],1 + mov byte[winonstype],1 + mov dword[cwinptr],winspdata+16 + ret +.outside + cmp dl,dh + jb .clip2 + mov byte[winonsp],0FFh + mov byte[winonstype],0FFh + mov dword[cwinptr],winspdata+16 + ret +.clip2 + cmp dl,1 + ja .nooutclip + cmp dh,254 + jae near .clipped +.nooutclip + mov edi,winspdata+16 + xor eax,eax + ; start drawing 1's from 0 to left +.nextdoti + mov byte[edi+eax],1 + inc al + cmp al,dl + jb .nextdoti +.nextdot2i + mov byte[edi+eax],0 + inc al + cmp al,dh + jb .nextdot2i + mov byte[edi+eax],0 + cmp al,255 + je .nextdot4i + inc al + ; start drawing 1's from right to 255 +.nextdot3i + mov byte[edi+eax],1 + inc al + jnz .nextdot3i +.nextdot4i + mov byte[winonsp],1 + mov byte[winonstype],1 + mov dword[cwinptr],winspdata+16 + ret +.finishwin + ret + +NEWSYM makedualwinsp + mov ecx,ebp + shl cl,1 + mov dl,[winlogicb] + and dl,03h + mov cl,dl + mov byte[winonsp],1 + ; check if data matches previous data + cmp cl,[dualwinsp] + jne .skipenab3 + cmp al,[pwinspenab] + jne .skipenab + mov ebx,[winl1] + cmp ebx,[pwinsptype] + jne .skipenab2 + mov dword[cwinptr],winspdata+16 + mov al,[winonstype] + mov [winonsp],al + ret +.skipenab3 + mov [dualwinsp],cl +.skipenab + mov [pwinspenab],al + mov ebx,[winl1] +.skipenab2 + mov [pwinsptype],ebx + mov dword[dwinptrproc],winspdata+16 + mov dword[cwinptr],winspdata+16 + mov byte[winonsp],1 + mov byte[winonstype],1 + jmp dualstartprocess + +; window logic data +NEWSYM windowdata, times 16 db 0 +NEWSYM numwin, db 0 +NEWSYM multiwin, db 0 +NEWSYM multiclip, db 0 +NEWSYM multitype, db 0 + +; jmp .finishwin +%macro procwindow 1 + cmp byte[disableeffects],1 + je near .finishwin + mov al,%1 + test al,00001010b + jz near .finishwin + mov esi,windowdata + mov bl,al + mov byte[winon],1 + and bl,00001010b + and al,00000101b + mov byte[numwin],0 + cmp bl,00001010b + je near .multiwin + mov byte[multiwin],0 + test bl,00000010b + jnz .win1 + mov cl,[winl2] + mov ch,[winr2] + shr al,2 + jmp .okaywin +.win1 + mov cl,[winl1] + mov ch,[winr1] + and al,01h +.okaywin + cmp ch,255 + je .noinc + inc ch +.noinc + test al,01h + jnz .wininside + cmp cl,ch + jae .noinsidemask + mov [esi],cl + mov byte[esi+1],01h + mov [esi+2],ch + mov byte[esi+3],0FFh + mov byte[numwin],2 + jmp .finishwin +.noinsidemask + mov byte[winon],0 + jmp .finishwin +.wininside + cmp cl,ch + ja .nooutsidemask +.nonotoutside + cmp ch,254 + jb .skipnodraw + cmp cl,1 + jbe .noinsidemask +.skipnodraw + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[esi+2],cl + mov byte[esi+3],0FFh + mov byte[esi+4],ch + mov byte[esi+5],01h + mov byte[numwin],3 + jmp .finishwin +.nooutsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[numwin],1 + jmp .finishwin + ; ************** + ; *Multiwindows* + ; ************** +.multiwin + mov byte[winon],0 + mov byte[multiwin],0 + mov byte[multiclip],al + mov al,[winlogica] + mov ecx,ebp + shl ecx,1 + shr al,cl + and al,3h + mov byte[multitype],al + mov cl,[winl1] + mov ch,[winr1] + mov esi,windowdata + cmp ch,255 + je .noinc2 + inc ch +.noinc2 + test byte[multiclip],01h + jnz .wininside2 + cmp cl,ch + jae .nowina + mov [esi],cl + mov byte[esi+1],01h + mov [esi+2],ch + mov byte[esi+3],0FFh + add esi,4 + mov byte[numwin],2 + jmp .secondwin +.nowina + mov cl,[winl2] + mov ch,[winr2] + mov al,[multiclip] + shr al,2 + jmp .okaywin +.wininside2 + cmp cl,ch + ja .nooutsidemask2 + cmp ch,254 + jb .skipnodraw2 + cmp cl,1 + jbe .nooutsidemask2 +.skipnodraw2 + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[esi+2],cl + mov byte[esi+3],0FFh + mov byte[esi+4],ch + mov byte[esi+5],01h + mov byte[numwin],3 + jmp .secondwin +.nooutsidemask2 + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[numwin],1 +.secondwin + mov byte[multiwin],1 + mov byte[winon],1 +.finishwin +%endmacro + +NEWSYM procspritessub + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon+1],10h + jz .nosprites + test byte[scrnon],10h + jnz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + or cl,cl + jz .nosprites + call drawsprites +.nosprites + ret + +NEWSYM procspritesmain + test byte[scrndis],10h + jnz .nosprites + test byte[scrnon],10h + jz .nosprites + cmp byte[winonsp],0FFh + je .nosprites + xor ebx,ebx + mov bl,[curypos] + add ebx,[cursprloc] + mov cl,[ebx] + cmp byte[sprprifix],0 + jne .sprprio + add dword[cursprloc],256 +.sprprio + or cl,cl + jz .nosprites + call drawsprites +.nosprites + ret + +NEWSYM curbgnum, db 0 + +NEWSYM drawbackgrndsub + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon+1],al + jz near .noback + test byte[scrnon],al + jnz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabs],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + shl eax,5 + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x8 + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn + jmp .noback +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x16 + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb +.noback + ret + +NEWSYM drawbackgrndmain + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + test byte[scrnon],al + jz near .noback + test byte[alreadydrawn],al + jnz near .noback + test byte[scrndis],al + jnz near .noback + mov byte[winon],0 + test byte[winenabm],al + jz near .nobackwin +; procwindow [winbg1en+ebp] + mov al,[winbg1en+ebp] + call makewindow + cmp byte[winon],0FFh + je near .noback +.nobackwin + mov bl,[curbgnum] + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl +.nomos + mov byte[bgcoloradder],0 + cmp byte[bgmode],0 + jne .nomode0 + mov eax,ebp + shl eax,5 + mov byte[bgcoloradder],al +.nomode0 + mov esi,[bg1vbufloc+ebp*4] + mov edi,[bg1tdatloc+ebp*4] + mov edx,[bg1tdabloc+ebp*4] + mov ebx,[bg1cachloc+ebp*4] + mov eax,[bg1xposloc+ebp*4] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw8x8 + cmp byte[drawn],33 + jne .notalldrawn + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawn + jmp .noback +.16x16 + mov ecx,[bg1yaddval+ebp*4] + call draw16x16 + cmp byte[drawn],33 + jne .notalldrawnb + mov al,[curbgnum] + or [alreadydrawn],al +.notalldrawnb +.noback + ret + +NEWSYM procbackgrnd + mov esi,[colormodeofs] + mov bl,[esi+ebp] + cmp bl,0 + je near .noback + mov al,[curbgnum] + mov ah,al + test byte[scrndis],al + jnz near .noback + test [scrnon],ax + jz near .noback + push ebp + shl ebp,6 + mov edi,cachebg1 + add edi,ebp + pop ebp + cmp bl,[curcolbg1+ebp] + je .skipclearcache + mov [curcolbg1+ebp],bl + mov ax,[bg1ptr+ebp*2] + mov [curbgofs1+ebp*2],ax + call fillwithnothing +.skipclearcache + xor eax,eax + mov [curcolor],bl + mov ax,[bg1objptr+ebp*2] + decideonmode + add edx,eax + xor eax,eax + mov [tempcach],edx + xor edx,edx + mov ax,[bg1objptr+ebp*2] + mov [curtileptr],ax + mov ax,[bg1ptr+ebp*2] + mov [bgptr],ax + cmp ax,[curbgofs1+ebp*2] + je .skipclearcacheb + mov [curbgofs1+ebp*2],ax + call fillwithnothing +.skipclearcacheb + mov ax,[bg1ptrb+ebp*2] + mov [bgptrb],ax + mov ax,[bg1ptrc+ebp*2] + mov [bgptrc],ax + mov ax,[bg1ptrd+ebp*2] + mov [bgptrd],ax + mov bl,[curbgnum] + mov ax,[curypos] + + mov byte[curmosaicsz],1 + test byte[mosaicon],bl + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor edx,edx + xor bh,bh + div bx + xor edx,edx + mul bx + xor edx,edx + mov dl,[mosaicsz] + add ax,[MosaicYAdder+edx*2] +.nomos + + add ax,[bg1scroly+ebp*2] + mov dx,[bg1scrolx+ebp*2] + mov cl,[curbgnum] + test byte[bgtilesz],cl + jnz .16x16 + call proc8x8 + mov [bg1vbufloc+ebp*4],esi + mov [bg1tdatloc+ebp*4],edi + mov [bg1tdabloc+ebp*4],edx + mov [bg1cachloc+ebp*4],ebx + mov [bg1yaddval+ebp*4],ecx + mov [bg1xposloc+ebp*4],eax + ret +.16x16 + call proc16x16 + mov [bg1vbufloc+ebp*4],esi + mov [bg1tdatloc+ebp*4],edi + mov [bg1tdabloc+ebp*4],edx + mov [bg1cachloc+ebp*4],ebx + mov [bg1yaddval+ebp*4],ecx + mov [bg1xposloc+ebp*4],eax +.noback + ret + +NEWSYM nextprimode, db 0 +NEWSYM cursprloc, dd 0 +NEWSYM curcolor, db 0 +NEWSYM curtileptr, dw 0 +; esi = pointer to video buffer +; edi = pointer to tile data +; ebx = cached memory +; al = current x position +NEWSYM bg1vbufloc, dd 0 +NEWSYM bg2vbufloc, dd 0 +NEWSYM bg3vbufloc, dd 0 +NEWSYM bg4vbufloc, dd 0 +NEWSYM bg1tdatloc, dd 0 +NEWSYM bg2tdatloc, dd 0 +NEWSYM bg3tdatloc, dd 0 +NEWSYM bg4tdatloc, dd 0 +NEWSYM bg1tdabloc, dd 0 +NEWSYM bg2tdabloc, dd 0 +NEWSYM bg3tdabloc, dd 0 +NEWSYM bg4tdabloc, dd 0 +NEWSYM bg1cachloc, dd 0 +NEWSYM bg2cachloc, dd 0 +NEWSYM bg3cachloc, dd 0 +NEWSYM bg4cachloc, dd 0 +NEWSYM bg1yaddval, dd 0 +NEWSYM bg2yaddval, dd 0 +NEWSYM bg3yaddval, dd 0 +NEWSYM bg4yaddval, dd 0 +NEWSYM bg1xposloc, dd 0 +NEWSYM bg2xposloc, dd 0 +NEWSYM bg3xposloc, dd 0 +NEWSYM bg4xposloc, dd 0 +NEWSYM alreadydrawn, db 0 + +NEWSYM fillwithnothing + push edi + xor eax,eax + mov ecx,16 +.loop + mov [edi],eax + add edi,4 + dec ecx + jnz .loop + pop edi + ret + +NEWSYM bg3draw, db 0 +NEWSYM maxbr, db 0 +NEWSYM blanker + ; calculate current video offset + push ebx + push esi + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,8 + shl ebx,5 + add esi,ebx + add esi,16 + add esi,[vidbuffer] + mov bl,64 +.next + mov dword[esi],0 + add esi,4 + dec bl + jnz .next + pop esi + pop ebx + ret + +ALIGN32 +NEWSYM bg3high2, dd 0 +NEWSYM newengen, dd 0 +NEWSYM cwinenabm, dd 0 + +NEWSYM drawline + mov al,[winenabs] + mov [cwinenabm],al + + mov byte[bg3high2],0 + cmp byte[bgmode],1 + jne .nohigh + mov al,[bg3highst] + mov [bg3high2],al +.nohigh + cmp byte[cbitmode],1 + je near drawline16b + mov al,[vidbright] + cmp al,[maxbr] + jbe .nochange + mov [maxbr],al +.nochange + cmp byte[ForceNewGfxOff],0 + jne .nonewgfx + cmp byte[newengen],1 + je near newengine8b +.nonewgfx + cmp byte[forceblnk],0 + jne near blanker + mov byte[alreadydrawn],0 +; cmp byte[curypos],70 +; jne .no +; push ebx +; mov bl,[winlogica] +; mov [bg1sx],bl +; pop ebx +;.no + push ebx + xor ebx,ebx + mov bl,[bgmode] + shl bl,2 + add ebx,colormodedef + mov [colormodeofs],ebx + pop ebx + + cmp byte[bgmode],7 + je near processmode7 + + mov al,[scrnon] + test [scrnon+1],al + jz .nomainsub + test byte[scrnon],10h + jnz .nomainsub + test byte[scrnon+1],10h + jz .nomainsub + mov al,[scrnon+1] + xor al,0FFh + and [scrnon],al +.nomainsub + + push esi + push edi + push ebx + push edx + push ebp + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,8 + shl ebx,5 + add esi,ebx + add esi,16 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; clear video buffer + mov edi,esi + mov ecx,64 + xor eax,eax + rep stosd + ; do sprite windowing + call makewindowsp + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + mov dword[cursprloc],sprleftpr + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio + ; clear registers + xor eax,eax + xor ecx,ecx +; process backgrounds +; do background 2 + mov byte[curbgnum],02h + mov ebp,01h + call procbackgrnd +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call procbackgrnd +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call procbackgrnd +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call procbackgrnd + + cmp byte[bgmode],1 + ja near priority2 + test byte[scaddset],02h + jz near .nosubsc +; draw backgrounds + mov byte[curbgpr],0h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndsub +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndsub + mov ebp,0 + call procspritessub + mov byte[curbgpr],20h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndsub +; do background 3 + cmp byte[bg3high2],1 + je .bg3nothigh + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndsub +.bg3nothigh + mov ebp,1 + call procspritessub +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub + mov ebp,2 + call procspritessub +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub + mov ebp,3 + call procspritessub + cmp byte[bg3high2],1 + jne .bg3high +; do background 3 + mov byte[curbgpr],20h + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndsub +.bg3high + +.nosubsc + mov al,[winenabm] + mov [cwinenabm],al + mov byte[curbgpr],0h + +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndmain +; do background 3 + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain + mov ebp,0 + call procspritesmain + mov byte[curbgpr],20h +; do background 4 + mov byte[curbgnum],08h + mov ebp,03h + call drawbackgrndmain +; do background 3 + cmp byte[bg3high2],1 + je .bg3nothighb + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain +.bg3nothighb + mov ebp,1 + call procspritesmain +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain + mov ebp,2 + call procspritesmain +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain + mov ebp,3 + call procspritesmain + cmp byte[bg3high2],1 + jne .bg3highb +; do background 3 + mov byte[curbgpr],20h + mov byte[curbgnum],04h + mov ebp,02h + call drawbackgrndmain +.bg3highb + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx +NEWSYM nodrawline + ret + +NEWSYM priority2 + test byte[scaddset],02h + jz near .nosubsc +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub + mov ebp,0 + call procspritessub +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub + mov ebp,1 + call procspritessub +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndsub + mov ebp,2 + call procspritessub +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndsub + mov ebp,3 + call procspritessub +.nosubsc + mov al,[winenabm] + mov [cwinenabm],al +; do background 2 + mov byte[curbgpr],0h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain + mov ebp,0 + call procspritesmain +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain + mov ebp,1 + call procspritesmain +; do background 2 + mov byte[curbgpr],20h + mov byte[curbgnum],02h + mov ebp,01h + call drawbackgrndmain + mov ebp,2 + call procspritesmain +; do background 1 + mov byte[curbgnum],01h + mov ebp,00h + call drawbackgrndmain + mov ebp,3 + call procspritesmain + pop ebp + pop edx + pop ebx + pop edi + pop esi + xor eax,eax + xor ecx,ecx + ret + +ALIGN32 +NEWSYM tempbuffer, times 33 dd 0 +NEWSYM currentobjptr, dd 0 +NEWSYM curmosaicsz, dd 0 +NEWSYM extbgdone, db 0 + + +NEWSYM processmode7 + mov al,[winenabm] + mov [cwinenabm],al + push esi + push edi + push ebx + push edx + push ebp + ; get current sprite table + xor ebx,ebx + mov bl,[curypos] + shl ebx,9 + add ebx,[spritetablea] + mov [currentobjptr],ebx + ; setup priorities + cmp byte[sprprifix],0 + je .nosprprio + mov dword[cursprloc],sprlefttot + call preparesprpr +.nosprprio + ; calculate current video offset + xor ebx,ebx + mov bx,[curypos] + mov esi,ebx + shl esi,8 + shl ebx,5 + add esi,ebx + add esi,16 + add esi,[vidbuffer] + mov [curvidoffset],esi + ; clear video buffer + mov edi,esi + mov ecx,64 + xor eax,eax + rep stosd + ; do sprite windowing + call makewindowsp + ; clear registers + xor eax,eax + xor ecx,ecx + + mov byte[extbgdone],0 + + test byte[interlval],40h + jz near .noback0 + test byte[scrndis],02h + jnz near .noback0 + ; do background 1, extbg pr 0 + test word[scrnon],0202h + jz near .noback0 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin0 + test word[winenabm],0100h + jnz near .nobackwin0 + mov ebp,0 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback0 +.nobackwin0 + mov byte[extbgdone],1 + procmode7extbg [bg1scroly],[bg1scrolx],1 +.noback0 + + ; do objects + test byte[scrndis],10h + jnz near .nosprites1 + test word[scrnon],1010h + jz near .nosprites1 + cmp byte[winonsp],0FFh + je .nosprites1 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr+ebx] + cmp byte[sprprifix],0 + je .nosprprio2 + mov cl,[sprlefttot+ebx] +.nosprprio2 + cmp cl,0 + je .nosprites1 + mov ebp,0 + call drawsprites +.nosprites1 + + ; display mode7 + test byte[interlval],40h + jnz near .noback1 + test byte[scrndis],01h + jnz near .noback1 + ; do background 1 + test word[scrnon],0101h + jz near .noback1 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin1 + test word[winenabm],0100h + jnz near .nobackwin1 + mov ebp,0 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback1 +.nobackwin1 + procmode7 [bg1scroly],[bg1scrolx],1 +.noback1 + + ; do objects + test byte[scrndis],10h + jnz near .nosprites2 + test word[scrnon],1010h + jz near .nosprites2 + cmp byte[winonsp],0FFh + je .nosprites2 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr1+ebx] + cmp byte[sprprifix],0 + je .nosprprio3 + mov cl,[sprlefttot+ebx] +.nosprprio3 + cmp cl,0 + je .nosprites2 + mov ebp,1 + call drawsprites +.nosprites2 + + test byte[interlval],40h + jz near .noback0b + cmp byte[extbgdone],0 + jne near .noback0b + test byte[scrndis],02h + jnz near .noback0b + ; do background 1, extbg pr 0 + test word[scrnon],0101h + jz near .noback0b + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin0b + test word[winenabm],0100h + jnz near .nobackwin0b + mov ebp,0 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback0b +.nobackwin0b + mov byte[extbgdone],1 + procmode7extbg [bg1scroly],[bg1scrolx],1 +.noback0b + + test byte[interlval],40h + jz near .noback2 + cmp byte[extbgdone],1 + jne near .noback2 + mov byte[winon],0 + test word[winenabm],0001h + jz near .nobackwin2 + test word[winenabm],0100h + jnz near .nobackwin2 + mov ebp,0 + mov al,[winbg1en] + call makewindow + cmp byte[winon],0FFh + je near .noback2 +.nobackwin2 + procmode7extbg2 [bg1scroly],[bg1scrolx],1 +.noback2 + + ; do objects + test byte[scrndis],10h + jnz near .nosprites3 + test word[scrnon],1010h + jz near .nosprites3 + cmp byte[winonsp],0FFh + je .nosprites3 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr2+ebx] + cmp byte[sprprifix],0 + je .nosprprio4 + mov cl,[sprlefttot+ebx] +.nosprprio4 + cmp cl,0 + je .nosprites3 + mov ebp,2 + call drawsprites +.nosprites3 + ; do objects + test byte[scrndis],10h + jnz near .nosprites4 + test word[scrnon],1010h + jz near .nosprites4 + cmp byte[winonsp],0FFh + je .nosprites4 + xor ebx,ebx + mov bl,[curypos] + mov cl,[sprleftpr3+ebx] + cmp byte[sprprifix],0 + je .nosprprio5 + mov cl,[sprlefttot+ebx] +.nosprprio5 + cmp cl,0 + je .nosprites4 + mov ebp,3 + call drawsprites +.nosprites4 + pop ebp + pop edx + pop ebx + pop edi + pop esi + ret + +;******************************************************* +; Processes & Draws 4-bit sprites +;******************************************************* + +NEWSYM drawsprites + cmp byte[sprprifix],1 + je near drawspritesprio +.returnfrompr + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near drawspriteswinon +.drawnowin + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + mov eax,[esi] + test al,0Fh + jz .skipa + add al,ch + mov [edi+ebx-8],al +.skipa + test ah,0Fh + jz .skipb + add ah,ch + mov [edi+ebx-7],ah +.skipb + shr eax,16 + test al,0Fh + jz .skipc + add al,ch + mov [edi+ebx-6],al +.skipc + test ah,0Fh + jz .skipd + add ah,ch + mov [edi+ebx-5],ah +.skipd + mov eax,[esi+4] + test al,0Fh + jz .skipe + add al,ch + mov [edi+ebx-4],al +.skipe + test ah,0Fh + jz .skipf + add ah,ch + mov [edi+ebx-3],ah +.skipf + shr eax,16 + test al,0Fh + jz .skipg + add al,ch + mov [edi+ebx-2],al +.skipg + test ah,0Fh + jz .skiph + add ah,ch + mov [edi+ebx-1],ah +.skiph + add edx,8 + mov esi,edx + dec cl + jnz .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + mov eax,[esi] + test al,0Fh + jz .skipa2 + add al,ch + mov [edi+ebx-1],al +.skipa2 + test ah,0Fh + jz .skipb2 + add ah,ch + mov [edi+ebx-2],ah +.skipb2 + shr eax,16 + test al,0Fh + jz .skipc2 + add al,ch + mov [edi+ebx-3],al +.skipc2 + test ah,0Fh + jz .skipd2 + add ah,ch + mov [edi+ebx-4],ah +.skipd2 + mov eax,[esi+4] + test al,0Fh + jz .skipe2 + add al,ch + mov [edi+ebx-5],al +.skipe2 + test ah,0Fh + jz .skipf2 + add ah,ch + mov [edi+ebx-6],ah +.skipf2 + shr eax,16 + test al,0Fh + jz .skipg2 + add al,ch + mov [edi+ebx-7],al +.skipg2 + test ah,0Fh + jz .skiph2 + add ah,ch + mov [edi+ebx-8],ah +.skiph2 + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawspriteswinon + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + mov eax,[esi] + test al,0Fh + jz .skipa + cmp byte[winspdata+ebx-8+16],0 + jne .skipa + add al,ch + mov [edi+ebx-8],al +.skipa + test ah,0Fh + jz .skipb + cmp byte[winspdata+ebx-7+16],0 + jne .skipb + add ah,ch + mov [edi+ebx-7],ah +.skipb + shr eax,16 + test al,0Fh + jz .skipc + cmp byte[winspdata+ebx-6+16],0 + jne .skipc + add al,ch + mov [edi+ebx-6],al +.skipc + test ah,0Fh + jz .skipd + cmp byte[winspdata+ebx-5+16],0 + jne .skipd + add ah,ch + mov [edi+ebx-5],ah +.skipd + mov eax,[esi+4] + test al,0Fh + jz .skipe + cmp byte[winspdata+ebx-4+16],0 + jne .skipe + add al,ch + mov [edi+ebx-4],al +.skipe + test ah,0Fh + jz .skipf + cmp byte[winspdata+ebx-3+16],0 + jne .skipf + add ah,ch + mov [edi+ebx-3],ah +.skipf + shr eax,16 + test al,0Fh + jz .skipg + cmp byte[winspdata+ebx-2+16],0 + jne .skipg + add al,ch + mov [edi+ebx-2],al +.skipg + test ah,0Fh + jz .skiph + cmp byte[winspdata+ebx-1+16],0 + jne .skiph + add ah,ch + mov [edi+ebx-1],ah +.skiph + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +.drawspriteflipx + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + mov eax,[esi] + test al,0Fh + jz .skipa2 + cmp byte[winspdata+ebx-1+16],0 + jne .skipa2 + add al,ch + mov [edi+ebx-1],al +.skipa2 + test ah,0Fh + jz .skipb2 + cmp byte[winspdata+ebx-2+16],0 + jne .skipb2 + add ah,ch + mov [edi+ebx-2],ah +.skipb2 + shr eax,16 + test al,0Fh + jz .skipc2 + cmp byte[winspdata+ebx-3+16],0 + jne .skipc2 + add al,ch + mov [edi+ebx-3],al +.skipc2 + test ah,0Fh + jz .skipd2 + cmp byte[winspdata+ebx-4+16],0 + jne .skipd2 + add ah,ch + mov [edi+ebx-4],ah +.skipd2 + mov eax,[esi+4] + test al,0Fh + jz .skipe2 + cmp byte[winspdata+ebx-5+16],0 + jne .skipe2 + add al,ch + mov [edi+ebx-5],al +.skipe2 + test ah,0Fh + jz .skipf2 + cmp byte[winspdata+ebx-6+16],0 + jne .skipf2 + add ah,ch + mov [edi+ebx-6],ah +.skipf2 + shr eax,16 + test al,0Fh + jz .skipg2 + cmp byte[winspdata+ebx-7+16],0 + jne .skipg2 + add al,ch + mov [edi+ebx-7],al +.skipg2 + test ah,0Fh + jz .skiph2 + cmp byte[winspdata+ebx-8+16],0 + jne .skiph2 + add ah,ch + mov [edi+ebx-8],ah +.skiph2 + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + mov [currentobjptr],esi + ret + +NEWSYM drawspritesprio + cmp byte[sprclprio+ebp],0 + je near .endobj + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near drawspritespriowinon +.drawnowin + cmp dword[sprsingle],1 + je near .drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,ebp + jne near .notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,ebp + jne near .notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa sprdrawprb + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf sprdrawprb + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + ret + +NEWSYM drawspritespriowinon + cmp dword[sprsingle],1 + je near .drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,ebp + jne near .notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpraw + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,ebp + jne near .notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpraw + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa sprdrawprbw + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf sprdrawprbw + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + ret + +NEWSYM prfixobjl, db 0 +NEWSYM csprbit, db 1 +NEWSYM csprprlft, db 0 +;******************************************************* +; Processes & Draws 8x8 tiles in 2, 4, & 8 bit mode +;******************************************************* +NEWSYM proc8x8 + cmp byte[bgmode],5 + je near proc16x8 + ; ax = # of rows down + mov ebx,eax + shr eax,3 + and eax,63 + and ebx,07h + cmp byte[CacheCheckSkip],1 + je .docache + cmp byte[edi+eax],0 + jne .nocachereq +.docache +; cmp byte[ccud],0 +; jne .nocachereq + mov byte[edi+eax],1 + cmp byte[curcolor],2 + jne .no4b + ; cache 4-bit + call cachetile4b + jmp .nocachereq +.no4b + cmp byte[curcolor],1 + je .2b + ; cache 8-bit + call cachetile8b + jmp .nocachereq +.2b + ; cache 2-bit + call cachetile2b +.nocachereq + test edx,0100h + jz .tilexa + test al,20h + jz .tileya + ; bgptrd/bgptrc + mov ecx,[bgptrd] + mov [bgptrx1],ecx + mov ecx,[bgptrc] + mov [bgptrx2],ecx + jmp .skiptile +.tileya + ; bgptrb/bgptra + mov ecx,[bgptrb] + mov [bgptrx1],ecx + mov ecx,[bgptr] + mov [bgptrx2],ecx + jmp .skiptile +.tilexa + test al,20h + jz .tileya2 + ; bgptrc/bgptrd + mov ecx,[bgptrc] + mov [bgptrx1],ecx + mov ecx,[bgptrd] + mov [bgptrx2],ecx + jmp .skiptile +.tileya2 + ; bgptra/bgptrb + mov ecx,[bgptr] + mov [bgptrx1],ecx + mov ecx,[bgptrb] + mov [bgptrx2],ecx +.skiptile + ; set up edi & yadder to point to tile data + shl ebx,3 + mov [yadder],ebx + and al,1Fh + mov edi,[vram] + mov ebx,eax + shl ebx,6 + mov eax,[bgptrx1] + add edi,ebx + mov [temptile],edi + add edi,eax + ; dx = # of columns right + ; cx = bgxlim + mov eax,edx + shr edx,3 + mov bl,[curypos] + and edx,1Fh + mov [temp],dl + and eax,07h + add dl,dl + add edi,edx + + mov esi,eax + mov ebx,[tempcach] + mov edx,[temptile] + mov eax,[bgptrx2] + and eax,0FFFFh + add edx,eax + mov al,[temp] + mov ecx,[yadder] + mov ah,[bshifter] + ; fill up tempbuffer with pointer #s that point to cached video mem + ; to calculate pointer, get first byte + ; esi = pointer to video buffer + ; edi = pointer to tile data + ; ebx = cached memory + ; ecx = y adder + ; edx = secondary tile pointer + ; al = current x position + ret + +NEWSYM proc16x8 + ; ax = # of rows down + mov ebx,eax + shr eax,3 + and ebx,07h + and eax,63 + cmp byte[edi+eax],0 + jne .nocachereq +; cmp byte[ccud],0 +; jne .nocachereq + mov byte[edi+eax],1 + cmp byte[curcolor],2 + jne .no4b + ; cache 4-bit + call cachetile4b16x16 + jmp .nocachereq +.no4b + cmp byte[curcolor],1 + je .2b + ; cache 8-bit + call cachetile8b16x16 + jmp .nocachereq +.2b + ; cache 2-bit + call cachetile2b16x16 +.nocachereq + test edx,0100h + jz .tilexa + test al,20h + jz .tileya + ; bgptrd/bgptrc + mov ecx,[bgptrd] + mov [bgptrx1],ecx + mov ecx,[bgptrc] + mov [bgptrx2],ecx + jmp .skiptile +.tileya + ; bgptrb/bgptra + mov ecx,[bgptrb] + mov [bgptrx1],ecx + mov ecx,[bgptr] + mov [bgptrx2],ecx + jmp .skiptile +.tilexa + test al,20h + jz .tileya2 + ; bgptrc/bgptrd + mov ecx,[bgptrc] + mov [bgptrx1],ecx + mov ecx,[bgptrd] + mov [bgptrx2],ecx + jmp .skiptile +.tileya2 + ; bgptra/bgptrb + mov ecx,[bgptr] + mov [bgptrx1],ecx + mov ecx,[bgptrb] + mov [bgptrx2],ecx +.skiptile + ; set up edi & yadder to point to tile data + shl ebx,3 + mov [yadder],ebx + and al,1Fh + mov edi,[vram] + mov ebx,eax + shl ebx,6 + mov eax,[bgptrx1] + add edi,ebx + mov [temptile],edi + add edi,eax + ; dx = # of columns right + ; cx = bgxlim + mov eax,edx + shr edx,3 + mov bl,[curypos] + and edx,1Fh + mov [temp],dl + and eax,07h + add dl,dl + add edi,edx + + mov esi,eax + mov ebx,[tempcach] + mov edx,[temptile] + mov eax,[bgptrx2] + and eax,0FFFFh + add edx,eax + mov al,[temp] + mov ecx,[yadder] + mov ah,[bshifter] + ; fill up tempbuffer with pointer #s that point to cached video mem + ; to calculate pointer, get first byte + ; esi = pointer to video buffer + ; edi = pointer to tile data + ; ebx = cached memory + ; ecx = y adder + ; edx = secondary tile pointer + ; al = current x position + ret + +NEWSYM drawn, db 0 +NEWSYM curbgpr, db 0 ; 00h = low priority, 20h = high priority + +%macro drawpixel8b8x8 3 + or %1,%1 + jz %2 + add %1,dh + mov [esi+%3],%1 +%2 +%endmacro + +%macro drawpixel8b8x8win 3 + or %1,%1 + jz %2 + test byte[ebp+%3],0FFh + jnz %2 + add %1,dh + mov [esi+%3],%1 +%2 +%endmacro + +NEWSYM winptrref, dd 0 + +NEWSYM draw8x8 + cmp byte[osm2dis],1 + je .osm2dis + cmp byte[bgmode],2 + je near draw8x8offset +.osm2dis + cmp byte[bgmode],5 + jae near draw16x8 + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx +.retfromoffset + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x8winon +.domosaic + mov ch,33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1 + drawpixel8b8x8 al, .loopd1, 0 + drawpixel8b8x8 ah, .loopd2, 1 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3, 2 + drawpixel8b8x8 ah, .loopd4, 3 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8 al, .loopd5, 4 + drawpixel8b8x8 ah, .loopd6, 5 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7, 6 + drawpixel8b8x8 ah, .loopd8, 7 +.skiploop2 +.hprior + add esi,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1b + drawpixel8b8x8 al, .loopd1b, 7 + drawpixel8b8x8 ah, .loopd2b, 6 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3b, 5 + drawpixel8b8x8 ah, .loopd4b, 4 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8 al, .loopd5b, 3 + drawpixel8b8x8 ah, .loopd6b, 2 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7b, 1 + drawpixel8b8x8 ah, .loopd8b, 0 +.skiploop2b + add esi,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw2 + ret + +NEWSYM draw8x8winon + mov ch,33 + mov byte[drawn],0 + mov ebp,[winptrref] + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1 + drawpixel8b8x8win al, .loopd1, 0 + drawpixel8b8x8win ah, .loopd2, 1 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3, 2 + drawpixel8b8x8win ah, .loopd4, 3 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8win al, .loopd5, 4 + drawpixel8b8x8win ah, .loopd6, 5 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7, 6 + drawpixel8b8x8win ah, .loopd8, 7 +.skiploop2 +.hprior + add esi,8 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1b + drawpixel8b8x8win al, .loopd1b, 7 + drawpixel8b8x8win ah, .loopd2b, 6 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3b, 5 + drawpixel8b8x8win ah, .loopd4b, 4 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8win al, .loopd5b, 3 + drawpixel8b8x8win ah, .loopd6b, 2 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7b, 1 + drawpixel8b8x8win ah, .loopd8b, 0 +.skiploop2b + add esi,8 + add ebp,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + ret + +NEWSYM alttile, db 0 +NEWSYM hirestiledat, times 256 db 0 + +NEWSYM draw16x8 + push eax + xor eax,eax + mov al,[curypos] + mov byte[hirestiledat+eax],1 + pop eax + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x8winon +.domosaic + cmp byte[res512switch],0 + jne near draw16x8b + mov ch,33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1 + drawpixel8b8x8 al, .loopd1, 0 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3, 1 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8 al, .loopd5, 2 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7, 3 +.skiploop2 + add ebx,64 + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1c + drawpixel8b8x8 al, .loopd1c, 4 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3c, 5 +.skiploop1c + mov eax,[ebx+4] + or eax,eax + je .skiploop2c + drawpixel8b8x8 al, .loopd5c, 6 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7c, 7 +.skiploop2c +.hprior + add esi,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + mov eax,[ebx] + or eax,eax + je .skiploop1b + drawpixel8b8x8 ah, .loopd1b, 7 + mov eax,[ebx+2] + drawpixel8b8x8 ah, .loopd3b, 6 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8 ah, .loopd5b, 5 + mov eax,[ebx+6] + drawpixel8b8x8 ah, .loopd7b, 4 +.skiploop2b + add ebx,64 + mov eax,[ebx] + or eax,eax + je .skiploop1d + drawpixel8b8x8 ah, .loopd1d, 3 + mov eax,[ebx+2] + drawpixel8b8x8 ah, .loopd3d, 2 +.skiploop1d + mov eax,[ebx+4] + or eax,eax + je .skiploop2d + drawpixel8b8x8 ah, .loopd5d, 1 + mov eax,[ebx+6] + drawpixel8b8x8 ah, .loopd7d, 0 +.skiploop2d + add esi,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + cmp byte[winon],0 + jne near dowindow +.nodraw2 + ret + +NEWSYM draw16x8b + mov ch,33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1 + drawpixel8b8x8 ah, .loopd1, 0 + mov eax,[ebx+2] + drawpixel8b8x8 ah, .loopd3, 1 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8 ah, .loopd5, 2 + mov eax,[ebx+6] + drawpixel8b8x8 ah, .loopd7, 3 +.skiploop2 + add ebx,64 + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1c + drawpixel8b8x8 ah, .loopd1c, 4 + mov eax,[ebx+2] + drawpixel8b8x8 ah, .loopd3c, 5 +.skiploop1c + mov eax,[ebx+4] + or eax,eax + je .skiploop2c + drawpixel8b8x8 ah, .loopd5c, 6 + mov eax,[ebx+6] + drawpixel8b8x8 ah, .loopd7c, 7 +.skiploop2c +.hprior + add esi,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + mov eax,[ebx] + or eax,eax + je .skiploop1b + drawpixel8b8x8 al, .loopd2b, 7 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd4b, 6 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8 al, .loopd5b, 5 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7b, 4 +.skiploop2b + add ebx,64 + mov eax,[ebx] + or eax,eax + je .skiploop1d + drawpixel8b8x8 al, .loopd1d, 3 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3d, 2 +.skiploop1d + mov eax,[ebx+4] + or eax,eax + je .skiploop2d + drawpixel8b8x8 al, .loopd5d, 1 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7d, 0 +.skiploop2d + add esi,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw2 + ret + +NEWSYM draw16x8winon + cmp byte[res512switch],0 + jne near draw16x8bwinon + mov ch,33 + mov ebp,[winptrref] + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1 + drawpixel8b8x8win al, .loopd1, 0 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3, 1 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8win al, .loopd5, 2 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7, 3 +.skiploop2 + add ebx,64 + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1c + drawpixel8b8x8win al, .loopd1c, 4 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3c, 5 +.skiploop1c + mov eax,[ebx+4] + or eax,eax + je .skiploop2c + drawpixel8b8x8win al, .loopd5c, 6 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7c, 7 +.skiploop2c +.hprior + add ebp,8 + add esi,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + mov eax,[ebx] + or eax,eax + je .skiploop1b + drawpixel8b8x8win ah, .loopd1b, 7 + mov eax,[ebx+2] + drawpixel8b8x8win ah, .loopd3b, 6 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8win ah, .loopd5b, 5 + mov eax,[ebx+6] + drawpixel8b8x8win ah, .loopd7b, 4 +.skiploop2b + add ebx,64 + mov eax,[ebx] + or eax,eax + je .skiploop1d + drawpixel8b8x8win ah, .loopd1d, 3 + mov eax,[ebx+2] + drawpixel8b8x8win ah, .loopd3d, 2 +.skiploop1d + mov eax,[ebx+4] + or eax,eax + je .skiploop2d + drawpixel8b8x8win ah, .loopd5d, 1 + mov eax,[ebx+6] + drawpixel8b8x8win ah, .loopd7d, 0 +.skiploop2d + add ebp,8 + add esi,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + ret + +NEWSYM draw16x8bwinon + mov ch,33 + mov ebp,[winptrref] + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1 + drawpixel8b8x8win ah, .loopd1, 0 + mov eax,[ebx+2] + drawpixel8b8x8win ah, .loopd3, 1 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8win ah, .loopd5, 2 + mov eax,[ebx+6] + drawpixel8b8x8win ah, .loopd7, 3 +.skiploop2 + add ebx,64 + ; Start loop + mov eax,[ebx] + or eax,eax + je .skiploop1c + drawpixel8b8x8win ah, .loopd1c, 4 + mov eax,[ebx+2] + drawpixel8b8x8win ah, .loopd3c, 5 +.skiploop1c + mov eax,[ebx+4] + or eax,eax + je .skiploop2c + drawpixel8b8x8win ah, .loopd5c, 6 + mov eax,[ebx+6] + drawpixel8b8x8win ah, .loopd7c, 7 +.skiploop2c +.hprior + add ebp,8 + add esi,8 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + mov eax,[ebx] + or eax,eax + je .skiploop1b + drawpixel8b8x8win al, .loopd2b, 7 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd4b, 6 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8win al, .loopd5b, 5 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7b, 4 +.skiploop2b + add ebx,64 + mov eax,[ebx] + or eax,eax + je .skiploop1d + drawpixel8b8x8win al, .loopd1d, 3 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3d, 2 +.skiploop1d + mov eax,[ebx+4] + or eax,eax + je .skiploop2d + drawpixel8b8x8win al, .loopd5d, 1 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7d, 0 +.skiploop2d + add ebp,8 + add esi,8 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + ret + +NEWSYM extraleft, db 0,0,0,1,0,1,2,2,0,2,3,1,2,4,2,1 + +NEWSYM domosaic + mov esi,xtravbuf+16 + mov edi,[curvidoffset] + xor ecx,ecx + mov cl,dh + mov dl,dh + sub dl,[extraleft+ecx] + mov ecx,256 + mov al,[esi] + cmp byte[winon],0 + jne near domosaicwin + test al,0FFh + jz .zeroloop +.loopm + mov [edi],al + inc esi + inc edi + dec ecx + jz .doneloop + dec dl + jnz .loopm + mov al,[esi] + mov dl,dh + test al,0FFh + jnz .loopm +.zeroloop + inc esi + inc edi + dec ecx + jz .doneloop + dec dl + jnz .zeroloop + mov al,[esi] + mov dl,dh + test al,0FFh + jnz .loopm + jmp .zeroloop +.doneloop + ret + +NEWSYM domosaicwin + mov ebp,[winptrref] + test al,0FFh + jz .zeroloop +.loopm + cmp byte[ebp],0 + jne .nozero2 + mov [edi],al +.nozero2 + inc esi + inc edi + inc ebp + dec ecx + jz .doneloop + dec dl + jnz .loopm + mov al,[esi] + mov dl,dh + test al,0FFh + jnz .loopm +.zeroloop + inc esi + inc edi + inc ebp + dec ecx + jz .doneloop + dec dl + jnz .zeroloop + mov al,[esi] + mov dl,dh + test al,0FFh + jnz .loopm + jmp .zeroloop +.doneloop + ret + +;windowdata times 16 db 0 +;numwin db 0 + +NEWSYM dowindow + mov ebx,windowdata + mov esi,xtravbuf+16 + mov edi,[curvidoffset] + xor edx,edx + xor ch,ch +.getnext + mov cl,[ebx] + cmp dl,cl + je .procnext +.dorest + sub cl,dl + cmp ch,0 + ja .nodraw +.loopa + mov eax,[esi+edx] + test al,0FFh + jz .nocopy + mov [edi+edx],al +.nocopy + inc dl + dec cl + jz .procnext + test ah,0FFh + jz .nocopyb + mov [edi+edx],ah +.nocopyb + inc dl + dec cl + jz .procnext + shr eax,16 + test al,0FFh + jz .nocopyc + mov [edi+edx],al +.nocopyc + inc dl + dec cl + jz .procnext + test ah,0FFh + jz .nocopyd + mov [edi+edx],ah +.nocopyd + inc dl + dec cl + jnz .loopa +.procnext + add ch,[ebx+1] + add ebx,2 + test byte[numwin],0FFh + jz .finishwin + dec byte[numwin] + jnz .getnext + xor cl,cl + jmp .dorest +.nodraw + add dl,cl + jmp .procnext +.finishwin + xor eax,eax + ret + +;xtravbuf times 576 db 0 +; bytes to add to match y coordinates + +ALIGN32 + +NEWSYM yadder, dd 0 +NEWSYM yrevadder, dd 0 +NEWSYM tempcach, dd 0 ; points to cached memory +NEWSYM temptile, dd 0 ; points to the secondary video pointer +NEWSYM bgptr, dd 0 +NEWSYM bgptrb, dd 0 +NEWSYM bgptrc, dd 0 +NEWSYM bgptrd, dd 0 +NEWSYM bgptrx1, dd 0 +NEWSYM bgptrx2, dd 0 +NEWSYM curvidoffset, dd 0 +NEWSYM winon, dd 0 +NEWSYM bgofwptr, dd 0 +NEWSYM bgsubby, dd 0 + + +NEWSYM draw8x8offset + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + initoffsetmode + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x8winon +.domosaic + mov byte[offsettilel],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 +; add dword[offsetptrb],2 +; add dword[offsetcedi],2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1 + drawpixel8b8x8 al, .loopd1, 0 + drawpixel8b8x8 ah, .loopd2, 1 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3, 2 + drawpixel8b8x8 ah, .loopd4, 3 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8 al, .loopd5, 4 + drawpixel8b8x8 ah, .loopd6, 5 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7, 6 + drawpixel8b8x8 ah, .loopd8, 7 +.skiploop2 +.hprior + procoffsetmode + add esi,8 + dec byte[offsettilel] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1b + drawpixel8b8x8 al, .loopd1b, 7 + drawpixel8b8x8 ah, .loopd2b, 6 + mov eax,[ebx+2] + drawpixel8b8x8 al, .loopd3b, 5 + drawpixel8b8x8 ah, .loopd4b, 4 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8 al, .loopd5b, 3 + drawpixel8b8x8 ah, .loopd6b, 2 + mov eax,[ebx+6] + drawpixel8b8x8 al, .loopd7b, 1 + drawpixel8b8x8 ah, .loopd8b, 0 +.skiploop2b + procoffsetmode + add esi,8 + dec byte[offsettilel] + jnz near .loopa + xor eax,eax + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic +.nodraw2 + ret + +NEWSYM draw8x8winonoffset + mov ch,33 + mov byte[drawn],0 + mov ebp,[winptrref] + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + offsetmcachechk + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1 + drawpixel8b8x8win al, .loopd1, 0 + drawpixel8b8x8win ah, .loopd2, 1 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3, 2 + drawpixel8b8x8win ah, .loopd4, 3 +.skiploop1 + mov eax,[ebx+4] + or eax,eax + je .skiploop2 + drawpixel8b8x8win al, .loopd5, 4 + drawpixel8b8x8win ah, .loopd6, 5 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7, 6 + drawpixel8b8x8win ah, .loopd8, 7 +.skiploop2 +.hprior + procoffsetmode + add esi,8 + add ebp,8 + dec ch + jnz near .loopa + xor eax,eax + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + or eax,eax + je .skiploop1b + drawpixel8b8x8win al, .loopd1b, 7 + drawpixel8b8x8win ah, .loopd2b, 6 + mov eax,[ebx+2] + drawpixel8b8x8win al, .loopd3b, 5 + drawpixel8b8x8win ah, .loopd4b, 4 +.skiploop1b + mov eax,[ebx+4] + or eax,eax + je .skiploop2b + drawpixel8b8x8win al, .loopd5b, 3 + drawpixel8b8x8win ah, .loopd6b, 2 + mov eax,[ebx+6] + drawpixel8b8x8win al, .loopd7b, 1 + drawpixel8b8x8win ah, .loopd8b, 0 +.skiploop2b + procoffsetmode + add esi,8 + add ebp,8 + dec ch + jnz near .loopa + xor eax,eax + ret + +ALIGN32 + +NEWSYM offsetmodeptr, dd 0 +NEWSYM offsetptra, dd 0 +NEWSYM offsetptrb, dd 0 +NEWSYM prevtempcache, dd 0 +NEWSYM prevoffsetdat, dd 0 +NEWSYM offsetenab, dd 0 +NEWSYM offsettilel, dd 0 +NEWSYM offsetrevval, dd 0 +NEWSYM posyscroll, dd 0 +NEWSYM offsetmcol, dd 0 +NEWSYM offsetmshl, dd 0 +NEWSYM offsetmptr, dd 0 +NEWSYM offsetmtst, dd 0 +NEWSYM offsetmclr, dd 0 +NEWSYM offsetcedi, dd 0 + +;******************************************************* +; Processes & Draws 16x16 tiles in 2, 4, & 8 bit mode +;******************************************************* + +NEWSYM proc16x16 + ; ax = # of rows down + xor ebx,ebx + mov ebx,eax + and ebx,07h + mov byte[a16x16yinc],0 + test eax,08h + jz .noincb + mov byte[a16x16yinc],1 +.noincb + shr eax,4 + and eax,63 + cmp byte[edi+eax],0 + jne .nocachereq + mov byte[edi+eax],1 + cmp byte[curcolor],2 + jne .no4b + ; cache 4-bit + call cachetile4b16x16 + jmp .nocachereq +.no4b + cmp byte[curcolor],1 + je .2b + ; cache 8-bit + call cachetile8b16x16 + jmp .nocachereq +.2b + ; cache 2-bit + call cachetile2b16x16 +.nocachereq + test edx,0200h + jz .tilexa + test eax,20h + jz .tileya + ; bgptrd/bgptrc + mov ecx,[bgptrd] + mov [bgptrx1],ecx + mov ecx,[bgptrc] + mov [bgptrx2],ecx + jmp .skiptile +.tileya + ; bgptrb/bgptra + mov ecx,[bgptrb] + mov [bgptrx1],ecx + mov ecx,[bgptr] + mov [bgptrx2],ecx + jmp .skiptile +.tilexa + test ax,20h + jz .tileya2 + ; bgptrc/bgptrd + mov ecx,[bgptrc] + mov [bgptrx1],ecx + mov ecx,[bgptrd] + mov [bgptrx2],ecx + jmp .skiptile +.tileya2 + ; bgptra/bgptrb + mov ecx,[bgptr] + mov [bgptrx1],ecx + mov ecx,[bgptrb] + mov [bgptrx2],ecx +.skiptile + and eax,1Fh + shl ebx,3 + mov [yadder],ebx + ; set up edi to point to tile data + mov edi,[vram] + mov ebx,eax + shl ebx,6 + mov ax,[bgptrx1] + add edi,ebx + mov [temptile],edi + add edi,eax + ; dx = # of columns right + ; cx = bgxlim + mov eax,edx + mov byte[a16x16xinc],0 + test edx,08h + jz .noincd + mov byte[a16x16xinc],1 +.noincd + shr edx,4 + and edx,1Fh + mov [temp],dl + and eax,07h + shl dl,1 + xor ebx,ebx + add edi,edx + + mov esi,eax + mov ebx,[tempcach] + xor eax,eax + mov edx,[temptile] + mov ax,[bgptrx2] + add edx,eax + mov ecx,[yadder] + mov eax,[temp] + ; fill up tempbuffer with pointer #s that point to cached video mem + ; to calculate pointer, get first byte + ; esi = pointer to video buffer + ; edi = pointer to tile data + ; ebx = cached memory + ; ecx = y adder + ; edx = secondary tile pointer + ; al = current x position + ret + +NEWSYM draw16x16 + mov byte[drawn],0 + mov [temp],eax + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + xor ebx,ebx + mov bl,[curypos] + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit + ; set up y adders + test byte[a16x16yinc],01h + jz .noincrc + mov word[.yadd],16 + mov word[.yflipadd],0 + jmp .yesincrc +.noincrc + mov word[.yadd],0 + mov word[.yflipadd],16 +.yesincrc + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 + sub esi,eax +.nomosaic + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x16winon +.domosaic + mov ch,33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[.yadd] + jmp .yesyflip +.noyflip + add ax,word[.yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + cmp eax,0 + je .skiploop1 + drawpixel8b8x8 al, .loopd1, 0 + drawpixel8b8x8 ah, .loopd2, 1 + shr eax,16 + drawpixel8b8x8 al, .loopd3, 2 + drawpixel8b8x8 ah, .loopd4, 3 +.skiploop1 + mov eax,[ebx+4] + cmp eax,0 + je .skiploop2 + drawpixel8b8x8 al, .loopd5, 4 + drawpixel8b8x8 ah, .loopd6, 5 + shr eax,16 + drawpixel8b8x8 al, .loopd7, 6 + drawpixel8b8x8 ah, .loopd8, 7 +.skiploop2 +.hprior + add esi,8 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + cmp eax,0 + je .skiploop1b + drawpixel8b8x8 al, .loopd1b, 7 + drawpixel8b8x8 ah, .loopd2b, 6 + shr eax,16 + drawpixel8b8x8 al, .loopd3b, 5 + drawpixel8b8x8 ah, .loopd4b, 4 +.skiploop1b + mov eax,[ebx+4] + cmp eax,0 + je .skiploop2b + drawpixel8b8x8 al, .loopd5b, 3 + drawpixel8b8x8 ah, .loopd6b, 2 + shr eax,16 + drawpixel8b8x8 al, .loopd7b, 1 + drawpixel8b8x8 ah, .loopd8b, 0 +.skiploop2b + add esi,8 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + +.yadd dw 0 +.yflipadd dw 0 + +NEWSYM draw16x16winon +.domosaic + mov ch,33 + mov ebp,[winptrref] + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[draw16x16.yadd] + jmp .yesyflip +.noyflip + add ax,word[draw16x16.yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + cmp eax,0 + je .skiploop1 + drawpixel8b8x8win al, .loopd1, 0 + drawpixel8b8x8win ah, .loopd2, 1 + shr eax,16 + drawpixel8b8x8win al, .loopd3, 2 + drawpixel8b8x8win ah, .loopd4, 3 +.skiploop1 + mov eax,[ebx+4] + cmp eax,0 + je .skiploop2 + drawpixel8b8x8win al, .loopd5, 4 + drawpixel8b8x8win ah, .loopd6, 5 + shr eax,16 + drawpixel8b8x8win al, .loopd7, 6 + drawpixel8b8x8win ah, .loopd8, 7 +.skiploop2 +.hprior + add ebp,8 + add esi,8 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec ch + jnz near .loopa + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + mov eax,[ebx] + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + ; Start fast loop + cmp eax,0 + je .skiploop1b + drawpixel8b8x8win al, .loopd1b, 7 + drawpixel8b8x8win ah, .loopd2b, 6 + shr eax,16 + drawpixel8b8x8win al, .loopd3b, 5 + drawpixel8b8x8win ah, .loopd4b, 4 +.skiploop1b + mov eax,[ebx+4] + cmp eax,0 + je .skiploop2b + drawpixel8b8x8win al, .loopd5b, 3 + drawpixel8b8x8win ah, .loopd6b, 2 + shr eax,16 + drawpixel8b8x8win al, .loopd7b, 1 + drawpixel8b8x8win ah, .loopd8b, 0 +.skiploop2b + add ebp,8 + add esi,8 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec ch + jnz near .loopa + ret + +NEWSYM temp, db 0 +NEWSYM bshifter, db 0 +NEWSYM a16x16xinc, db 0 +NEWSYM a16x16yinc, db 0 + + + \ No newline at end of file diff --git a/zsnes/src/video/mode7.asm b/zsnes/src/video/mode7.asm new file mode 100644 index 00000000..d5c631a0 --- /dev/null +++ b/zsnes/src/video/mode7.asm @@ -0,0 +1,818 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM mode7tab,winptrref,nglogicval,winlogicaval +EXTSYM curmosaicsz,curvidoffset,cwinptr,domosaic,mode7A,mode7B +EXTSYM mode7C,mode7D,mode7X0,mode7Y0,mode7set,vram,vrama,winon,xtravbuf +EXTSYM ngwinen, winbg1enval, BuildWindow, ngwintable, ngcwinptr, domosaicng +EXTSYM pesimpng +EXTSYM mode7hr +EXTSYM BGMA, mode7ab, mode7cd, BG1SYl, BG1SXl, mosenng, mosszng + +%include "video/mode7.mac" + + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + +%macro Mode7Normal 0 + or dl,dl + jz %%nodrawb + mov byte[esi],dl +%%nodrawb + inc esi +%endmacro + +%macro Mode7Window 0 + or dl,dl + jz %%nodrawbw + test byte[ebp],0FFh + jnz %%nodrawbw + mov byte[esi],dl +%%nodrawbw + inc esi + inc ebp +%endmacro + +NEWSYM Makemode7Table + xor eax,eax +.nextentry + mov cl,al + mov dl,ah + and cl,07h + and dl,07h + shl cl,4 + shl dl,1 + inc dl + add dl,cl + mov [mode7tab+eax],dl + dec ax + jnz .nextentry + ret + +;mode7tab times 65536 db 0 + +; backup mode7X0, mode7Y0, Mode7A, and Mode7B +NEWSYM drawmode7 + mov esi,[cwinptr] + mov [winptrref],esi + Mode7Calculate + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawmode7win +.domosaic + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process Mode7Normal, domosaic, 1 +.nextval3 + Mode7ProcessB Mode7Normal, domosaic, 1 + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +.drawmode7win +.domosaicw + + mov ebp,[cwinptr] + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3w + cmp dword[.mode7xadder],-7F0h + jl near .nextval3w + cmp dword[.mode7yadder],7F0h + jg near .nextval3w + cmp dword[.mode7yadder],-7F0h + jl near .nextval3w + + Mode7Process Mode7Window, domosaic, 1 +.nextval3w + Mode7ProcessB Mode7Window, domosaic, 1 + + +NEWSYM drawmode7win + cmp byte[mode7hr+ebx],1 + je near drawmode7winhr + ProcessBuildWindow 0 +.nohr + + mov esi,[cwinptr] + mov [winptrref],esi + Mode7Calculate + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov [pesimpng],esi + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + cmp byte[ngwinen],1 + je near .drawmode7win + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process Mode7Normal, domosaicng, 1 +.nextval3 + Mode7ProcessB Mode7Normal, domosaicng, 1 + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +.drawmode7win +.domosaicw + mov ebx,[.mode7xrpos] + mov [mode7xrpos],ebx + mov ebx,[.mode7yrpos] + mov [mode7yrpos],ebx + mov ebx,[.mode7xadder] + mov [mode7xadder],ebx + mov ebx,[.mode7yadder] + mov [mode7yadder],ebx + mov ebx,[.mode7xpos] + mov [mode7xpos],ebx + mov ebx,[.mode7ypos] + mov [mode7ypos],ebx + + mov edi,[vram] + Mode7Processngw Mode7Normal, domosaicng, 1 + +NEWSYM drawmode7winB + cmp byte[mode7hr+ebx],1 + je near drawmode7winBhr + ProcessBuildWindow 0 +.nohr + + mov esi,[cwinptr] + mov [winptrref],esi + Mode7CalculateB + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + cmp byte[ngwinen],1 + je near .drawmode7win + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process Mode7Normal, domosaic, 1 +.nextval3 + Mode7ProcessB Mode7Normal, domosaic, 1 + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +.drawmode7win +.domosaicw + mov ebx,[.mode7xrpos] + mov [mode7xrpos],ebx + mov ebx,[.mode7yrpos] + mov [mode7yrpos],ebx + mov ebx,[.mode7xpos] + mov [mode7xpos],ebx + mov ebx,[.mode7ypos] + mov [mode7ypos],ebx + mov ebx,[.mode7xadder] + mov [mode7xadder],ebx + mov ebx,[.mode7yadder] + mov [mode7yadder],ebx + + mov edi,[vram] + Mode7Processngw Mode7Normal, domosaic, 1 + +NEWSYM drawmode7winhr + ProcessBuildWindow 0 + + cmp byte[ngwinen],1 + jne .notwinen + mov byte[mode7hr+ebx],0 + jmp drawmode7win.nohr +.notwinen + + mov esi,[cwinptr] + mov [winptrref],esi + Mode7Calculate + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov [pesimpng],esi + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + sar dword[.mode7xadder],1 + sar dword[.mode7yadder],1 + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Processhr Mode7Normal, domosaicng, 1 +.nextval3 + Mode7ProcessBhr Mode7Normal, domosaicng, 1 + +ALIGN32 +.temp dd 0 ; for byte move left +.temp2 dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +NEWSYM drawmode7winBhr + ProcessBuildWindow 0 + + cmp byte[ngwinen],1 + jne .notwinen + mov byte[mode7hr+ebx],0 + jmp drawmode7winB.nohr +.notwinen + + mov esi,[cwinptr] + mov [winptrref],esi + Mode7CalculateB + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + sar dword[.mode7xadder],1 + sar dword[.mode7yadder],1 + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Processhr Mode7Normal, domosaic, 1 +.nextval3 + Mode7ProcessBhr Mode7Normal, domosaic, 1 + +ALIGN32 +.temp dd 0 ; for byte move left +.temp2 dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +ALIGN32 +NEWSYM ngwleft, dd 0 ; for byte move left +NEWSYM ngwleftb, dd 0 ; for byte move left +NEWSYM mode7xpos, dd 0,0 ; x position +NEWSYM mode7ypos, dd 0,0 ; x position +NEWSYM mode7xrpos, dd 0,0 ; x position, relative +NEWSYM mode7yrpos, dd 0,0 ; y position, relative +NEWSYM mode7xadder, dd 0,0 ; number to add for x +NEWSYM mode7yadder, dd 0,0 ; number to add for y + +NEWSYM ProcessMode7ngwin + mov ecx,[ngcwinptr] + mov ecx,[ecx] + or ecx,ecx + jz near .winb + cmp ecx,[ngwleft] + jae .alldisplay + sub [ngwleft],ecx + mov dword[ngwleftb],ecx + xor ecx,ecx + mov eax,[mode7xrpos] + ret +.alldisplay + mov ecx,[ngwleft] + mov dword[ngwleftb],ecx + mov dword[ngwleft],0 + xor ecx,ecx + mov eax,[mode7xrpos] + ret +.winb +NEWSYM ProcessMode7ngwinB + add dword[ngcwinptr],4 + mov ecx,[ngcwinptr] + mov ecx,[ecx] + cmp ecx,[ngwleft] + jae near .finishmode7 + sub [ngwleft],ecx + or ecx,ecx + jz .noclip +.nextvalngw + mov eax,[mode7xadder] + add [mode7xrpos],eax + mov eax,[mode7yadder] + sub [mode7yrpos],eax + inc esi + dec ecx + jnz near .nextvalngw +.noclip + add dword[ngcwinptr],4 + jmp ProcessMode7ngwin +.finishmode7 + mov dword[ngwleft],0 + mov dword[ngwleftb],0 + ret + +NEWSYM ProcessMode7ngwinC + mov ecx,[ngcwinptr] + mov ecx,[ecx] + or ecx,ecx + jz near .winb + cmp ecx,[ngwleft] + jae .alldisplay + sub [ngwleft],ecx + mov dword[ngwleftb],ecx + xor ecx,ecx + mov eax,[mode7xpos] + ret +.alldisplay + mov ecx,[ngwleft] + mov dword[ngwleftb],ecx + mov dword[ngwleft],0 + xor ecx,ecx + mov eax,[mode7xpos] + ret +.winb +NEWSYM ProcessMode7ngwinD + add dword[ngcwinptr],4 + mov ecx,[ngcwinptr] + mov ecx,[ecx] + cmp ecx,[ngwleft] + jae near .finishmode7 + sub [ngwleft],ecx + or ecx,ecx + jz .noclip +.nextvalngw + mov eax,[mode7xadder] + add [mode7xpos],eax + mov eax,[mode7yadder] + sub [mode7ypos],eax + inc esi + dec ecx + jnz near .nextvalngw +.noclip + add dword[ngcwinptr],4 + jmp ProcessMode7ngwin +.finishmode7 + mov dword[ngwleft],0 + mov dword[ngwleftb],0 + ret + +%macro newvaluepred 2 + mov dx,word[%1+ebx*4+8] + cmp dx,word[%1+ebx*4] + je %%nodivide + cmp byte[BGMA+ebx+2],7 + je %%mode7scaleb +%%nodivide + movsx edx,word[%1+ebx*4+4] + movsx ecx,word[%1+ebx*4] + add ecx,edx + sar ecx,1 + mov [%2],cx + jmp %%mode7scalend +%%mode7scaleb + mov esi,ebx + movsx ebx,word[%1+esi*4+8] + movsx edx,word[%1+esi*4] + sub ebx,edx + movsx ecx,word[%1+esi*4+4] + sub ecx,edx + mov eax,ecx + imul ecx + idiv ebx + add ax,word[%1+esi*4] + mov ebx,esi + mov [%2],ax +%%mode7scalend +%endmacro + +NEWSYM processmode7hires + cmp byte[BGMA+ebx+1],7 + jne near .nogo + + push esi + push ebx + ; predict new values + push eax + push edx + push ebx + push esi + newvaluepred mode7ab,mode7A + newvaluepred mode7ab+2,mode7B + newvaluepred mode7cd,mode7C + newvaluepred mode7cd+2,mode7D + pop esi + pop ebx + pop edx + pop eax + + mov ecx,edx + xor edx,edx + mov dx,[BG1SXl+ebx*2+2] + add edx,ecx + shr edx,1 + + mov ecx,eax + mov eax,ebx + inc eax + test byte[mode7set],02h + jz .noflip + mov eax,261 + sub eax,ebx +.noflip + add ax,[BG1SYl+ebx*2+2] + add eax,ecx + + add esi,75036 + mov [curvidoffset],esi + call drawmode7winB + pop ebx + pop esi +.nogo + ret + \ No newline at end of file diff --git a/zsnes/src/video/mode7.mac b/zsnes/src/video/mode7.mac new file mode 100644 index 00000000..3de18dac --- /dev/null +++ b/zsnes/src/video/mode7.mac @@ -0,0 +1,1563 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +%macro Mode7Calculate 0 + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[.cyloc] + imul eax,ebx + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[.cxloc] + neg eax + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + test byte[mode7set],1 + jz .nohflip + mov eax,[.mode7xadder] + shl eax,8 + add [.mode7xpos],eax + neg dword[.mode7xadder] + mov eax,[.mode7yadder] + shl eax,8 + sub [.mode7ypos],eax + neg dword[.mode7yadder] +.nohflip +%endmacro + +%macro Mode7CalculateB 0 + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0011111111111111b ; 13 -> 16 bit signed value + test bx,0010000000000000b + jz .nonegc + or bx,1100000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + add bx,bx + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[.cyloc] + imul eax,ebx + sar eax,1 + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx + sar eax,1 + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[.cxloc] + neg eax + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + test byte[mode7set],1 + jz .nohflip + mov eax,[.mode7xadder] + shl eax,8 + add [.mode7xpos],eax + neg dword[.mode7xadder] + mov eax,[.mode7yadder] + shl eax,8 + sub [.mode7ypos],eax + neg dword[.mode7yadder] +.nohflip +%endmacro + +%macro Mode7Process 3 + mov dword[.temp],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ecx,ecx + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[.mode7xrpos] + mov ebx,[.mode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,08h + jnz near %%rposoffx +%%nextposx + test byte[.mode7yrpos+1],08h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov edx,[.mode7yadder] + mov cl,byte[.mode7yrpos+1] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[.mode7xadder] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + add bl,[.mode7xinc] + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,[.mode7xadd2] + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + sub bh,[.mode7yinc] + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + mov edx,[.mode7yadd2] + shl ecx,7 + add dword[.mode7yrpos],edx + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[.mode7ypos+2],3 + ja %%offscr2 + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,%3 + dec dword[.temp] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[.mode7ypos+2],3 + ja %%offscr2b + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + dec dword[.temp] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[.temp] + jz near %%fin2 +%%nextvalr + test byte[.mode7xrpos+1],08h + jnz near %%rposoffxr +%%nextposxr + test byte[.mode7yrpos+1],08h + jnz near %%rposoffyr +%%nextposyr + mov cl,[.mode7yrpos+1] + mov ch,[.mode7xrpos+1] + mov edx,[.mode7xadder] + add dword[.mode7xrpos],edx + mov edx,[.mode7yadder] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextvalr +%%fin2 + jmp %%finishmode7 +%%rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp %%nextposxr +%%rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp %%nextposyr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + %1 + dec dword[.temp] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + +; ************************************************************************ + +%macro Mode7ProcessB 3 + mov dword[.temp],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + xor dl,dl + xor ecx,ecx + mov ebx,[.mode7xadder] + test ebx,80000000h + jz %%nexta + neg ebx +%%nexta + cmp ebx,0800h + jl %%skipx + sub ebx,800h + add ecx,[.mode7xadd2] + add dl,[.mode7xinc] + jmp %%nexta +%%skipx + mov [.m7xaddofa],ecx + mov [.m7xaddof2a],dl + + xor dl,dl + xor ecx,ecx + mov ebx,[.mode7yadder] + test ebx,80000000h + jz %%nextay + neg ebx +%%nextay + cmp ebx,0800h + jl %%skipy + sub ebx,800h + add ecx,[.mode7yadd2] + add dl,[.mode7yinc] + jmp %%nextay +%%skipy + mov [.m7yaddofa],ecx + mov [.m7yaddof2a],dl + + xor ecx,ecx + + mov eax,[.mode7xrpos] + mov ebx,[.mode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,0F8h + jnz near %%rposoffx +%%nextposx + test byte[.mode7yrpos+1],0F8h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov edx,[.mode7yadder] + mov cl,byte[.mode7yrpos+1] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[.mode7xadder] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + sub eax,[.m7xaddofa] + add bl,[.m7xaddof2a] + test ah,0F8h + jz %%noaddstuff + add bl,[.mode7xinc] + sub eax,[.mode7xadd2] +%%noaddstuff + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + mov edx,[.m7yaddofa] + sub bh,[.m7yaddof2a] + add dword[.mode7yrpos],edx + test byte[.mode7yrpos+1],0F8h + jz %%noaddstuff2 + mov edx,[.mode7yadd2] + sub bh,[.mode7yinc] + add dword[.mode7yrpos],edx +%%noaddstuff2 + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[.mode7ypos+2],3 + ja %%offscr2 + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,%3 + dec dword[.temp] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[.mode7ypos+2],3 + ja %%offscr2b + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + dec dword[.temp] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[.temp] + jz near %%fin2 +%%nextvalr + test byte[.mode7xrpos+1],0F8h + jnz near %%rposoffxr +%%nextposxr + test byte[.mode7yrpos+1],0F8h + jnz near %%rposoffyr +%%nextposyr + mov cl,[.mode7yrpos+1] + mov ch,[.mode7xrpos+1] + mov edx,[.mode7xadder] + add dword[.mode7xrpos],edx + mov edx,[.mode7yadder] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextvalr +%%fin2 + jmp %%finishmode7 +%%rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp %%nextvalr +%%rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp %%nextposxr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + %1 + dec dword[.temp] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + +%macro Mode7Processhr 3 + mov dword[.temp],256 + mov dword[.temp2],2 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[.mode7xrpos] + mov ebx,[.mode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,08h + jnz near %%rposoffx +%%nextposx + test byte[.mode7yrpos+1],08h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov edx,[.mode7yadder] + mov cl,byte[.mode7yrpos+1] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[.mode7xadder] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextval + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + add bl,[.mode7xinc] + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,[.mode7xadd2] + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + sub bh,[.mode7yinc] + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + mov edx,[.mode7yadd2] + shl ecx,7 + add dword[.mode7yrpos],edx + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[.mode7ypos+2],3 + ja %%offscr2 + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,%3 + dec dword[.temp] + jnz near %%nextvalb2 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[.mode7ypos+2],3 + ja %%offscr2b + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + dec dword[.temp] + jnz near %%nextvalb3 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[.temp] + jz near %%fin2 +%%nextvalr + test byte[.mode7xrpos+1],08h + jnz near %%rposoffxr +%%nextposxr + test byte[.mode7yrpos+1],08h + jnz near %%rposoffyr +%%nextposyr + mov cl,[.mode7yrpos+1] + mov ch,[.mode7xrpos+1] + mov edx,[.mode7xadder] + add dword[.mode7xrpos],edx + mov edx,[.mode7yadder] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextvalr +%%fin2 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextvalr + jmp %%finishmode7 +%%rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp %%nextposxr +%%rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp %%nextposyr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + %1 + dec dword[.temp] + jnz near %%tilerep3 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + +; ************************************************************************ + +%macro Mode7ProcessBhr 3 + mov dword[.temp],256 + mov dword[.temp2],2 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + xor dl,dl + xor ecx,ecx + mov ebx,[.mode7xadder] + test ebx,80000000h + jz %%nexta + neg ebx +%%nexta + cmp ebx,0800h + jl %%skipx + sub ebx,800h + add ecx,[.mode7xadd2] + add dl,[.mode7xinc] + jmp %%nexta +%%skipx + mov [.m7xaddofa],ecx + mov [.m7xaddof2a],dl + + xor dl,dl + xor ecx,ecx + mov ebx,[.mode7yadder] + test ebx,80000000h + jz %%nextay + neg ebx +%%nextay + cmp ebx,0800h + jl %%skipy + sub ebx,800h + add ecx,[.mode7yadd2] + add dl,[.mode7yinc] + jmp %%nextay +%%skipy + mov [.m7yaddofa],ecx + mov [.m7yaddof2a],dl + + xor ecx,ecx + + mov eax,[.mode7xrpos] + mov ebx,[.mode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,0F8h + jnz near %%rposoffx +%%nextposx + test byte[.mode7yrpos+1],0F8h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov edx,[.mode7yadder] + mov cl,byte[.mode7yrpos+1] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[.mode7xadder] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextval + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + sub eax,[.m7xaddofa] + add bl,[.m7xaddof2a] + test ah,0F8h + jz %%noaddstuff + add bl,[.mode7xinc] + sub eax,[.mode7xadd2] +%%noaddstuff + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + mov edx,[.m7yaddofa] + sub bh,[.m7yaddof2a] + add dword[.mode7yrpos],edx + test byte[.mode7yrpos+1],0F8h + jz %%noaddstuff2 + mov edx,[.mode7yadd2] + sub bh,[.mode7yinc] + add dword[.mode7yrpos],edx +%%noaddstuff2 + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[.mode7ypos+2],3 + ja %%offscr2 + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,%3 + dec dword[.temp] + jnz near %%nextvalb2 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[.mode7ypos+2],3 + ja %%offscr2b + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + dec dword[.temp] + jnz near %%nextvalb3 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[.temp] + jz near %%fin2 +%%nextvalr + test byte[.mode7xrpos+1],0F8h + jnz near %%rposoffxr +%%nextposxr + test byte[.mode7yrpos+1],0F8h + jnz near %%rposoffyr +%%nextposyr + mov cl,[.mode7yrpos+1] + mov edx,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add dword[.mode7xrpos],edx + mov edx,[.mode7yadder] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextvalr +%%fin2 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%nextvalr + jmp %%finishmode7 +%%rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp %%nextvalr +%%rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp %%nextposxr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + %1 + dec dword[.temp] + jnz near %%tilerep3 + mov dword[.temp],256 + add esi,75036*2-256 + dec dword[.temp2] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + +%macro ProcessBuildWindow 1 + mov dword[ngwinen],0 + test byte[winbg1enval+ebx+%1*256],0Ah + jz %%nowindowing + push eax + push ebx + mov al,[winlogicaval+ebx*2] + shr al,%1*2 + and al,03h + mov [nglogicval],al + mov eax,ebx + add ebx,%1*256 + call BuildWindow + cmp dword[ngwintable],0 + je %%zero + dec dword[ngwintable] + jmp %%notzero +%%zero + dec dword[ngwintable+4] +%%notzero + pop ebx + pop eax + mov dword[ngcwinptr],ngwintable +%%nowindowing +%endmacro + +;************************************ + +%macro Mode7Processngw 3 + mov dword[ngwleftb],256 + mov dword[ngwleft],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + xor dl,dl + xor ecx,ecx + mov ebx,[.mode7xadder] + test ebx,80000000h + jz %%nexta + neg ebx +%%nexta + cmp ebx,0800h + jl %%skipx + sub ebx,800h + add ecx,[.mode7xadd2] + add dl,[.mode7xinc] + jmp %%nexta +%%skipx + mov [.m7xaddofa],ecx + mov [.m7xaddof2a],dl + + xor dl,dl + xor ecx,ecx + mov ebx,[.mode7yadder] + test ebx,80000000h + jz %%nextay + neg ebx +%%nextay + cmp ebx,0800h + jl %%skipy + sub ebx,800h + add ecx,[.mode7yadd2] + add dl,[.mode7yinc] + jmp %%nextay +%%skipy + mov [.m7yaddofa],ecx + mov [.m7yaddof2a],dl + + xor ecx,ecx + + mov eax,[mode7xrpos] + mov ebx,[.mode7ptr] + + call ProcessMode7ngwin + cmp dword[ngwleftb],0 + jne near %%nextval + jmp %%finishmode7 + ALIGN16 +%%nextval + test ah,0F8h + jnz near %%rposoffx +%%nextposx + test byte[mode7yrpos+1],0F8h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov cl,byte[mode7yrpos+1] + mov edx,[mode7yadder] + sub dword[mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[mode7xadder] + mov dl,[edi+edx] + %1 + dec dword[ngwleftb] + jnz near %%nextval + mov [mode7xrpos],eax + cmp dword[ngwleft],0 + je %%notskipvalues + call ProcessMode7ngwinB + cmp dword[ngwleftb],0 + jne near %%nextval +%%notskipvalues + jmp %%finishmode7 + +%%rposoffx + sub eax,[.m7xaddofa] + add bl,[.m7xaddof2a] + test ah,0F8h + jz %%noaddstuff + add bl,[.mode7xinc] + sub eax,[.mode7xadd2] +%%noaddstuff + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + mov edx,[.m7yaddofa] + sub bh,[.m7yaddof2a] + add dword[mode7yrpos],edx + test byte[mode7yrpos+1],0F8h + jz %%noaddstuff2 + mov edx,[.mode7yadd2] + sub bh,[.mode7yinc] + add dword[mode7yrpos],edx +%%noaddstuff2 + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + call ProcessMode7ngwinC + cmp dword[ngwleftb],0 + jne near %%nextvald + jmp %%finishmode7 +%%nextvald + mov dword[ngwleft],0 + + test byte[mode7set],40h + jnz near %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[mode7ypos+2],3 + ja %%offscr2 + cmp byte[mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[mode7xadder] + mov ebx,[mode7yadder] + add [mode7xpos],eax + sub [mode7ypos],ebx + add esi,%3 + dec dword[ngwleftb] + jnz near %%nextvalb2 + + cmp dword[ngwleft],0 + je %%notskipvalues3b + call ProcessMode7ngwinD + cmp dword[ngwleftb],0 + jne near %%nextvalb2 +%%notskipvalues3b + + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[mode7ypos+2],3 + ja %%offscr2b + cmp byte[mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[mode7xpos+1] + mov eax,[mode7xadder] + mov cl,[mode7ypos+1] + mov ebx,[mode7yadder] + mov dl,[mode7tab+ecx] + add [mode7xpos],eax + mov dl,[vrama+edx] + sub [mode7ypos],ebx + %1 + dec dword[ngwleftb] + jnz near %%nextvalb3 + + cmp dword[ngwleft],0 + je %%notskipvalues3 + call ProcessMode7ngwinD + cmp dword[ngwleftb],0 + jne near %%nextvalb3 +%%notskipvalues3 + + jmp %%finishmode7 +%%offscr3 + mov eax,[mode7xpos] + and eax,7FFh + mov [mode7xrpos],eax + mov eax,[mode7ypos] + and eax,7FFh + mov [mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mode7ypos+1] + mov eax,[mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[ngwleftb] + jz near %%fin2 +%%nextvalr + test byte[mode7xrpos+1],0F8h + jnz near %%rposoffxr +%%nextposxr + test byte[mode7yrpos+1],0F8h + jnz near %%rposoffyr +%%nextposyr + mov cl,[mode7yrpos+1] + mov ch,[mode7xrpos+1] + mov edx,[mode7xadder] + add dword[mode7xrpos],edx + mov edx,[mode7yadder] + sub dword[mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[ngwleftb] + jnz near %%nextvalr +%%fin2 + + cmp dword[ngwleft],0 + je %%notskipvalues4 + call ProcessMode7ngwinB + cmp dword[ngwleftb],0 + jne near %%nextvalr +%%notskipvalues4 + + jmp %%finishmode7 +%%rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [mode7xrpos],eax + add edi,ecx + jmp %%nextvalr +%%rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [mode7yrpos],eax + add edi,ecx + jmp %%nextposxr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[mode7yrpos+1],07h + and byte[mode7xrpos+1],07h + mov cl,[mode7yrpos+1] + mov eax,[mode7xadder] + mov ch,[mode7xrpos+1] + add [mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[mode7yadder] + mov dl,[vrama+edx] + sub [mode7yrpos],eax + %1 + dec dword[ngwleftb] + jnz near %%tilerep3 + + mov [mode7xrpos],eax + cmp dword[ngwleft],0 + je %%notskipvalues5 + call ProcessMode7ngwinB + cmp dword[ngwleftb],0 + jne near %%tilerep3 +%%notskipvalues5 + + jmp %%finishmode7 +%endmacro + +;************************************ + + + \ No newline at end of file diff --git a/zsnes/src/video/mode716.asm b/zsnes/src/video/mode716.asm new file mode 100644 index 00000000..879f5108 --- /dev/null +++ b/zsnes/src/video/mode716.asm @@ -0,0 +1,687 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM mode7tab,winptrref,nglogicval,winlogicaval +EXTSYM curmosaicsz,curvidoffset,cwinptr,domosaic,mode7A,mode7B +EXTSYM mode7C,mode7D,mode7X0,mode7Y0,mode7set,vram,vrama,winon,xtravbuf +EXTSYM ngwleft,ngwleftb,mode7xpos,mode7ypos,mode7xrpos,mode7yrpos +EXTSYM mode7xadder,mode7yadder,mode7hr,drawmode7winhr,dcolortab +EXTSYM UnusedBitXor,UnusedBit +EXTSYM scrndis +EXTSYM vidbright,prevbrightdc,Gendcolortable +EXTSYM mode7ab,mode7cd,BGMA +EXTSYM BG1SXl,BG1SYl + EXTSYM processmode7hires + +%include "video/mode716.mac" + + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + +%macro Mode7Normal 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Normalnt 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Normalt 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2+512] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Normalmsnt 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi],dx + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Normalmst 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2+512] + mov [esi],dx + and dx,[UnusedBitXor] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Normalsnt 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Normalst 0 + or dl,dl + jz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Direct 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Directnt 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Directt 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + or dx,[UnusedBit] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Directmsnt 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + mov [esi],dx + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Directmst 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + mov [esi+75036*2],dx + or dx,[UnusedBit] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Directsnt 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Directst 0 + or dl,dl + jz %%nodrawb + mov dx,[dcolortab+edx*4] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBG 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBGnt 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBGt 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2+512] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBGmsnt 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi],dx + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBGmst 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2+512] + mov [esi+75036*2],dx + or dx,[UnusedBit] + mov [esi],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBGsnt 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7ExtBGst 0 + mov [esi+75036*8],dl + or dl,dl + jz %%nodrawb + test dl,80h + jnz %%nodrawb + mov dx,[ebp+edx*2] + mov [esi+75036*2],dx + xor edx,edx +%%nodrawb + add esi,2 +%endmacro + +NEWSYM drawmode7win16b + test byte[scrndis],1 + jz .notdisabled + ret +.notdisabled + CheckTransparency 01h,drawmode7win16bt +normal + Mode7NonMainSub Mode7Normal +drawmode7win16bt + test byte[scadtng+ebx],1h + jz near drawmode7win16bnt + test byte[BGMS1+ebx*2+1],1h + jnz near drawmode716bmst + Mode7NonMainSub Mode7Normalt +drawmode716bmst: + mov edi,[CMainWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmt + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bst +drawmode7w16bmst + Mode7NonMainSub Mode7Normalmst +drawmode7w16bmt + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmst + Mode7MainSub Mode7Normalmst,Mode7Normalst +drawmode7w16bst + Mode7MainSub Mode7Normalmst,Mode7Normalt +drawmode7win16bnt: + test byte[BGMS1+ebx*2+1],1h + jnz near drawsprngm716bmsnt + Mode7NonMainSub Mode7Normalnt +drawsprngm716bmsnt: + cmp dword[ngwinen],0 + je drawmode7w16bmsnt + mov edi,[CMainWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmnt + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bsnt +drawmode7w16bmsnt + Mode7NonMainSub Mode7Normalmsnt +drawmode7w16bmnt + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmsnt + Mode7MainSub Mode7Normalmsnt,Mode7Normalsnt +drawmode7w16bsnt + Mode7MainSub Mode7Normalmsnt,Mode7Normalnt + +NEWSYM drawmode7win16bd + test byte[scrndis],1 + jz .notdisabled + ret +.notdisabled + mov bl,[vidbright] + cmp bl,[prevbrightdc] + je .nodcchange + mov [prevbrightdc],bl + call Gendcolortable +.nodcchange + CheckTransparency 01h,drawmode7win16btd + Mode7NonMainSub Mode7Direct +drawmode7win16btd + test byte[scadtng+ebx],1h + jz near drawmode7win16bntd + test byte[BGMS1+ebx*2+1],1h + jnz near drawmode716bmstd + Mode7NonMainSub Mode7Directt +drawmode716bmstd: + mov edi,[CMainWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmtd + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bstd +drawmode7w16bmstd + Mode7NonMainSub Mode7Directmst +drawmode7w16bmtd + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmstd + Mode7MainSub Mode7Directmst,Mode7Directst +drawmode7w16bstd + Mode7MainSub Mode7Directmst,Mode7Directt +drawmode7win16bntd: + test byte[BGMS1+ebx*2+1],1h + jnz near drawsprngm716bmsntd + Mode7NonMainSub Mode7Directnt +drawsprngm716bmsntd: + cmp dword[ngwinen],0 + je drawmode7w16bmsntd + mov edi,[CMainWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmntd + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bsntd +drawmode7w16bmsntd + Mode7NonMainSub Mode7Directmsnt +drawmode7w16bmntd + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmsntd + Mode7MainSub Mode7Directmsnt,Mode7Directsnt +drawmode7w16bsntd + Mode7MainSub Mode7Directmsnt,Mode7Directnt + + +NEWSYM drawmode7ngextbg16b + test byte[scrndis],1 + jz .notdisabled + ret +.notdisabled + mov byte[curmosaicsz],1 + push ecx + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov ecx,256 +.loop + mov byte[esi+75036*8],0 + add esi,2 + loop .loop + pop ecx + + cmp byte[mode7hr+ebx],1 +; je near drawmode7winextbghr16e + CheckTransparency 02h,drawmode7win16bte + mov esi,[cwinptr] + mov [winptrref],esi + mov esi,[curvidoffset] + Mode7NonMainSube Mode7ExtBG +drawmode7win16bte + test byte[scadtng+ebx],1h + jz near drawmode7win16bnte + test byte[BGMS1+ebx*2+1],1h + jnz near drawmode716bmste + Mode7NonMainSube Mode7ExtBGt +drawmode716bmste: + mov edi,[CMainWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmte + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bste +drawmode7w16bmste + Mode7NonMainSube Mode7ExtBGmst +drawmode7w16bmte + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmste + Mode7MainSube Mode7ExtBGmst,Mode7ExtBGst +drawmode7w16bste + Mode7MainSube Mode7ExtBGmst,Mode7ExtBGt +drawmode7win16bnte: + test byte[BGMS1+ebx*2+1],1h + jnz near drawsprngm716bmsnte + Mode7NonMainSube Mode7ExtBGnt +drawsprngm716bmsnte: + cmp dword[ngwinen],0 + je drawmode7w16bmsnte + mov edi,[CMainWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmnte + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bsnte +drawmode7w16bmsnte + Mode7NonMainSube Mode7ExtBGmsnt +drawmode7w16bmnte + mov edi,[CSubWinScr] + cmp byte[edi+ebx],0 + jne near drawmode7w16bmsnte + Mode7MainSube Mode7ExtBGmsnt,Mode7ExtBGsnt +drawmode7w16bsnte + Mode7MainSube Mode7ExtBGmsnt,Mode7ExtBGnt + +%macro ExtBG2 1 + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov ecx,256 + xor eax,eax +.loop + mov al,[esi+75036*8] + test al,80h + jz .nopr2 + and al,7Fh + %1 +.nopr2 + add esi,2 + loop .loop + xor eax,eax + ret +%endmacro + +%macro ExtBGNormal 0 + mov dx,[ebp+eax*2] + mov [esi],dx +%endmacro +%macro ExtBGNormalt 0 + mov dx,[ebp+eax*2+512] + mov [esi],dx +%endmacro +%macro ExtBGNormalnt 0 + mov dx,[ebp+eax*2] + mov [esi],dx +%endmacro +%macro ExtBGNormalst 0 + mov dx,[ebp+eax*2] + mov [esi+75036*2],dx +%endmacro +%macro ExtBGNormalsnt 0 + mov dx,[ebp+eax*2] + mov [esi+75036*2],dx +%endmacro +%macro ExtBGNormalmst 0 + mov dx,[ebp+eax*2+512] + mov [esi],dx + and dx,[UnusedBitXor] + mov [esi+75036*2],dx +%endmacro +%macro ExtBGNormalmsnt 0 + mov dx,[ebp+eax*2] + mov [esi],dx + mov [esi+75036*2],dx +%endmacro + +NEWSYM drawmode7ngextbg216b + test byte[scrndis],1 + jz .notdisabled + ret +.notdisabled + cmp byte[mode7hr+ebx],1 +; je near drawmode7winextbg2hr16b + ; esi = pointer to video buffer + CheckTransparency 01h,drawmode7ngextbg216bt + test byte[FillSubScr+ebx],1 + jz .main + test byte[BGMS1+ebx*2],01h + jnz .main + add esi,75036*2 +.main + ExtBG2 ExtBGNormal +drawmode7ngextbg216bt: + test byte[scadtng+ebx],1h + jz near drawmode7ngextbg216bnt + test byte[BGMS1+ebx*2+1],1h + jnz near drawmode7ngextbg216bmst + ExtBG2 ExtBGNormalt +drawmode7ngextbg216bmst + test byte[BGMS1+ebx*2],1h + jz near drawmode7ngextbg216bst + ExtBG2 ExtBGNormalmst +drawmode7ngextbg216bst: + ExtBG2 ExtBGNormalst +drawmode7ngextbg216bnt: + test byte[BGMS1+ebx*2+1],1h + jnz near drawmode7ngextbg216bmsnt + ExtBG2 ExtBGNormalnt +drawmode7ngextbg216bmsnt + test byte[BGMS1+ebx*2],1h + jz near drawmode7ngextbg216bsnt + ExtBG2 ExtBGNormalmsnt +drawmode7ngextbg216bsnt: + ExtBG2 ExtBGNormalsnt + +ALIGN32 +mtemp dd 0 ; for byte move left +mmode7xpos dd 0 ; x position +mtempa2 dd 0 ; keep this blank! +mmode7xrpos dd 0 ; x position +mtempa dd 0 ; keep this blank! +mmode7ypos dd 0 ; y position +mtempb2 dd 0 ; keep this blank! +mmode7yrpos dd 0 ; y position +mtempb dd 0 ; keep this blank! +mmode7xadder dd 0 ; number to add for x +mtempc2 dd 0 ; keep this blank! +mmode7xadd2 dd 0 ; number to add for x +mtempc dd 0 ; keep this blank! +mmode7yadder dd 0 ; number to add for y +mtempd2 dd 0 ; keep this blank! +mmode7yadd2 dd 0 ; number to add for y +mtempd dd 0 ; keep this blank! +mmode7ptr dd 0 ; pointer value +mmode7xinc dd 0 ; number to add for x +mmode7xincc dd 0 ; range check for x +mmode7yinc dd 0 ; number to add for y +mmode7xsloc dd 0 ; which screen x +mmode7ysloc dd 0 ; which screen y +mmode7xsrl dd 0 ; which relative screen x +mmode7ysrl dd 0 ; which relative screen y +mcxloc dw 0 ; cx location +mcyloc dw 0 ; cy location +M7HROn dd 0 ; High Resolution On +switchtorep3 dd 0 + +m7xaddof dd 0 +m7xaddof2 dd 0 +m7yaddof dd 0 +m7yaddof2 dd 0 +pixelsleft dd 0 +mm7xaddof dd 0 +mm7xaddof2 dd 0 +mm7yaddof dd 0 +mm7yaddof2 dd 0 + +%macro newvaluepred 2 + mov dx,word[%1+ebx*4+8] + cmp dx,word[%1+ebx*4] + je %%nodivide + cmp byte[BGMA+ebx+2],7 + je %%mode7scaleb +%%nodivide + movsx edx,word[%1+ebx*4+4] + movsx ecx,word[%1+ebx*4] + add ecx,edx + sar ecx,1 + mov [%2],cx + jmp %%mode7scalend +%%mode7scaleb + mov esi,ebx + movsx ebx,word[%1+esi*4+8] + movsx edx,word[%1+esi*4] + sub ebx,edx + movsx ecx,word[%1+esi*4+4] + sub ecx,edx + mov eax,ecx + imul ecx + idiv ebx + add ax,word[%1+esi*4] + mov ebx,esi + mov [%2],ax +%%mode7scalend +%endmacro + +CalculateNewValues: + ; predict new values + push eax + push edx + push ebx + push esi + newvaluepred mode7ab,mode7A + newvaluepred mode7ab+2,mode7B + newvaluepred mode7cd,mode7C + newvaluepred mode7cd+2,mode7D + pop esi + pop ebx + pop edx + pop eax + + mov ecx,edx + xor edx,edx + mov dx,[BG1SXl+ebx*2+2] + add edx,ecx + shr edx,1 + + mov ecx,eax + mov eax,ebx + inc eax + test byte[mode7set],02h + jz .noflip + mov eax,261 + sub eax,ebx +.noflip + add ax,[BG1SYl+ebx*2+2] + add eax,ecx + ret + + +NEWSYM processmode7hires16b + cmp byte[BGMA+ebx+1],7 + jne near .nogo + push esi + push ebx + call CalculateNewValues + add esi,75036*4 + mov [curvidoffset],esi + mov dword[M7HROn],1 + call drawmode7win16b + mov dword[M7HROn],0 + pop ebx + pop esi +.nogo + ret + +NEWSYM processmode7hires16bd + cmp byte[BGMA+ebx+1],7 + jne near .nogo + push esi + push ebx + call CalculateNewValues + add esi,75036*4 + mov [curvidoffset],esi + mov dword[M7HROn],1 + call drawmode7win16bd + mov dword[M7HROn],0 + pop ebx + pop esi +.nogo + ret + + \ No newline at end of file diff --git a/zsnes/src/video/mode716.mac b/zsnes/src/video/mode716.mac new file mode 100644 index 00000000..8e894497 --- /dev/null +++ b/zsnes/src/video/mode716.mac @@ -0,0 +1,1904 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM BGMS1,FillSubScr,CMainWinScr,CSubWinScr,scadtng +EXTSYM ngwinen, winbg1enval, BuildWindow, ngwintable, ngcwinptr, domosaicng16b +EXTSYM pesimpng + + + + + + +%macro ProcessBuildWindow 1 + mov dword[ngwinen],0 + test byte[winbg1enval+ebx+%1*256],0Ah + jz %%nowindowing + push eax + push ebx + mov al,[winlogicaval+ebx*2] + shr al,%1*2 + and al,03h + mov [nglogicval],al + mov eax,ebx + add ebx,%1*256 + call BuildWindow + cmp dword[ngwintable],0 + je %%zero + dec dword[ngwintable] + jmp %%notzero +%%zero + dec dword[ngwintable+4] +%%notzero + pop ebx + pop eax + mov dword[ngcwinptr],ngwintable +%%nowindowing +%endmacro + +;Skip transparency if the bg is just a sub-screen or there are no sub-screens +;for that line: +%macro CheckTransparency 2 + cmp byte[curmosaicsz],1 + jne %%nosubmain + test byte[BGMS1+ebx*2],%1 + jz %%nosubmain + test byte[FillSubScr+ebx],1 + jnz near %2 +%%nosubmain +%endmacro + +%macro Mode7NoTranspPreStartUp 0 + mov esi,[cwinptr] + mov [winptrref],esi + mov esi,[curvidoffset] + test byte[FillSubScr+ebx],1 + jz %%main + test byte[BGMS1+ebx*2],01h + jnz %%main + add esi,75036*2 +%%main +%endmacro + +%macro Mode7NoTranspPreStartUp2 0 + mov esi,[cwinptr] + mov [winptrref],esi + mov esi,[curvidoffset] +%endmacro + +%macro WinEnCheck 0 + mov esi,[CMainWinScr] + test byte[FillSubScr+ebx],1 + jz %%main2 + test byte[BGMS1+ebx*2],01h + jnz %%main2 + mov esi,[CSubWinScr] +%%main2 +%endmacro + +%macro WinEnCheckMS 0 + mov esi,winbg1enval +%endmacro + +%macro Mode7Calculate16b 0 + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + cmp byte[M7HROn],1 + je near .calculateb + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [mcxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [mcxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [mcyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[mcyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[mcyloc] + imul eax,ebx + mov [mmode7xpos],eax + mov bx,word[mode7X0] + add [mmode7xpos+1],bx + + movsx ebx,word[mcyloc] + movsx eax,word[mode7D] + imul eax,ebx + mov [mmode7ypos],eax + mov bx,word[mode7Y0] + add [mmode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[mcxloc] + movsx eax,word[mode7A] + mov [mmode7xadder],eax + imul eax,ebx + neg eax + add [mmode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[mcxloc] + neg eax + mov [mmode7yadder],eax + imul eax,ebx + add [mmode7ypos],eax + + test byte[mode7set],1 + jz .nohflip + mov eax,[mmode7xadder] + shl eax,8 + add [mmode7xpos],eax + neg dword[mmode7xadder] + mov eax,[mmode7yadder] + shl eax,8 + sub [mmode7ypos],eax + neg dword[mmode7yadder] +.nohflip + jmp .calculatea +.calculateb + + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegacb + or bx,1110000000000000b +.nonegacb + mov [mcxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegbcb + or bx,1110000000000000b +.nonegbcb + sub [mcxloc],bx + mov bx,ax + and bx,0011111111111111b ; 13 -> 16 bit signed value + test bx,0010000000000000b + jz .nonegccb + or bx,1100000000000000b +.nonegccb + mov [mcyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegdcb + or bx,1110000000000000b +.nonegdcb + add bx,bx + sub word[mcyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[mcyloc] + imul eax,ebx + sar eax,1 + mov [mmode7xpos],eax + mov bx,word[mode7X0] + add [mmode7xpos+1],bx + + movsx ebx,word[mcyloc] + movsx eax,word[mode7D] + imul eax,ebx + sar eax,1 + mov [mmode7ypos],eax + mov bx,word[mode7Y0] + add [mmode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[mcxloc] + movsx eax,word[mode7A] + mov [mmode7xadder],eax + imul eax,ebx + neg eax + add [mmode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[mcxloc] + neg eax + mov [mmode7yadder],eax + imul eax,ebx + add [mmode7ypos],eax + + test byte[mode7set],1 + jz .nohflipcb + mov eax,[mmode7xadder] + shl eax,8 + add [mmode7xpos],eax + neg dword[mmode7xadder] + mov eax,[mmode7yadder] + shl eax,8 + sub [mmode7ypos],eax + neg dword[mmode7yadder] +.nohflipcb +.calculatea +%endmacro + +Mode7Startup16b: + Mode7Calculate16b + ; esi = pointer to video buffer + mov [pesimpng],esi + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[mmode7xadd2],800h + mov byte[mmode7xinc],2 + mov byte[mmode7xincc],0 + test dword[mmode7xadder],80000000h + jz .noneg + mov dword[mmode7xadd2],-800h + mov byte[mmode7xinc],-2 + mov byte[mmode7xincc],0FEh +.noneg + mov dword[mmode7yadd2],800h + mov byte[mmode7yinc],1 + test dword[mmode7yadder],80000000h + jz .noneg2 + mov dword[mmode7yadd2],-800h + mov byte[mmode7yinc],-1 +.noneg2 + ret + +%macro Mode7Startup 0 + call Mode7Startup16b + + cmp byte[ngwinen],1 + je near .drawmode7win + + mov edi,[vram] + cmp dword[mmode7xadder],7F0h + jg near .nextval3 + cmp dword[mmode7xadder],-7F0h + jl near .nextval3 + cmp dword[mmode7yadder],7F0h + jg near .nextval3 + cmp dword[mmode7yadder],-7F0h + jl near .nextval3 +%endmacro + +%macro Mode7MidRoutines 0 + +.drawmode7win +.domosaicw + mov ebx,[mmode7xrpos] + mov [mode7xrpos],ebx + mov ebx,[mmode7yrpos] + mov [mode7yrpos],ebx + mov ebx,[mmode7xadder] + mov [mode7xadder],ebx + mov ebx,[mmode7yadder] + mov [mode7yadder],ebx + mov ebx,[mmode7xpos] + mov [mode7xpos],ebx + mov ebx,[mmode7ypos] + mov [mode7ypos],ebx +%endmacro + + +NEWSYM ProcessMode7ngwin16b + mov ecx,[ngcwinptr] + mov ecx,[ecx] + or ecx,ecx + jz near .winb + cmp ecx,[ngwleft] + jae .alldisplay + sub [ngwleft],ecx + mov dword[ngwleftb],ecx + xor ecx,ecx + mov eax,[mode7xrpos] + ret +.alldisplay + mov ecx,[ngwleft] + mov dword[ngwleftb],ecx + mov dword[ngwleft],0 + xor ecx,ecx + mov eax,[mode7xrpos] + ret +.winb +NEWSYM ProcessMode7ngwinB16b + add dword[ngcwinptr],4 + mov ecx,[ngcwinptr] + mov ecx,[ecx] + cmp ecx,[ngwleft] + jae near .finishmode7 + +; mov ecx,[ngwleft] +; mov dword[ngwleftb],ecx +; mov dword[ngwleft],0 +; xor ecx,ecx +; mov eax,[mode7xrpos] +; ret + + sub [ngwleft],ecx + or ecx,ecx + jz .noclip + mov [pixelsleft],ecx +.nextvalngw + test byte[mode7xrpos+1],0F8h + jnz near .rposoffx +.nextposx + test byte[mode7yrpos+1],0F8h + jnz near .rposoffy +.nextposy + + mov eax,[mode7xadder] + add [mode7xrpos],eax + mov eax,[mode7yadder] + sub [mode7yrpos],eax + add esi,2 + dec dword[pixelsleft] + jnz near .nextvalngw +.noclip + add dword[ngcwinptr],4 + jmp ProcessMode7ngwin16b +.finishmode7 + mov dword[ngwleft],0 + mov dword[ngwleftb],0 + ret + +.rposoffx + mov eax,[m7xaddof] + sub [mode7xrpos],eax + add bl,[m7xaddof2] + test byte[mode7xrpos+1],0F8h + jz .noaddstuff + add bl,[mmode7xinc] + mov eax,[mmode7xadd2] + sub [mode7xrpos],eax +.noaddstuff + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp .nextposx +.rposoffy + mov eax,[m7yaddof] + add dword[mode7yrpos],eax + sub bh,[m7yaddof2] + test byte[mode7yrpos+1],0F8h + jz .noaddstuff2 + sub bh,[mmode7yinc] + mov eax,[mmode7yadd2] + add dword[mode7yrpos],eax +.noaddstuff2 + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp .nextposy + +NEWSYM ProcessMode7ngwinC16b + mov ecx,[ngcwinptr] + mov ecx,[ecx] + or ecx,ecx + jz near .winb + cmp ecx,[ngwleft] + jae .alldisplay + sub [ngwleft],ecx + mov dword[ngwleftb],ecx + xor ecx,ecx + mov eax,[mode7xpos] + ret +.alldisplay + mov ecx,[ngwleft] + mov dword[ngwleftb],ecx + mov dword[ngwleft],0 + xor ecx,ecx + mov eax,[mode7xpos] + ret +.winb +NEWSYM ProcessMode7ngwinD16b + add dword[ngcwinptr],4 + mov ecx,[ngcwinptr] + mov ecx,[ecx] + cmp ecx,[ngwleft] + jae near .finishmode7 + sub [ngwleft],ecx + or ecx,ecx + jz .noclip +.nextvalngw +.nextvalr +; cmp byte[switchtorep3],1 +; je .nextposy +; test byte[mode7xpos+1],0F8h +; jnz near .rposoffx +.nextposx +; test byte[mode7ypos+1],0F8h +; jnz near .rposoffy +.nextposy + mov eax,[mode7xadder] + add [mode7xpos],eax + mov eax,[mode7yadder] + sub [mode7ypos],eax + add esi,2 + dec ecx + jnz near .nextvalngw +.noclip + add dword[ngcwinptr],4 + jmp ProcessMode7ngwin16b +.finishmode7 + mov dword[ngwleft],0 + mov dword[ngwleftb],0 + ret +.rposoffx + mov al,[mmode7xinc] + mov edi,[vram] + add [mmode7ptr],al + mov cl,byte[mmode7xincc] + cmp byte[mmode7ptr],cl + je .roffx +.roffxretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7xadd2] + shl ecx,7 + sub [mode7xrpos],eax + add edi,ecx + jmp .nextvalr +.roffx + mov byte[switchtorep3],1 + jmp .roffxretb +.rposoffy + mov al,[mmode7yinc] + mov edi,[vram] + sub [mmode7ptr+1],al + js .roffy +.roffyretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7yadd2] + shl ecx,7 + add [mode7yrpos],eax + add edi,ecx + jmp .nextposx +.roffy + mov byte[switchtorep3],1 + jmp .roffyretb + +%macro ProcessBuildWindow16b 1 + mov dword[ngwinen],0 + test byte[esi+ebx+%1*256],0Ah + jz %%nowindowing + push eax + push ebx + mov al,[winlogicaval+ebx*2] + shr al,%1*2 + and al,03h + mov [nglogicval],al + mov eax,ebx + add ebx,%1*256 + call BuildWindow + cmp dword[ngwintable],0 + je %%zero + dec dword[ngwintable] + jmp %%notzero +%%zero + dec dword[ngwintable+4] +%%notzero + pop ebx + pop eax + mov dword[ngcwinptr],ngwintable +%%nowindowing +%endmacro + +%macro Mode7Process 3 + mov dword[mtemp],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[mmode7xrpos] + mov ebx,[mmode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,08h + jnz near %%rposoffx +%%nextposx + test byte[mmode7yrpos+1],08h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov edx,[mmode7yadder] + mov cl,byte[mmode7yrpos+1] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[mmode7xadder] + mov dl,[edi+edx] + %1 + dec dword[mtemp] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + add bl,[mmode7xinc] + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,[mmode7xadd2] + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + sub bh,[mmode7yinc] + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + mov edx,[mmode7yadd2] + shl ecx,7 + add dword[mmode7yrpos],edx + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[mmode7ypos+2],3 + ja %%offscr2 + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[mmode7xadder] + mov ebx,[mmode7yadder] + add [mmode7xpos],eax + sub [mmode7ypos],ebx + add esi,%3 + dec dword[mtemp] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[mmode7ypos+2],3 + ja %%offscr2b + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[mmode7xpos+1] + mov eax,[mmode7xadder] + mov cl,[mmode7ypos+1] + mov ebx,[mmode7yadder] + mov dl,[mode7tab+ecx] + add [mmode7xpos],eax + mov dl,[vrama+edx] + sub [mmode7ypos],ebx + %1 + dec dword[mtemp] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[mtemp] + jz near %%fin2 +%%nextvalr + test byte[mmode7xrpos+1],08h + jnz near %%rposoffxr +%%nextposxr + test byte[mmode7yrpos+1],08h + jnz near %%rposoffyr +%%nextposyr + mov cl,[mmode7yrpos+1] + mov ch,[mmode7xrpos+1] + mov edx,[mmode7xadder] + add dword[mmode7xrpos],edx + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] +%%m7yrpa2 + mov dl,[edi+edx] + %1 + dec dword[mtemp] + jnz near %%nextvalr +%%fin2 + jmp %%finishmode7 +%%rposoffxr + mov al,[mmode7xinc] + mov edi,[vram] + add [mmode7ptr],al + mov cl,byte[mmode7xincc] + cmp byte[mmode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7xadd2] + shl ecx,7 + sub [mmode7xrpos],eax + add edi,ecx + jmp %%nextposxr +%%rposoffyr + mov al,[mmode7yinc] + mov edi,[vram] + sub [mmode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7yadd2] + shl ecx,7 + add [mmode7yrpos],eax + add edi,ecx + jmp %%nextposyr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[mmode7yrpos+1],07h + and byte[mmode7xrpos+1],07h + mov cl,[mmode7yrpos+1] + mov eax,[mmode7xadder] + mov ch,[mmode7xrpos+1] + add [mmode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[mmode7yadder] + mov dl,[vrama+edx] + sub [mmode7yrpos],eax + %1 + dec dword[mtemp] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + +%macro Mode7ProcessB 3 + mov dword[mtemp],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + xor dl,dl + xor ecx,ecx + mov ebx,[mmode7xadder] + test ebx,80000000h + jz %%nexta + neg ebx +%%nexta + cmp ebx,0800h + jl %%skipx + sub ebx,800h + add ecx,[mmode7xadd2] + add dl,[mmode7xinc] + jmp %%nexta +%%skipx + mov [mm7xaddof],ecx + mov [mm7xaddof2],dl + + xor dl,dl + xor ecx,ecx + mov ebx,[mmode7yadder] + test ebx,80000000h + jz %%nextay + neg ebx +%%nextay + cmp ebx,0800h + jl %%skipy + sub ebx,800h + add ecx,[mmode7yadd2] + add dl,[mmode7yinc] + jmp %%nextay +%%skipy + mov [mm7yaddof],ecx + mov [mm7yaddof2],dl + + xor ecx,ecx + + mov eax,[mmode7xrpos] + mov ebx,[mmode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,0F8h + jnz near %%rposoffx +%%nextposx + test byte[mmode7yrpos+1],0F8h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov cl,byte[mmode7yrpos+1] + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[mmode7xadder] + mov dl,[edi+edx] + %1 + dec dword[mtemp] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + sub eax,[mm7xaddof] + add bl,[mm7xaddof2] + test ah,0F8h + jz %%noaddstuff + add bl,[mmode7xinc] + sub eax,[mmode7xadd2] +%%noaddstuff + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + mov edx,[m7yaddof] + add dword[mmode7yrpos],edx + sub bh,[mm7yaddof2] + test byte[mmode7yrpos+1],0F8h + jz %%noaddstuff2 + mov edx,[mmode7yadd2] + sub bh,[mmode7yinc] + add dword[mmode7yrpos],edx +%%noaddstuff2 + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[mmode7ypos+2],3 + ja %%offscr2 + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[mmode7xadder] + mov ebx,[mmode7yadder] + add [mmode7xpos],eax + sub [mmode7ypos],ebx + add esi,%3 + dec dword[mtemp] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[mmode7ypos+2],3 + ja %%offscr2b + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[mmode7xpos+1] + mov eax,[mmode7xadder] + mov cl,[mmode7ypos+1] + mov ebx,[mmode7yadder] + mov dl,[mode7tab+ecx] + add [mmode7xpos],eax + mov dl,[vrama+edx] + sub [mmode7ypos],ebx + %1 + dec dword[mtemp] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[mtemp] + jz near %%fin2 +%%nextvalr + test byte[mmode7xrpos+1],0F8h + jnz near %%rposoffxr +%%nextposxr + test byte[mmode7yrpos+1],0F8h + jnz near %%rposoffyr +%%nextposyr + mov cl,[mmode7yrpos+1] + mov ch,[mmode7xrpos+1] + mov edx,[mmode7xadder] + add dword[mmode7xrpos],edx + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[mtemp] + jnz near %%nextvalr +%%fin2 + jmp %%finishmode7 +%%rposoffxr + mov al,[mmode7xinc] + mov edi,[vram] + add [mmode7ptr],al + mov cl,byte[mmode7xincc] + cmp byte[mmode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7xadd2] + shl ecx,7 + sub [mmode7xrpos],eax + add edi,ecx + jmp %%nextvalr +%%rposoffyr + mov al,[mmode7yinc] + mov edi,[vram] + sub [mmode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7yadd2] + shl ecx,7 + add [mmode7yrpos],eax + add edi,ecx + jmp %%nextposxr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[mmode7yrpos+1],07h + and byte[mmode7xrpos+1],07h + mov cl,[mmode7yrpos+1] + mov eax,[mmode7xadder] + mov ch,[mmode7xrpos+1] + add [mmode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[mmode7yadder] + mov dl,[vrama+edx] + sub [mmode7yrpos],eax + %1 + dec dword[mtemp] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + +%macro Mode7Processngw16b 3 + mov dword[ngwleftb],256 + mov dword[ngwleft],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[mmode7xpos] + and eax,7FFh + mov [mode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + xor dl,dl + xor ecx,ecx + mov ebx,[mmode7xadder] + test ebx,80000000h + jz %%nexta + neg ebx +%%nexta + cmp ebx,0800h + jl %%skipx + sub ebx,800h + add ecx,[mmode7xadd2] + add dl,[mmode7xinc] + jmp %%nexta +%%skipx + mov [mm7xaddof],ecx + mov [mm7xaddof2],dl + mov [m7xaddof],ecx + mov [m7xaddof2],dl + + xor dl,dl + xor ecx,ecx + mov ebx,[mmode7yadder] + test ebx,80000000h + jz %%nextay + neg ebx +%%nextay + cmp ebx,0800h + jl %%skipy + sub ebx,800h + add ecx,[mmode7yadd2] + add dl,[mmode7yinc] + jmp %%nextay +%%skipy + mov [mm7yaddof],ecx + mov [mm7yaddof2],dl + mov [m7yaddof],ecx + mov [m7yaddof2],dl + + xor ecx,ecx + + mov eax,[mode7xrpos] + mov ebx,[mmode7ptr] + + call ProcessMode7ngwin16b + + cmp dword[ngwleftb],0 + jne near %%nextval + jmp %%finishmode7 + ALIGN16 +%%nextval + test ah,0F8h + jnz near %%rposoffx +%%nextposx + test byte[mode7yrpos+1],0F8h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov cl,byte[mode7yrpos+1] + mov edx,[mode7yadder] + sub dword[mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[mode7xadder] + mov dl,[edi+edx] + %1 + dec dword[ngwleftb] + jnz near %%nextval + mov [mode7xrpos],eax + cmp dword[ngwleft],0 + je %%notskipvalues + call ProcessMode7ngwinB16b + cmp dword[ngwleftb],0 + jne near %%nextval +%%notskipvalues + jmp %%finishmode7 + +%%rposoffx + sub eax,[mm7xaddof] + add bl,[mm7xaddof2] + test ah,0F8h + jz %%noaddstuff + add bl,[mmode7xinc] + sub eax,[mmode7xadd2] +%%noaddstuff + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + mov edx,[mm7yaddof] + add dword[mode7yrpos],edx + sub bh,[mm7yaddof2] + test byte[mode7yrpos+1],0F8h + jz %%noaddstuff2 + mov edx,[mmode7yadd2] + sub bh,[mmode7yinc] + add dword[mode7yrpos],edx +%%noaddstuff2 + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + mov byte[switchtorep3],0 + +; mov dword[ngcwinptr],ngwintable blahblah +; mov ebx,dword[ngcwinptr] +; mov dword[ebx],900 + ;ngwintable +; jmp %%finishmode7 + + call ProcessMode7ngwinC16b + cmp dword[ngwleftb],0 + jne near %%nextvald + jmp %%finishmode7 +%%nextvald + mov dword[ngwleft],0 + + test byte[mode7set],40h + jnz near %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[mode7ypos+2],3 + ja %%offscr2 + cmp byte[mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[mode7xadder] + mov ebx,[mode7yadder] + add [mode7xpos],eax + sub [mode7ypos],ebx + add esi,%3 + dec dword[ngwleftb] + jnz near %%nextvalb2 + + cmp dword[ngwleft],0 + je %%notskipvalues3b + call ProcessMode7ngwinD16b + cmp dword[ngwleftb],0 + jne near %%nextvalb2 +%%notskipvalues3b + + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[mode7ypos+2],3 + ja %%offscr2b + cmp byte[mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[mode7xpos+1] + mov eax,[mode7xadder] + mov cl,[mode7ypos+1] + mov ebx,[mode7yadder] + mov dl,[mode7tab+ecx] + add [mode7xpos],eax + mov dl,[vrama+edx] + sub [mode7ypos],ebx + %1 + dec dword[ngwleftb] + jnz near %%nextvalb3 + + cmp dword[ngwleft],0 + je %%notskipvalues3 + call ProcessMode7ngwinD16b + cmp dword[ngwleftb],0 + jne near %%nextvalb3 +%%notskipvalues3 + + jmp %%finishmode7 +%%offscr3 + mov eax,[mode7xpos] + and eax,7FFh + mov [mode7xrpos],eax + mov eax,[mode7ypos] + and eax,7FFh + mov [mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mode7ypos+1] + mov eax,[mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[ngwleftb] + jz near %%fin2 +%%nextvalr + test byte[mode7xrpos+1],0F8h + jnz near %%rposoffxr +%%nextposxr + test byte[mode7yrpos+1],0F8h + jnz near %%rposoffyr +%%nextposyr + mov cl,[mode7yrpos+1] + mov ch,[mode7xrpos+1] + mov edx,[mode7xadder] + add dword[mode7xrpos],edx + mov edx,[mode7yadder] + sub dword[mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[ngwleftb] + jnz near %%nextvalr +%%fin2 + + cmp dword[ngwleft],0 + je %%notskipvalues4 + call ProcessMode7ngwinB16b + cmp byte[switchtorep3],0 + jne near %%tilerep3 + cmp dword[ngwleftb],0 + jne near %%nextvalr +%%notskipvalues4 + + jmp %%finishmode7 +%%rposoffxr + mov al,[mmode7xinc] + mov edi,[vram] + add [mmode7ptr],al + mov cl,byte[mmode7xincc] + cmp byte[mmode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7xadd2] + shl ecx,7 + sub [mode7xrpos],eax + add edi,ecx + jmp %%nextvalr +%%rposoffyr + mov al,[mmode7yinc] + mov edi,[vram] + sub [mmode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7yadd2] + shl ecx,7 + add [mode7yrpos],eax + add edi,ecx + jmp %%nextposxr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[mode7yrpos+1],07h + and byte[mode7xrpos+1],07h + mov cl,[mode7yrpos+1] + mov eax,[mode7xadder] + mov ch,[mode7xrpos+1] + add [mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[mode7yadder] + mov dl,[vrama+edx] + sub [mode7yrpos],eax + %1 + dec dword[ngwleftb] + jnz near %%tilerep3 + + mov [mode7xrpos],eax + cmp dword[ngwleft],0 + je %%notskipvalues5 + call ProcessMode7ngwinB16b + cmp dword[ngwleftb],0 + jne near %%tilerep3 +%%notskipvalues5 + + jmp %%finishmode7 +%endmacro + +%macro Mode7Processngw216b 4 + mov eax,[ngcwinptr] + mov eax,[eax] + mov [ngwleft],eax + + mov dword[mtemp],256 + test byte[mode7set],80h + jnz near %%norep2start + + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[mmode7xrpos] + mov ebx,[mmode7ptr] + + cmp dword[ngwleft],0 + jne %%nextvalwb + jmp %%nextvalwc +%%nextvalw + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%nextvalwb + + test ah,08h + jnz near %%rposoffxw +%%nextposxw + test byte[mmode7yrpos+1],08h + jnz near %%rposoffyw +%%nextposyw + mov ch,ah + mov cl,byte[mmode7yrpos+1] + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[mmode7xadder] + mov dl,[edi+edx] + %1 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalwb + jmp %%nextvalwc + +%%rposoffxw + add bl,[mmode7xinc] + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,[mmode7xadd2] + lea edi,[ecx+vrama] + jmp %%nextposxw +%%rposoffyw + sub bh,[mmode7yinc] + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + mov edx,[mmode7yadd2] + shl ecx,7 + add dword[mmode7yrpos],edx + lea edi,[ecx+vrama] + jmp %%nextposyw + +%%nextvalwc + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%nextval + test ah,08h + jnz near %%rposoffx +%%nextposx + test byte[mmode7yrpos+1],08h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov cl,byte[mmode7yrpos+1] + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + add eax,[mmode7xadder] + mov dl,[edi+edx] + %4 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextval + jmp %%nextvalw +%%rposoffx + add bl,[mmode7xinc] + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,[mmode7xadd2] + lea edi,[ecx+vrama] + jmp %%nextposx +%%rposoffy + sub bh,[mmode7yinc] + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + mov edx,[mmode7yadd2] + shl ecx,7 + add dword[mmode7yrpos],edx + lea edi,[ecx+vrama] + jmp %%nextposy +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +; ******************************************* + +%%norep2start + cmp dword[ngwleft],0 + jne %%firstsetwb + jmp %%firstsetww +%%firstsetw + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%firstsetwb +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 +%%nextvalb2 + cmp byte[mmode7ypos+2],3 + ja %%offscr2 + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[mmode7xadder] + mov ebx,[mmode7yadder] + add [mmode7xpos],eax + sub [mmode7ypos],ebx + add esi,%3 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalb2 + jmp %%firstsetww +%%tilerep2 +%%nextvalb3 + cmp byte[mmode7ypos+2],3 + ja %%offscr2b + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[mmode7xpos+1] + mov eax,[mmode7xadder] + mov cl,[mmode7ypos+1] + mov ebx,[mmode7yadder] + mov dl,[mode7tab+ecx] + add [mmode7xpos],eax + mov dl,[vrama+edx] + sub [mmode7ypos],ebx + %1 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalb3 + jmp %%firstsetw + +%%offscr3 + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + jmp %%nextvalr +%%nodr2 + add esi,%3 + + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz %%nextvalr +%%secondsetw + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%nextvalr + test byte[mmode7xrpos+1],08h + jnz near %%rposoffxr +%%nextposxr + test byte[mmode7yrpos+1],08h + jnz near %%rposoffyr +%%nextposyr + mov cl,[mmode7yrpos+1] + mov ch,[mmode7xrpos+1] + mov edx,[mmode7xadder] + add dword[mmode7xrpos],edx + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalr + jmp %%secondsetww +%%rposoffxr + mov al,[mmode7xinc] + mov edi,[vram] + add [mmode7ptr],al + mov cl,byte[mmode7xincc] + cmp byte[mmode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7xadd2] + shl ecx,7 + sub [mmode7xrpos],eax + add edi,ecx + jmp %%nextposxr +%%rposoffyr + mov al,[mmode7yinc] + mov edi,[vram] + sub [mmode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7yadd2] + shl ecx,7 + add [mmode7yrpos],eax + add edi,ecx + jmp %%nextposyr + +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%thirdsetw + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%tilerep3 + and byte[mmode7yrpos+1],07h + and byte[mmode7xrpos+1],07h + mov cl,[mmode7yrpos+1] + mov eax,[mmode7xadder] + mov ch,[mmode7xrpos+1] + add [mmode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[mmode7yadder] + mov dl,[vrama+edx] + sub [mmode7yrpos],eax + %1 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%tilerep3 + jmp %%thirdsetww + +; ************************************* +%%firstsetww + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%norep2w + test byte[mode7set],40h + jnz %%tilerep2w +%%nextvalb2w + cmp byte[mmode7ypos+2],3 + ja %%offscr2w + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3w +%%offscr2w + mov eax,[mmode7xadder] + mov ebx,[mmode7yadder] + add [mmode7xpos],eax + sub [mmode7ypos],ebx + add esi,%3 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalb2w + jmp %%firstsetw +%%tilerep2w +%%nextvalb3w + cmp byte[mmode7ypos+2],3 + ja %%offscr2bw + cmp byte[mmode7xpos+2],3 + jbe near %%offscr3w +%%offscr2bw + mov ch,[mmode7xpos+1] + mov eax,[mmode7xadder] + mov cl,[mmode7ypos+1] + mov ebx,[mmode7yadder] + mov dl,[mode7tab+ecx] + add [mmode7xpos],eax + mov dl,[vrama+edx] + sub [mmode7ypos],ebx + %4 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalb3w + jmp %%firstsetw + +%%offscr3w + mov eax,[mmode7xpos] + and eax,7FFh + mov [mmode7xrpos],eax + mov eax,[mmode7ypos] + and eax,7FFh + mov [mmode7yrpos],eax + ; get tile data offset into edi + mov ebx,[mmode7ypos+1] + mov eax,[mmode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [mmode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + jmp %%nextvalrw +%%nodr2w + add esi,%3 + + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz %%nextvalrw +%%secondsetww + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%nextvalrw + test byte[mmode7xrpos+1],08h + jnz near %%rposoffxrw +%%nextposxrw + test byte[mmode7yrpos+1],08h + jnz near %%rposoffyrw +%%nextposyrw + mov cl,[mmode7yrpos+1] + mov ch,[mmode7xrpos+1] + mov edx,[mmode7xadder] + add dword[mmode7xrpos],edx + mov edx,[mmode7yadder] + sub dword[mmode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %4 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%nextvalrw + jmp %%secondsetw +%%rposoffxrw + mov al,[mmode7xinc] + mov edi,[vram] + add [mmode7ptr],al + mov cl,byte[mmode7xincc] + cmp byte[mmode7ptr],cl + je %%roffw +%%roffxretbw + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7xadd2] + shl ecx,7 + sub [mmode7xrpos],eax + add edi,ecx + jmp %%nextposxrw +%%rposoffyrw + mov al,[mmode7yinc] + mov edi,[vram] + sub [mmode7ptr+1],al + js %%roffw +%%roffyretbw + mov ebx,[mmode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[mmode7yadd2] + shl ecx,7 + add [mmode7yrpos],eax + add edi,ecx + jmp %%nextposyrw + +%%roffw + test byte[mode7set],40h + jnz %%tilerep3w + jmp %%finishmode7 +%%thirdsetww + add dword[ngcwinptr],4 + mov edx,[ngcwinptr] + mov edx,[edx] + mov dword[ngwleft],edx + xor edx,edx +%%tilerep3w + and byte[mmode7yrpos+1],07h + and byte[mmode7xrpos+1],07h + mov cl,[mmode7yrpos+1] + mov eax,[mmode7xadder] + mov ch,[mmode7xrpos+1] + add [mmode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[mmode7yadder] + mov dl,[vrama+edx] + sub [mmode7yrpos],eax + %4 + dec dword[mtemp] + jz near %%finishmode7 + dec dword[ngwleft] + jnz near %%tilerep3w + jmp %%thirdsetw +%endmacro + +; ********************************************************************* + +%macro Mode7NonMainSub 1 + WinEnCheck + ProcessBuildWindow16b 0 +.nohr + Mode7NoTranspPreStartUp + Mode7Startup + Mode7Process %1, domosaicng16b, 2 +.nextval3 + Mode7ProcessB %1, domosaicng16b, 2 + Mode7MidRoutines + mov edi,[vram] + Mode7Processngw16b %1, domosaicng16b, 2 +%endmacro + +%macro Mode7NonMainSube 1 + WinEnCheck + ProcessBuildWindow16b 0 +.nohr + Mode7NoTranspPreStartUp2 + Mode7Startup + Mode7Process %1, domosaicng16b, 2 +.nextval3 + Mode7ProcessB %1, domosaicng16b, 2 + Mode7MidRoutines + mov edi,[vram] + Mode7Processngw16b %1, domosaicng16b, 2 +%endmacro + +%macro Mode7MainSub 2 + WinEnCheckMS + ProcessBuildWindow16b 0 +.nohr + Mode7NoTranspPreStartUp + call Mode7Startup16b + Mode7MidRoutines + mov edi,[vram] + Mode7Processngw216b %1, domosaicng16b, 2, %2 +%endmacro + +%macro Mode7MainSube 2 + WinEnCheckMS + ProcessBuildWindow16b 0 +.nohr + Mode7NoTranspPreStartUp2 + call Mode7Startup16b + Mode7MidRoutines + mov edi,[vram] + Mode7Processngw216b %1, domosaicng16b, 2, %2 +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/video/mode716b.asm b/zsnes/src/video/mode716b.asm new file mode 100644 index 00000000..c75a1012 --- /dev/null +++ b/zsnes/src/video/mode716b.asm @@ -0,0 +1,189 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM curmosaicsz,curvidoffset,domosaic16b,winptrref,scaddset +EXTSYM mode7A,mode7B,mode7C,mode7D,mode7X0,mode7Y0,mode7set +EXTSYM pal16b,vram,vrama,winon,mode7tab,xtravbuf,drawmode7dcolor +EXTSYM cwinptr + +%include "video/mode7.mac" + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + +ALIGN16 + +%macro Mode7Normal 0 + or dl,dl + jz %%nodrawb + mov ecx,[pal16b+edx*4] + mov [esi],cx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Window 0 + or dl,dl + jz %%nodrawbw + test byte[ebp],0FFh + jnz %%nodrawbw + mov ecx,[pal16b+edx*4] + mov [esi],cx +%%nodrawbw + add esi,2 + inc ebp +%endmacro + + +NEWSYM drawmode716b + test byte[scaddset],1 + jnz near drawmode7dcolor + mov esi,[cwinptr] + mov [winptrref],esi + + Mode7Calculate + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawmode7win +.domosaic + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process Mode7Normal, domosaic16b, 2 +.nextval3 + Mode7ProcessB Mode7Normal, domosaic16b, 2 + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +.drawmode7win +.domosaicw + mov ebp,[cwinptr] + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3w + cmp dword[.mode7xadder],-7F0h + jl near .nextval3w + cmp dword[.mode7yadder],7F0h + jg near .nextval3w + cmp dword[.mode7yadder],-7F0h + jl near .nextval3w + + Mode7Process Mode7Window, domosaic16b, 2 +.nextval3w + Mode7ProcessB Mode7Window, domosaic16b, 2 + \ No newline at end of file diff --git a/zsnes/src/video/mode716d.asm b/zsnes/src/video/mode716d.asm new file mode 100644 index 00000000..bb20c367 --- /dev/null +++ b/zsnes/src/video/mode716d.asm @@ -0,0 +1,233 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM curmosaicsz,curvidoffset,domosaic16b,winptrref,scaddset +EXTSYM mode7A,mode7B,mode7C,mode7D,mode7X0,mode7Y0,mode7set,cwinptr +EXTSYM pal16b,vram,vrama,winon,mode7tab,xtravbuf,dcolortab,vidbright + +%include "video/mode7.mac" + + + + + + +NEWSYM Gendcolortable + ; generate Direct Color Table + push eax + push edx + xor ecx,ecx +.loopdct + mov al,cl + and eax,00000111b + mov bl,[vidbright] + mul bl + mov bl,15 + div bl + xor ah,ah + shl eax,13 + mov edx,eax + mov al,cl + and eax,00111000b + shr eax,3 + mov bl,[vidbright] + mul bl + mov bl,15 + div bl + xor ah,ah + shl eax,8 + or edx,eax + mov al,cl + and eax,11000000b + shr eax,6 + mov bl,[vidbright] + mul bl + mov bl,15 + div bl + xor ah,ah + shl eax,3 + or edx,eax + and edx,0FFFFh + mov [dcolortab+ecx*4],edx + inc cl + jnz .loopdct + pop edx + pop eax + ret + +%macro Mode7Normal 0 + or dl,dl + jz %%nodrawb + mov ecx,[dcolortab+edx*4] + mov [esi],cx +%%nodrawb + add esi,2 +%endmacro + +%macro Mode7Window 0 + or dl,dl + jz %%nodrawbw + test byte[ebp],0FFh + jnz %%nodrawbw + mov ecx,[dcolortab+edx*4] + mov [esi],cx +%%nodrawbw + add esi,2 + inc ebp +%endmacro + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* +NEWSYM prevbrightdc, db 0 +NEWSYM drawmode7dcolor + mov bl,[vidbright] + cmp bl,[prevbrightdc] + je .nodcchange + mov [prevbrightdc],bl + call Gendcolortable +.nodcchange + mov esi,[cwinptr] + mov [winptrref],esi + + Mode7Calculate + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawmode7win +.domosaic + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process Mode7Normal, domosaic16b, 2 +.nextval3 + Mode7ProcessB Mode7Normal, domosaic16b, 2 + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +.drawmode7win +.domosaicw + mov ebp,[cwinptr] + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3w + cmp dword[.mode7xadder],-7F0h + jl near .nextval3w + cmp dword[.mode7yadder],7F0h + jg near .nextval3w + cmp dword[.mode7yadder],-7F0h + jl near .nextval3w + + Mode7Process Mode7Window, domosaic16b, 2 +.nextval3w + Mode7ProcessB Mode7Window, domosaic16b, 2 + \ No newline at end of file diff --git a/zsnes/src/video/mode716e.asm b/zsnes/src/video/mode716e.asm new file mode 100644 index 00000000..8757a346 --- /dev/null +++ b/zsnes/src/video/mode716e.asm @@ -0,0 +1,1261 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM curmosaicsz,curvidoffset,domosaic16b,winptrref,scaddset +EXTSYM mode7A,mode7B,mode7C,mode7D,mode7X0,mode7Y0,mode7set +EXTSYM pal16b,vram,vrama,winon,mode7tab,xtravbuf,drawmode7dcolor +EXTSYM cwinptr + + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + +ALIGN16 + +NEWSYM drawmode716extbg +; test byte[scaddset],1 +; jnz near drawmode7dcolor + mov esi,[cwinptr] + mov [winptrref],esi + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near drawmode716bwinonextbg +.domosaic + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[.cyloc] + imul eax,ebx + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[.cxloc] + neg eax + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + test byte[mode7set],1 + jz .nohflip + mov eax,[.mode7xadder] + shl eax,8 + add [.mode7xpos],eax + neg dword[.mode7xadder] + mov eax,[.mode7yadder] + shl eax,8 + sub [.mode7ypos],eax + neg dword[.mode7yadder] +.nohflip + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + mov byte[.temp],0 + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + test byte[mode7set],80h + jnz near .norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextval + test byte[.mode7xrpos+1],08h + jnz .rposoffx +.nextposx + test byte[.mode7yrpos+1],08h + jnz near .rposoffy +.nextposy + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[edi+edx] + sub [.mode7yrpos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodrawb + test dl,0FFh + jz .nodrawb + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodrawb + add esi,2 + dec byte[.temp] + jnz .nextval + jmp .finishmode7 +.rposoffx + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposx +.rposoffy + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + and byte[.mode7ptr+1],7Fh + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposy +.finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +.norep2 + test byte[mode7set],40h + jnz .tilerep2 +.nextvalb2 + cmp byte[.mode7ypos+2],3 + ja .offscr2 + cmp byte[.mode7xpos+2],3 + jbe near .offscr3 +.offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,2 + dec byte[.temp] + jnz near .nextvalb2 + jmp .finishmode7 +.tilerep2 +.nextvalb3 + cmp byte[.mode7ypos+2],3 + ja .offscr2b + cmp byte[.mode7xpos+2],3 + jbe .offscr3 +.offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2trb2 + test dl,0FFh + jz .nodraw2trb2 + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2trb2 + add esi,2 + dec byte[.temp] + jnz .nextvalb3 + jmp .finishmode7 +.offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextvalr + test byte[.mode7xrpos+1],08h + jnz .rposoffxr +.nextposxr + test byte[.mode7yrpos+1],08h + jnz near .rposoffyr +.nextposyr + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[edi+edx] + sub [.mode7yrpos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodrawbr + test dl,0FFh + jz .nodrawbr + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodrawbr + add esi,2 + dec byte[.temp] + jnz .nextvalr + jmp .finishmode7 +.rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je .roff +.roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposxr +.rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js .roff +.roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposyr +.roff + test byte[mode7set],40h + jnz .tilerep3 + jmp .finishmode7 +.tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodrawbr2 + test dl,0FFh + jz .nodrawbr2 + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodrawbr2 + add esi,2 + dec byte[.temp] + jnz .tilerep3 + jmp .finishmode7 + +;********************************************************** +; Mode 7, old routines +;********************************************************** + +.nextval3 + test byte[mode7set],80h + jnz near .norep +.nextval2 + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodraw + test dl,0FFh + jz .nodraw + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw + add esi,2 + dec byte[.temp] + jnz .nextval2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + ; Color repetition +.norep + test byte[mode7set],40h + jnz near .tilerep +.nextvalb + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscr + cmp byte[.mode7xpos+2],3 + ja near .offscr +.offscrb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2 + test dl,0FFh + jz .nodraw2 + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2 + add esi,2 + dec byte[.temp] + jnz near .nextvalb + jmp .goon +.offscrc + cmp byte[.mode7ypos+2],3 + ja .offscr + cmp byte[.mode7xpos+2],3 + jbe near .offscrb +.offscr + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,2 + dec byte[.temp] + jnz .offscrc +.goon + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +.tilerep +.nextvalbtr + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscrtr + cmp byte[.mode7xpos+2],3 + ja near .offscrtr +.offscrtrb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2tr + test dl,0FFh + jz .nodraw2tr + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2tr + add esi,2 + dec byte[.temp] + jnz near .nextvalbtr + jmp .goon +.offscrtrc + cmp byte[.mode7ypos+2],3 + ja .offscrtr + cmp byte[.mode7xpos+2],3 + jbe near .offscrtrb +.offscrtr + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2trb + test dl,0FFh + jz .nodraw2trb + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2trb + add esi,2 + dec byte[.temp] + jnz near .offscrtrc + jmp .goon + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dd 0 ; cx location +.cyloc dd 0 ; cy location + +NEWSYM drawmode716bwinonextbg + + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx ebx,word[.cyloc] + movsx eax,word[mode7C] + imul eax,ebx + neg eax + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx +; neg ax + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx ebx,word[.cxloc] + movsx eax,word[mode7B] + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + mov byte[.temp],0 + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + mov edi,[vram] + mov ebp,[cwinptr] + + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + test byte[mode7set],80h + jnz near .norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextval + test byte[.mode7xrpos+1],08h + jnz .rposoffx +.nextposx + test byte[.mode7yrpos+1],08h + jnz near .rposoffy +.nextposy + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[edi+edx] + sub [.mode7yrpos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodrawb + test dl,0FFh + jz .nodrawb + test byte[ebp],0FFh + jnz .nodrawb + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodrawb + add esi,2 + inc ebp + dec byte[.temp] + jnz .nextval + jmp .finishmode7 +.rposoffx + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposx +.rposoffy + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + and byte[.mode7ptr+1],7Fh + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposy +.finishmode7 + xor eax,eax + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +.norep2 + test byte[mode7set],40h + jnz .tilerep2 +.nextvalb2 + cmp byte[.mode7ypos+2],3 + ja .offscr2 + cmp byte[.mode7xpos+2],3 + jbe near .offscr3 +.offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,2 + dec byte[.temp] + jnz near .nextvalb2 + jmp .finishmode7 +.tilerep2 +.nextvalb3 + cmp byte[.mode7ypos+2],3 + ja .offscr2b + cmp byte[.mode7xpos+2],3 + jbe .offscr3 +.offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2trb2 + test dl,0FFh + jz .nodraw2trb2 + test byte[ebp],0FFh + jnz .nodraw2trb2 + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2trb2 + add esi,2 + inc ebp + dec byte[.temp] + jnz .nextvalb3 + jmp .finishmode7 +.offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextvalr + test byte[.mode7xrpos+1],08h + jnz .rposoffxr +.nextposxr + test byte[.mode7yrpos+1],08h + jnz near .rposoffyr +.nextposyr + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[edi+edx] + sub [.mode7yrpos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodrawbr + test dl,0FFh + jz .nodrawbr + test byte[ebp],0FFh + jnz .nodrawbr + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodrawbr + add esi,2 + inc ebp + dec byte[.temp] + jnz .nextvalr + jmp .finishmode7 +.rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je .roff +.roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposxr +.rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js .roff +.roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposyr +.roff + test byte[mode7set],40h + jnz .tilerep3 + jmp .finishmode7 +.tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodrawbr2 + test dl,0FFh + jz .nodrawbr2 + test byte[ebp],0FFh + jnz .nodrawbr2 + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodrawbr2 + add esi,2 + inc ebp + dec byte[.temp] + jnz .tilerep3 + jmp .finishmode7 + +;********************************************************** +; Mode 7, old routines +;********************************************************** + +.nextval3 + test byte[mode7set],80h + jnz near .norep +.nextval2 + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodraw + test dl,0FFh + jz .nodraw + test byte[ebp],0FFh + jnz .nodraw + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw + add esi,2 + inc ebp + dec byte[.temp] + jnz .nextval2 + xor eax,eax + ret + ; Color repetition +.norep + test byte[mode7set],40h + jnz near .tilerep +.nextvalb + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscr + cmp byte[.mode7xpos+2],3 + ja near .offscr +.offscrb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2 + test dl,0FFh + jz .nodraw2 + test byte[ebp],0FFh + jnz .nodraw2 + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2 + add esi,2 + inc ebp + dec byte[.temp] + jnz near .nextvalb + jmp .goon +.offscrc + cmp byte[.mode7ypos+2],3 + ja .offscr + cmp byte[.mode7xpos+2],3 + jbe near .offscrb +.offscr + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,2 + dec byte[.temp] + jnz .offscrc +.goon + xor eax,eax + ret + +.tilerep +.nextvalbtr + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscrtr + cmp byte[.mode7xpos+2],3 + ja near .offscrtr +.offscrtrb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov dl,[edi+ecx] + sub [.mode7ypos],eax + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2tr + test dl,0FFh + jz .nodraw2tr + test byte[ebp],0FFh + jnz .nodraw2tr + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2tr + add esi,2 + inc ebp + dec byte[.temp] + jnz near .nextvalbtr + jmp .goon +.offscrtrc + cmp byte[.mode7ypos+2],3 + ja near .offscrtr + cmp byte[.mode7xpos+2],3 + jbe near .offscrtrb +.offscrtr + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + mov [esi+288*2],dl + test dl,80h + jnz .nodraw2trb + test dl,0FFh + jz .nodraw2trb + test byte[ebp],0FFh + jnz .nodraw2trb + mov ecx,[pal16b+edx*4] + mov [esi],cx +.nodraw2trb + add esi,2 + inc ebp + dec byte[.temp] + jnz near .offscrtrc + jmp .goon + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dd 0 ; cx location +.cyloc dd 0 ; cy location + +NEWSYM drawmode716extbg2 + mov esi,[cwinptr] + mov [winptrref],esi + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawwin +.domosaic + mov ecx,256 + xor eax,eax +.loop + mov al,[esi+288*2] + test al,80h + jz .nopr2 + and al,7Fh + mov ebx,[pal16b+eax*4] + mov [esi],bx +.nopr2 + add esi,2 + loop .loop + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret +.drawwin + mov ebp,[cwinptr] + mov byte[esi],cl +.nodrawbw + mov ecx,256 + xor eax,eax +.loop2 + mov al,[esi+288*2] + test byte[ebp],0FFh + jnz .nopr2b + test al,80h + jz .nopr2b + and al,7Fh + mov ebx,[pal16b+eax*4] + mov [esi],bx +.nopr2b + add esi,2 + inc ebp + loop .loop2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + \ No newline at end of file diff --git a/zsnes/src/video/mode716t.asm b/zsnes/src/video/mode716t.asm new file mode 100644 index 00000000..af61cab3 --- /dev/null +++ b/zsnes/src/video/mode716t.asm @@ -0,0 +1,364 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM cwinptr +EXTSYM coladdr,curmosaicsz,curvidoffset,domosaic16b,mode7A,drawmode7dcolor +EXTSYM mode7B,mode7C,mode7D,mode7X0,mode7Y0,mode7set,mode7tab,DoTransp +EXTSYM pal16b,pal16bcl,pal16bxcl,scaddtype,scrnon,transpbuf,drawmode716b +EXTSYM vesa2_clbit,vram,vrama,winon,xtravbuf,winptrref,scaddset +EXTSYM fulladdtab + +%include "video/mode7.mac" + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + + +%macro mode7halfadd 0 + or dl,dl + jz %%nodraw + mov ecx,[ebp] + mov edx,[pal16bcl+edx*4] + or cx,cx + jz %%noadd + and edx,[vesa2_clbit] + and ecx,[vesa2_clbit] + add edx,ecx + shr edx,1 +%%noadd + mov [esi],dx + xor ecx,ecx + xor edx,edx +%%nodraw + add esi,2 + add ebp,2 +%endmacro + +%macro mode7fulladd 0 + or dl,dl + jz %%nodraw + mov ecx,[ebp] + mov edx,[pal16bcl+edx*4] + and ecx,[vesa2_clbit] + add edx,ecx + shr edx,1 + mov edx,[fulladdtab+edx*2] + mov [esi],dx + xor edx,edx +%%nodraw + add esi,2 + add ebp,2 +%endmacro + +%macro mode7fullsub 0 + or dl,dl + jz %%nodraw + mov ecx,[ebp] + mov edx,[pal16bxcl+edx*4] + and ecx,[vesa2_clbit] + add edx,ecx + shr edx,1 + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [esi],dx + xor edx,edx +%%nodraw + add esi,2 + add ebp,2 +%endmacro + +%macro mode7mainsub 0 + or dl,dl + jz %%nodraw + mov ecx,[pal16b+edx*4] + mov [esi],cx + mov [ebp],cx +%%nodraw + add esi,2 + add ebp,2 +%endmacro + +%macro mode7halfaddwinon 0 + mov ecx,[cwinptr2] + or dl,dl + jz %%nodraw + test byte[ecx],0FFh + jnz %%nodraw + mov ecx,[ebp] + mov edx,[pal16bcl+edx*4] + or cx,cx + je %%noadd + and edx,[vesa2_clbit] + and ecx,[vesa2_clbit] + add edx,ecx + shr edx,1 +%%noadd + mov [esi],dx + xor edx,edx +%%nodraw + xor ecx,ecx + inc dword[cwinptr2] + add esi,2 + add ebp,2 +%endmacro + +%macro mode7fulladdwinon 0 + mov ecx,[cwinptr2] + or dl,dl + jz %%nodraw + test byte[ecx],0FFh + jnz %%nodraw + mov ecx,[ebp] + mov edx,[pal16bcl+edx*4] + and ecx,[vesa2_clbit] + add edx,ecx + shr edx,1 + mov edx,[fulladdtab+edx*2] + mov [esi],dx + xor edx,edx +%%nodraw + inc dword[cwinptr2] + xor ecx,ecx + add esi,2 + add ebp,2 +%endmacro + +%macro mode7fullsubwinon 0 + mov ecx,[cwinptr2] + or dl,dl + jz %%nodraw + test byte[ecx],0FFh + jnz %%nodraw + mov ecx,[ebp] + mov edx,[pal16bxcl+edx*4] + and ecx,[vesa2_clbit] + add edx,ecx + shr edx,1 + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [esi],dx + xor edx,edx +%%nodraw + xor ecx,ecx + inc dword[cwinptr2] + add esi,2 + add ebp,2 +%endmacro + +%macro mode7mainsubwinon 0 + mov ecx,[cwinptr2] + or dl,dl + jz %%nodraw + test byte[ecx],0FFh + jnz %%nodraw + mov ecx,[pal16b+edx*4] + mov [esi],cx + mov [ebp],cx +%%nodraw + inc dword[cwinptr2] + xor ecx,ecx + add esi,2 + add ebp,2 +%endmacro + +%macro mode716tmacro 2 + Mode7Calculate + mov ebp,transpbuf+32 + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + mov edi,[vram] + + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawmode7win +.domosaic + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process %1, domosaic16b, 2 +.nextval3 + Mode7ProcessB %1, domosaic16b, 2 + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + +.drawmode7win +.domosaicw + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3w + cmp dword[.mode7xadder],-7F0h + jl near .nextval3w + cmp dword[.mode7yadder],7F0h + jg near .nextval3w + cmp dword[.mode7yadder],-7F0h + jl near .nextval3w + + Mode7Process %2, domosaic16b, 2 +.nextval3w + Mode7ProcessB %2, domosaic16b, 2 +%endmacro + +;******************************************************* +; Processes & Draws Mode 7 half Addition +;******************************************************* +NEWSYM drawmode716t + test byte[scaddset],1 + jnz near drawmode7dcolor + cmp byte[DoTransp],1 + jne .transpfull + jmp drawmode716b +.transpfull + mov esi,[cwinptr] + mov [winptrref],esi + mov [cwinptr2],esi + test byte[scaddtype],80h + jnz near drawmode716tsub + test byte[scaddtype],40h + jz near drawmode716tfulladd + cmp byte[scrnon+1],0 + je near drawmode716tfulladd + cmp dword[coladdr],0 + jnz near drawmode716tfulladd +; cmp byte[scrnon+1],10h +; je near drawmode716tfulladd +;.n + mode716tmacro mode7halfadd,mode7halfaddwinon + + +;******************************************************* +; Processes & Draws Mode 7 Full Addition +;******************************************************* +NEWSYM drawmode716tfulladd + mode716tmacro mode7fulladd,mode7fulladdwinon + +;********************************************************** +; Processes and draws Mode 7 subtract +;********************************************************** + +drawmode716tsub: + mode716tmacro mode7fullsub,mode7fullsubwinon + +;********************************************************** +; Mode 7, main & sub mode +;********************************************************** + +NEWSYM drawmode716tb + mov esi,[cwinptr] + mov [winptrref],esi + mov [cwinptr2],esi + mode716tmacro mode7mainsub,mode7mainsubwinon + +cwinptr2 dd 0 + + \ No newline at end of file diff --git a/zsnes/src/video/mode7cal.inc b/zsnes/src/video/mode7cal.inc new file mode 100644 index 00000000..a66d5a95 --- /dev/null +++ b/zsnes/src/video/mode7cal.inc @@ -0,0 +1,326 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +%macro Mode7Calculate 0 + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[.cyloc] + imul eax,ebx + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[.cxloc] + neg eax + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + test byte[mode7set],1 + jz .nohflip + mov eax,[.mode7xadder] + shl eax,8 + add [.mode7xpos],eax + neg dword[.mode7xadder] + mov eax,[.mode7yadder] + shl eax,8 + sub [.mode7ypos],eax + neg dword[.mode7yadder] +.nohflip +%endmacro + +%macro Mode7Process 3 + mov dword[.temp],256 + test byte[mode7set],80h + jnz near %%norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ecx,ecx + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[.mode7xrpos] + mov ebx,[.mode7ptr] + jmp %%nextval + ALIGN16 +%%nextval + test ah,08h + jnz near %%rposoffx +%%nextposx + test byte[.mode7yrpos+1],08h + jnz near %%rposoffy +%%nextposy + mov ch,ah + mov edx,[.mode7yadder] + mov cl,byte[.mode7yrpos+1] + sub dword[.mode7yrpos],edx + xor edx,edx + add eax,[.mode7xadder] + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextval + jmp %%finishmode7 + +%%rposoffx + add bl,[.mode7xinc] + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,[.mode7xadd2] + lea edi,[ecx+vrama] + jmp %%nextposx + +%%rposoffy + sub bh,[.mode7yinc] + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + mov edx,[.mode7yadd2] + shl ecx,7 + add dword[.mode7yrpos],edx + lea edi,[ecx+vrama] + jmp %%nextposy + +%%finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near %2 + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +%%norep2 + test byte[mode7set],40h + jnz %%tilerep2 + jmp %%nextvalb2 + ALIGN16 +%%nextvalb2 + cmp byte[.mode7ypos+2],3 + ja %%offscr2 + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + add esi,%3 + dec dword[.temp] + jnz near %%nextvalb2 + jmp %%finishmode7 +%%tilerep2 +%%nextvalb3 + cmp byte[.mode7ypos+2],3 + ja %%offscr2b + cmp byte[.mode7xpos+2],3 + jbe near %%offscr3 +%%offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov dl,[vrama+edx] + sub [.mode7ypos],ebx + %1 + dec dword[.temp] + jnz near %%nextvalb3 + jmp %%finishmode7 +%%offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + jmp %%nextvalr + ALIGN16 +%%nodr2 + add esi,%3 + dec dword[.temp] + jz near %%fin2 +%%nextvalr + test byte[.mode7xrpos+1],08h + jnz near %%rposoffxr +%%nextposxr + test byte[.mode7yrpos+1],08h + jnz near %%rposoffyr +%%nextposyr + mov cl,[.mode7yrpos+1] + mov ch,[.mode7xrpos+1] + mov edx,[.mode7xadder] + add dword[.mode7xrpos],edx + mov edx,[.mode7xadder] + sub dword[.mode7yrpos],edx + xor edx,edx + mov dl,[mode7tab+ecx] + mov dl,[edi+edx] + %1 + dec dword[.temp] + jnz near %%nextvalr +%%fin2 + jmp %%finishmode7 +%%rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je %%roff +%%roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp %%nextposxr +%%rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js %%roff +%%roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp %%nextposyr +%%roff + test byte[mode7set],40h + jnz %%tilerep3 + jmp %%finishmode7 +%%tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov dl,[vrama+edx] + sub [.mode7yrpos],eax + %1 + dec dword[.temp] + jnz near %%tilerep3 + jmp %%finishmode7 +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/video/mode7ext.asm b/zsnes/src/video/mode7ext.asm new file mode 100644 index 00000000..6ea92f33 --- /dev/null +++ b/zsnes/src/video/mode7ext.asm @@ -0,0 +1,1318 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM mode7tab,winptrref +EXTSYM curmosaicsz,curvidoffset,cwinptr,domosaic,mode7A,mode7B +EXTSYM mode7C,mode7D,mode7X0,mode7Y0,mode7set,vram,vrama,winon,xtravbuf +EXTSYM ngwleft,ngwleftb,mode7xpos,mode7ypos,mode7xrpos,mode7yrpos,mode7xadder +EXTSYM mode7yadder +EXTSYM nglogicval,winlogicaval,ProcessMode7ngwinD,ProcessMode7ngwinC +EXTSYM ngwinen, winbg1enval, BuildWindow, ngwintable, ngcwinptr +EXTSYM ProcessMode7ngwin,ProcessMode7ngwinB + +%include "video/mode7.mac" + + + + + +;******************************************************* +; Processes & Draws Mode 7 +;******************************************************* + +NEWSYM drawmode7extbg + mov esi,[cwinptr] + mov [winptrref],esi + ; mode 7, ax = curyposition, dx = curxposition (left side) + ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen + ; center map coordinates = (X0,Y0) + ; 1.) cx=X0-bg1scrolx, cy =Y0-ax + + mov bx,[mode7X0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonega + or bx,1110000000000000b +.nonega + mov [.cxloc],bx + mov bx,dx + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegb + or bx,1110000000000000b +.nonegb + sub [.cxloc],bx + mov bx,ax + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegc + or bx,1110000000000000b +.nonegc + mov [.cyloc],bx + mov bx,[mode7Y0] + and bx,0001111111111111b ; 13 -> 16 bit signed value + test bx,0001000000000000b + jz .nonegd + or bx,1110000000000000b +.nonegd + sub word[.cyloc],bx + + ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D) + + movsx eax,word[mode7B] + movsx ebx,word[.cyloc] + imul eax,ebx + mov [.mode7xpos],eax + mov bx,word[mode7X0] + add [.mode7xpos+1],bx + + movsx ebx,word[.cyloc] + movsx eax,word[mode7D] + imul eax,ebx + mov [.mode7ypos],eax + mov bx,word[mode7Y0] + add [.mode7ypos+1],bx + + ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B) + + movsx ebx,word[.cxloc] + movsx eax,word[mode7A] + mov [.mode7xadder],eax + imul eax,ebx + neg eax + add [.mode7xpos],eax + + movsx eax,word[mode7C] + movsx ebx,word[.cxloc] + neg eax + mov [.mode7yadder],eax + imul eax,ebx + add [.mode7ypos],eax + + test byte[mode7set],1 + jz .nohflip + mov eax,[.mode7xadder] + shl eax,8 + add [.mode7xpos],eax + neg dword[.mode7xadder] + mov eax,[.mode7yadder] + shl eax,8 + sub [.mode7ypos],eax + neg dword[.mode7yadder] +.nohflip + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + mov dword[.temp],256 + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawmode7win +.domosaic + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + + test byte[mode7set],80h + jnz near .norep2 + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[.mode7xadder] + mov dword[.m7xrpa-4],eax + mov eax,[.mode7yadder] + mov dword[.m7yrpa-4],eax + mov al,[.mode7xinc] + mov [.m7xin-1],al + mov eax,[.mode7xadd2] + mov [.m7xad2-4],eax + mov al,[.mode7yinc] + mov [.m7yin-1],al + mov eax,[.mode7yadd2] + mov [.m7yad2-4],eax + mov eax,[.mode7xrpos] + mov ebx,[.mode7ptr] + jmp .nextval + ALIGN16 +.nextval + test ah,08h + jnz .rposoffx +.nextposx + test byte[.mode7yrpos+1],08h + jnz .rposoffy +.nextposy + mov ch,ah + mov cl,byte[.mode7yrpos+1] + add eax,0 +.m7xrpa + mov dl,[mode7tab+ecx] + sub dword[.mode7yrpos],0 +.m7yrpa + mov cl,[edi+edx] + mov byte[esi+288],cl + test cl,80h + jnz .nodrawb + or cl,cl + jz .nodrawb + mov byte[esi],cl +.nodrawb + inc esi + dec dword[.temp] + jnz .nextval + jmp .finishmode7 + +.rposoffx + add bl,0 +.m7xin + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + sub eax,0 +.m7xad2 + lea edi,[ecx+vrama] + jmp .nextposx + +.rposoffy + sub bh,0 +.m7yin + and ebx,07FFFh + xor ecx,ecx + mov cl,[vrama+ebx] + shl ecx,7 + add dword[.mode7yrpos],0 +.m7yad2 + lea edi,[ecx+vrama] + jmp .nextposy + +.finishmode7 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +.norep2 + test byte[mode7set],40h + jnz .tilerep2 + jmp .nextvalb2 + ALIGN16 +.nextvalb2 + cmp byte[.mode7ypos+2],3 + ja .offscr2 + cmp byte[.mode7xpos+2],3 + jbe near .offscr3 +.offscr2 + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + inc esi + dec dword[.temp] + jnz near .nextvalb2 + jmp .finishmode7 +.tilerep2 +.nextvalb3 + cmp byte[.mode7ypos+2],3 + ja .offscr2b + cmp byte[.mode7xpos+2],3 + jbe .offscr3 +.offscr2b + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov cl,[vrama+edx] + sub [.mode7ypos],ebx + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2trb2 + or cl,cl + jz .nodraw2trb2 + mov byte[esi],cl +.nodraw2trb2 + inc esi + dec dword[.temp] + jnz .nextvalb3 + jmp .finishmode7 +.offscr3 + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + + mov eax,[.mode7xadder] + mov dword[.m7xrpa2-4],eax + mov eax,[.mode7yadder] + mov dword[.m7yrpa2-4],eax + + jmp .nextvalr + ALIGN16 +.nodr2 + inc esi + dec dword[.temp] + jz .fin2 +.nextvalr + test byte[.mode7xrpos+1],08h + jnz .rposoffxr +.nextposxr + test byte[.mode7yrpos+1],08h + jnz near .rposoffyr +.nextposyr + mov cl,[.mode7yrpos+1] + mov ch,[.mode7xrpos+1] + add dword[.mode7xrpos],0 +.m7xrpa2 + mov dl,[mode7tab+ecx] + sub dword[.mode7yrpos],0 +.m7yrpa2 + mov cl,[edi+edx] + mov byte[esi+288],cl + test cl,80h + jnz .nodr2 + or cl,cl + jz .nodr2 + mov byte[esi],cl +.nodrawbr + inc esi + dec dword[.temp] + jnz .nextvalr +.fin2 + jmp .finishmode7 +.rposoffxr + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je .roff +.roffxretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposxr +.rposoffyr + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js .roff +.roffyretb + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposyr +.roff + test byte[mode7set],40h + jnz .tilerep3 + jmp .finishmode7 +.tilerep3 + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov cl,[vrama+edx] + sub [.mode7yrpos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodrawbr2 + or cl,cl + jz .nodrawbr2 + mov byte[esi],cl +.nodrawbr2 + inc esi + dec dword[.temp] + jnz .tilerep3 + jmp .finishmode7 + +;********************************************************** +; Mode 7, old routines +;********************************************************** + +.nextval3 + test byte[mode7set],080h + jnz near .norep + jmp .nextval2 + ALIGN16 +.nextval2 + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov cl,[edi+ecx] + sub [.mode7ypos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodraw + or cl,cl + jz .nodraw + mov byte[esi],cl +.nodraw + inc esi + dec dword[.temp] + jnz .nextval2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + ; Color repetition +.norep + test byte[mode7set],40h + jnz near .tilerep + jmp .nextvalb + ALIGN16 +.nextvalb + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscr + cmp byte[.mode7xpos+2],3 + ja near .offscr +.offscrc + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov cl,[edi+ecx] + sub [.mode7ypos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2 + or cl,cl + jz .nodraw2 + mov byte[esi],cl +.nodraw2 + inc esi + dec dword[.temp] + jnz near .nextvalb + jmp .goon +.offscrb + cmp byte[.mode7ypos+2],3 + ja .offscr + cmp byte[.mode7xpos+2],3 + jbe near .offscrc +.offscr + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + inc esi + dec dword[.temp] + jnz .offscrb +.goon + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + +.tilerep + jmp .nextvalbtr + ALIGN16 +.nextvalbtr + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscrtr + cmp byte[.mode7xpos+2],3 + ja near .offscrtr +.notoffscrtr + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov cl,[edi+ecx] + sub [.mode7ypos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2tr + or cl,cl + jz .nodraw2tr + mov byte[esi],cl +.nodraw2tr + inc esi + dec dword[.temp] + jnz near .nextvalbtr + jmp .goon +.offscrtrb + cmp byte[.mode7ypos+2],3 + ja .offscrtr + cmp byte[.mode7xpos+2],3 + jbe .notoffscrtr +.offscrtr + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov cl,[vrama+edx] + sub [.mode7ypos],ebx + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2trb + or cl,cl + jz .nodraw2trb + mov byte[esi],cl +.nodraw2trb + inc esi + dec dword[.temp] + jnz near .offscrtrb + jmp .goon + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location + +.drawmode7win +.domosaicw + + mov ebp,[cwinptr] + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3w + cmp dword[.mode7xadder],-7F0h + jl near .nextval3w + cmp dword[.mode7yadder],7F0h + jg near .nextval3w + cmp dword[.mode7yadder],-7F0h + jl near .nextval3w + + test byte[mode7set],80h + jnz near .norep2w + + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + jmp .nextvalw + ALIGN16 +.nextvalw + test byte[.mode7xrpos+1],08h + jnz .rposoffxw +.nextposxw + test byte[.mode7yrpos+1],08h + jnz near .rposoffyw +.nextposyw + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov cl,[edi+edx] + sub [.mode7yrpos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodrawbw + or cl,cl + jz .nodrawbw + test byte[ebp],0FFh + jnz .nodrawbw + mov byte[esi],cl +.nodrawbw + inc esi + inc ebp + dec byte[.temp] + jnz .nextvalw + jmp .finishmode7w +.rposoffxw + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposxw +.rposoffyw + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + and byte[.mode7ptr+1],7Fh + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposyw +.finishmode7w + xor eax,eax + ret + +;********************************************************** +; Mode 7, no repetition mode +;********************************************************** + +.norep2w + test byte[mode7set],40h + jnz .tilerep2w +.nextvalb2w + cmp byte[.mode7ypos+2],3 + ja .offscr2w + cmp byte[.mode7xpos+2],3 + jbe near .offscr3w +.offscr2w + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + inc esi + inc ebp + dec byte[.temp] + jnz near .nextvalb2w + jmp .finishmode7w +.tilerep2w +.nextvalb3w + cmp byte[.mode7ypos+2],3 + ja .offscr2bw + cmp byte[.mode7xpos+2],3 + jbe .offscr3w +.offscr2bw + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov cl,[vrama+edx] + sub [.mode7ypos],ebx + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2trb2w + or cl,cl + jz .nodraw2trb2w + test byte[ebp],0FFh + jnz .nodraw2trb2w + mov byte[esi],cl +.nodraw2trb2w + inc esi + inc ebp + dec byte[.temp] + jnz .nextvalb3w + jmp .finishmode7w +.offscr3w + mov eax,[.mode7xpos] + and eax,7FFh + mov [.mode7xrpos],eax + mov eax,[.mode7ypos] + and eax,7FFh + mov [.mode7yrpos],eax + + ; get tile data offset into edi + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + shl ebx,5 + shr eax,3 + and ebx,07FF8h + shl al,1 + mov bl,al + mov edi,[vram] + xor ch,ch + mov [.mode7ptr],ebx + mov cl,[edi+ebx] + shl ecx,7 + add edi,ecx + +.nextvalrw + test byte[.mode7xrpos+1],08h + jnz .rposoffxrw +.nextposxrw + test byte[.mode7yrpos+1],08h + jnz near .rposoffyrw +.nextposyrw + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov cl,[edi+edx] + sub [.mode7yrpos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodrawbrw + or cl,cl + jz .nodrawbrw + test byte[ebp],0FFh + jnz .nodrawbrw + mov byte[esi],cl +.nodrawbrw + inc esi + inc ebp + dec byte[.temp] + jnz .nextvalrw + jmp .finishmode7w +.rposoffxrw + mov al,[.mode7xinc] + mov edi,[vram] + add [.mode7ptr],al + mov cl,byte[.mode7xincc] + cmp byte[.mode7ptr],cl + je .roffw +.roffxretbw + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7xadd2] + shl ecx,7 + sub [.mode7xrpos],eax + add edi,ecx + jmp .nextposxrw +.rposoffyrw + mov al,[.mode7yinc] + mov edi,[vram] + sub [.mode7ptr+1],al + js .roffw +.roffyretbw + mov ebx,[.mode7ptr] + xor ecx,ecx + mov cl,[edi+ebx] + mov eax,[.mode7yadd2] + shl ecx,7 + add [.mode7yrpos],eax + add edi,ecx + jmp .nextposyrw +.roffw + test byte[mode7set],40h + jnz .tilerep3w + jmp .finishmode7w +.tilerep3w + and byte[.mode7yrpos+1],07h + and byte[.mode7xrpos+1],07h + mov cl,[.mode7yrpos+1] + mov eax,[.mode7xadder] + mov ch,[.mode7xrpos+1] + add [.mode7xrpos],eax + mov dl,[mode7tab+ecx] + mov eax,[.mode7yadder] + mov cl,[vrama+edx] + sub [.mode7yrpos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodrawbr2w + or cl,cl + jz .nodrawbr2w + test byte[ebp],0FFh + jnz .nodrawbr2w + mov byte[esi],cl +.nodrawbr2w + inc esi + inc ebp + dec byte[.temp] + jnz .tilerep3w + jmp .finishmode7w + +;********************************************************** +; Mode 7, old routines +;********************************************************** + +.nextval3w + test byte[mode7set],80h + jnz near .norepw +.nextval2w + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov cl,[edi+ecx] + sub [.mode7ypos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodraww + or cl,cl + jz .nodraww + test byte[ebp],0FFh + jnz .nodraww + mov byte[esi],cl +.nodraww + inc esi + inc ebp + dec byte[.temp] + jnz .nextval2w + xor eax,eax + ret + ; Color repetition +.norepw + test byte[mode7set],40h + jnz near .tilerepw +.nextvalbw + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscrw + cmp byte[.mode7xpos+2],3 + ja near .offscrw +.offscrwb + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov cl,[edi+ecx] + sub [.mode7ypos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2w + or cl,cl + jz .nodraw2w + test byte[ebp],0FFh + jnz .nodraw2w + mov byte[esi],cl +.nodraw2w + inc esi + inc ebp + dec byte[.temp] + jnz near .nextvalbw + jmp .goonw +.offscrwc + cmp byte[.mode7ypos+2],3 + ja .offscrw + cmp byte[.mode7xpos+2],3 + jbe near .offscrwb +.offscrw + mov eax,[.mode7xadder] + mov ebx,[.mode7yadder] + add [.mode7xpos],eax + sub [.mode7ypos],ebx + inc esi + inc ebp + dec byte[.temp] + jnz .offscrwc +.goonw + xor eax,eax + ret + +.tilerepw +.nextvalbtrw + ; get tile # @ ([.mode7xpos],[.mode7ypos]) + ; get tile location in vram (tileloc=x*2+y*256) + cmp byte[.mode7ypos+2],3 + ja near .offscrtrw + cmp byte[.mode7xpos+2],3 + ja near .offscrtrw +.notoffscrtrw + mov ebx,[.mode7ypos+1] + mov eax,[.mode7xpos+1] + mov cl,bl + mov ch,al + shl ebx,5 + shr eax,3 + mov dl,[mode7tab+ecx] + and ebx,07FF8h + shl al,1 + mov bl,al + xor ch,ch + mov cl,[edi+ebx] + mov eax,[.mode7xadder] + shl ecx,7 + add [.mode7xpos],eax + add ecx,edx + mov eax,[.mode7yadder] + mov cl,[edi+ecx] + sub [.mode7ypos],eax + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2trw + or cl,cl + jz .nodraw2trw + test byte[ebp],0FFh + jnz .nodraw2trw + mov byte[esi],cl +.nodraw2trw + inc esi + inc ebp + dec byte[.temp] + jnz near .nextvalbtrw + jmp .goonw +.offscrtrwb + cmp byte[.mode7ypos+2],3 + ja .offscrtrw + cmp byte[.mode7xpos+2],3 + jbe near .notoffscrtrw +.offscrtrw + mov ch,[.mode7xpos+1] + mov eax,[.mode7xadder] + mov cl,[.mode7ypos+1] + mov ebx,[.mode7yadder] + mov dl,[mode7tab+ecx] + add [.mode7xpos],eax + mov cl,[vrama+edx] + sub [.mode7ypos],ebx + mov byte[esi+288],cl + test cl,80h + jnz .nodraw2trbw + or cl,cl + jz .nodraw2trbw + test byte[ebp],0FFh + jnz .nodraw2trbw + mov byte[esi],cl +.nodraw2trbw + inc esi + inc ebp + dec byte[.temp] + jnz near .offscrtrwb + jmp .goonw + +NEWSYM drawmode7extbg2 + mov esi,[cwinptr] + mov [winptrref],esi + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near .drawwin +.domosaic + mov ecx,256 +.loop + mov al,[esi+288] + test al,80h + jz .nopr2 + and al,7Fh + mov [esi],al +.nopr2 + inc esi + loop .loop + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret +.drawwin + mov ebp,[cwinptr] + mov byte[esi],cl +.nodrawbw + mov ecx,256 +.loop2 + mov al,[esi+288] + test byte[ebp],0FFh + jnz .nopr2b + test al,80h + jz .nopr2b + and al,7Fh + mov [esi],al +.nopr2b + inc esi + inc ebp + loop .loop2 + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + +%macro Mode7Normalng 0 + mov byte[esi+75036],dl + test dl,80h + jnz %%nodrawb + or dl,dl + jz %%nodrawb + mov byte[esi],dl +%%nodrawb + inc esi +%endmacro + +%macro Mode7Windowng 0 + mov byte[esi+75036],dl + test dl,80h + jnz %%nodrawbw + or dl,dl + jz %%nodrawbw + test byte[ebp],0FFh + jnz %%nodrawbw + mov byte[esi],dl +%%nodrawbw + inc esi + inc ebp +%endmacro + + +NEWSYM drawmode7ngextbg + ProcessBuildWindow 0 + + mov esi,[cwinptr] + mov [winptrref],esi + Mode7Calculate + + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + + ; esi = pointer to video buffer + ; edi = pointer to vram + ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit) + ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit) + ; [.mode7xpos] = dword value of x position, decimal between 7 & 8bit + ; [.mode7xpos+1] = word value of x position + ; [.mode7ypos] = dword value of y position, decimal between 7 & 8bit + ; [.mode7ypos+1] = word value of y position + xor ebx,ebx + xor edx,edx + xor ecx,ecx + mov dword[.mode7xadd2],800h + mov byte[.mode7xinc],2 + mov byte[.mode7xincc],0 + test dword[.mode7xadder],80000000h + jz .noneg + mov dword[.mode7xadd2],-800h + mov byte[.mode7xinc],-2 + mov byte[.mode7xincc],0FEh +.noneg + mov dword[.mode7yadd2],800h + mov byte[.mode7yinc],1 + test dword[.mode7yadder],80000000h + jz .noneg2 + mov dword[.mode7yadd2],-800h + mov byte[.mode7yinc],-1 +.noneg2 + + cmp byte[ngwinen],1 + je near .drawmode7win + + mov edi,[vram] + cmp dword[.mode7xadder],7F0h + jg near .nextval3 + cmp dword[.mode7xadder],-7F0h + jl near .nextval3 + cmp dword[.mode7yadder],7F0h + jg near .nextval3 + cmp dword[.mode7yadder],-7F0h + jl near .nextval3 + Mode7Process Mode7Normalng, domosaic, 1 +.nextval3 + Mode7ProcessB Mode7Normalng, domosaic, 1 + ret + +ALIGN32 +.temp dd 0 ; for byte move left +.mode7xpos dd 0 ; x position +.tempa2 dd 0 ; keep this blank! +.mode7xrpos dd 0 ; x position +.tempa dd 0 ; keep this blank! +.mode7ypos dd 0 ; y position +.tempb2 dd 0 ; keep this blank! +.mode7yrpos dd 0 ; y position +.tempb dd 0 ; keep this blank! +.mode7xadder dd 0 ; number to add for x +.tempc2 dd 0 ; keep this blank! +.mode7xadd2 dd 0 ; number to add for x +.tempc dd 0 ; keep this blank! +.mode7yadder dd 0 ; number to add for y +.tempd2 dd 0 ; keep this blank! +.mode7yadd2 dd 0 ; number to add for y +.tempd dd 0 ; keep this blank! +.mode7ptr dd 0 ; pointer value +.mode7xinc dd 0 ; number to add for x +.mode7xincc dd 0 ; range check for x +.mode7yinc dd 0 ; number to add for y +.mode7xsloc dd 0 ; which screen x +.mode7ysloc dd 0 ; which screen y +.mode7xsrl dd 0 ; which relative screen x +.mode7ysrl dd 0 ; which relative screen y +.cxloc dw 0 ; cx location +.cyloc dw 0 ; cy location +.m7xaddofa dd 0 +.m7xaddof2a dd 0 +.m7yaddofa dd 0 +.m7yaddof2a dd 0 + + +.drawmode7win +.domosaicw + mov ebx,[.mode7xrpos] + mov [mode7xrpos],ebx + mov ebx,[.mode7yrpos] + mov [mode7yrpos],ebx + mov ebx,[.mode7xadder] + mov [mode7xadder],ebx + mov ebx,[.mode7yadder] + mov [mode7yadder],ebx + + mov edi,[vram] + Mode7Processngw Mode7Normalng, domosaic, 1 + +NEWSYM drawmode7ngextbg2 + ; esi = pointer to video buffer + mov esi,[curvidoffset] ; esi = [vidbuffer] + curypos * 288 + 16 + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+16 + mov ecx,64 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+16 +.nomosaic + mov ecx,256 +.loop + mov al,[esi+75036] + test al,80h + jz .nopr2 + and al,7Fh + mov [esi],al +.nopr2 + inc esi + loop .loop + xor eax,eax + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic + ret + + \ No newline at end of file diff --git a/zsnes/src/video/mv16tms.asm b/zsnes/src/video/mv16tms.asm new file mode 100644 index 00000000..8722c4a6 --- /dev/null +++ b/zsnes/src/video/mv16tms.asm @@ -0,0 +1,1502 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM bgcoloradder,bgofwptr,bgsubby,bshifter,curbgpr,curmosaicsz +EXTSYM curvidoffset,cwinptr,domosaic16b,drawn,pal16b,scaddtype +EXTSYM scrnon,temp,tempcach,temptile,tileleft16b,transpbuf,vcache2b +EXTSYM vcache4b,vcache8b,winon,winptrref,xtravbuf,yadd,yadder +EXTSYM yrevadder,draw16x816t,bgmode +EXTSYM vcache2ba,vcache4ba,vcache8ba +EXTSYM fulladdtab,pal16bcl +EXTSYM pal16bxcl +EXTSYM coadder16 +EXTSYM a16x16xinc,a16x16yinc,curypos,yflipadd + +%include "video/vidmacro.mac" + + + + + +;******************************************************* +; Processes & Draws 8x8 tiles in 2, 4, & 8 bit mode +;******************************************************* + +%macro draw8x816tams 2 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + mov [ebp+%2],ax + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbms 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + mov [ebp+%2],cx + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcms 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + mov [ebp+%2],cx + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinonms 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + mov [ebp+%2],ax + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbwinonms 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + mov [ebp+%2],cx + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinonms 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + mov [ebp+%2],cx + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinonbms 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + mov [ebp+%2],ax + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbwinonbms 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + mov [ebp+%2],cx + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinonbms 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + mov [ebp+%2],cx + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + + +NEWSYM draw8x816tms + cmp byte[bgmode],5 + je near draw16x816t + + mov [temp],al + mov [bshifter],ah + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov [temptile],edx + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit +; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value +; bit 10-12 = palette, 0-9=tile# + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw8x816twinonms +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw8x816tsms + test byte[scaddtype],40h + jz near draw8x8fulladdms + cmp byte[scrnon+1],0 + jz near draw8x8fulladdms + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tams +.hprior + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpf draw8x816tams + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x8fulladdms + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbms +.hprior + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbms + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + cmp byte[drawn],0 + je .nodraw2 + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b +.nodraw2 + ret + +NEWSYM draw8x816tsms + mov byte[tileleft16b],33 + mov byte[drawn],0 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + add edi,2 + push edi + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + + ; Begin Normal Loop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcms +.hprior + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcms + pop edi + add esi,16 + add ebp,16 + inc dl + cmp dl,20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw8x816twinonms + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw8x816tswinonms + test byte[scaddtype],40h + jz near draw8x8fulladdwinonms + cmp byte[scrnon+1],0 + jz near draw8x8fulladdwinonms + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl eax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test cl,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tawinonms +.hprior + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpf draw8x816tawinonbms + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw8x8fulladdwinonms + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbwinonms +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbwinonbms + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw8x816tswinonms + mov byte[tileleft16b],33 + mov edx,[winptrref] + mov byte[drawn],0 +.loopa + mov ax,[edi] + mov cl,ah + add edi,2 + push edi + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + and eax,03FFh ; filter out tile # + mov edi,[tempcach] + shl eax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + + ; Begin Normal Loop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcwinonms +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc2 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcwinonbms + pop edi + add esi,16 + add edx,8 + add ebp,16 + inc byte[temp] + cmp byte[temp],20h + jne .loopc + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +;******************************************************* +; Processes & Draws 16x16 tiles in 2, 4, & 8 bit mode +;******************************************************* +NEWSYM draw16x1616tms + mov byte[drawn],0 + mov [temp],eax + mov eax,esi + mov [yadder],ecx + mov [tempcach],ebx + mov ebx,56 + sub ebx,ecx + mov [yrevadder],ebx + xor ebx,ebx + mov bl,[curypos] + mov [temptile],edx + ; set up y adders + test byte[a16x16yinc],01h + jz .noincrc + mov word[yadd],16 + mov word[yflipadd],0 + jmp .yesincrc +.noincrc + mov word[yadd],0 + mov word[yflipadd],16 +.yesincrc + ; esi = pointer to video buffer + mov esi,[cwinptr] + sub esi,eax + mov [winptrref],esi + mov esi,[curvidoffset] + sub esi,eax ; esi = [vidbuffer] + curypos * 288 + 16 - HOfs + sub esi,eax + cmp byte[curmosaicsz],1 + je .nomosaic + mov esi,xtravbuf+32 + mov ecx,128 +.clearnext + mov dword[esi],0 + add esi,4 + dec ecx + jnz .clearnext + mov esi,xtravbuf+32 + sub esi,eax + sub esi,eax +.nomosaic + mov dword[bgofwptr],vcache2ba+262144 + mov dword[bgsubby],262144 + cmp dword[tempcach],vcache2ba+262144 + jb .nobit + mov dword[bgofwptr],vcache4ba+131072 + mov dword[bgsubby],131072 + cmp dword[tempcach],vcache4ba+131072 + jb .nobit + mov dword[bgofwptr],vcache8ba+65536 + mov dword[bgsubby],65536 +.nobit + cmp byte[curmosaicsz],1 + jne .domosaic + cmp byte[winon],0 + jne near draw16x1616twinonms +.domosaic + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw16x1616tsms + test byte[scaddtype],40h + jz near draw16x16fulladdms + cmp byte[scrnon+1],0 + je near draw16x16fulladdms + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + test dh,20h + jnz near .hprior + inc byte[drawn] + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test dh,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tams +.hprior + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpf draw8x816tams +.skiploop2b + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +draw16x16fulladdms: + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + push edi + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbms +.hprior + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbms + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +NEWSYM draw16x1616tsms + mov byte[tileleft16b],33 + mov dl,[temp] +.loopa + mov ax,[edi] + mov dh,ah + xor byte[a16x16xinc],1 + + test dh,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor dh,[curbgpr] + push edi + test dh,20h + jnz near .hprior + inc byte[drawn] + + test dh,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test dh,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test dh,40h + jnz near .rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcms +.hprior + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc dl +.noincrb2 + cmp dl,20h + jne .loopc2 + xor dl,dl + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + + ; reversed loop +.rloop + mov cl,[bshifter] + and dh,1Ch + shl dh,cl ; process palette # (bits 10-12) + add dh,[bgcoloradder] + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcms + pop edi + add esi,16 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc dl +.noincrb + cmp dl,20h + jne .loopc + xor dl,dl + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + mov dh,byte[curmosaicsz] + cmp dh,1 + jne near domosaic16b + ret + +NEWSYM draw16x1616twinonms + mov ebp,transpbuf+32 + sub ebp,eax + sub ebp,eax + test byte[scaddtype],80h + jnz near draw16x1616tswinonms + test byte[scaddtype],40h + jz near draw16x16fulladdwinonms + cmp byte[scrnon+1],0 + je near draw16x16fulladdwinonms + mov byte[tileleft16b],33 + mov edx,[winptrref] +.loopa + mov ax,[edi] + mov cl,ah + xor byte[a16x16xinc],1 + test cl,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor cl,[curbgpr] + test cl,20h + jnz near .hprior + inc byte[drawn] + test cl,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + and ax,03FFh ; filter out tile # + mov ebx,[tempcach] + shl ax,6 + add ebx,eax + cmp ebx,[bgofwptr] + jb .noclip + sub ebx,[bgsubby] +.noclip + test cl,80h + jz .normadd + add ebx,[yrevadder] + jmp .skipadd +.normadd + add ebx,[yadder] +.skipadd + test cl,40h + jnz near .rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrp draw8x816tawinonms +.hprior + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc byte[temp] +.noincrb2 + cmp byte[temp],20h + jne .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpf draw8x816tawinonbms +.skiploop2b + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc byte[temp] +.noincrb + cmp byte[temp],20h + jne near .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw16x16fulladdwinonms + mov byte[tileleft16b],33 + mov edx,[winptrref] +.loopa + mov ax,[edi] + mov cl,ah + xor byte[a16x16xinc],1 + + test cl,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor cl,[curbgpr] + push edi + test cl,20h + jnz near .hprior + inc byte[drawn] + + test cl,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tbwinonms +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc byte[temp] +.noincrb2 + cmp byte[temp],20h + jne .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tbwinonbms + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc byte[temp] +.noincrb + cmp byte[temp],20h + jne near .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + +NEWSYM draw16x1616tswinonms + mov byte[tileleft16b],33 + mov edx,[winptrref] +.loopa + mov ax,[edi] + mov cl,ah + xor byte[a16x16xinc],1 + + test cl,40h + jnz .noxflip + test byte[a16x16xinc],01h + jnz .noincr2 + inc ax + add edi,2 +.noincr2 + jmp .yesxflip +.noxflip + test byte[a16x16xinc],01h + jnz .noincr + add edi,2 + jmp .yesincr +.noincr + inc ax +.yesincr +.yesxflip + xor cl,[curbgpr] + push edi + test cl,20h + jnz near .hprior + inc byte[drawn] + + test cl,80h + jnz .noyflip + add ax,word[yadd] + jmp .yesyflip +.noyflip + add ax,word[yflipadd] +.yesyflip + + and ax,03FFh ; filter out tile # + mov edi,[tempcach] + shl ax,6 + add edi,eax + cmp edi,[bgofwptr] + jb .noclip + sub edi,[bgsubby] +.noclip + test cl,80h + jz .normadd + add edi,[yrevadder] + jmp .skipadd +.normadd + add edi,[yadder] +.skipadd + test cl,40h + jnz near .rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + ; Start loop + drawtilegrpfull draw8x816tcwinonms +.hprior + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb2 + inc byte[temp] +.noincrb2 + cmp byte[temp],20h + jne .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc2 + dec byte[tileleft16b] + jnz near .loopa + ret + + ; reversed loop +.rloop + mov al,cl + mov cl,[bshifter] + and al,1Ch + shl al,cl ; process palette # (bits 10-12) + add al,[bgcoloradder] + mov [coadder16],al + xor eax,eax + xor ecx,ecx + drawtilegrpfullf draw8x816tcwinonbms + pop edi + add esi,16 + add edx,8 + add ebp,16 + test byte[a16x16xinc],01h + jnz .noincrb + inc byte[temp] +.noincrb + cmp byte[temp],20h + jne near .loopc2 + mov byte[temp],0 + mov edi,[temptile] +.loopc + dec byte[tileleft16b] + jnz near .loopa + ret + \ No newline at end of file diff --git a/zsnes/src/video/newg162.asm b/zsnes/src/video/newg162.asm new file mode 100644 index 00000000..5cf5775d --- /dev/null +++ b/zsnes/src/video/newg162.asm @@ -0,0 +1,1402 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM ngwintable,ngwinen,ngcwinptr,ngcpixleft,ngcwinmode +EXTSYM tleftn, ng16bprval, vrama, bg1drwng, ng16bbgval, bg1totng +EXTSYM bgtxadd, taddnfy16x16, taddfy16x16, switch16x16, curmosaicsz, domosaicng16b +EXTSYM vidmemch4,vidmemch2,vidmemch8,mode0add,vcache4b,vcache2b,vcache8b +EXTSYM cachesingle2bng,cachesingle8bng,ngpalcon4b,ngpalcon8b +EXTSYM ngpalcon2b,tleftnb,tltype2b,tltype4b,tltype8b,yposng,flipyposng +EXTSYM ofsmcptr,ofsmtptr,ofsmmptr,ofsmcyps,ofsmady,ofsmadx,FillSubScr,UnusedBitXor +EXTSYM yposngom,flipyposngom,cbgval,ofsmval,ofsmvalh,vram,CPalPtrng,BGMS1,scadtng +EXTSYM CMainWinScr,CSubWinScr,UnusedBit,res640,mosclineval,mostranspval +EXTSYM vcache2bs,vcache4bs,vcache8bs +EXTSYM vidmemch2s,vidmemch4s,vidmemch8s +EXTSYM cpalval +EXTSYM SpecialLine + +%include "video/vidmacro.mac" +%include "video/newg162.mac" +%include "video/newgfx16.mac" +%include "video/newg16wn.mac" + + + + + + + + + +;****************************************** +; 16bitng caching functions +;****************************************** + +%macro cacheloopstuff 1 + mov bl,[esi+%1] + or bl,bl + jnz %%okay + mov ax,0FFFFh + jmp %%transp +%%okay + or bl,dl + mov ax,[ebp+ebx*2] +%%transp + mov [edi+%1*2],ax + mov [edi+14-%1*2+128],ax +%endmacro + +%macro DoCache 2 + push ecx + push eax + push esi + push edi + mov esi,ecx + xor ebx,ebx + shl esi,6 + shl ecx,8 + add esi,[%1] + add ecx,[%2] + mov edi,ecx + mov ecx,8 +.loop + cacheloopstuff 0 + cacheloopstuff 1 + cacheloopstuff 2 + cacheloopstuff 3 + cacheloopstuff 4 + cacheloopstuff 5 + cacheloopstuff 6 + cacheloopstuff 7 + add edi,16 + add esi,8 + dec ecx + jnz near .loop + pop edi + pop esi + pop eax + pop ecx + ret +%endmacro + +cache2b16b: + DoCache vcache2b,vcache2bs +cache4b16b: + DoCache vcache4b,vcache4bs +cache8b16b: + DoCache vcache8b,vcache8bs + +;****************************************** +; 8x8 tiles - tile engine +;****************************************** + +%macro WinClipMacro 1 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + add ax,2 + mov ebx,[ng16bbgval] + add edi,16 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jnz .notileadd + add ax,[bgtxadd] +.notileadd + dec byte[tleftn] + jnz .winclipped + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline +%endmacro + +%macro determinetransp 1 + mov [mostranspval],dl + mov [mosclineval],ebx + add ecx,[CMainWinScr] + cmp byte[curmosaicsz],1 + jne .mosaic + test byte[BGMS1+ebx*2],dl + jz .nosubmain + test byte[FillSubScr+ebx],1 + jnz near %1 + jmp .main +.nosubmain + test byte[FillSubScr+ebx],1 + jz .main + sub ecx,[CMainWinScr] + add ecx,[CSubWinScr] + add edi,75036*2 + jmp .main +.mosaic + test byte[FillSubScr+ebx],1 + jz .main + sub ecx,[CMainWinScr] + add ecx,[CSubWinScr] +.main +%endmacro + +%macro CheckWindowing 1 + cmp byte[ngwinen],0 + je %%nowindowing + cmp byte[ecx],0 + jne near %1 +%%nowindowing +%endmacro + +%macro DetermineWindow 3 ; both,main,sub + cmp byte[ngwinen],0 + je %%nowindow + cmp byte[ecx],0 + jz near %3 + sub ecx,[CMainWinScr] + add ecx,[CSubWinScr] + cmp byte[ecx],0 + jnz near %1 + jmp %2 +%%nowindow +%endmacro + +%macro drawtile16b 10 + mov byte[tleftn],33 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawtileng16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8,%9,%10 + ret +%endmacro + +%macro drawtile16bw 12 + WinClipMacro %%processwinclip2b + drawtileng16b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8,%9,%10 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawtilengwin16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8,%11,%12 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +%macro drawtile16bw2 14 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %%processwinclip2b + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finlineb + drawtileng16b %1,%2,%3,.winclipped,.finlineb,%4,%5,%6,%7,%8,%13,%14 +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %%processwinclip2b + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng16b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8,%9,%10 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawtilengwin16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8,%11,%12 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +NEWSYM drawtileng2b16b + mov ebp,[cpalval+ebx*4] + determinetransp drawtileng2b16bt +drawtileng2b16bnt + CheckWindowing drawtileng2bwin + drawtile16b tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormal,tilenormalb +drawtileng2bwin: + drawtile16bw tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormal,tilenormalb,tilenormalw,tilenormalwb +drawtileng2b16bt + test byte[BGMS1+ebx*2+1],dl + jnz near drawtileng2b16bms + test byte[scadtng+ebx],dl + jz near drawtileng2b16bnt + CheckWindowing drawtileng2bwint + drawtile16b tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalt,tilenormalbt +drawtileng2bwint: + drawtile16bw tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalt,tilenormalbt,tilenormalwt,tilenormalwbt +drawtileng2b16bms: + test byte[scadtng+ebx],dl + jz near drawtileng2b16bmsnt + DetermineWindow drawtileng2b16bmstmsw, drawtileng2b16bmstmw, drawtileng2b16bmstsw + drawtile16b tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst +drawtileng2b16bmstmsw: + drawtile16bw tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst,tilenormalwmst,tilenormalwbmst +drawtileng2b16bmstmw: + drawtile16bw2 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst,tilenormalwsmt,tilenormalwbsmt,tilenormals,tilenormalbs +drawtileng2b16bmstsw: + drawtile16bw2 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst,tilenormalwmsbt,tilenormalwbmsbt,tilenormalt,tilenormalbt +drawtileng2b16bmsnt + DetermineWindow drawtileng2b16bmsntmsw, drawtileng2b16bmsntmw, drawtileng2b16bmsntsw + drawtile16b tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt +drawtileng2b16bmsntmsw: + drawtile16bw tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsnt,tilenormalwbmsnt +drawtileng2b16bmsntmw: + drawtile16bw2 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwsmnt,tilenormalwbsmnt,tilenormals,tilenormalbs +drawtileng2b16bmsntsw: + drawtile16bw2 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsbnt,tilenormalwbmsbnt,tilenormal,tilenormalb + +NEWSYM drawtileng4b16b + mov ebp,[cpalval+ebx*4] + determinetransp drawtileng4b16bt +drawtileng4b16bnt + CheckWindowing drawtileng4bwin + drawtile16b tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormal,tilenormalb +drawtileng4bwin: + drawtile16bw tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormal,tilenormalb,tilenormalw,tilenormalwb +drawtileng4b16bt + test byte[BGMS1+ebx*2+1],dl + jnz near drawtileng4b16bms + test byte[scadtng+ebx],dl + jz near drawtileng4b16bnt + CheckWindowing drawtileng4bwint + drawtile16b tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalt,tilenormalbt +drawtileng4bwint: + drawtile16bw tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalt,tilenormalbt,tilenormalwt,tilenormalwbt +drawtileng4b16bms: + test byte[scadtng+ebx],dl + jz near drawtileng4b16bmsnt + DetermineWindow drawtileng4b16bmstmsw, drawtileng4b16bmstmw, drawtileng4b16bmstsw + drawtile16b tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst +drawtileng4b16bmstmsw: + drawtile16bw tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst,tilenormalwmst,tilenormalwbmst +drawtileng4b16bmstmw: + drawtile16bw2 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst,tilenormalwsmt,tilenormalwbsmt,tilenormals,tilenormalbs +drawtileng4b16bmstsw: + drawtile16bw2 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst,tilenormalwmsbt,tilenormalwbmsbt,tilenormalt,tilenormalbt +drawtileng4b16bmsnt + DetermineWindow drawtileng4b16bmsntmsw, drawtileng4b16bmsntmw, drawtileng4b16bmsntsw + drawtile16b tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt +drawtileng4b16bmsntmsw: + drawtile16bw tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsnt,tilenormalwbmsnt +drawtileng4b16bmsntmw: + drawtile16bw2 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwsmnt,tilenormalwbsmnt,tilenormals,tilenormalbs +drawtileng4b16bmsntsw: + drawtile16bw2 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsbnt,tilenormalwbmsbnt,tilenormal,tilenormalb + +NEWSYM drawtileng8b16b + mov ebp,[cpalval+ebx*4] + determinetransp drawtileng8b16bt +drawtileng8b16bnt + CheckWindowing drawtileng8bwin + drawtile16b tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0Fh,vidmemch8s,cache8b16b,tilenormal,tilenormalb +drawtileng8bwin: + drawtile16bw tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0Fh,vidmemch8s,cache8b16b,tilenormal,tilenormalb,tilenormalw,tilenormalwb +drawtileng8b16bt + test byte[BGMS1+ebx*2+1],dl + jnz near drawtileng8b16bms + test byte[scadtng+ebx],dl + jz near drawtileng8b16bnt + CheckWindowing drawtileng8bwint + drawtile16b tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0Fh,vidmemch8s,cache8b16b,tilenormalt,tilenormalbt +drawtileng8bwint: + drawtile16bw tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0Fh,vidmemch8s,cache8b16b,tilenormalt,tilenormalbt,tilenormalwt,tilenormalwbt +drawtileng8b16bms: + test byte[scadtng+ebx],dl + jz near drawtileng8b16bmsnt + DetermineWindow drawtileng8b16bmstmsw, drawtileng8b16bmstmw, drawtileng8b16bmstsw + drawtile16b tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst +drawtileng8b16bmstmsw: + drawtile16bw tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst,tilenormalwmst,tilenormalwbmst +drawtileng8b16bmstmw: + drawtile16bw2 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst,tilenormalwsmt,tilenormalwbsmt,tilenormals,tilenormalbs +drawtileng8b16bmstsw: + drawtile16bw2 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst,tilenormalwmsbt,tilenormalwbmsbt,tilenormalt,tilenormalbt +drawtileng8b16bmsnt + DetermineWindow drawtileng8b16bmsntmsw, drawtileng8b16bmsntmw, drawtileng8b16bmsntsw + drawtile16b tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt +drawtileng8b16bmsntmsw: + drawtile16bw tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsnt,tilenormalwbmsnt +drawtileng8b16bmsntmw: + drawtile16bw2 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwsmnt,tilenormalwbsmnt,tilenormals,tilenormalbs +drawtileng8b16bmsntsw: + drawtile16bw2 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsbnt,tilenormalwbmsbnt,tilenormal,tilenormalb + +;****************************************** +; 16x16 tiles - tile engine +;****************************************** + +%macro WinClipMacro16x16 1 + mov byte[tleftn],17 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %1 + sub dword[ebx],16 + add ax,2 + mov ebx,[ng16bbgval] + add edi,32 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jnz .notileadd + add ax,[bgtxadd] +.notileadd + dec byte[tleftn] + jnz .winclipped + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %1 + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline +%endmacro + +%macro drawtile16b16x16 10 + mov byte[tleftn],17 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawtileng16x1616b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8,%9,%10 + ret +%endmacro + +%macro drawtile16bw16x16 12 + WinClipMacro16x16 %%processwinclip2b + drawtileng16x1616b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8,%9,%10 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawtileng16x16win16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8,%11,%12 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +%macro drawtile16bw216x16 14 + mov byte[tleftn],17 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %%processwinclip2b + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finlineb + drawtileng16x1616b %1,%2,%3,.winclipped,.finlineb,%4,%5,%6,%7,%8,%13,%14 +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %%processwinclip2b + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng16x1616b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8,%9,%10 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawtileng16x16win16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8,%11,%12 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +NEWSYM drawtileng16x162b16b + mov ebp,[cpalval+ebx*4] + determinetransp drawtileng2b16bt16x16 +drawtileng2b16bnt16x16 + CheckWindowing drawtileng2bwin16x16 + drawtile16b16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormal,tilenormalb +drawtileng2bwin16x16: + drawtile16bw16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormal,tilenormalb,tilenormalw,tilenormalwb +drawtileng2b16bt16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawtileng2b16bms16x16 + test byte[scadtng+ebx],dl + jz near drawtileng2b16bnt16x16 + CheckWindowing drawtileng2bwint16x16 + drawtile16b16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalt,tilenormalbt +drawtileng2bwint16x16: + drawtile16bw16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalt,tilenormalbt,tilenormalwt,tilenormalwbt +drawtileng2b16bms16x16: + test byte[scadtng+ebx],dl + jz near drawtileng2b16bmsnt16x16 + DetermineWindow drawtileng2b16bmstmsw16x16, drawtileng2b16bmstmw16x16, drawtileng2b16bmstsw16x16 + drawtile16b16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst +drawtileng2b16bmstmsw16x16: + drawtile16bw16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst,tilenormalwmst,tilenormalwbmst +drawtileng2b16bmstmw16x16: + drawtile16bw216x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst,tilenormalwsmt,tilenormalwbsmt,tilenormals,tilenormalbs +drawtileng2b16bmstsw16x16: + drawtile16bw216x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmst,tilenormalbmst,tilenormalwmsbt,tilenormalwbmsbt,tilenormalt,tilenormalbt +drawtileng2b16bmsnt16x16 + DetermineWindow drawtileng2b16bmsntmsw16x16, drawtileng2b16bmsntmw16x16, drawtileng2b16bmsntsw16x16 + drawtile16b16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt +drawtileng2b16bmsntmsw16x16: + drawtile16bw16x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsnt,tilenormalwbmsnt +drawtileng2b16bmsntmw16x16: + drawtile16bw216x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwsmnt,tilenormalwbsmnt,tilenormals,tilenormalbs +drawtileng2b16bmsntsw16x16: + drawtile16bw216x16 tltype2b, preparet2batile, cachesingle2bng,ngpalcon2b,test2ba,03h,vidmemch2s,cache2b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsbnt,tilenormalwbmsbnt,tilenormal,tilenormalb + +NEWSYM drawtileng16x164b16b + mov ebp,[cpalval+ebx*4] + determinetransp drawtileng4b16bt16x16 +drawtileng4b16bnt16x16 + CheckWindowing drawtileng4bwin16x16 + drawtile16b16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormal,tilenormalb +drawtileng4bwin16x16: + drawtile16bw16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormal,tilenormalb,tilenormalw,tilenormalwb +drawtileng4b16bt16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawtileng4b16bms16x16 + test byte[scadtng+ebx],dl + jz near drawtileng4b16bnt16x16 + CheckWindowing drawtileng4bwint16x16 + drawtile16b16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalt,tilenormalbt +drawtileng4bwint16x16: + drawtile16bw16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalt,tilenormalbt,tilenormalwt,tilenormalwbt +drawtileng4b16bms16x16: + test byte[scadtng+ebx],dl + jz near drawtileng4b16bmsnt16x16 + DetermineWindow drawtileng4b16bmstmsw16x16, drawtileng4b16bmstmw16x16, drawtileng4b16bmstsw16x16 + drawtile16b16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst +drawtileng4b16bmstmsw16x16: + drawtile16bw16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst,tilenormalwmst,tilenormalwbmst +drawtileng4b16bmstmw16x16: + drawtile16bw216x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst,tilenormalwsmt,tilenormalwbsmt,tilenormals,tilenormalbs +drawtileng4b16bmstsw16x16: + drawtile16bw216x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmst,tilenormalbmst,tilenormalwmsbt,tilenormalwbmsbt,tilenormalt,tilenormalbt +drawtileng4b16bmsnt16x16 + DetermineWindow drawtileng4b16bmsntmsw16x16, drawtileng4b16bmsntmw16x16, drawtileng4b16bmsntsw16x16 + drawtile16b16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt +drawtileng4b16bmsntmsw16x16: + drawtile16bw16x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsnt,tilenormalwbmsnt +drawtileng4b16bmsntmw16x16: + drawtile16bw216x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwsmnt,tilenormalwbsmnt,tilenormals,tilenormalbs +drawtileng4b16bmsntsw16x16: + drawtile16bw216x16 tltype4b, preparet4batile, cachesingle4bng,ngpalcon4b,test4ba,0Fh,vidmemch4s,cache4b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsbnt,tilenormalwbmsbnt,tilenormal,tilenormalb + +NEWSYM drawtileng16x168b16b + mov ebp,[cpalval+ebx*4] + determinetransp drawtileng8b16bt16x16 +drawtileng8b16bnt16x16 + CheckWindowing drawtileng8bwin16x16 + drawtile16b16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormal,tilenormalb +drawtileng8bwin16x16: + drawtile16bw16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormal,tilenormalb,tilenormalw,tilenormalwb +drawtileng8b16bt16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawtileng8b16bms16x16 + test byte[scadtng+ebx],dl + jz near drawtileng8b16bnt16x16 + CheckWindowing drawtileng8bwint16x16 + drawtile16b16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalt,tilenormalbt +drawtileng8bwint16x16: + drawtile16bw16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalt,tilenormalbt,tilenormalwt,tilenormalwbt +drawtileng8b16bms16x16: + test byte[scadtng+ebx],dl + jz near drawtileng8b16bmsnt16x16 + DetermineWindow drawtileng8b16bmstmsw16x16, drawtileng8b16bmstmw16x16, drawtileng8b16bmstsw16x16 + drawtile16b16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst +drawtileng8b16bmstmsw16x16: + drawtile16bw16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst,tilenormalwmst,tilenormalwbmst +drawtileng8b16bmstmw16x16: + drawtile16bw216x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst,tilenormalwsmt,tilenormalwbsmt,tilenormals,tilenormalbs +drawtileng8b16bmstsw16x16: + drawtile16bw216x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmst,tilenormalbmst,tilenormalwmsbt,tilenormalwbmsbt,tilenormalt,tilenormalbt +drawtileng8b16bmsnt16x16 + DetermineWindow drawtileng8b16bmsntmsw16x16, drawtileng8b16bmsntmw16x16, drawtileng8b16bmsntsw16x16 + drawtile16b16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt +drawtileng8b16bmsntmsw16x16: + drawtile16bw16x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsnt,tilenormalwbmsnt +drawtileng8b16bmsntmw16x16: + drawtile16bw216x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwsmnt,tilenormalwbsmnt,tilenormals,tilenormalbs +drawtileng8b16bmsntsw16x16: + drawtile16bw216x16 tltype8b, preparet8batile, cachesingle8bng,ngpalcon8b,test8ba,0FFh,vidmemch8s,cache8b16b,tilenormalmsnt,tilenormalbmsnt,tilenormalwmsbnt,tilenormalwbmsbnt,tilenormal,tilenormalb + +;****************************************** +; 8x8 tiles - line by line engine +;****************************************** + +%macro drawline16bmacro 8 + mov byte[tleftn],33 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawlineng16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8 + ret +%endmacro + +%macro drawline16bwmacro 9 + WinClipMacro %%processwinclip2b + drawlineng16b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlinengwin16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +%macro drawline16bw2macro 11 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %%processwinclip2b + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finlineb + drawlineng16b %1,%2,%3,.winclipped,.finlineb,%4,%5,%6,%10,%11 +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %%processwinclip2b + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng16b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlinengwin16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +NEWSYM drawlineng2b16b + determinetransp drawlineng2b16bt +drawlineng2b16bnt + CheckWindowing drawlineng2bwin + drawline16bmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixels,procpixelst +drawlineng2bwin: + drawline16bwmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixels,procpixelst,procpixelstw +drawlineng2b16bt + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng2b16bms + test byte[scadtng+ebx],dl + jz near drawlineng2b16bnt + CheckWindowing drawlineng2bwint + drawline16bmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelstr,procpixelstt +drawlineng2bwint: + drawline16bwmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelstr,procpixelstt,procpixelstwt +drawlineng2b16bms: + test byte[scadtng+ebx],dl + jz near drawlineng2b16bmsnt + DetermineWindow drawlineng2b16bmstmsw, drawlineng2b16bmstmw, drawlineng2b16bmstsw + drawline16bmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst +drawlineng2b16bmstmsw: + drawline16bwmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng2b16bmstmw: + drawline16bw2macro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng2b16bmstsw: + drawline16bw2macro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng2b16bmsnt + DetermineWindow drawlineng2b16bmsntmsw, drawlineng2b16bmsntmw, drawlineng2b16bmsntsw + drawline16bmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt +drawlineng2b16bmsntmsw: + drawline16bwmacro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng2b16bmsntmw: + drawline16bw2macro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng2b16bmsntsw: + drawline16bw2macro tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +NEWSYM drawlineng4b16b + determinetransp drawlineng4b16bt +drawlineng4b16bnt + CheckWindowing drawlineng4bwin + drawline16bmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst +drawlineng4bwin: + drawline16bwmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst,procpixelstw +drawlineng4b16bt + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng4b16bms + test byte[scadtng+ebx],dl + jz near drawlineng4b16bnt + CheckWindowing drawlineng4bwint + drawline16bmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt +drawlineng4bwint: + drawline16bwmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt,procpixelstwt +drawlineng4b16bms: + test byte[scadtng+ebx],dl + jz near drawlineng4b16bmsnt + DetermineWindow drawlineng4b16bmstmsw, drawlineng4b16bmstmw, drawlineng4b16bmstsw + drawline16bmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst +drawlineng4b16bmstmsw: + drawline16bwmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng4b16bmstmw: + drawline16bw2macro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng4b16bmstsw: + drawline16bw2macro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng4b16bmsnt + DetermineWindow drawlineng4b16bmsntmsw, drawlineng4b16bmsntmw, drawlineng4b16bmsntsw + drawline16bmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt +drawlineng4b16bmsntmsw: + drawline16bwmacro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng4b16bmsntmw: + drawline16bw2macro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng4b16bmsntsw: + drawline16bw2macro tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +NEWSYM drawlineng8b16b + determinetransp drawlineng8b16bt +drawlineng8b16bnt + CheckWindowing drawlineng8bwin + drawline16bmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixels,procpixelst +drawlineng8bwin: + drawline16bwmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixels,procpixelst,procpixelstw +drawlineng8b16bt + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng8b16bms + test byte[scadtng+ebx],dl + jz near drawlineng8b16bnt + CheckWindowing drawlineng8bwint + drawline16bmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelstr,procpixelstt +drawlineng8bwint: + drawline16bwmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelstr,procpixelstt,procpixelstwt +drawlineng8b16bms: + test byte[scadtng+ebx],dl + jz near drawlineng8b16bmsnt + DetermineWindow drawlineng8b16bmstmsw, drawlineng8b16bmstmw, drawlineng8b16bmstsw + drawline16bmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst +drawlineng8b16bmstmsw: + drawline16bwmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng8b16bmstmw: + drawline16bw2macro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng8b16bmstsw: + drawline16bw2macro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng8b16bmsnt + DetermineWindow drawlineng8b16bmsntmsw, drawlineng8b16bmsntmw, drawlineng8b16bmsntsw + drawline16bmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt +drawlineng8b16bmsntmsw: + drawline16bwmacro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng8b16bmsntmw: + drawline16bw2macro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng8b16bmsntsw: + drawline16bw2macro tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +;****************************************** +; 16x16 tiles - line by line engine +;****************************************** + +%macro drawline16bmacro16x16 8 + mov byte[tleftn],17 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawlineng16x1616b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8 + ret +%endmacro + +%macro drawline16bwmacro16x16 9 + WinClipMacro16x16 %%processwinclip2b + drawlineng16x1616b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlineng16x16win16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +%macro drawline16bw2macro16x16 11 + mov byte[tleftn],17 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %%processwinclip2b + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finlineb + drawlineng16x1616b %1,%2,%3,.winclipped,.finlineb,%4,%5,%6,%10,%11 +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %%processwinclip2b + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng16x1616b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlineng16x16win16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + + +NEWSYM drawlineng16x162b16b + determinetransp drawlineng2b16bt16x16 +drawlineng2b16bnt16x16 + CheckWindowing drawlineng2bwin16x16 + drawline16bmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixels,procpixelst +drawlineng2bwin16x16: + drawline16bwmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixels,procpixelst,procpixelstw +drawlineng2b16bt16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng2b16bms16x16 + test byte[scadtng+ebx],dl + jz near drawlineng2b16bnt16x16 + CheckWindowing drawlineng2bwint16x16 + drawline16bmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelstr,procpixelstt +drawlineng2bwint16x16: + drawline16bwmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelstr,procpixelstt,procpixelstwt +drawlineng2b16bms16x16: + test byte[scadtng+ebx],dl + jz near drawlineng2b16bmsnt16x16 + DetermineWindow drawlineng2b16bmstmsw16x16, drawlineng2b16bmstmw16x16, drawlineng2b16bmstsw16x16 + drawline16bmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst +drawlineng2b16bmstmsw16x16: + drawline16bwmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng2b16bmstmw16x16: + drawline16bw2macro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng2b16bmstsw16x16: + drawline16bw2macro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng2b16bmsnt16x16 + DetermineWindow drawlineng2b16bmsntmsw16x16, drawlineng2b16bmsntmw16x16, drawlineng2b16bmsntsw16x16 + drawline16bmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt +drawlineng2b16bmsntmsw16x16: + drawline16bwmacro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng2b16bmsntmw16x16: + drawline16bw2macro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng2b16bmsntsw16x16: + drawline16bw2macro16x16 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +NEWSYM drawlineng16x164b16b + determinetransp drawlineng4b16bt16x16 +drawlineng4b16bnt16x16 + CheckWindowing drawlineng4bwin16x16 + drawline16bmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst +drawlineng4bwin16x16: + drawline16bwmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst,procpixelstw +drawlineng4b16bt16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng4b16bms16x16 + test byte[scadtng+ebx],dl + jz near drawlineng4b16bnt16x16 + CheckWindowing drawlineng4bwint16x16 + drawline16bmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt +drawlineng4bwint16x16: + drawline16bwmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt,procpixelstwt +drawlineng4b16bms16x16: + test byte[scadtng+ebx],dl + jz near drawlineng4b16bmsnt16x16 + DetermineWindow drawlineng4b16bmstmsw16x16, drawlineng4b16bmstmw16x16, drawlineng4b16bmstsw16x16 + drawline16bmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst +drawlineng4b16bmstmsw16x16: + drawline16bwmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng4b16bmstmw16x16: + drawline16bw2macro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng4b16bmstsw16x16: + drawline16bw2macro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng4b16bmsnt16x16 + DetermineWindow drawlineng4b16bmsntmsw16x16, drawlineng4b16bmsntmw16x16, drawlineng4b16bmsntsw16x16 + drawline16bmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt +drawlineng4b16bmsntmsw16x16: + drawline16bwmacro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng4b16bmsntmw16x16: + drawline16bw2macro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng4b16bmsntsw16x16: + drawline16bw2macro16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +NEWSYM drawlineng16x168b16b + determinetransp drawlineng8b16bt16x16 +drawlineng8b16bnt16x16 + CheckWindowing drawlineng8bwin16x16 + drawline16bmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixels,procpixelst +drawlineng8bwin16x16: + drawline16bwmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixels,procpixelst,procpixelstw +drawlineng8b16bt16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng8b16bms16x16 + test byte[scadtng+ebx],dl + jz near drawlineng8b16bnt16x16 + CheckWindowing drawlineng8bwint16x16 + drawline16bmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelstr,procpixelstt +drawlineng8bwint16x16: + drawline16bwmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelstr,procpixelstt,procpixelstwt +drawlineng8b16bms16x16: + test byte[scadtng+ebx],dl + jz near drawlineng8b16bmsnt16x16 + DetermineWindow drawlineng8b16bmstmsw16x16, drawlineng8b16bmstmw16x16, drawlineng8b16bmstsw16x16 + drawline16bmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst +drawlineng8b16bmstmsw16x16: + drawline16bwmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng8b16bmstmw16x16: + drawline16bw2macro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng8b16bmstsw16x16: + drawline16bw2macro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng8b16bmsnt16x16 + DetermineWindow drawlineng8b16bmsntmsw16x16, drawlineng8b16bmsntmw16x16, drawlineng8b16bmsntsw16x16 + drawline16bmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt +drawlineng8b16bmsntmsw16x16: + drawline16bwmacro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng8b16bmsntmw16x16: + drawline16bw2macro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng8b16bmsntsw16x16: + drawline16bw2macro16x16 tltype8b,preparet8ba,cachesingle8bng,ngpalcon8b,test8ba,0FFh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +%macro drawline16bmacro16x8 10 + cmp byte[curmosaicsz],1 + ja near %%res640 + cmp byte[res640],0 + je near %%res640 + mov byte[tleftn],33 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawlineng16x816b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8 + ret +%%res640 + push ebx + mov cl,[curmosaicsz] +%%mosloop + mov byte[SpecialLine+ebx],0 + inc ebx + dec cl + jnz %%mosloop + pop ebx + mov byte[tleftn],33 +%%loopb + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finlineb + drawlineng16x816b %1,%2,%3,%%loopb,%%finlineb,%4,%5,%6,%9,%10 + ret +%endmacro + +NEWSYM drawlineng16x84b16b + determinetransp drawlineng4b16bt16x8 +drawlineng4b16bnt16x8 + drawline16bmacro16x8 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels16x8,procpixelst16x8,procpixels16x8b,procpixelst16x8b +drawlineng4b16bt16x8 + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng4b16bms16x8 + test byte[scadtng+ebx],dl + jz near drawlineng4b16bnt16x8 + drawline16bmacro16x8 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr16x8,procpixelstt16x8,procpixelstr16x8b,procpixelstt16x8b +drawlineng4b16bms16x8: + test byte[scadtng+ebx],dl + jz near drawlineng4b16bmsnt16x8 + drawline16bmacro16x8 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst16x8,procpixelstmst16x8,procpixelsmst16x8b,procpixelstmst16x8b +drawlineng4b16bmsnt16x8 + drawline16bmacro16x8 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt16x8,procpixelstmsnt16x8,procpixelsmsnt16x8b,procpixelstmsnt16x8b + +NEWSYM drawlineng16x82b16b + determinetransp drawlineng2b16bt16x8 +drawlineng2b16bnt16x8 + drawline16bmacro16x8 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixels16x8,procpixelst16x8,procpixels16x8b,procpixelst16x8b +drawlineng2b16bt16x8 + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng2b16bms16x8 + test byte[scadtng+ebx],dl + jz near drawlineng2b16bnt16x8 + drawline16bmacro16x8 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelstr16x8,procpixelstt16x8,procpixelstr16x8b,procpixelstt16x8b +drawlineng2b16bms16x8: + test byte[scadtng+ebx],dl + jz near drawlineng2b16bmsnt16x8 + drawline16bmacro16x8 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmst16x8,procpixelstmst16x8,procpixelsmst16x8b,procpixelstmst16x8b +drawlineng2b16bmsnt16x8 + drawline16bmacro16x8 tltype2b,preparet2ba,cachesingle2bng,ngpalcon2b,test2ba,03h,procpixelsmsnt16x8,procpixelstmsnt16x8,procpixelsmsnt16x8b,procpixelstmsnt16x8b + +%macro WinClipMacroom 1 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,16 + test eax,03Fh + jnz .next + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx +.next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz .noofsm2 + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz .noupper2 + add ax,[ofsmady] +.noupper2 + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +.noofsm2 + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmvalh] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz .noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz .noleft + add ax,[ofsmadx] +.noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +.noofsmh + + dec byte[tleftn] + jnz near .winclipped + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline +%endmacro + +%macro drawline16bmacroom 8 + mov byte[tleftn],33 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawlinengom16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8 + ret +%endmacro + +%macro drawline16bwmacroom 9 + WinClipMacroom %%processwinclip2b + drawlinengom16b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlinengomwin16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +%macro drawline16bw2macroom 11 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %%processwinclip2b + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finlineb + drawlinengom16b %1,%2,%3,.winclipped,.finlineb,%4,%5,%6,%10,%11 +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %%processwinclip2b + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlinengom16b %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlinengomwin16b %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +NEWSYM drawlinengom4b16b + determinetransp drawlineng4b16btom +drawlineng4b16bntom + CheckWindowing drawlineng4bwinom + drawline16bmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst +drawlineng4bwinom: + drawline16bwmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst,procpixelstw +drawlineng4b16btom + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng4b16bmsom + test byte[scadtng+ebx],dl + jz near drawlineng4b16bntom + CheckWindowing drawlineng4bwintom + drawline16bmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt +drawlineng4bwintom: + drawline16bwmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt,procpixelstwt +drawlineng4b16bmsom: + test byte[scadtng+ebx],dl + jz near drawlineng4b16bmsntom + DetermineWindow drawlineng4b16bmstmswom, drawlineng4b16bmstmwom, drawlineng4b16bmstswom + drawline16bmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst +drawlineng4b16bmstmswom: + drawline16bwmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwmst +drawlineng4b16bmstmwom: + drawline16bw2macroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwsmt,procpixelss,procpixelsts +drawlineng4b16bmstswom: + drawline16bw2macroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst,procpixelstwmsbt,procpixelstr,procpixelstt +drawlineng4b16bmsntom + DetermineWindow drawlineng4b16bmsntmswom, drawlineng4b16bmsntmwom, drawlineng4b16bmsntswom + drawline16bmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt +drawlineng4b16bmsntmswom: + drawline16bwmacroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsnt +drawlineng4b16bmsntmwom: + drawline16bw2macroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwsmnt,procpixelss,procpixelsts +drawlineng4b16bmsntswom: + drawline16bw2macroom tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt,procpixelstwmsbnt,procpixelsnt,procpixelstnt + +%macro drawline16bmacroom16x16 8 + mov byte[tleftn],17 +%%loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near %%finline + drawlinengom16b16x16 %1,%2,%3,%%loop,%%finline,%4,%5,%6,%7,%8 + ret +%endmacro + +%macro drawline16bwmacroom16x16 9 + WinClipMacro16x16 %%processwinclip2b + drawlinengom16b16x16 %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlinengomwin16b16x16 %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +%macro drawline16bw2macroom16x16 11 + mov byte[tleftn],17 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %%processwinclip2b + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finlineb + drawlinengom16b16x16 %1,%2,%3,.winclipped,.finlineb,%4,%5,%6,%10,%11 +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %%processwinclip2b + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlinengom16b16x16 %1,%2,%3,.loop,.finline,%4,%5,%6,%7,%8 +%%processwinclip2b + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near %%finline + drawlinengomwin16b16x16 %1,%2,%3,%%loop,%%finline,%4,%5,%6,%9 +%%loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near .winclipped + jmp .loop +%endmacro + +NEWSYM drawlinengom16x164b16b + determinetransp drawlineng4b16btom16x16 +drawlineng4b16bntom16x16 + drawline16bmacroom16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixels,procpixelst +drawlineng4b16btom16x16 + test byte[BGMS1+ebx*2+1],dl + jnz near drawlineng4b16bmsom16x16 + test byte[scadtng+ebx],dl + jz near drawlineng4b16bntom16x16 + drawline16bmacroom16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelstr,procpixelstt +drawlineng4b16bmsom16x16: + test byte[scadtng+ebx],dl + jz near drawlineng4b16bmsntom16x16 + drawline16bmacroom16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmst,procpixelstmst +drawlineng4b16bmsntom16x16 + drawline16bmacroom16x16 tltype4b,preparet4ba,cachesingle4bng,ngpalcon4b,test4ba,0Fh,procpixelsmsnt,procpixelstmsnt + + \ No newline at end of file diff --git a/zsnes/src/video/newg162.mac b/zsnes/src/video/newg162.mac new file mode 100644 index 00000000..aec8867f --- /dev/null +++ b/zsnes/src/video/newg162.mac @@ -0,0 +1,872 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +; Finish up parttile + +%macro procpixels16x8 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2] + mov [edi+%3+75036*4],bx + mov bx,[eax+ecx*2] + mov [edi+%3],bx + xor ebx,ebx +%endmacro + +%macro procpixelst16x8 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelstr16x8 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2+512] + mov [edi+%3+75036*4],bx + mov bx,[eax+ecx*2+512] + mov [edi+%3],bx + xor ebx,ebx +%endmacro + +%macro procpixelstt16x8 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelsmst16x8 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2+512] + mov [edi+%3+75036*4],bx + and ebx,[UnusedBitXor] + mov [edi+%3+75036*6],bx + mov bx,[eax+ecx*2+512] + mov [edi+%3],bx + and ebx,[UnusedBitXor] + mov [edi+%3+75036*2],bx + xor ebx,ebx +%endmacro + +%macro procpixelstmst16x8 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx + and cx,[UnusedBitXor] + mov [edi+%2+75036*2],cx +%%nodraw +%endmacro + +%macro procpixelsmsnt16x8 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2] + mov [edi+%3+75036*4],bx + mov [edi+%3+75036*6],bx + mov bx,[eax+ecx*2] + mov [edi+%3],bx + mov [edi+%3+75036*2],bx + xor ebx,ebx +%endmacro + +%macro procpixelstmsnt16x8 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx + mov [edi+%2+75036*2],cx +%%nodraw +%endmacro + +%macro procpixels16x8b 3 + mov bl,[esi+%2] + add bl,dl + mov cx,[eax+ebx*2] + mov [edi+%3],cx +%endmacro + +%macro procpixelst16x8b 3 + %if %2<8 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx +%%nodraw + %endif +%endmacro + +%macro procpixelstr16x8b 3 + mov bl,[esi+%2] + add bl,dl + mov cx,[eax+ebx*2+512] + mov [edi+%3],cx +%endmacro + +%macro procpixelstt16x8b 3 + %if %2<8 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx +%%nodraw + %endif +%endmacro + +%macro procpixelsmst16x8b 3 + mov bl,[esi+%2] + add bl,dl + mov cx,[eax+ebx*2+512] + mov [edi+%3],cx + and ecx,[UnusedBitXor] + mov [edi+%3+75036*2],cx +%endmacro + +%macro procpixelstmst16x8b 3 + %if %2<8 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx + and cx,[UnusedBitXor] + mov [edi+%2+75036*2],cx +%%nodraw + %endif +%endmacro + +%macro procpixelsmsnt16x8b 3 + mov bl,[esi+%2] + add bl,dl + mov cx,[eax+ebx*2] + mov [edi+%3],cx + mov [edi+%3+75036*2],cx +%endmacro + +%macro procpixelstmsnt16x8b 3 + %if %2<8 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx + mov [edi+%2+75036*2],cx +%%nodraw + %endif +%endmacro + +%macro drawlineng16x816b 10 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jz %%notflipyfull + add ecx,[flipyposng] + jmp %%yesflipyfull +%%notflipyfull + add ecx,[yposng] +%%yesflipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 0,1,0 + %9 2,3,2 + %9 4,5,4 + %9 6,7,6 + pop eax + jmp %%done +%%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 7,6,0 + %9 5,4,2 + %9 3,2,4 + %9 1,0,6 + pop eax + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test dword[vrama+eax],8000h + jz %%notflipypart + add ecx,[flipyposng] + jmp %%yesflipypart +%%notflipypart + add ecx,[yposng] +%%yesflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 0,0,%8 + %10 1,0+75036*4,%8 + %10 2,2,%8 + %10 3,2+75036*4,%8 + %10 4,4,%8 + %10 5,4+75036*4,%8 + %10 6,6,%8 + %10 7,6+75036*4,%8 + pop eax + jmp %%done +%%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 7,0,%8 + %10 6,0+75036*4,%8 + %10 5,2,%8 + %10 4,2+75036*4,%8 + %10 3,4,%8 + %10 2,4+75036*4,%8 + %10 1,6,%8 + %10 0,6+75036*4,%8 + pop eax +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[cbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%5 + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlinengom216b 9 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov dl,ch + inc dword[bg1drwng+%9*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jz %%notflipyfull + add ecx,[flipyposng] + jmp %%yesflipyfull +%%notflipyfull + add ecx,[yposng] +%%yesflipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + procpixels 0,1,0 + procpixels 2,3,4 + procpixels 4,5,8 + procpixels 6,7,12 + pop eax + jmp %5 +%%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + procpixels 7,6,0 + procpixels 5,4,4 + procpixels 3,2,8 + procpixels 1,0,12 + pop eax + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test dword[vrama+eax],8000h + jz %%notflipypart + add ecx,[flipyposng] + jmp %%yesflipypart +%%notflipypart + add ecx,[yposng] +%%yesflipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + procpixelst 0,0,%8 + procpixelst 1,2,%8 + procpixelst 2,4,%8 + procpixelst 3,6,%8 + procpixelst 4,8,%8 + procpixelst 5,10,%8 + procpixelst 6,12,%8 + procpixelst 7,14,%8 + pop eax + jmp %5 + +%%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + procpixelst 7,0,%8 + procpixelst 6,2,%8 + procpixelst 5,4,%8 + procpixelst 4,6,%8 + procpixelst 3,8,%8 + procpixelst 2,10,%8 + procpixelst 1,12,%8 + procpixelst 0,14,%8 + pop eax +%5 + inc dword[bg1totng+%9*4] + add word[ofsmmptr],2 + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,16 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofshvaladd],8 + test dword[ebx-40h],8000h + jz near %%noofsm + test dword[ebx-40h],2000h << %9 + jz %%noofsm + mov ebx,[ebx-40h] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],8000h + jnz near %%noofsmh + test dword[ebx-40h],2000h << %9 + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + + +%macro drawlinengom16b 10 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jz %%notflipyfull + add ecx,[flipyposng] + jmp %%yesflipyfull +%%notflipyfull + add ecx,[yposng] +%%yesflipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 0,1,0 + %9 2,3,4 + %9 4,5,8 + %9 6,7,12 + pop eax + jmp %5 +%%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 7,6,0 + %9 5,4,4 + %9 3,2,8 + %9 1,0,12 + pop eax + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test dword[vrama+eax],8000h + jz %%notflipypart + add ecx,[flipyposng] + jmp %%yesflipypart +%%notflipypart + add ecx,[yposng] +%%yesflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 0,0,%8 + %10 1,2,%8 + %10 2,4,%8 + %10 3,6,%8 + %10 4,8,%8 + %10 5,10,%8 + %10 6,12,%8 + %10 7,14,%8 + pop eax + jmp %5 +%%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 7,0,%8 + %10 6,2,%8 + %10 5,4,%8 + %10 4,6,%8 + %10 3,8,%8 + %10 2,10,%8 + %10 1,12,%8 + %10 0,14,%8 + pop eax +%5 + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,16 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz %%noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmvalh] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + +%macro drawlinengom16b16x16 10 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx + test byte[switch16x16],1 + jz %%noflipxb + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test word[vrama+eax],8000h + jz %%noflipyfull + add ecx,[flipyposng] + jmp %%yesflipyfull +%%noflipyfull + add ecx,[yposng] +%%yesflipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 0,1,0 + %9 2,3,4 + %9 4,5,8 + %9 6,7,12 + pop eax + jmp %%done +%%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 7,6,0 + %9 5,4,4 + %9 3,2,8 + %9 1,0,12 + pop eax + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jz %%noflipypart + add ecx,[flipyposng] + jmp %%yesflipypart +%%noflipypart + add ecx,[yposng] +%%yesflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 0,0,%8 + %10 1,2,%8 + %10 2,4,%8 + %10 3,6,%8 + %10 4,8,%8 + %10 5,10,%8 + %10 6,12,%8 + %10 7,14,%8 + pop eax + jmp %%done +%%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 7,0,%8 + %10 6,2,%8 + %10 5,4,%8 + %10 4,6,%8 + %10 3,8,%8 + %10 2,10,%8 + %10 1,12,%8 + %10 0,14,%8 + pop eax +%%done + pop edx + pop ecx + + test byte[switch16x16],1 + jz %%nextb + add word[ofsmmptr],2 + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + test eax,03Fh + jz near %%tileaddb +%%nextb + + mov ebx,[cbgval] + inc dword[bg1totng+ebx*4] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz %%noofsm + + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,200h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,01FFh + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ebx,8 + jz %%noflipy16x16 + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +%%noflipy16x16 + mov edx,ebx + shr ebx,4 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +%%noofsm + add dword[ofsmcptr2],2 + and dword[ofsmcptr2],3Fh + + add edi,16 + xor dword[switch16x16],1 + jnz near %4 +%%ntile + mov ebx,[ng16bbgval] +; add ax,2 + inc dword[bg1totng+ebx*4] +; test eax,03Fh +; jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%5 + add edi,32 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%%tileaddb + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%nextb +%endmacro + \ No newline at end of file diff --git a/zsnes/src/video/newg16wn.mac b/zsnes/src/video/newg16wn.mac new file mode 100644 index 00000000..ae1672fa --- /dev/null +++ b/zsnes/src/video/newg16wn.mac @@ -0,0 +1,1191 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + + +%macro procpixelstw 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwnt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwmst 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx + and cx,[UnusedBitXor] + mov [edi+75036*2+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwmsnt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx + mov [edi+75036*2+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwmsbt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx + cmp dword[ngcwinmode],1 + je %%nodraw + and cx,[UnusedBitXor] + mov [edi+75036*2+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwmsbnt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx + cmp dword[ngcwinmode],1 + je %%nodraw + mov [edi+75036*2+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwsmt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+75036*2+%2],cx + cmp dword[ngcwinmode],1 + je %%nodraw + or cx,[UnusedBit] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelstwsmnt 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+75036*2+%2],cx + cmp dword[ngcwinmode],1 + je %%nodraw + mov [edi+%2],cx +%%nodraw +%endmacro + +Nextwinmode: + push ebx + mov ebx,[ngcwinptr] + xor dword[ngcwinmode],1 + mov ebx,[ebx+4] + add dword[ngcwinptr],4 + mov [ngcpixleft],ebx + pop ebx + ret + +%macro processnextdrawwin 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + test %1,%3 + jz %%nodraw + mov [edi+%2],%1 +%%nodraw +%endmacro + +%macro processwinpixel 0 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + dec dword[ngcpixleft] + jnz %%notzero2 + call Nextwinmode +%%notzero2 +%endmacro + +%macro drawlinengwin16b 9 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jz %%noflipypart + add ecx,[flipyposng] + jmp %%flipypart +%%noflipypart + add ecx,[yposng] +%%flipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 0,0,%8 + %9 1,2,%8 + %9 2,4,%8 + %9 3,6,%8 + %9 4,8,%8 + %9 5,10,%8 + %9 6,12,%8 + %9 7,14,%8 + pop eax + jmp .fin +%%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 7,0,%8 + %9 6,2,%8 + %9 5,4,%8 + %9 4,6,%8 + %9 3,8,%8 + %9 2,10,%8 + %9 1,12,%8 + %9 0,14,%8 + pop eax + jmp .fin +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +.fin + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,16 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlineng16x16win16b 9 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz %%flipypart + add ecx,[yposng] + jmp %%noflipypart +%%flipypart + add ecx,[flipyposng] +%%noflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 0,0,%8 + %9 1,2,%8 + %9 2,4,%8 + %9 3,6,%8 + %9 4,8,%8 + %9 5,10,%8 + %9 6,12,%8 + %9 7,14,%8 + pop eax + jmp %%done +%%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 7,0,%8 + %9 6,2,%8 + %9 5,4,%8 + %9 4,6,%8 + %9 3,8,%8 + %9 2,10,%8 + %9 1,12,%8 + %9 0,14,%8 + pop eax +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,16 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz near %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + add edi,32 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlinengomwin16b 9 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + jmp %%notflipypart +%%flipypart + add ecx,[flipyposng] +%%notflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 0,0,%8 + %9 1,2,%8 + %9 2,4,%8 + %9 3,6,%8 + %9 4,8,%8 + %9 5,10,%8 + %9 6,12,%8 + %9 7,14,%8 + pop eax + jmp %%endokay +%%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 7,0,%8 + %9 6,2,%8 + %9 5,4,%8 + %9 4,6,%8 + %9 3,8,%8 + %9 2,10,%8 + %9 1,12,%8 + %9 0,14,%8 + pop eax + jmp %%endokay +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%endokay + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,16 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz %%noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmval] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + +%macro parttilewin 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[ecx+%1*8] + or bl,bl + jz %%nodraw + add bl,dl + mov [edi+%2*288*2],bl +%%nodraw +%endmacro + +%macro tilenormalw 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwb 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwt 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + or bx,[UnusedBit] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwbt 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + or bx,[UnusedBit] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwnt 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwbnt 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwmst 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + mov [edi+%1+75036*2],bx + or bx,[UnusedBit] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwbmst 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + mov [edi+%1+75036*2],bx + or bx,[UnusedBit] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwmsnt 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + mov [edi+%1+75036*2],bx + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwbmsnt 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + mov [edi+%1+75036*2],bx + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwmsbt 2 + mov bx,[ecx+%2] + or bx,[UnusedBit] + mov [edi+%1],bx + cmp dword[ngcwinmode],1 + je %%nodraw + and bx,[UnusedBitXor] + mov [edi+%1+75036*2],bx +%%nodraw +%endmacro + +%macro tilenormalwbmsbt 2 + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + or bx,[UnusedBit] + mov [edi+%1],bx + cmp dword[ngcwinmode],1 + je %%nodraw + and bx,[UnusedBitXor] + mov [edi+%1+75036*2],bx +%%nodraw +%endmacro + +%macro tilenormalwmsbnt 2 + mov bx,[ecx+%2] + mov [edi+%1],bx + cmp dword[ngcwinmode],1 + je %%nodraw + mov [edi+%1+75036*2],bx +%%nodraw +%endmacro + +%macro tilenormalwbmsbnt 2 + cmp bx,0FFFFh + je %%nodraw + mov bx,[ecx+%2] + mov [edi+%1],bx + cmp dword[ngcwinmode],1 + je %%nodraw + mov [edi+%1+75036*2],bx +%%nodraw +%endmacro + +%macro tilenormalwsmt 2 + mov bx,[ecx+%2] + mov [edi+%1+75036*2],bx + cmp dword[ngcwinmode],1 + je %%nodraw + or bx,[UnusedBit] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwbsmt 2 + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + mov [edi+%1+75036*2],bx + cmp dword[ngcwinmode],1 + je %%nodraw + or bx,[UnusedBit] + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwsmnt 2 + mov bx,[ecx+%2] + mov [edi+%1+75036*2],bx + cmp dword[ngcwinmode],1 + je %%nodraw + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro tilenormalwbsmnt 2 + mov bx,[ecx+%2] + cmp bx,0FFFFh + je %%nodraw + mov [edi+%1+75036*2],bx + cmp dword[ngcwinmode],1 + je %%nodraw + mov [edi+%1],bx +%%nodraw +%endmacro + +%macro drawtilengwin16b 12 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache + cmp byte[%9+ecx],dl + je %%returnfromcache + mov byte[%9+ecx],dl + call %10 +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],4000h + jz %%notflipxfull + add ecx,128 +%%notflipxfull + test dword[vrama+eax],8000h + jnz near %%flipyfull + mov dword[tleftnb],8 +%%loopfa + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + %11 0,0 + %11 288*2,16 + %11 288*4,16*2 + %11 288*6,16*3 + %11 288*8,16*4 + %11 288*10,16*5 + %11 288*12,16*6 + %11 288*14,16*7 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfa + sub edi,16 + jmp %%end +%%flipyfull + mov dword[tleftnb],8 +%%loopfc + dec dword[ngcpixleft] + jnz %%notzeroc + call Nextwinmode +%%notzeroc + %11 0,16*7 + %11 288*2,16*6 + %11 288*4,16*5 + %11 288*6,16*4 + %11 288*8,16*3 + %11 288*10,16*2 + %11 288*12,16*1 + %11 288*14,0 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfc + sub edi,16 + jmp %%end +%%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],4000h + jz %%notflipxpart + add ecx,128 +%%notflipxpart + test dword[vrama+eax],8000h + jnz near %%flipyfullp + mov dword[tleftnb],8 +%%loopfap + dec dword[ngcpixleft] + jnz %%notzerop + call Nextwinmode +%%notzerop + %12 0,0 + %12 288*2,16 + %12 288*4,16*2 + %12 288*6,16*3 + %12 288*8,16*4 + %12 288*10,16*5 + %12 288*12,16*6 + %12 288*14,16*7 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfap + sub edi,16 + jmp %%end +%%flipyfullp + mov dword[tleftnb],8 +%%loopfcp + dec dword[ngcpixleft] + jnz %%notzerocp + call Nextwinmode +%%notzerocp + %12 0,16*7 + %12 288*2,16*6 + %12 288*4,16*5 + %12 288*6,16*4 + %12 288*8,16*3 + %12 288*10,16*2 + %12 288*12,16*1 + %12 288*14,0 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfcp + sub edi,16 + jmp %%end +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%end + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,16 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%docache + call %3 + mov byte[%9+ecx],dl + call %10 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawtileng16x16win16b 12 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache + cmp byte[%9+ecx],dl + je %%returnfromcache + mov byte[%9+ecx],dl + call %10 +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%skip + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],4000h + jz %%notflipxfull + add ecx,128 +%%notflipxfull + test dword[vrama+eax],8000h + jnz near %%flipyfull + mov dword[tleftnb],8 +%%loopfa + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + %11 0,0 + %11 288*2,16 + %11 288*4,16*2 + %11 288*6,16*3 + %11 288*8,16*4 + %11 288*10,16*5 + %11 288*12,16*6 + %11 288*14,16*7 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfa + sub edi,16 + jmp %%end +%%flipyfull + mov dword[tleftnb],8 +%%loopfc + dec dword[ngcpixleft] + jnz %%notzeroc + call Nextwinmode +%%notzeroc + %11 0,16*7 + %11 288*2,16*6 + %11 288*4,16*5 + %11 288*6,16*4 + %11 288*8,16*3 + %11 288*10,16*2 + %11 288*12,16*1 + %11 288*14,0 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfc + sub edi,16 + jmp %%end +%%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],4000h + jz %%notflipxpart + add ecx,128 +%%notflipxpart + test dword[vrama+eax],8000h + jnz near %%flipyfullp + mov dword[tleftnb],8 +%%loopfap + dec dword[ngcpixleft] + jnz %%notzerop + call Nextwinmode +%%notzerop + %12 0,0 + %12 288*2,16 + %12 288*4,16*2 + %12 288*6,16*3 + %12 288*8,16*4 + %12 288*10,16*5 + %12 288*12,16*6 + %12 288*14,16*7 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfap + sub edi,16 + jmp %%end +%%flipyfullp + mov dword[tleftnb],8 +%%loopfcp + dec dword[ngcpixleft] + jnz %%notzerocp + call Nextwinmode +%%notzerocp + %12 0,16*7 + %12 288*2,16*6 + %12 288*4,16*5 + %12 288*6,16*4 + %12 288*8,16*3 + %12 288*10,16*2 + %12 288*12,16*1 + %12 288*14,0 + add ecx,2 + add edi,2 + dec dword[tleftnb] + jnz near %%loopfcp + sub edi,16 + jmp %%end +%%skip + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%end + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,16 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz near %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%done +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + add edi,32 + jmp %%ntile +%%docache + call %3 + mov byte[%9+ecx],dl + call %10 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlinengomwin16b16x16 9 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + jmp %%endokay + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + jmp %%notflipypart +%%flipypart + add ecx,[flipyposng] +%%notflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 0,0,%8 + %9 1,2,%8 + %9 2,4,%8 + %9 3,6,%8 + %9 4,8,%8 + %9 5,10,%8 + %9 6,12,%8 + %9 7,14,%8 + pop eax + jmp %%endokay +%%flipxpart + push eax + xor ebx,ebx + mov esi,ecx + mov eax,[CPalPtrng] + %9 7,0,%8 + %9 6,2,%8 + %9 5,4,%8 + %9 4,6,%8 + %9 3,8,%8 + %9 2,10,%8 + %9 1,12,%8 + %9 0,14,%8 + pop eax + jmp %%endokay +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%endokay + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,16 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz %%noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmval] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + \ No newline at end of file diff --git a/zsnes/src/video/newgfx.asm b/zsnes/src/video/newgfx.asm new file mode 100644 index 00000000..0682a314 --- /dev/null +++ b/zsnes/src/video/newgfx.asm @@ -0,0 +1,2337 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM BG116x16t,BG1SXl,BG1SYl,BG216x16t,BG2SXl,BG2SYl,BG316x16t,BG3PRI +EXTSYM BG3SXl,BG3SYl,BG416x16t,BG4SXl,BG4SYl,BGFB,BGMA,BGMS1,BGOPT1,BGOPT2 +EXTSYM BGOPT3,BGOPT4,BGPT1,BGPT1X,BGPT1Y,BGPT2,BGPT2X,BGPT2Y,BGPT3,BGPT3X +EXTSYM BGPT3Y,BGPT4,BGPT4X,BGPT4Y,StartDrawNewGfx16b,bg1objptr,bg1ptr +EXTSYM bg1ptrx,bg1ptry,bg1scrolx,bg1scroly,bg2objptr,bg2ptr,bg2ptrx +EXTSYM bg2ptry,bg2scrolx,bg2scroly,bg3highst,bg3objptr,bg3ptr,bg3ptrx +EXTSYM bg3ptry,bg3scrolx,bg3scroly,bg4objptr,bg4ptr,bg4ptrx,bg4ptry +EXTSYM bg4scrolx,bg4scroly,bgmode,bgtxad,cachesingle2bng +EXTSYM cachesingle8bng,cbitmode,cfield,colormodedef,csprbit,curmosaicsz +EXTSYM curvidoffset,curypos,drawmode716b,forceblnk,interlval,intrlng,mode7A +EXTSYM mode7C,mode7X0,mode7ab,mode7cd,mode7set,mode7st,mode7xy,mosaicon +EXTSYM mosaicsz,mosenng,mosszng,ngceax,ngcedi,ngpalcon2b,ngpalcon4b +EXTSYM ngpalcon8b,ngptrdat,prdata,prdatb,prdatc,res640,resolutn,scrndis +EXTSYM scrnon,spritetablea,sprleftpr,sprlefttot,sprpriodata,sprtbng,sprtlng +EXTSYM t16x161,t16x162,t16x163,t16x164,tltype2b,tltype4b,tltype8b,vcache2b +EXTSYM vcache4b,vcache8b,vidbuffer,vidmemch2,vidmemch4,vidmemch8,vram,vrama +EXTSYM winon,xtravbuf,ng16bbgval,ng16bprval,bgwinchange,res480 +EXTSYM drawtileng2b,drawtileng4b,drawtileng8b,drawmode7win,hdmaearlstart +EXTSYM drawtileng16x162b,drawtileng16x164b,drawtileng16x168b,osm2dis +EXTSYM drawlineng2b,drawlineng4b,drawlineng8b,processmode7hires +EXTSYM drawlineng16x162b,drawlineng16x164b,drawlineng16x168b,mode7hr +EXTSYM winboundary,winbg1enval,winbg2enval,winbg3enval,winbg4enval +EXTSYM winbgobjenval,winlogicaval,disableeffects,winenabs,scanlines +EXTSYM winl1,winbg1en,winbg2en,winbg3en,winbg4en,winobjen,winlogica,winenabm +EXTSYM bgallchange,bg1change,bg2change,bg3change,bg4change,hiresstuff +EXTSYM drawlineng16x84b,drawlineng16x82b,drawlinengom4b,WindowDisables +EXTSYM winlogicb +EXTSYM ngwinptr,objwlrpos,objwen,objclineptr,CSprWinPtr +EXTSYM WindowRedraw + +%include "video/vidmacro.mac" +%include "video/newgfx2.mac" +%include "video/newgfx.mac" + + + + + +; vidbufferofsmos pointer to mosaic buffer + +%macro WinBGCheck 1 + mov bl,[winbg1en+%1] + test bl,0Ah + jz %%disable + test byte[scrnon],1 << %1 + jnz %%nbgen + test byte[winenabs],1 << %1 + jnz %%bg + jmp %%disable +%%nbgen + test byte[winenabm],1 << %1 + jnz %%bg +%%disable + xor bl,bl + jmp %%skip +%%bg + mov cl,bl + and cl,0Ah + cmp cl,0Ah + je %%skip +; jne %%notskip +; and bl,03h +; and cl,03h +;%%notskip + mov ch,bl + mov edx,[winl1] + cmp cl,02h + je %%bg1 + shr ch,2 + shr edx,16 +%%bg1 + test ch,01h + jnz %%outside + cmp dl,dh + jbe %%skip + xor bl,bl + jmp %%skip +%%outside + cmp dl,0 + ja %%skip + cmp dh,255 + jb %%skip + xor bl,bl +%%skip + mov [winbg1enval+eax+%1*256],bl +%endmacro + +NEWSYM newengine8b + ; store line by line data + ; BGMode, BGxScrollX, BGxScrollY, both BGPtrs + mov eax,[curypos] + and eax,0FFh + + mov byte[bgallchange+eax],0 + mov byte[bg1change+eax],0 + mov byte[bg2change+eax],0 + mov byte[bg3change+eax],0 + mov byte[bg4change+eax],0 + + ; BG3 Priority + mov ebx,[bg3highst] + mov [BG3PRI+eax],ebx + ; Main/Sub Screen + mov ebx,[scrnon] + or [bgcmsung],ebx + mov [BGMS1+eax*2],ebx + cmp [BGMS1+eax*2-2],bx + je .nosbgms1 + mov byte[bgallchange+eax],1 +.nosbgms1 + + ; Scroll Values + mov ebx,[bg1scrolx] + mov [BG1SXl+eax*2],ebx + cmp [BG1SXl+eax*2-2],bx + je .nosbgx1 + mov byte[bg1change+eax],1 +.nosbgx1 + mov ebx,[bg2scrolx] + mov [BG2SXl+eax*2],ebx + cmp [BG2SXl+eax*2-2],bx + je .nosbgx2 + mov byte[bg2change+eax],1 +.nosbgx2 + mov ebx,[bg3scrolx] + mov [BG3SXl+eax*2],ebx + cmp [BG3SXl+eax*2-2],bx + je .nosbgx3 + mov byte[bg3change+eax],1 +.nosbgx3 + mov ebx,[bg4scrolx] + mov [BG4SXl+eax*2],ebx + cmp [BG4SXl+eax*2-2],bx + je .nosbgx4 + mov byte[bg4change+eax],1 +.nosbgx4 + + mov ebx,[bg1scroly] + mov [BG1SYl+eax*2],ebx + cmp [BG1SYl+eax*2-2],bx + je .nosbgy1 + mov byte[bg1change+eax],1 +.nosbgy1 + mov ebx,[bg2scroly] + mov [BG2SYl+eax*2],ebx + cmp [BG2SYl+eax*2-2],bx + je .nosbgy2 + mov byte[bg2change+eax],1 +.nosbgy2 + mov ebx,[bg3scroly] + mov [BG3SYl+eax*2],ebx + cmp [BG3SYl+eax*2-2],bx + je .nosbgy3 + mov byte[bg3change+eax],1 +.nosbgy3 + mov ebx,[bg4scroly] + mov [BG4SYl+eax*2],ebx + cmp [BG4SYl+eax*2-2],bx + je .nosbgy4 + mov byte[bg1change+eax],1 +.nosbgy4 + + ; Background Mode + mov bl,[bgmode] + and ebx,07h + mov [BGMA+eax],bl + cmp [BGMA+eax-1],bl + je .nobgma + mov byte[bgallchange+eax],1 +.nobgma + + mov byte[modeused+eax],1 + + ; Pointer to OBJ tile data + mov ebx,[bg1objptr] + mov [BGOPT1+eax*2],ebx + cmp [BGOPT1+eax*2-2],bx + je .nosbgo1 + mov byte[bg1change+eax],1 +.nosbgo1 + mov ebx,[bg2objptr] + mov [BGOPT2+eax*2],ebx + cmp [BGOPT2+eax*2-2],bx + je .nosbgo2 + mov byte[bg2change+eax],1 +.nosbgo2 + mov ebx,[bg3objptr] + mov [BGOPT3+eax*2],ebx + cmp [BGOPT3+eax*2-2],bx + je .nosbgo3 + mov byte[bg3change+eax],1 +.nosbgo3 + mov ebx,[bg4objptr] + mov [BGOPT4+eax*2],ebx + cmp [BGOPT4+eax*2-2],bx + je .nosbgo4 + mov byte[bg4change+eax],1 +.nosbgo4 + + ; Pointer to tile status data + mov ebx,[bg1ptr] + mov [BGPT1+eax*2],ebx + cmp [BGPT1+eax*2-2],bx + je .nosbgp1 + mov byte[bg1change+eax],1 +.nosbgp1 + mov ebx,[bg2ptr] + mov [BGPT2+eax*2],ebx + cmp [BGPT2+eax*2-2],bx + je .nosbgp2 + mov byte[bg2change+eax],1 +.nosbgp2 + mov ebx,[bg3ptr] + mov [BGPT3+eax*2],ebx + cmp [BGPT3+eax*2-2],bx + je .nosbgp3 + mov byte[bg3change+eax],1 +.nosbgp3 + mov ebx,[bg4ptr] + mov [BGPT4+eax*2],ebx + cmp [BGPT4+eax*2-2],bx + je .nosbgp4 + mov byte[bg4change+eax],1 +.nosbgp4 + + mov ebx,[bg1ptrx] + mov [BGPT1X+eax*2],ebx + cmp [BGPT1X+eax*2-2],bx + je .nosbgpx1 + mov byte[bg1change+eax],1 +.nosbgpx1 + mov ebx,[bg2ptrx] + mov [BGPT2X+eax*2],ebx + cmp [BGPT2X+eax*2-2],bx + je .nosbgpx2 + mov byte[bg2change+eax],1 +.nosbgpx2 + mov ebx,[bg3ptrx] + mov [BGPT3X+eax*2],ebx + cmp [BGPT3X+eax*2-2],bx + je .nosbgpx3 + mov byte[bg3change+eax],1 +.nosbgpx3 + mov ebx,[bg4ptrx] + mov [BGPT4X+eax*2],ebx + cmp [BGPT4X+eax*2-2],bx + je .nosbgpx4 + mov byte[bg4change+eax],1 +.nosbgpx4 + + mov ebx,[bg1ptry] + mov [BGPT1Y+eax*2],ebx + cmp [BGPT1Y+eax*2-2],bx + je .nosbgpy1 + mov byte[bg1change+eax],1 +.nosbgpy1 + mov ebx,[bg2ptry] + mov [BGPT2Y+eax*2],ebx + cmp [BGPT2Y+eax*2-2],bx + je .nosbgpy2 + mov byte[bg2change+eax],1 +.nosbgpy2 + mov ebx,[bg3ptry] + mov [BGPT3Y+eax*2],ebx + cmp [BGPT3Y+eax*2-2],bx + je .nosbgpy3 + mov byte[bg3change+eax],1 +.nosbgpy3 + mov ebx,[bg4ptry] + mov [BGPT4Y+eax*2],ebx + cmp [BGPT4Y+eax*2-2],bx + je .nosbgpy4 + mov byte[bg4change+eax],1 +.nosbgpy4 + mov ebx,[forceblnk] + or bl,bl + jne .dontdraw + mov dword[scfbl],0 +.dontdraw + mov [BGFB+eax],ebx + cmp [BGFB+eax-1],bx + je .nosbgfb + mov byte[bgallchange+eax],1 +.nosbgfb + + mov ebx,[mode7A] + mov [mode7ab+eax*4],ebx + mov ebx,[mode7C] + mov [mode7cd+eax*4],ebx + mov ebx,[mode7X0] + mov [mode7xy+eax*4],ebx + mov ebx,[mode7set] + mov [mode7st+eax],ebx + + ; 16x16 tiles + mov ebx,[BG116x16t] + mov [t16x161+eax],ebx + cmp [t16x161+eax-1],bl + je .not16x161 + mov byte[bg1change+eax],1 +.not16x161 + mov ebx,[BG216x16t] + mov [t16x162+eax],ebx + cmp [t16x162+eax-1],bl + je .not16x162 + mov byte[bg2change+eax],1 +.not16x162 + mov ebx,[BG316x16t] + mov [t16x163+eax],ebx + cmp [t16x163+eax-1],bl + je .not16x163 + mov byte[bg3change+eax],1 +.not16x163 + mov ebx,[BG416x16t] + mov [t16x164+eax],ebx + cmp [t16x164+eax-1],bl + je .not16x164 + mov byte[bg4change+eax],1 +.not16x164 + +; mov byte[mode7hr+eax],0 + cmp byte[bgmode],7 + jne .noextbg +; cmp byte[res640],0 +; je .nomode7512 +; mov byte[mode7hr+eax],1 +;.nomode7512 + test byte[interlval],40h + jz .noextbg + mov byte[ngextbg],1 +.noextbg + + ; mosaic + mov ebx,[mosaicon] + mov [mosenng+eax],ebx + mov ebx,[mosaicsz] + mov [mosszng+eax],ebx + + ; Interlaced + mov ebx,[interlval] + mov [intrlng+eax],ebx + + ; Windowing Stuff +;NEWSYM winl1, db 0 ; window 1 left position +;NEWSYM winr1, db 0 ; window 1 right position +;NEWSYM winl2, db 0 ; window 2 left position +;NEWSYM winr2, db 0 ; window 2 right position +;NEWSYM winbg1en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG1 +;NEWSYM winbg2en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG2 +;NEWSYM winbg3en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG3 +;NEWSYM winbg4en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG4 +;NEWSYM winobjen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on sprites +;NEWSYM wincolen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on backarea +;NEWSYM winlogica, db 0 ; Window logic type for BG1 to 4 +;NEWSYM winlogicb, db 0 ; Window logic type for Sprites and Backarea +;NEWSYM winenabm, db 0 ; Window logic enable for main screen +;NEWSYM winenabs, db 0 ; Window logic enable for sub screen + +;NEWSYM winboundary, times 256 dd 0 +;NEWSYM winbg1enval, times 256 db 0 +;NEWSYM winbg2enval, times 256 db 0 +;NEWSYM winbg3enval, times 256 db 0 +;NEWSYM winbg4enval, times 256 db 0 +;NEWSYM winbgobjenval, times 256 db 0 +;NEWSYM winlogicaval, times 256 dw 0 + mov byte[bgwinchange+eax],0 + cmp byte[disableeffects],1 + je near .finishwin + push ecx + push edx + WinBGCheck 0 + WinBGCheck 1 + WinBGCheck 2 + WinBGCheck 3 + WinBGCheck 4 + + mov ebx,[winlogica] + mov [winlogicaval+eax*2],ebx + cmp [winlogicaval+eax*2-2],bx + je .winnchangedb + mov byte[bgwinchange+eax],1 +.winnchangedb + mov ebx,[winl1] + mov [winboundary+eax*4],ebx + cmp [winboundary+eax*4-4],ebx + je .winnchanged + mov byte[bgwinchange+eax],1 +.winnchanged + + ; generate sprite window + cmp byte[winbg1enval+eax+4*256],0 + je near .skipobjw + + mov ebx,[winl1] + mov dl,[winobjen] + mov dh,[winlogicb] + and dh,03h + ; Same as previous line? + cmp [objwlrpos+eax*4-4],ebx + jne .changedb + cmp [objwen+eax*2-2],dx + je near .notchanged +.changedb + cmp [objwlrpos+eax*4],ebx + jne .changed + cmp [objwen+eax*2],dx + jne .changed + mov ecx,[CSprWinPtr] + cmp [objclineptr+eax*4],ecx + ja near .usecurrent +.changed + mov [objwlrpos+eax*4],ebx + mov [objwen+eax*2],dx + + mov bl,[winlogicb] + and bl,03h + mov [nglogicval],bl + mov ebx,4*256 + add ebx,eax + call BuildWindow + mov ecx,[CSprWinPtr] + add ecx,260 + mov [CSprWinPtr],ecx + mov [objclineptr+eax*4],ecx + add ecx,[ngwinptr] + ; Construct Window in ecx + push eax + mov ebx,ngwintable + dec ecx + mov eax,256 +.procnotempty + mov edx,[ebx] + add ebx,4 + or edx,edx + jz .procempty + dec edx +.swloop + mov dword[ecx],0 + add ecx,4 + sub eax,4 + jc .done + sub edx,4 + jnc .swloop + sub eax,edx + add ecx,edx + dec eax + inc ecx +.procempty + mov edx,[ebx] + dec edx + add ebx,4 +.swloop2 + mov dword[ecx],01010101h + add ecx,4 + sub eax,4 + jc .done + sub edx,4 + jnc .swloop2 + sub eax,edx + add ecx,edx + dec eax + inc ecx + jmp .procnotempty +.done + pop eax +;NEWSYM objwlrpos , times 256 dd 0 +;NEWSYM objwen , times 256 dw 0 ; en,log +;NEWSYM objclineptr, times 256 dd 0 ; l1,r1,l2,r2,en,log,ptr + jmp .skipobjw +.usecurrent + mov ecx,[objclineptr+eax*4] + mov [CSprWinPtr],ecx + jmp .skipobjw + ; copy over if it's the same +.notchanged + mov [objwlrpos+eax*4],ebx + mov [objwen+eax*2],dx + mov ebx,[objclineptr+eax*4-4] + mov [objclineptr+eax*4],ebx +.skipobjw + pop edx + pop ecx + jmp .okaywin +.finishwin + mov byte[winbg1enval+eax],0 + mov byte[winbg2enval+eax],0 + mov byte[winbg3enval+eax],0 + mov byte[winbg4enval+eax],0 + mov byte[winbgobjenval+eax],0 +.okaywin + +; cmp byte[Mode7HiRes],1 +; jne .nomode7hires +; cmp byte[bgmode],7 +; je .hires +.nomode7hires + cmp byte[res640],0 + je near .no512 + cmp byte[bgmode],5 + jb .no512 + cmp byte[Mode7HiRes],1 + je .hires + cmp byte[bgmode],7 + je .no512 +.hires + mov byte[hiresstuff],1 + push edi + push eax + push ecx + mov ebx,eax + mov edi,[vidbuffer] + mov eax,ebx + add edi,16+75036 + shl eax,8 + add edi,eax + mov eax,ebx + shl eax,5 + add edi,eax + xor eax,eax + mov ecx,64 + rep stosd + pop ecx + pop eax + pop edi +.no512 + mov ebx,dword[sprleftpr+eax*4] + cmp ebx,00000001h + je .single + cmp ebx,00000100h + je .single + cmp ebx,00010000h + je .single + cmp ebx,01000000h + je .single + or [sprprdrn],ebx + xor ebx,ebx + ret +.single + or [sprprdrn],ebx + or dword[sprleftpr+eax*4],80000000h + xor ebx,ebx + ret + +%macro Process1DualWindow 0 + test ch,1 + jnz %%outside + inc ebx + cmp edx,ebx + jb %%noclip + ; Process Inside window + mov [esi],ebx + sub edx,ebx + add edx,2 + mov [esi+4],edx + mov dword[esi+8],0EE00h + add esi,12 + jmp %%finwin +%%noclip + mov dword[esi],0EE00h + add esi,4 + jmp %%finwin +%%outside + ; Process Outside window + cmp edx,ebx + jb %%completeclip + or ebx,ebx + jz %%skipclip + inc ebx + mov dword[esi],0 + mov [esi+4],ebx + add esi,8 +%%skipclip + sub edx,ebx + add edx,2 + mov [esi],edx + mov dword[esi+4],0EE00h + add esi,8 + jmp %%finwin +%%completeclip + mov dword[esi],0 + mov dword[esi+4],0EE00h + add esi,8 +%%finwin +%endmacro + +NEWSYM BuildWindow2 + jmp BuildWindow.ns2 +NEWSYM BuildWindow + cmp byte[WindowRedraw],1 + je .ns2 + cmp byte[WindowDisables],0 + je .nodisable + ret +.nodisable + mov dword[valtemp],0EE00h + push edx + push ecx + mov edx,[winlogicaval+eax*2] + shl edx,16 + mov dl,[winbg1enval+ebx] + cmp edx,[pwinen] + jne .notsimilar + mov edx,[winboundary+eax*4] + cmp edx,[pwinbound] + jne .notsimilarb + mov ecx,ngwintable +.loopc + mov edx,[ecx+64] + mov [ecx],edx + add ecx,4 + cmp edx,0D000h + ja .finloopc + cmp ecx,ngwintable+64 + jne .loopc +.finloopc + mov edx,[pngwinen] + mov [ngwinen],edx + pop ecx + pop edx + ret +.ns2 + mov byte[WindowRedraw],0 + push edx + push ecx + jmp .ns +.notsimilar + mov [pwinen],edx + mov edx,[winboundary+eax*4] +.notsimilarb + mov [pwinbound],edx +.ns + push esi + mov cl,byte[winbg1enval+ebx] + xor edx,edx + mov ch,cl + and cl,0Ah + mov esi,ngwintable + cmp cl,0Ah + je near .dualwin + xor ebx,ebx + cmp cl,2 + jne .winb + mov bl,[winboundary+eax*4] + mov dl,[winboundary+eax*4+1] + jmp .wina +.winb + mov bl,[winboundary+eax*4+2] + mov dl,[winboundary+eax*4+3] + shr ch,2 +.wina + test ch,1 + jnz .outside + inc ebx + cmp edx,ebx + jb .noclip + ; Process Inside window + mov [esi],ebx + mov [esi+64],ebx + sub edx,ebx + add edx,2 + mov [esi+4],edx + mov dword[esi+8],0EE00h + mov [esi+4+64],edx + mov dword[esi+8+64],0EE00h + mov dword[ngwinen],1 +.noclip + pop esi + mov edx,[ngwinen] + mov [pngwinen],edx + pop ecx + pop edx + ret +.outside + ; Process Outside window + cmp edx,ebx + jb .completeclip + or ebx,ebx + jz .skipclip + inc ebx + mov dword[esi],0 + mov [esi+4],ebx + mov dword[esi+64],0 + mov [esi+4+64],ebx + add esi,8 +.skipclip + sub edx,ebx + add edx,2 + mov [esi],edx + mov [esi+64],edx + mov dword[esi+4],0EE00h + mov dword[esi+4+64],0EE00h + mov dword[ngwinen],1 + pop esi + mov edx,[ngwinen] + mov [pngwinen],edx + pop ecx + pop edx + ret +.completeclip + mov dword[esi],0 + mov dword[esi+4],0EE00h + mov dword[esi+64],0 + mov dword[esi+4+64],0EE00h + mov dword[ngwinen],1 + pop esi + mov edx,[ngwinen] + mov [pngwinen],edx + pop ecx + pop edx + ret +.dualwin + push ebx + xor ebx,ebx + mov dl,[winboundary+eax*4+1] + mov bl,[winboundary+eax*4] + Process1DualWindow + pop ebx + mov dword[WinPtrAPos],esi + + mov ch,byte[winbg1enval+ebx] + xor ebx,ebx + xor edx,edx + mov bl,[winboundary+eax*4+2] + mov dl,[winboundary+eax*4+3] + shr ch,2 + Process1DualWindow + mov dword[WinPtrBPos],esi + + ; Convert displacement table to cumulative table + mov esi,ngwintable + xor ebx,ebx +.loopapos + add ebx,[esi] + mov [esi],ebx + add esi,4 + cmp esi,[WinPtrAPos] + jne .loopapos + xor ebx,ebx +.loopbpos + add ebx,[esi] + mov [esi],ebx + add esi,4 + cmp esi,[WinPtrBPos] + jne .loopbpos + + ; Combine both lists + push edi + mov ecx,0101h + mov edx,ngwintablec + mov esi,ngwintable + mov edi,[WinPtrAPos] + mov dword[edx],0 + mov dword[edx+64],0 + cmp dword[esi],0 + jne .notzeroa + add esi,4 + inc dword[edx+64] + neg cl +.notzeroa + cmp dword[edi],0 + jne .notzerob + add edi,4 + inc dword[edx+64] + neg ch +.notzerob + add edx,4 +.loop + mov ebx,[esi] + cmp ebx,0EE00h + jae .edi +.noedi + cmp ebx,[edi] + je .equal + jb .esi +.edi + mov ebx,[edi] + cmp ebx,0EE00h + jae .esib + mov [edx],ebx + mov [edx+64],ch + add edx,4 + add edi,4 + neg ch + jmp .loop +.esib + mov ebx,[esi] + cmp ebx,0EE00h + jae .fin +.esi + mov [edx],ebx + mov [edx+64],cl + add edx,4 + add esi,4 + neg cl + jmp .loop +.equal + mov [edx],ebx + mov [edx+64],cl + add [edx+64],ch + neg cl + neg ch + add edx,4 + add esi,4 + add edi,4 + cmp ebx,0EE00h + jb .loop + jmp .finb +.fin + mov dword[edx],0EE00h + add edx,4 +.finb + + mov dword[WinPtrAPos],edx + +; jmp .c + + ; Convert list to proper on/off format + mov edi,[nglogicval] + and edi,3 + shl edi,2 + add edi,OrLogicTable + mov edx,ngwintablec + xor ecx,ecx +.loopp + add cl,[edx+64] + mov bl,[edi+ecx] + mov [edx+64],bl + add edx,4 + cmp edx,[WinPtrAPos] + jne .loopp + + ; Shorten & Convert back to displacement format + mov edx,ngwintablec + mov esi,ngwintable + mov cl,1 + xor ebx,ebx +.loops + cmp byte[edx+64],cl + jne .noadd + mov edi,[edx] + sub edi,ebx + add ebx,edi + mov [esi],edi + mov [esi+64],edi + add esi,4 + xor cl,1 +.noadd + add edx,4 + cmp edx,[WinPtrAPos] + jne .loops + mov dword[esi],0EE00h + mov dword[esi+64],0EE00h + +.c + + pop edi + pop esi + mov dword[ngwinen],1 + mov dword[pngwinen],1 + pop ecx + pop edx + ret + +NEWSYM firstdrawn, db 0 +ALIGN32 +NEWSYM bgusedng + dd 01010101h,00010101h,00000101h,00000101h,00000101h,00000101h + dd 00000001h,00000001h +NEWSYM bgcmsung, dd 0 +NEWSYM modeused, dd 0,0 +NEWSYM reslbyl, dd 0 +NEWSYM sprprdrn, dd 0 +NEWSYM csprival, dd 0 +NEWSYM pesimpng2, dd 0 +NEWSYM cfieldad, dd 0 +NEWSYM ignor512, dd 0 +NEWSYM ofsmcptr, dd 0 +NEWSYM ofsmtptr, dd 0 +NEWSYM ofsmmptr, dd 0 +NEWSYM ofsmcyps, dd 0 +NEWSYM ofsmady, dd 0 +NEWSYM ofsmadx, dd 0 +NEWSYM mosoldtab, times 15 dd 0 +NEWSYM ngwintable, times 16 dd 0EE00h +NEWSYM ngwintableb, times 16 dd 0EE00h +NEWSYM ngwintablec, times 16 dd 0EE00h +NEWSYM ngwintabled, times 16 dd 0EE00h +NEWSYM valtemp, dd 0EE00h, 0EE00h +NEWSYM ngwinen, dd 0 +NEWSYM ngcwinptr, dd ngwintable +NEWSYM ngcwinmode, dd 0 +NEWSYM ngcpixleft, dd 0 +NEWSYM Mode7BackA, dd 0 +NEWSYM Mode7BackC, dd 0 +NEWSYM Mode7BackX0, dd 0 +NEWSYM Mode7BackSet, dd 0 +NEWSYM ngextbg, dd 0 +NEWSYM cbgval, dd 0 +NEWSYM ofsmval, dd 0 +NEWSYM ofsmvalh, dd 0 +NEWSYM pwinen, dd 0FFFFh +NEWSYM pngwinen, dd 0FFFFh +NEWSYM pwinbound, dd 0 +NEWSYM WinPtrAPos, dd 0 +NEWSYM WinPtrBPos, dd 0 +NEWSYM OrLogicTable, db 0,1,1,0 +NEWSYM AndLogicTable, db 0,0,1,0 +NEWSYM XorLogicTable, db 0,1,0,0 +NEWSYM XNorLogicTable, db 1,0,1,0 +NEWSYM nglogicval, dd 0 +NEWSYM pnglogicval, dd 0 +NEWSYM mosjmptab, times 15 dd 0 +NEWSYM Mode7HiRes, dd 0 +NEWSYM pesimpng, dd 0 + +NEWSYM StartDrawNewGfx + mov byte[WindowRedraw],1 + mov dword[ignor512],1 + mov dword[cfieldad],0 + cmp byte[res480],1 + jne .scan2 + cmp byte[scanlines],0 + jne .scan2 + mov al,[cfield] + mov [cfieldad],al +.scan2 + mov ax,[resolutn] + sub ax,8 + mov [reslbyl],ax + cmp byte[cbitmode],1 + je near StartDrawNewGfx16b + push edx + push esi + push edi + push ebp + + ; Clear video memory + mov edi,[vidbuffer] + xor eax,eax + add edi,16 + mov dl,[resolutn] +.loopa + mov ecx,64 + rep stosd + add edi,32 + dec dl + jnz .loopa + + cmp dword[scfbl],0 + jne near .dontdraw + + ; Sprite Layering : + ; Mode 0/1 - BG4/BG3pr0 * BG4/BG3pr1 * BG2/BG1pr0 * BG2/BG1pr0 * BG3pr1 + ; Mode 2-6 - BG2pr0 * BG1pr0 * BG2pr1 * BG1pr1 * + ; Mode 7 - * BG1pr0 * BG1pr1 * * + + ; Copy data to sprite table + mov ecx,256 + mov eax,[spritetablea] + mov ebx,sprlefttot + mov edi,sprtbng +.loop + mov [edi],eax + add eax,512 + inc ebx + add edi,4 + dec ecx + jnz .loop + + xor eax,eax + mov edi,sprtlng + mov ecx,64 + rep stosd + + mov byte[firstdrawn],1 + mov dword[bg1totng],0 + mov dword[bg2totng],0 + mov dword[bg3totng],0 + mov dword[bg4totng],0 + mov dword[bg1drwng],0 + mov dword[bg2drwng],0 + mov dword[bg3drwng],0 + mov dword[bg4drwng],0 + + ; Draw SubScreens + test byte[scrndis],8h + jnz near .nodobg4s + test dword[bgcmsung],800h + jz near .nodobg4s + mov dword[mode0ads],60606060h + Procbgpr0 3, drawbg4line, drawbg4tile, 800h, 8h +.nodobg4s + test byte[scrndis],4h + jnz near .nodobg3s + test dword[bgcmsung],400h + jz near .nodobg3s + mov dword[mode0ads],40404040h + Procbg3pr0 2, drawbg3line, drawbg3tile, 400h, 4h +.nodobg3s + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprpra + test dword[modeused],00000101h + jz near .nosprpra + test dword[bgcmsung],1000h + jz near .nosprpra + Procsprng01 1000h, 10h +.nosprpra + + test byte[scrndis],8h + jnz near .nodobg4sb + test dword[bgcmsung],800h + jz near .nodobg4sb + mov eax,[bg4totng] + cmp eax,[bg4drwng] + je near .nodobg4sb + mov dword[mode0ads],60606060h + Procbgpr1 3, drawbg4linepr1, drawbg4tilepr1, prdata, 800h, 8h +.nodobg4sb + test byte[scrndis],4h + jnz near .nodobg3sb + test dword[bgcmsung],400h + jz near .nodobg3sb + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3sb + mov dword[mode0ads],40404040h + Procbg3pr1 2, drawbg3linepr1, drawbg3tilepr1, prdatc, 400h, 4h +.nodobg3sb + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprprb + test dword[modeused],00000101h + jz near .nosprprb + test dword[bgcmsung],1000h + jz near .nosprprb + Procsprng01 1000h, 10h +.nosprprb + + test byte[scrndis],2h + jnz near .nodobg2s + test dword[bgcmsung],200h + jz near .nodobg2s + mov dword[mode0ads],20202020h + Procbgpr0 1, drawbg2line, drawbg2tile, 200h, 2h +.nodobg2s + + ; draw mode 7 extbg pr 0 + cmp byte[ngextbg],0 + je near .noextbgsc + test dword[bgcmsung],300h + jz near .noextbgsc + ProcMode7ngextbg 100h, 1h +.noextbgsc + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprprc + test dword[modeused],01010000h + jnz near .yessprprc + test dword[modeused+4],01010101h + jz near .nosprprc +.yessprprc + test dword[bgcmsung],1000h + jz near .nosprprc + Procsprng234567 1000h, 10h +.nosprprc + + test byte[scrndis],1h + jnz near .nodobg1s + test dword[bgcmsung],100h + jz near .nodobg1s + mov dword[mode0ads],00000000h + Procbgpr0 0, drawbg1line, drawbg1tile, 100h, 1h +.nodobg1s + + ; draw mode 7, priority 0 + cmp byte[modeused+7],0 + je near .nomode7 + test dword[bgcmsung],300h + jz near .nomode7 + ProcMode7ng 100h, 1h +.nomode7 + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprd + test dword[bgcmsung],1000h + jz near .nosprprd + Procsprng 1000h, 10h +.nosprprd + + test byte[scrndis],2h + jnz near .nodobg2sb + test dword[bgcmsung],200h + jz near .nodobg2sb + mov eax,[bg2totng] + cmp eax,[bg2drwng] + je near .nodobg2sb + mov dword[mode0ads],20202020h + Procbgpr1 1, drawbg2linepr1, drawbg2tilepr1, prdata, 200h, 2h +.nodobg2sb + + ; draw mode 7 extbg pr 1 + cmp byte[ngextbg],0 + je near .noextbgscb + test dword[bgcmsung],300h + jz near .noextbgscb + ProcMode7ngextbg2 200h, 2h +.noextbgscb + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprpre + test dword[modeused],01010000h + jnz near .yessprpre + test dword[modeused+4],01010101h + jz near .nosprpre +.yessprpre + test dword[bgcmsung],1000h + jz near .nosprpre + Procsprng234567 1000h, 10h +.nosprpre + + test byte[scrndis],1h + jnz near .nodobg1sb + test dword[bgcmsung],100h + jz near .nodobg1sb + mov eax,[bg1totng] + cmp eax,[bg1drwng] + je near .nodobg1sb + mov dword[mode0ads],00000000h + Procbgpr1 0, drawbg1linepr1, drawbg1tilepr1, prdatb, 100h, 1h +.nodobg1sb + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprf + test dword[bgcmsung],1000h + jz near .nosprprf + Procsprng 1000h, 10h +.nosprprf + + test byte[scrndis],4h + jnz near .nodobg3sb2 + cmp byte[modeused+1],0 + je near .nodobg3sb2 + test dword[bgcmsung],400h + jz near .nodobg3sb2 + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3sb2 + mov dword[mode0ads],40404040h + Procbg3pr1b 2, drawbg3linepr1, drawbg3tilepr1, prdatc, 400h, 4h +.nodobg3sb2 + + mov dword[bg1totng],0 + mov dword[bg2totng],0 + mov dword[bg3totng],0 + mov dword[bg4totng],0 + mov dword[bg1drwng],0 + mov dword[bg2drwng],0 + mov dword[bg3drwng],0 + mov dword[bg4drwng],0 + + ; Draw MainScreens + test byte[scrndis],8h + jnz near .nodobg4m + test dword[bgcmsung],8h + jz near .nodobg4m + mov dword[mode0ads],60606060h + Procbgpr0 3, drawbg4line, drawbg4tile, 8h, 0 +.nodobg4m + test byte[scrndis],4h + jnz near .nodobg3m + test dword[bgcmsung],4h + jz near .nodobg3m + mov dword[mode0ads],40404040h + Procbg3pr0 2, drawbg3line, drawbg3tile, 4h, 0 +.nodobg3m + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprprma + test dword[modeused],00000101h + jz near .nosprprma + test dword[bgcmsung],10h + jz near .nosprprma + Procsprng01 10h, 0 +.nosprprma + + test byte[scrndis],8h + jnz near .nodobg4mb + test dword[bgcmsung],8h + jz near .nodobg4mb + mov eax,[bg4totng] + cmp eax,[bg4drwng] + je near .nodobg4mb + mov dword[mode0ads],60606060h + Procbgpr1 3, drawbg4linepr1, drawbg4tilepr1, prdata, 8h, 0 +.nodobg4mb + test byte[scrndis],4h + jnz near .nodobg3mb + test dword[bgcmsung],4h + jz near .nodobg3mb + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3mb + mov dword[mode0ads],40404040h + Procbg3pr1 2, drawbg3linepr1, drawbg3tilepr1, prdatc, 4h, 0 +.nodobg3mb + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprprmb + test dword[modeused],00000101h + jz near .nosprprmb + test dword[bgcmsung],10h + jz near .nosprprmb + Procsprng01 10h, 0 +.nosprprmb + + test byte[scrndis],2h + jnz near .nodobg2m + test dword[bgcmsung],2h + jz near .nodobg2m + mov dword[mode0ads],20202020h + Procbgpr0 1, drawbg2line, drawbg2tile, 2h, 0 +.nodobg2m + + ; draw mode 7 extbg pr 0 + cmp byte[ngextbg],0 + je near .noextbgmn + test dword[bgcmsung],1h + jz near .noextbgmn + ProcMode7ngextbg 1h, 0 +.noextbgmn + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprprmc + test dword[modeused],01010000h + jnz near .yessprprmc + test dword[modeused+4],01010101h + jz near .nosprprmc +.yessprprmc + test dword[bgcmsung],10h + jz near .nosprprmc + Procsprng234567 10h, 0h +.nosprprmc + + test byte[scrndis],1h + jnz near .nodobg1m + test dword[bgcmsung],1h + jz near .nodobg1m + mov dword[mode0ads],00000000h + Procbgpr0 0, drawbg1line, drawbg1tile, 1h, 0 +.nodobg1m + + ; draw mode 7, priority 0 + cmp byte[modeused+7],0 + je near .nomode7m + test dword[bgcmsung],1h + jz near .nomode7m + ProcMode7ng 1h, 0 +.nomode7m + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprmd + test dword[bgcmsung],10h + jz near .nosprprmd + Procsprng 10h, 0 +.nosprprmd + + ; draw mode 7 extbg pr 1 + cmp byte[ngextbg],0 + je near .noextbgmn2 + test dword[bgcmsung],3h + jz near .noextbgmn2 + ProcMode7ngextbg2 2h, 0 +.noextbgmn2 + + test byte[scrndis],2h + jnz near .nodobg2mb + test dword[bgcmsung],2h + jz near .nodobg2mb + mov eax,[bg2totng] + cmp eax,[bg2drwng] + je near .nodobg2mb + mov dword[mode0ads],20202020h + Procbgpr1 1, drawbg2linepr1, drawbg2tilepr1, prdata, 2h, 0 +.nodobg2mb + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprprme + test dword[modeused],01010000h + jnz near .yessprprme + test dword[modeused+4],01010101h + jz near .nosprprme +.yessprprme + test dword[bgcmsung],10h + jz near .nosprprme + Procsprng234567 10h, 0 +.nosprprme + + test byte[scrndis],1h + jnz near .nodobg1mb + test dword[bgcmsung],1h + jz near .nodobg1mb + mov eax,[bg1totng] + cmp eax,[bg1drwng] + je near .nodobg1mb + mov dword[mode0ads],00000000h + Procbgpr1 0, drawbg1linepr1, drawbg1tilepr1, prdatb, 1h, 0 +.nodobg1mb + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprmf + test dword[bgcmsung],10h + jz near .nosprprmf + Procsprng 10h, 0 +.nosprprmf + + test byte[scrndis],4h + jnz near .nodobg3mb2 + cmp byte[modeused+1],0 + je near .nodobg3mb2 + test dword[bgcmsung],4h + jz near .nodobg3mb2 + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3mb2 + mov dword[mode0ads],40404040h + Procbg3pr1b 2, drawbg3linepr1, drawbg3tilepr1, prdatc, 4h, 0 +.nodobg3mb2 + +.dontdraw + xor ebx,ebx + xor ecx,ecx + pop ebp + pop edi + pop esi + pop edx + ret + +NEWSYM drawbg1tile + mov byte[prdatb+ebx],1 + drawbgtileng 0,0 + ret + +NEWSYM drawbg2tile + mov byte[prdata+ebx],1 + drawbgtileng 1,1 + ret + +NEWSYM drawbg3tile + mov byte[prdatc+ebx],1 + drawbgtileng 2,2 + ret + +NEWSYM drawbg4tile + mov byte[prdata+ebx],1 + drawbgtileng 3,1 + ret + +NEWSYM drawbg1tilepr1 + drawbgtilengpr1 0,0 + ret + +NEWSYM drawbg2tilepr1 + drawbgtilengpr1 1,1 + ret + +NEWSYM drawbg3tilepr1 + drawbgtilengpr1 2,2 + ret + +NEWSYM drawbg4tilepr1 + drawbgtilengpr1 3,1 + ret + +NEWSYM drawbg1line + mov byte[prdatb+ebx],0 + drawbglineng 0,0 + +NEWSYM drawbg2line + mov byte[prdata+ebx],0 + drawbglineng 1,1 + +NEWSYM drawbg3line + mov byte[prdatc+ebx],0 + drawbglineng 2,2 + +NEWSYM drawbg4line + mov byte[prdata+ebx],0 + drawbglineng 3,1 + +NEWSYM domosaicng + mov esi,[pesimpng] + xor eax,eax + mov edi,xtravbuf+16 + mov al,[curmosaicsz] + cmp al,16 + ja .notokay + cmp al,1 + jbe .notokay + push esi + jmp [mosjmptab+eax*4-8] +.notokay + ret + +NEWSYM mosdraw2 + mov ecx,128 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mosender 2 + +NEWSYM mosdraw3 + mov ecx,86 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mosender 3 + +NEWSYM mosdraw4 + mov ecx,64 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mosender 4 + +NEWSYM mosdraw5 + mov ecx,52 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mosender 5 + +NEWSYM mosdraw6 + mov ecx,43 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mosender 6 + +NEWSYM mosdraw7 + mov ecx,37 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mosender 7 + +NEWSYM mosdraw8 + mov ecx,32 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mosender 8 + +NEWSYM mosdraw9 + mov ecx,29 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mosender 9 + +NEWSYM mosdraw10 + mov ecx,26 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mosender 10 + +NEWSYM mosdraw11 + mov ecx,24 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mov [esi+10],al + mosender 11 + +NEWSYM mosdraw12 + mov ecx,22 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mov [esi+10],al + mov [esi+11],al + mosender 12 + +NEWSYM mosdraw13 + mov ecx,20 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mov [esi+10],al + mov [esi+11],al + mov [esi+12],al + mosender 13 + +NEWSYM mosdraw14 + mov ecx,19 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mov [esi+10],al + mov [esi+11],al + mov [esi+12],al + mov [esi+13],al + mosender 14 + +NEWSYM mosdraw15 + mov ecx,18 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mov [esi+10],al + mov [esi+11],al + mov [esi+12],al + mov [esi+13],al + mov [esi+14],al + mosender 15 + +NEWSYM mosdraw16 + mov ecx,16 +.next + mov al,[edi] + or al,al + jz .nodraw + mov [esi],al + mov [esi+1],al + mov [esi+2],al + mov [esi+3],al + mov [esi+4],al + mov [esi+5],al + mov [esi+6],al + mov [esi+7],al + mov [esi+8],al + mov [esi+9],al + mov [esi+10],al + mov [esi+11],al + mov [esi+12],al + mov [esi+13],al + mov [esi+14],al + mov [esi+15],al + mosender 16 + +NEWSYM drawbg1linepr1 + drawbglinengpr1 0,0 + +NEWSYM drawbg2linepr1 + drawbglinengpr1 1,1 + +NEWSYM drawbg3linepr1 + drawbglinengpr1 2,2 + +NEWSYM drawbg4linepr1 + drawbglinengpr1 3,1 + + +ALIGN32 +NEWSYM bgtxadd, dd 0 +NEWSYM bgcyval, dd 0 +NEWSYM bgcxval, dd 0 +NEWSYM tleftn, dd 0 +NEWSYM tleftnb, dd 0 +NEWSYM bg1totng, dd 0 +NEWSYM bg2totng, dd 0 +NEWSYM bg3totng, dd 0 +NEWSYM bg4totng, dd 0 +NEWSYM bg1drwng, dd 0 +NEWSYM bg2drwng, dd 0 +NEWSYM bg3drwng, dd 0 +NEWSYM bg4drwng, dd 0 +NEWSYM sprcurng, dd 0 +NEWSYM scfbl, dd 0 +NEWSYM mode0ads, dd 0 +NEWSYM mode0add, dd 0 +NEWSYM taddnfy16x16, dd 0 +NEWSYM taddfy16x16, dd 0 +NEWSYM switch16x16, dd 0 +NEWSYM yposng, dd 0 +NEWSYM flipyposng, dd 0 +NEWSYM yposngom, dd 0 +NEWSYM flipyposngom, dd 0 + +NEWSYM drawsprng + cmp byte[winbg1enval+ebx+4*256],0 + jne near drawsprngw + test dword[sprleftpr+ebx*4],80000000h + jnz near .drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + pop ebx + pop esi + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + pop ebx + pop esi + ret + +.drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,ecx + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa sprdrawprb + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + pop ebx + pop esi + ret +.drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf sprdrawprb + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + pop ebx + pop esi + ret + +NEWSYM drawsprngm7h + cmp byte[winbg1enval+ebx+4*256],0 + jne near drawsprngm7w + test dword[sprleftpr+ebx*4],80000000h + jnz near .drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + pop ebx + pop esi + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + pop ebx + pop esi + ret + +.drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,ecx + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa sprdrawprb + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + pop ebx + pop esi + ret +.drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf sprdrawprb + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + pop ebx + pop esi + ret + +NEWSYM NGNumSpr, db 0 + +; cmp byte[winbg1enval+eax+4*256],0 +; je near .skipobjw +;NEWSYM objclineptr, times 256 dd 0 ; l1,r1,l2,r2,en,log,ptr +NEWSYM drawsprngw + mov [NGNumSpr],cl + mov ecx,[objclineptr+ebx*4] + add ecx,[ngwinptr] + test dword[sprleftpr+ebx*4],80000000h + jnz near .drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notprio + mov dh,[esi+6] + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawprawb + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notpriof + mov dh,[esi+6] + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawprawb + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + pop ebx + pop esi + xor ecx,ecx + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + xor ecx,ecx + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + pop ebx + pop esi + ret + +.drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + xor edx,edx + mov dl,[NGNumSpr] + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + push edx + mov bx,[esi] + mov dh,[esi+6] + mov esi,[esi+2] + sprdrawa sprdrawprbwb + pop edx + sub edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj2 + pop ebx + pop esi + xor ecx,ecx + ret +.drawspriteflipx2 + push edx + mov bx,[esi] + mov dh,[esi+6] + mov esi,[esi+2] + sprdrawaf sprdrawprbwb + pop edx + sub edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj2 + pop ebx + pop esi + xor ecx,ecx + ret + +NEWSYM drawsprngm7w + mov [NGNumSpr],cl + mov ecx,[objclineptr+ebx*4] + add ecx,[ngwinptr] + test dword[sprleftpr+ebx*4],80000000h + jnz near .drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notprio + mov dh,[esi+6] + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawprawb + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notpriof + mov dh,[esi+6] + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawprawb + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + pop ebx + pop esi + xor ecx,ecx + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + pop ebx + pop esi + ret + +.drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + xor edx,edx + mov dl,[NGNumSpr] + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + push edx + mov bx,[esi] + mov dh,[esi+6] + mov esi,[esi+2] + sprdrawa sprdrawprbwb + pop edx + sub edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj2 + pop ebx + pop esi + xor ecx,ecx + ret +.drawspriteflipx2 + push edx + mov bx,[esi] + mov dh,[esi+6] + mov esi,[esi+2] + sprdrawaf sprdrawprbwb + pop edx + sub edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj2 + pop ebx + pop esi + xor ecx,ecx + ret + +;******************************************************* +; Prepare Sprite Priorities +;******************************************************* + +NEWSYM makesprprtable + ret + +NEWSYM preparesprpr + xor ebx,ebx + mov bl,[curypos] + mov eax,dword[sprleftpr+ebx*4] + mov [sprclprio],eax + cmp eax,00000001h + je .single + cmp eax,00000100h + je .single + cmp eax,00010000h + je .single + cmp eax,01000000h + je .single + mov dword[sprsingle],0 + ret +.single + mov dword[sprsingle],1 + ret + +ALIGN32 +NEWSYM sprclprio, dd 0 +NEWSYM sprsingle, dd 0 + \ No newline at end of file diff --git a/zsnes/src/video/newgfx.mac b/zsnes/src/video/newgfx.mac new file mode 100644 index 00000000..ac9a2138 --- /dev/null +++ b/zsnes/src/video/newgfx.mac @@ -0,0 +1,3320 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM mode7B, mode7D +EXTSYM drawmode7ngextbg,drawmode7ngextbg2 + + + + + + + +%macro Procbgpr0 5 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%4 + jz %%nogo + test dword[BGMS1+ebx*2],%5 + jnz %%nogo + ; Check if at a tile alignment + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + test ecx,07h + jz %%tilecheck +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja %%nextline + jmp %%donextbg +%%tilecheck + test dword[bgwinchange+ebx],0FFFFFF00h + jnz %%linebyline + test dword[bgwinchange+ebx+4],0FFFFFFFFh + jz %%tilebytile +%%linebyline + test dword[winbg1enval+ebx+%1*256],0A0A0A0Ah + jnz %%proclinebyline + test dword[winbg1enval+ebx+%1*256+4],0A0A0A0Ah + jnz %%proclinebyline +%%tilebytile + test dword[BGMS1+ebx*2+14],%4 + jz %%proclinebyline + test dword[BGMS1+ebx*2+14],%5 + jnz %%proclinebyline + cmp ebx,[reslbyl] + jae %%proclinebyline + test dword[bgallchange+ebx],0FFFFFF00h + jnz %%proclinebyline + test dword[bgallchange+ebx+4],0FFFFFFFFh + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256],0FFFFFF00h + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256+4],0FFFFFFFFh + jnz near %%proclinebyline + cmp byte[BGMA+ebx],5 + jae near %%proclinebyline + cmp byte[BGMA+ebx],2 + je near %%proclinebyline + test dword[intrlng+ebx],01010101h + jnz near %%proclinebyline + test dword[intrlng+ebx+4],01010101h + jnz near %%proclinebyline + test byte[mosenng+ebx],1 << %1 + jnz %%mosaic +%%nomosaic + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja near %%nextline + jmp %%donextbg +%%mosaic + cmp byte[mosszng+ebx],0 + je %%nomosaic + jmp %%proclinebyline +%%donextbg +%endmacro + +%macro Procbg3pr0 5 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%4 + jz %%nogo + test dword[BGMS1+ebx*2],%5 + jnz %%nogo + ; Check if at a tile alignment + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + test ecx,07h + jz %%tilecheck +%%proclinebyline + ; process line by line +; call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja %%nextline + jmp %%donextbg +%%tilecheck + test dword[bgwinchange+ebx],0FFFFFF00h + jnz %%linebyline + test dword[bgwinchange+ebx+4],0FFFFFFFFh + jz %%tilebytile +%%linebyline + test dword[winbg1enval+ebx+%1*256],0A0A0A0Ah + jnz %%proclinebyline + test dword[winbg1enval+ebx+%1*256+4],0A0A0A0Ah + jnz %%proclinebyline +%%tilebytile + test dword[BGMS1+ebx*2+14],%4 + jz %%proclinebyline + test dword[BGMS1+ebx*2+14],%5 + jnz %%proclinebyline + cmp ebx,[reslbyl] + jae %%proclinebyline + test dword[bgallchange+ebx],0FFFFFF00h + jnz %%proclinebyline + test dword[bgallchange+ebx+4],0FFFFFFFFh + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256],0FFFFFF00h + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256+4],0FFFFFFFFh + jnz near %%proclinebyline + mov eax,[BG3PRI+ebx] + cmp eax,[BG3PRI+ebx+4] + jne near %%proclinebyline + test dword[intrlng+ebx],01010101h + jnz near %%proclinebyline + test dword[intrlng+ebx+4],01010101h + jnz near %%proclinebyline + test byte[mosenng+ebx],1 << %1 + jnz %%mosaic +%%nomosaic + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja near %%nextline + jmp %%donextbg +%%mosaic + cmp byte[mosszng+ebx],0 + je %%nomosaic + jmp %%proclinebyline +%%donextbg +%endmacro + +%macro Procbgpr1 6 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%5 + jz %%nogo + test dword[BGMS1+ebx*2],%6 + jnz %%nogo + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja %%nextline +%%donextbg +%endmacro + +%macro Procbg3pr1 6 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%5 + jz %%nogo + test dword[BGMS1+ebx*2],%6 + jnz %%nogo + cmp byte[BGMA+ebx],1 + jne %%nomode1 + cmp byte[BG3PRI+ebx],0 + jne %%nogo +%%nomode1 + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja %%nextline + jmp %%donextbg +%%tile + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja %%nextline +%%donextbg +%endmacro + +%macro Procbg3pr1b 6 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%5 + jz %%nogo + test dword[BGMS1+ebx*2],%6 + jnz %%nogo + cmp byte[BGMA+ebx],1 + jne %%nogo + cmp byte[BG3PRI+ebx],0 + je %%nogo + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja %%nextline + jmp %%donextbg +%%tile + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja %%nextline +%%donextbg +%endmacro + +%macro Procsprng 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%1 + jz %%nogo + test dword[BGMS1+ebx*2],%2 + jnz %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + call drawsprng + cmp byte[BGMA+ebx],5 + jb %%nogo + cmp byte[hiresstuff],0 + je %%nogo + add esi,75036 + mov cl,byte[sprlefttot+ebx] + call drawsprng + sub esi,75036 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja near %%nextline +%endmacro + +%macro Procsprng01 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%1 + jz %%nogo + test dword[BGMS1+ebx*2],%2 + jnz %%nogo + cmp byte[BGMA+ebx],1 + ja %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + call drawsprng + cmp byte[BGMA+ebx],5 + jb %%nogo + cmp byte[hiresstuff],0 + je %%nogo + add esi,75036 + mov cl,byte[sprlefttot+ebx] + call drawsprng + sub esi,75036 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja near %%nextline +%endmacro + +%macro Procsprng234567 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%1 + jz %%nogo + test dword[BGMS1+ebx*2],%2 + jnz %%nogo + cmp byte[BGMA+ebx],1 + jbe %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + call drawsprng + cmp byte[BGMA+ebx],5 + jb %%nogo + cmp byte[hiresstuff],0 + je %%nogo + add esi,75036 + mov cl,byte[sprlefttot+ebx] + call drawsprng + sub esi,75036 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja near %%nextline +%endmacro + +%macro ProcMode7ng 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,[mode7A] + mov [Mode7BackA],ebx + mov ebx,[mode7C] + mov [Mode7BackC],ebx + mov ebx,[mode7X0] + mov [Mode7BackX0],ebx + mov bl,[mode7set] + mov [Mode7BackSet],ebx + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + test byte[intrlng+ebx],40h + jnz near %%nogo + test dword[BGMS1+ebx*2],%1 + jz near %%nogo + test dword[BGMS1+ebx*2],%2 + jnz near %%nogo + push ebx + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + pop ebx + push eax + push edx + push esi + push ebx + call drawmode7win + pop ebx + pop esi + pop edx + pop eax + cmp byte[Mode7HiRes],0 + je %%nogo + call processmode7hires +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja near %%nextline + mov ebx,[Mode7BackA] + mov [mode7A],ebx + mov ebx,[Mode7BackC] + mov [mode7C],ebx + mov ebx,[Mode7BackX0] + mov [mode7X0],ebx + mov ebx,[Mode7BackSet] + mov [mode7set],bl +%endmacro + + +%macro ProcMode7ngextbg 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,[mode7A] + mov [Mode7BackA],ebx + mov ebx,[mode7C] + mov [Mode7BackC],ebx + mov ebx,[mode7X0] + mov [Mode7BackX0],ebx + mov bl,[mode7set] + mov [Mode7BackSet],ebx + mov ebx,1 +%%nextline + mov byte[esi-1],0 + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + test dword[BGMS1+ebx*2],%1 + jz near %%nogo + test dword[BGMS1+ebx*2],%2 + jnz near %%nogo + test byte[intrlng+ebx],40h + jz near %%nogo + mov byte[esi-1],1 + push ebx + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + push esi + call drawmode7ngextbg + pop esi + pop ebx +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja near %%nextline + mov ebx,[Mode7BackA] + mov [mode7A],ebx + mov ebx,[Mode7BackC] + mov [mode7C],ebx + mov ebx,[Mode7BackX0] + mov [mode7X0],ebx + mov ebx,[Mode7BackSet] + mov [mode7set],bl +%endmacro + +%macro ProcMode7ngextbg2 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,[mode7A] + mov [Mode7BackA],ebx + mov ebx,[mode7C] + mov [Mode7BackC],ebx + mov ebx,[mode7X0] + mov [Mode7BackX0],ebx + mov bl,[mode7set] + mov [Mode7BackSet],ebx + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + test dword[BGMS1+ebx*2],%1 + jz near %%nogo + test dword[BGMS1+ebx*2],%2 + jnz near %%nogo + test byte[intrlng+ebx],40h + jz near %%nogo + push ebx + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + push esi + cmp byte[esi-1],1 + je %%drawb + call drawmode7ngextbg + jmp %%drawa +%%drawb + call drawmode7ngextbg2 +%%drawa + pop esi + pop ebx +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + ja near %%nextline + mov ebx,[Mode7BackA] + mov [mode7A],ebx + mov ebx,[Mode7BackC] + mov [mode7C],ebx + mov ebx,[Mode7BackX0] + mov [mode7X0],ebx + mov ebx,[Mode7BackSet] + mov [mode7set],bl +%endmacro + +%macro preparet4ba 0 + shl cx,5 + add ecx,ecx + add ecx,[vcache4b] +%endmacro + +%macro preparet2ba 0 + shl cx,4 + shl ecx,2 + add ecx,[vcache2b] +%endmacro + +%macro preparet8ba 0 + shl cx,6 + add ecx,[vcache8b] +%endmacro + +%macro test4ba 0 + and ecx,2047 + test dword[vidmemch4+ecx*2],0FFFFh +%endmacro + +%macro test2ba 0 + and ecx,4095 + add edx,dword[mode0add] + test dword[vidmemch2+ecx],0FFh +%endmacro + +%macro test8ba 0 + and ecx,1023 + test dword[vidmemch8+ecx*4],0FFFFFFFFh +%endmacro + +%macro drawtileng 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + mov ebx,[ecx+8] + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+12] + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+16] + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+20] + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+24] + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+28] + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+32] + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+36] + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+40] + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+44] + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+48] + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+52] + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+56] + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx+60] + add ebx,edx + mov [edi+288*7+4],ebx + jmp %5 +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + mov ebx,[ecx+12] + bswap ebx + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+8] + bswap ebx + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+20] + bswap ebx + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+16] + bswap ebx + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+28] + bswap ebx + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+24] + bswap ebx + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+36] + bswap ebx + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+32] + bswap ebx + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+44] + bswap ebx + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+40] + bswap ebx + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+52] + bswap ebx + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+48] + bswap ebx + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+60] + bswap ebx + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx+56] + bswap ebx + add ebx,edx + mov [edi+288*7+4],ebx + jmp %5 +%%flipyfull + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+288*7+4],ebx + mov ebx,[ecx+8] + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+12] + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+16] + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+20] + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+24] + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+28] + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+32] + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+36] + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+40] + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+44] + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+48] + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+52] + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+56] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+60] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+288*7+4],ebx + mov ebx,[ecx+12] + bswap ebx + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+8] + bswap ebx + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+20] + bswap ebx + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+16] + bswap ebx + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+28] + bswap ebx + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+24] + bswap ebx + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+36] + bswap ebx + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+32] + bswap ebx + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+44] + bswap ebx + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+40] + bswap ebx + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+52] + bswap ebx + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+48] + bswap ebx + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+60] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+56] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov dword[tleftnb],8 +%%nextb + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextb + sub edi,288*8 + jmp %5 +%%flipxpart + mov dword[tleftnb],8 +%%nextbf + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextbf + sub edi,288*8 + jmp %5 +%%flipypart + add edi,288*7 + test word[vrama+eax],4000h + jnz near %%flipxypart + mov dword[tleftnb],8 +%%nextbm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbm + add edi,288 + jmp %5 +%%flipxypart + mov dword[tleftnb],8 +%%nextbfm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbfm + add edi,288 +%5 + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,8 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawtileng16x16 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov ebx,[ecx] + mov eax,[ecx+4] + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + mov ebx,[ecx+8] + mov eax,[ecx+12] + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+16] + mov eax,[ecx+20] + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+24] + mov eax,[ecx+28] + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+32] + mov eax,[ecx+36] + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+40] + mov eax,[ecx+44] + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+48] + mov eax,[ecx+52] + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+56] + mov eax,[ecx+60] + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + pop eax + jmp %%done +%%flipxfull + push eax + mov ebx,[ecx+4] + mov eax,[ecx] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + mov ebx,[ecx+12] + mov eax,[ecx+8] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+20] + mov eax,[ecx+16] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+28] + mov eax,[ecx+24] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+36] + mov eax,[ecx+32] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+44] + mov eax,[ecx+40] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+52] + mov eax,[ecx+48] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+60] + mov eax,[ecx+56] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + pop eax + jmp %%done +%%flipyfull + test word[vrama+eax],4000h + jnz near %%flipxyfull + push eax + mov ebx,[ecx] + mov eax,[ecx+4] + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + mov ebx,[ecx+8] + mov eax,[ecx+12] + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+16] + mov eax,[ecx+20] + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+24] + mov eax,[ecx+28] + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+32] + mov eax,[ecx+36] + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+40] + mov eax,[ecx+44] + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+48] + mov eax,[ecx+52] + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+56] + mov eax,[ecx+60] + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + pop eax + jmp %%done +%%flipxyfull + push eax + mov ebx,[ecx+4] + mov eax,[ecx] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + mov ebx,[ecx+12] + mov eax,[ecx+8] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+20] + mov eax,[ecx+16] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+28] + mov eax,[ecx+24] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+36] + mov eax,[ecx+32] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+44] + mov eax,[ecx+40] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+52] + mov eax,[ecx+48] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+60] + mov eax,[ecx+56] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + pop eax + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov dword[tleftnb],8 +%%nextb + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextb + sub edi,288*8 + jmp %%done +%%flipxpart + mov dword[tleftnb],8 +%%nextbf + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextbf + sub edi,288*8 + jmp %%done +%%flipypart + add edi,288*7 + test word[vrama+eax],4000h + jnz near %%flipxypart + mov dword[tleftnb],8 +%%nextbm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbm + add edi,288 + jmp %%done +%%flipxypart + mov dword[tleftnb],8 +%%nextbfm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbfm + add edi,288 +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%5 + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro ProcessBuildWindow 1 + mov dword[ngwinen],0 + test byte[winbg1enval+ebx+%1*256],0Ah + jz %%nowindowing + push eax + push ebx +;NEWSYM winlogicaval, times 256 dw 0 + mov al,[winlogicaval+ebx*2] + shr al,%1*2 + and al,03h + mov [nglogicval],al + mov eax,ebx + add ebx,%1*256 + call BuildWindow + mov eax,edi + sub eax,esi + cmp dword[ngwintable],0 + jne %%notzero + sub [ngwintable+4],eax + jmp %%done +%%notzero + sub [ngwintable],eax +%%done + pop ebx + pop eax +%%nowindowing +%endmacro + +%macro drawbgtileng 2 + mov dword[ng16bprval],0 + mov dword[ng16bbgval],%1 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + push ebx + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc + lea ecx,[ecx*8] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxinc + add eax,edx + neg dx +.noxinc + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng4b +.no4bit + cmp dl,1 + jne near .no2bit + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawtileng2b +.no2bit + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng8b +.no8bit + pop ebx + ret + +.tiles16x16 + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + push ebx + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2 + lea ecx,[ecx*4] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2 + add eax,edx + neg dx +.noxinc2 + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit2 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawtileng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng16x168b +.no8bit2 + pop ebx + ret +%endmacro + +%macro drawbgtilengpr1 2 + mov dword[ng16bprval],2000h + mov dword[ng16bbgval],%1 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + push ebx + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng4b +.no4bit + cmp dl,1 + jne near .no2bit + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawtileng2b +.no2bit + cmp dl,3 + jne near .no8bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng8b +.no8bit + pop ebx + ret +.tiles16x16 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + mov dword[taddnfy16x16],0 + add ecx,ebx + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + push ebx + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawtileng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawtileng16x168b +.no8bit2 + pop ebx + ret +%endmacro + +%macro drawlineng 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + jmp %5 + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %5 + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + jmp %5 + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%5 + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,8 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlineng16x16 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + jmp %%done + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %%done + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + jmp %%done + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%5 + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawbglineng 2 + mov dword[ng16bprval],0 + mov dword[ng16bbgval],%1 + cmp byte[bgmode],5 + jb %%nointerl + test byte[intrlng+ebx],01h + jz %%nointerl + add ecx,ebx + add ecx,[cfieldad] +%%nointerl + push ebx + mov byte[curmosaicsz],1 + xor eax,eax + test byte[mosenng+ebx],1 << %1 + jz %%nomosaic + mov al,[mosszng+ebx] + or al,al + jz %%nomosaic + inc al + mov byte[curmosaicsz],al + mov cl,al + mov al,bl + div cl + mul cl + mov ebx,eax + mov [pesimpng],esi + mov edi,xtravbuf+16 + mov ecx,64 + xor eax,eax + mov esi,xtravbuf+16 + rep stosd + or ebx,ebx + jnz %%nozeroline + inc ebx +%%nozeroline + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + jmp %%yesmosaic +%%nomosaic + cmp byte[BGMA+ebx],5 + jae near .tiles16x8 +%%yesmosaic + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + cmp byte[BGMA+ebx],2 + je near .offsetm +; cmp byte[BGMA+ebx],4 +; je near .offsetm + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxinc + add eax,edx + neg dx +.noxinc + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng4b +.no4bit + cmp dl,1 + jne near .no2bit + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawlineng2b +.no2bit + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng8b +.no8bit + pop ebx + ret + +.tiles16x16 + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2 + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2 + add eax,edx + neg dx +.noxinc2 + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit2 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawlineng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng16x168b +.no8bit2 + pop ebx + ret + +.tiles16x8 + cmp byte[t16x161+ebx+%1*256],1 + je .tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],0 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc2c + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2c + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + jmp .tiles16x8hr +.tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy2 + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy2 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2b + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2b + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h +.tiles16x8hr + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + add ecx,ecx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2b + add eax,edx + neg dx +.noxinc2b + mov edi,ecx + sub dx,64 + and ecx,01F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + shr edi,1 + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit2b + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[cbgval],%1 + jmp drawlineng16x84b +.no4bit2b + cmp dl,1 + jne near .no2bit2b + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov dword[cbgval],%1 + jmp drawlineng16x82b +.no2bit2b + pop ebx + ret + + ; Offsetmode calculation : *1024+*32+ +.offsetm + xor edx,edx + mov dx,[BG3SYl+ebx*2] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma + and dx,0F000h + shr dx,5 + add ax,dx +.nooma + cmp byte[BGMA+ebx],4 + je .offsetm4 + add eax,40h +.offsetm4 + mov edx,eax + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincd + add eax,[BGPT1Y+ebx*2+%1*512] +.noyincd + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + mov [yposngom],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov [flipyposngom],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincd + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincd + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bitd + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[ofsmval],2000h << %1 + mov dword[ofsmvalh],2000h << %1 + cmp byte[hdmaearlstart],0 + je .ofsmvalhack + mov dword[ofsmvalh],0 +.ofsmvalhack + mov dword[cbgval],%1 + ProcessBuildWindow %1 + jmp drawlinengom4b +.no4bitd + cmp dl,1 + jne near .no2bitdn + ; eax = pointer to beginning of tile area + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov byte[tleftn],33 +.loopdn + mov cx,[vrama+eax] + test cx,2000h + jnz near .fintiledn + drawlinengom2 tltype2b, preparet2ba, cachesingle2bng,.loopdn,.fintiledn,ngpalcon2b,test2ba,03h,%1 +.no2bitdn + cmp dl,3 + jne near .no8bitdn + ; eax = pointer to beginning of tile area + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn2 + mov cx,[vrama+eax] + test cx,2000h + jnz near .fintiledn2 + drawlinengom2 tltype8b, preparet8ba, cachesingle8bng,.loopdn2,.fintiledn2,ngpalcon8b,test8ba,0FFh,%1 +.no8bitdn + pop ebx + ret +%endmacro + +%macro mosender 1 +.nodraw + add edi,%1 + add esi,%1 + dec ecx + jnz .next + pop esi + mov dword[ignor512],0 + ret +%endmacro + +%macro drawbglinengpr1 2 + mov dword[ng16bprval],2000h + mov dword[ng16bbgval],%1 + push ebx + mov byte[curmosaicsz],1 + xor eax,eax + test byte[mosenng+ebx],1 << %1 + jz %%nomosaic + mov al,[mosszng+ebx] + or al,al + jz %%nomosaic + inc al + mov byte[curmosaicsz],al + mov cl,al + mov al,bl + div cl + mul cl + mov ebx,eax + mov [pesimpng],esi + mov edi,xtravbuf+16 + mov ecx,64 + xor eax,eax + mov esi,xtravbuf+16 + rep stosd + or ebx,ebx + jnz %%nomosaic + inc ebx + jmp %%yesmosaic +%%nomosaic + cmp byte[BGMA+ebx],5 + jae near .tiles16x8 +%%yesmosaic + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + cmp byte[BGMA+ebx],2 + je near .offsetm +; cmp byte[BGMA+ebx],4 +; je near .offsetm + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng4b +.no4bit + cmp dl,1 + jne near .no2bit + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawlineng2b +.no2bit + cmp dl,3 + jne near .no8bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng8b +.no8bit + pop ebx + ret + +.tiles16x16 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + mov dword[taddnfy16x16],0 + add ecx,ebx + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + + lea eax,[ecx*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawlineng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + jmp drawlineng16x168b +.no8bit2 + pop ebx + ret + +.tiles16x8 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomyb + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomyb + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],0 +.tiles16x16hr + + lea eax,[ecx*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2b + ; eax = pointer to beginning of tile area + mov dword[cbgval],%1 + jmp drawlineng16x84b +.no4bit2b + cmp dl,1 + jne near .no2bit2b + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov dword[cbgval],%1 + jmp drawlineng16x82b +.no2bit2b + pop ebx + ret + +.offsetm + xor edx,edx + mov dx,[BG3SYl+ebx*2] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma + and dx,0F000h + shr dx,5 + add ax,dx +.nooma + mov edx,eax + cmp byte[BGMA+ebx],4 + je .offsetm4 + add edx,40h +.offsetm4 + and edx,0FFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincdd + add [ofsmtptr],edx +.noxincdd + and ecx,0F8h + shr ecx,2 + add [ofsmtptr],ecx + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + mov [yposngom],eax + xor eax,38h + mov [flipyposng],eax + mov [flipyposngom],eax + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + cmp dl,2 + jne near .no4bitd + ; eax = pointer to beginning of tile area + mov dword[ofsmval],2000h << %1 + mov dword[ofsmvalh],2000h << %1 + cmp byte[hdmaearlstart],0 + je .ofsmvalhack + mov dword[ofsmvalh],0 +.ofsmvalhack + mov dword[cbgval],%1 + ProcessBuildWindow %1 + jmp drawlinengom4b +.no4bitd + cmp dl,1 + jne near .no2bitdn + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiledn + drawlinengom2 tltype2b, preparet2ba, cachesingle2bng,.loopdn,.fintiledn,ngpalcon2b,test2ba,03h,%1 +.no2bitdn + cmp dl,3 + jne near .no8bitdn + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn2 + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiledn2 + drawlinengom2 tltype8b, preparet8ba, cachesingle8bng,.loopdn2,.fintiledn2,ngpalcon8b,test8ba,0FFh,%1 +.no8bitdn + pop ebx + ret +%endmacro + \ No newline at end of file diff --git a/zsnes/src/video/newgfx16.asm b/zsnes/src/video/newgfx16.asm new file mode 100644 index 00000000..93961cea --- /dev/null +++ b/zsnes/src/video/newgfx16.asm @@ -0,0 +1,3410 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM BG116x16t,BG1SXl,BG1SYl,BG216x16t,BG2SXl,BG2SYl,BG316x16t,BG3PRI +EXTSYM BG3SXl,BG3SYl,BG416x16t,BG4SXl,BG4SYl,BGFB,BGMA,BGMS1,BGOPT1 +EXTSYM BGOPT2,BGOPT3,BGOPT4,BGPT1,BGPT1X,BGPT1Y,BGPT2,BGPT2X,BGPT2Y,BGPT3 +EXTSYM BGPT3X,BGPT3Y,BGPT4,BGPT4X,BGPT4Y,bg1drwng,bg1objptr,bg1ptr,bg1ptrx +EXTSYM bg1ptry,bg1scrolx,bg1scroly,bg1totng,bg2drwng,bg2objptr,bg2ptr +EXTSYM bg2ptrx,bg2ptry,bg2scrolx,bg2scroly,bg2totng,bg3drwng,bg3highst +EXTSYM bg3objptr,bg3ptr,bg3ptrx,bg3ptry,bg3scrolx,bg3scroly,bg3totng +EXTSYM bg4drwng,bg4objptr,bg4ptr,bg4ptrx,bg4ptry,bg4scrolx,bg4scroly +EXTSYM bg4totng,bgcmsung,bgmode,bgtxad,bgtxadd,cachesingle2bng +EXTSYM cachesingle8bng,cfieldad,cgfxmod,cgmod,cgram,coladdb +EXTSYM coladdg,coladdr,colleft16b,colormodedef,cpalval,csprbit,csprival +EXTSYM curmosaicsz,curvidoffset,curypos,firstdrawn +EXTSYM flipyposng,forceblnk,interlval,intrlng,maxbr,mode0add,mode0ads,mode7A +EXTSYM mode7C,mode7X0,mode7ab,mode7cd,mode7set,mode7st,mode7xy,modeused +EXTSYM mosaicon,mosaicsz,mosenng,mosszng,ngceax,ngcedi,ngpalcon2b,ngpalcon4b +EXTSYM ngpalcon8b,ngptrdat,pesimpng,prdata,prdatb,prdatc,prevbright +;EXTSYM ngpalcon8b,pesimpng,prdata,prdatb,prdatc,prevbright +EXTSYM prevpal,reslbyl,resolutn,scaddset,scaddtype,scadsng,scadtng,scbcong +EXTSYM scfbl,scrndis,scrnon,spritetablea,sprleftpr,sprlefttot,sprprdrn +EXTSYM sprpriodata,sprtbng,sprtlng,switch16x16,t16x161,t16x162,t16x163 +EXTSYM t16x164,taddfy16x16,taddnfy16x16,tleftn,tleftnb,tltype2b,tltype4b +EXTSYM tltype8b,vcache2b,vcache4b,vcache8b,vesa2_bposng,vesa2_clbitng,vesa2_gposng +EXTSYM vesa2_rposng,vidbright,vidbuffer,vidmemch2,vidmemch4,drawsprng +EXTSYM vidmemch8,vrama,winon,xtravbuf,yposng,vbufdptr,preparesprpr +EXTSYM drawtileng2b16b,drawtileng4b16b,drawtileng8b16b +EXTSYM drawtileng16x162b16b,drawtileng16x164b16b,drawtileng16x168b16b +EXTSYM drawlineng2b16b,drawlineng4b16b,drawlineng8b16b,BuildWindow +EXTSYM drawlineng16x162b16b,drawlineng16x164b16b,drawlineng16x168b16b +EXTSYM ngextbg,bgwinchange,disableeffects,winbg1en,winenabs,winenabm +EXTSYM winl1,winbg1enval,winbg1envalm +EXTSYM winlogica,winlogicaval,winboundary,winobjen,winlogicb,nglogicval +EXTSYM ngwintable,winbg2enval,winbg3enval,winbg4enval,winbgobjenval +EXTSYM Mode7HiRes16b,res640,hiresstuff,Mode7BackA,Mode7BackC,Mode7BackX0 +EXTSYM Mode7BackSet,drawmode7win16b,processmode7hires,ngwinen +EXTSYM drawlineng16x84b16b,drawlineng16x82b16b,ofsmcyps,vram,ofsmcptr +EXTSYM ofsmady,ofsmadx,ofsmtptr,yposngom,flipyposngom,ofsmmptr +EXTSYM ofsmval,ofsmvalh,hdmaearlstart,ofsmvalh,cbgval,drawlinengom4b16b +EXTSYM drawsprngw,ignor512,winbg1envals,FillSubScr,scanlines +EXTSYM drawmode7win16bd,SpecialLine,vidmemch2s +EXTSYM smallscreenon,ScreenScale,SA1Enable,drawlinengom16x164b16b +EXTSYM doveg,V8Mode +EXTSYM bgallchange,bg1change,bg2change,bg3change,bg4change +EXTSYM ngwinptr,objwlrpos,objwen,objclineptr,CSprWinPtr +EXTSYM BuildWindow2 +EXTSYM NGNumSpr +EXTSYM fulladdtab +EXTSYM FPUCopy + +%include "video/vidmacro.mac" +%include "video/newgfx16.mac" +%include "video/newg162.mac" + + + + + +; mov ebp,[cpalval+ebx*4] +; 75036*2 +; Different routines for: +; Normal (just one screen) +; Transparency +; No Transparency + +; Sub+Main: +; Different Window Modes for each: +; SubWin+MainWin +; Sub+MainWin +; SubWin+Main + + + + +; cgfxmod : +; 0 = No addition whatsoever +; 1 = Addition in the back area only +; 2 = All of subscreen added to all of mainscreen +; 3 = All of subscreen added to specific mainscreens +; 4 = Add+Sub enabled + +NEWSYM setpalallng + + mov dword[palchanged],1 + mov byte[cgmod],0 + push esi + push eax + push edx + push ebp + mov esi,[cpalptrng] + mov byte[colleft16b],0 + add esi,1024 + xor ebp,ebp + and esi,255*1024 + mov dword[cpalptrng],esi + + add esi,[vbufdptr] + +.loopa + mov dx,[cgram+ebp] + mov [prevpal2+ebp],dx + mov ax,dx + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[ngrposng] + xor ebx,ebx + shl ax,cl + add bx,ax + mov ax,dx + shr ax,5 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[nggposng] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[ngbposng] + shl ax,cl + add bx,ax + mov ax,bx + mov [esi],bx ; standard + or bx,[UnusedBit] + mov [esi+512],bx ; standard + add esi,2 + add ebp,2 + inc byte[colleft16b] + jnz near .loopa + mov al,[vidbright] + mov [prevbright],al + pop ebp + pop edx + pop eax + pop esi + xor ecx,ecx + ret + +NEWSYM setpalette16bng + cmp byte[V8Mode],1 + jne .noveg + call doveg +.noveg + mov bl,[vidbright] + cmp bl,[prevbright] + jne near setpalallng + cmp byte[cgmod],0 + je near .skipall + push esi + push edi + push eax + push edx + push ebp + mov byte[cgmod],0 + xor ebp,ebp + mov esi,[cpalptrng] + mov edi,esi + add esi,1024 + and esi,255*1024 + mov dword[cpalptrng],esi + + add esi,[vbufdptr] + add edi,[vbufdptr] + + mov byte[colleft16b],0 + jmp .loopa +.skipa + mov bx,[edi] + mov [esi],bx + mov bx,[edi+512] + mov [esi+512],bx + add edi,2 + add esi,2 + add ebp,2 + inc byte[colleft16b] + jz near .endpal +.loopa + mov dx,[cgram+ebp] + cmp [prevpal2+ebp],dx + je .skipa + mov [prevpal2+ebp],dx + cmp byte[colleft16b],0 + je .notchanged + mov dword[palchanged],1 +.notchanged + mov ax,dx + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[ngrposng] + xor ebx,ebx + shl ax,cl + add bx,ax + mov ax,dx + shr ax,5 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[nggposng] + shl ax,cl + add bx,ax + mov ax,dx + shr ax,10 + and al,01Fh + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[ngbposng] + shl ax,cl + add bx,ax + mov [esi],bx ; standard + or bx,[UnusedBit] + mov [esi+512],bx ; standard + add edi,2 + add esi,2 + add ebp,2 + inc byte[colleft16b] + jnz near .loopa +.endpal + pop ebp + pop edx + pop eax + pop edi + pop esi + xor ecx,ecx +.skipall + ret + +prevpal2 times 256 dw 0F00Fh + +%macro WinBGCheck 1 + mov bl,[winbg1en+%1] + mov bh,bl + test bl,0Ah + jz %%disable + + test byte[scrnon],1 << %1 + jz %%nomainbg + test byte[scrnon+1],1 << %1 + jnz %%bg + xor bh,bh + jmp %%bg +%%nomainbg + xor bl,bl + test byte[scrnon+1],1 << %1 + jnz %%bg + xor bh,bh + jmp %%skip +%%disable + xor bl,bl + xor bh,bh + jmp %%skip +%%bg + test byte[winenabs],1 << %1 + jnz %%nbgs + xor bh,bh +%%nbgs + test byte[winenabm],1 << %1 + jnz %%nbgm + xor bl,bl +%%nbgm + jmp %%skip + mov cl,bl + or cl,bh + and cl,0Ah + cmp cl,0Ah + je %%skip + mov ch,bl + or ch,bh + mov edx,[winl1] + cmp cl,02h + je %%bg1 + shr ch,2 + shr edx,16 +%%bg1 + test ch,01h + jnz %%outside + cmp dl,dh + jbe %%skip + xor bl,bl + xor bh,bh + jmp %%skip +%%outside + cmp dl,0 + ja %%skip + cmp dh,255 + jb %%skip + xor bl,bl + xor bh,bh +%%skip + mov [winbg1envalm+eax+%1*256],bl + mov [winbg1envals+eax+%1*256],bh + or bl,bh + mov [winbg1enval+eax+%1*256],bl +%endmacro + +%macro WinBGCheckb 1 + mov bl,[winbg1en+%1] + test bl,0Ah + jz %%disable + test byte[scrnon],1 << %1 + jnz %%nbgen + test byte[winenabs],1 << %1 + jnz %%bg + jmp %%disable +%%nbgen + test byte[winenabm],1 << %1 + jnz %%bg +%%disable + xor bl,bl + jmp %%skip +%%bg + mov cl,bl + and cl,0Ah + cmp cl,0Ah + je %%skip +; jne %%notskip +; and bl,03h +; and cl,03h +;%%notskip + mov ch,bl + mov edx,[winl1] + cmp cl,02h + je %%bg1 + shr ch,2 + shr edx,16 +%%bg1 + test ch,01h + jnz %%outside + cmp dl,dh + jbe %%skip + xor bl,bl + jmp %%skip +%%outside + cmp dl,0 + ja %%skip + cmp dh,255 + jb %%skip + xor bl,bl +%%skip + mov [winbg1enval+eax+%1*256],bl + mov [winbg1envalm+eax+%1*256],bl + mov [winbg1envals+eax+%1*256],bl +%endmacro + +%macro WinBGCheck2 1 + mov bl,[winbg1en+%1] + test bl,0Ah + jnz %%nodisable + xor bl,bl + jmp %%skip +%%nodisable + mov cl,bl + or cl,bh + and cl,0Ah + cmp cl,0Ah + je %%skip + mov ch,bl + or ch,bh + mov edx,[winl1] + cmp cl,02h + je %%bg1 + shr ch,2 + shr edx,16 +%%bg1 + test ch,01h + jnz %%outside + cmp dl,dh + jbe %%skip + xor bl,bl + jmp %%skip +%%outside + cmp dl,0 + ja %%skip + cmp dh,255 + jb %%skip + xor bl,bl +%%skip + mov [winbg1enval+eax+%1*256],bl +%endmacro + +BackAreaAdd dd 0 +BackAreaUnFillCol dd 0 +BackAreaFillCol dd 0 +clinemainsub dd 0 + +BackAreaFill: + cmp byte[winbg1enval+eax+5*256],0 + je near .nowindowb + mov ebx,[BackAreaFillCol] + cmp ebx,[BackAreaUnFillCol] + je near .nowindowb + push ecx + push edx + push eax + push edi + + mov ebx,eax + mov ecx,[vidbuffer] + add ecx,16*2 + shl eax,9 + add ecx,eax + mov eax,ebx + shl eax,6 + add ecx,eax + add ecx,[BackAreaAdd] + + ; Construct Window in ecx + mov edi,ngwintable + sub ecx,2 + mov eax,256 +.procnotemptyb + mov edx,[edi] + add edi,4 + or edx,edx + jz .procemptyb + dec edx + mov ebx,[BackAreaUnFillCol] +.swloopb + mov dword[ecx],ebx + mov dword[ecx+4],ebx + add ecx,8 + sub eax,4 + jc .doneb + sub edx,4 + jnc .swloopb + sub eax,edx + add ecx,edx + add ecx,edx + dec eax + add ecx,2 +.procemptyb + mov edx,[edi] + dec edx + add edi,4 + mov ebx,[BackAreaFillCol] +.swloop2b + mov dword[ecx],ebx + mov dword[ecx+4],ebx + add ecx,8 + sub eax,4 + jc .doneb + sub edx,4 + jnc .swloop2b + sub eax,edx + add ecx,edx + add ecx,edx + dec eax + add ecx,2 + jmp .procnotemptyb +.doneb + pop edi + pop eax + pop edx + pop ecx + jmp .yeswindowb +.nowindowb + push eax + push ecx + mov ebx,eax + mov ecx,[vidbuffer] + mov eax,ebx + add ecx,16*2 + shl eax,9 + add ecx,eax + mov eax,ebx + shl eax,6 + add ecx,eax + add ecx,[BackAreaAdd] + mov ebx,[BackAreaUnFillCol] + mov eax,128 +.nowinloop + mov [ecx],ebx + add ecx,4 + dec eax + jnz .nowinloop + pop ecx + pop eax +.yeswindowb + ret + +NEWSYM newengine16b + ; store line by line data + ; BGMode, BGxScrollX, BGxScrollY, both BGPtrs + mov eax,[curypos] + and eax,0FFh + + cmp eax,1 + jne .noclearcache + push eax + push ecx + mov ebx,vidmemch2s + mov ecx,1024+512+256 + mov eax,0FFFFFFFFh +.loopcc + mov dword[ebx],eax + add ebx,4 + loop .loopcc + pop ecx + pop eax + mov dword[startlinet],0 + mov dword[endlinet],255 + xor ebx,ebx +.noclearcache + + mov byte[bgallchange+eax],0 + mov byte[bgallchange+eax+1],0FFh + mov byte[bg1change+eax],0 + mov byte[bg2change+eax],0 + mov byte[bg3change+eax],0 + mov byte[bg4change+eax],0 + mov dword[palchanged],0 + + ; BG3 Priority + mov bl,[bg3highst] + mov [BG3PRI+eax],bl + cmp [BG3PRI+eax-1],bl + je .nosbg3pr + mov byte[bgallchange+eax],1 +.nosbg3pr + + ; Main/Sub Screen + cmp byte[SA1Enable],0 + je .noscrnona + cmp word[scrnon],1317h + jne .noscrnona + cmp byte[scaddtype],0 + jne .noscrnona + mov word[scrnon],1317h + mov byte[scaddtype],44h + mov byte[scaddset],02h +.noscrnona + mov ebx,[scrnon] + ; clear + push ecx + mov cl,[scrnon] + and cl,1Fh + or cl,20h + and cl,[scaddtype] + and cl,3Fh + mov byte[FillSubScr+eax],1 + or cl,cl + jnz .yessub + xor bh,bh + mov byte[FillSubScr+eax],0 +.yessub + pop ecx + test byte[scaddset],2 + jnz .subscrnon + xor bh,bh +.subscrnon + or [bgcmsung],ebx + mov [BGMS1+eax*2],ebx + cmp [BGMS1+eax*2-2],bx + je .nosbgms1 + mov byte[bgallchange+eax],1 +.nosbgms1 + + ; if palette[0] = 0 and transparency is just add to back area, + ; set ngmsdraw to 1 + mov byte[clinemainsub],0 + cmp word[cgram],0 + jne .ngmsdraw0 + mov bl,[scrnon] + and bl,1Fh + or bl,0E0h + and bl,[scaddtype] + cmp bl,20h + jne .ngmsdraw0 + mov byte[ngmsdraw],1 + mov byte[FillSubScr+eax],0 + mov byte[clinemainsub],1 +.ngmsdraw0 + + ; Scroll Values + mov bx,[bg1scrolx] + mov [BG1SXl+eax*2],bx + cmp [BG1SXl+eax*2-2],bx + je .nosbgx1 + mov byte[bg1change+eax],1 +.nosbgx1 + mov bx,[bg2scrolx] + mov [BG2SXl+eax*2],bx + cmp [BG2SXl+eax*2-2],bx + je .nosbgx2 + mov byte[bg2change+eax],1 +.nosbgx2 + mov bx,[bg3scrolx] + mov [BG3SXl+eax*2],bx + cmp [BG3SXl+eax*2-2],bx + je .nosbgx3 + mov byte[bg3change+eax],1 +.nosbgx3 + mov bx,[bg4scrolx] + mov [BG4SXl+eax*2],bx + cmp [BG4SXl+eax*2-2],bx + je .nosbgx4 + mov byte[bg4change+eax],1 +.nosbgx4 + + mov bx,[bg1scroly] + mov [BG1SYl+eax*2],bx + cmp [BG1SYl+eax*2-2],bx + je .nosbgy1 + mov byte[bg1change+eax],1 +.nosbgy1 + mov bx,[bg2scroly] + mov [BG2SYl+eax*2],bx + cmp [BG2SYl+eax*2-2],bx + je .nosbgy2 + mov byte[bg2change+eax],1 +.nosbgy2 + mov bx,[bg3scroly] + mov [BG3SYl+eax*2],bx + cmp [BG3SYl+eax*2-2],bx + je .nosbgy3 + mov byte[bg3change+eax],1 +.nosbgy3 + mov bx,[bg4scroly] + mov [BG4SYl+eax*2],bx + cmp [BG4SYl+eax*2-2],bx + je .nosbgy4 + mov byte[bg1change+eax],1 +.nosbgy4 + + ; Background Mode + mov bl,[bgmode] + and bl,07h + mov [BGMA+eax],bl + cmp [BGMA+eax-1],bl + je .nobgma + mov byte[bgallchange+eax],1 +.nobgma + + mov byte[modeused+eax],1 + + ; Pointer to OBJ tile data + mov ebx,[bg1objptr] + mov [BGOPT1+eax*2],ebx + cmp [BGOPT1+eax*2-2],bx + je .nosbgo1 + mov byte[bg1change+eax],1 +.nosbgo1 + mov ebx,[bg2objptr] + mov [BGOPT2+eax*2],ebx + cmp [BGOPT2+eax*2-2],bx + je .nosbgo2 + mov byte[bg2change+eax],1 +.nosbgo2 + mov ebx,[bg3objptr] + mov [BGOPT3+eax*2],ebx + cmp [BGOPT3+eax*2-2],bx + je .nosbgo3 + mov byte[bg3change+eax],1 +.nosbgo3 + mov ebx,[bg4objptr] + mov [BGOPT4+eax*2],ebx + cmp [BGOPT4+eax*2-2],bx + je .nosbgo4 + mov byte[bg4change+eax],1 +.nosbgo4 + + ; Pointer to tile status data + mov ebx,[bg1ptr] + mov [BGPT1+eax*2],ebx + cmp [BGPT1+eax*2-2],bx + je .nosbgp1 + mov byte[bg1change+eax],1 +.nosbgp1 + mov ebx,[bg2ptr] + mov [BGPT2+eax*2],ebx + cmp [BGPT2+eax*2-2],bx + je .nosbgp2 + mov byte[bg2change+eax],1 +.nosbgp2 + mov ebx,[bg3ptr] + mov [BGPT3+eax*2],ebx + cmp [BGPT3+eax*2-2],bx + je .nosbgp3 + mov byte[bg3change+eax],1 +.nosbgp3 + mov ebx,[bg4ptr] + mov [BGPT4+eax*2],ebx + cmp [BGPT4+eax*2-2],bx + je .nosbgp4 + mov byte[bg4change+eax],1 +.nosbgp4 + + mov ebx,[bg1ptrx] + mov [BGPT1X+eax*2],ebx + cmp [BGPT1X+eax*2-2],bx + je .nosbgpx1 + mov byte[bg1change+eax],1 +.nosbgpx1 + mov ebx,[bg2ptrx] + mov [BGPT2X+eax*2],ebx + cmp [BGPT2X+eax*2-2],bx + je .nosbgpx2 + mov byte[bg2change+eax],1 +.nosbgpx2 + mov ebx,[bg3ptrx] + mov [BGPT3X+eax*2],ebx + cmp [BGPT3X+eax*2-2],bx + je .nosbgpx3 + mov byte[bg3change+eax],1 +.nosbgpx3 + mov ebx,[bg4ptrx] + mov [BGPT4X+eax*2],ebx + cmp [BGPT4X+eax*2-2],bx + je .nosbgpx4 + mov byte[bg4change+eax],1 +.nosbgpx4 + + mov ebx,[bg1ptry] + mov [BGPT1Y+eax*2],ebx + cmp [BGPT1Y+eax*2-2],bx + je .nosbgpy1 + mov byte[bg1change+eax],1 +.nosbgpy1 + mov ebx,[bg2ptry] + mov [BGPT2Y+eax*2],ebx + cmp [BGPT2Y+eax*2-2],bx + je .nosbgpy2 + mov byte[bg2change+eax],1 +.nosbgpy2 + mov ebx,[bg3ptry] + mov [BGPT3Y+eax*2],ebx + cmp [BGPT3Y+eax*2-2],bx + je .nosbgpy3 + mov byte[bg3change+eax],1 +.nosbgpy3 + mov ebx,[bg4ptry] + mov [BGPT4Y+eax*2],ebx + cmp [BGPT4Y+eax*2-2],bx + je .nosbgpy4 + mov byte[bg4change+eax],1 +.nosbgpy4 + mov ebx,[forceblnk] + or bl,bl + jne .dontdraw + mov dword[scfbl],0 +.dontdraw + mov [BGFB+eax],ebx + cmp [BGFB+eax-1],bx + je .nosbgfb + mov byte[bgallchange+eax],1 +.nosbgfb + + mov ebx,[mode7A] + mov [mode7ab+eax*4],ebx + mov ebx,[mode7C] + mov [mode7cd+eax*4],ebx + mov ebx,[mode7X0] + mov [mode7xy+eax*4],ebx + mov ebx,[mode7set] + mov [mode7st+eax],ebx + + ; 16x16 tiles + mov ebx,[BG116x16t] + mov [t16x161+eax],ebx + cmp [t16x161+eax-1],bl + je .not16x161 + mov byte[bg1change+eax],1 +.not16x161 + mov ebx,[BG216x16t] + mov [t16x162+eax],ebx + cmp [t16x162+eax-1],bl + je .not16x162 + mov byte[bg2change+eax],1 +.not16x162 + mov ebx,[BG316x16t] + mov [t16x163+eax],ebx + cmp [t16x163+eax-1],bl + je .not16x163 + mov byte[bg3change+eax],1 +.not16x163 + mov ebx,[BG416x16t] + mov [t16x164+eax],ebx + cmp [t16x164+eax-1],bl + je .not16x164 + mov byte[bg4change+eax],1 +.not16x164 + +; mov byte[mode7hr+eax],0 + cmp byte[bgmode],7 + jne .noextbg +; cmp byte[res640],0 +; je .nomode7512 +; mov byte[mode7hr+eax],1 +;.nomode7512 + test byte[interlval],40h + jz .noextbg + mov byte[ngextbg],1 +.noextbg + + ; mosaic + mov ebx,[mosaicon] + mov [mosenng+eax],ebx + mov ebx,[mosaicsz] + mov [mosszng+eax],ebx + + ; Interlaced + mov ebx,[interlval] + mov [intrlng+eax],ebx + + ; Set palette + call setpalette16bng + + cmp dword[palchanged],1 + jne .notpchanged + cmp eax,112 + jae .endl + mov dword[startlinet],eax + jmp .notpchanged +.endl + cmp dword[endlinet],255 + jb .notpchanged + mov dword[endlinet],eax +.notpchanged + + mov ebx,[cpalptrng] + add ebx,[vbufdptr] + mov [cpalval+eax*4],ebx + + ; Set Transparency + mov bl,[scaddtype] + mov [scadtng+eax],bl + cmp [scadtng+eax-1],bl + je .noscadt + mov byte[bgallchange+eax],1 +.noscadt + + mov bl,[scaddset] + mov [scadsng+eax],bl + cmp [scadsng+eax-1],bl + je .noscads + mov byte[bgallchange+eax],1 +.noscads + + ; Windowing Stuff +;NEWSYM winl1, db 0 ; window 1 left position +;NEWSYM winr1, db 0 ; window 1 right position +;NEWSYM winl2, db 0 ; window 2 left position +;NEWSYM winr2, db 0 ; window 2 right position +;NEWSYM winbg1en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG1 +;NEWSYM winbg2en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG2 +;NEWSYM winbg3en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG3 +;NEWSYM winbg4en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG4 +;NEWSYM winobjen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on sprites +;NEWSYM wincolen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on backarea +;NEWSYM winlogica, db 0 ; Window logic type for BG1 to 4 +;NEWSYM winlogicb, db 0 ; Window logic type for Sprites and Backarea +;NEWSYM winenabm, db 0 ; Window logic enable for main screen +;NEWSYM winenabs, db 0 ; Window logic enable for sub screen + +;NEWSYM winboundary, times 256 dd 0 +;NEWSYM winbg1enval, times 256 db 0 +;NEWSYM winbg2enval, times 256 db 0 +;NEWSYM winbg3enval, times 256 db 0 +;NEWSYM winbg4enval, times 256 db 0 +;NEWSYM winbgobjenval, times 256 db 0 +;NEWSYM winlogicaval, times 256 dw 0 + mov byte[bgwinchange+eax],0 + cmp byte[disableeffects],1 + je near .finishwin + push ecx + push edx + WinBGCheck 0 + WinBGCheck 1 + WinBGCheck 2 + WinBGCheck 3 + WinBGCheck 4 + WinBGCheck2 5 + + mov ebx,[winlogica] + mov [winlogicaval+eax*2],ebx + cmp [winlogicaval+eax*2-2],bx + je .winnchangedb + mov byte[bgwinchange+eax],1 +.winnchangedb + mov ebx,[winl1] + mov [winboundary+eax*4],ebx + cmp [winboundary+eax*4-4],ebx + je .winnchanged + mov byte[bgwinchange+eax],1 +.winnchanged + + ; generate sprite window + cmp byte[winbg1enval+eax+4*256],0 + je near .skipobjw + + mov ebx,[winl1] + mov dl,[winobjen] + mov dh,[winlogicb] + and dh,03h + ; Same as previous line? + cmp [objwlrpos+eax*4-4],ebx + jne .changedb + cmp [objwen+eax*2-2],dx + je near .notchanged +.changedb + cmp [objwlrpos+eax*4],ebx + jne .changed + cmp [objwen+eax*2],dx + jne .changed + mov ecx,[CSprWinPtr] + cmp [objclineptr+eax*4],ecx + ja near .usecurrent +.changed + mov [objwlrpos+eax*4],ebx + mov [objwen+eax*2],dx + + mov bl,[winlogicb] + and bl,03h + mov [nglogicval],bl + mov ebx,4*256 + add ebx,eax + mov dword[ngwinen],0 + call BuildWindow2 + cmp dword[ngwinen],0 + je near .disablesprwin + mov ecx,[CSprWinPtr] + add ecx,260 + mov [CSprWinPtr],ecx + mov [objclineptr+eax*4],ecx + add ecx,[ngwinptr] + ; Construct Window in ecx + push eax + mov ebx,ngwintable + dec ecx + mov eax,256 +.procnotempty + mov edx,[ebx] + add ebx,4 + or edx,edx + jz .procempty + dec edx +.swloop + mov dword[ecx],0 + add ecx,4 + sub eax,4 + jc .done + sub edx,4 + jnc .swloop + sub eax,edx + add ecx,edx + dec eax + inc ecx +.procempty + mov edx,[ebx] + dec edx + add ebx,4 +.swloop2 + mov dword[ecx],01010101h + add ecx,4 + sub eax,4 + jc .done + sub edx,4 + jnc .swloop2 + sub eax,edx + add ecx,edx + dec eax + inc ecx + jmp .procnotempty +.done + pop eax +;NEWSYM objwlrpos , times 256 dd 0 +;NEWSYM objwen , times 256 dw 0 ; en,log +;NEWSYM objclineptr, times 256 dd 0 ; l1,r1,l2,r2,en,log,ptr + jmp .skipobjw +.usecurrent + mov ecx,[objclineptr+eax*4] + mov [CSprWinPtr],ecx + cmp ecx,0FFFFFFFFh + jnz .skipobjw + jmp .disablesprwin + ; copy over if it's the same +.notchanged + mov [objwlrpos+eax*4],ebx + mov [objwen+eax*2],dx + mov ebx,[objclineptr+eax*4-4] + mov [objclineptr+eax*4],ebx + cmp ebx,0FFFFFFFFh + je .disablesprwin +.skipobjw + pop edx + pop ecx + jmp .okaywin +.disablesprwin + mov dword[objclineptr+eax*4],0FFFFFFFFh + mov byte[winbg1enval+eax+4*256],0 + mov byte[winbg1envals+eax+4*256],0 + mov byte[winbg1envalm+eax+4*256],0 + pop edx + pop ecx + jmp .okaywin +.finishwin + mov byte[winbg1enval+eax],0 + mov byte[winbg2enval+eax],0 + mov byte[winbg3enval+eax],0 + mov byte[winbg4enval+eax],0 + mov byte[winbgobjenval+eax],0 +.okaywin + xor ebx,ebx + + mov ebx,[coladdr-1] + mov bl,[vidbright] + cmp [Prevcoladdr],ebx + je .samecolor + mov [Prevcoladdr],ebx + push ecx + push eax + mov al,[coladdr] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[ngrposng] + xor ebx,ebx + shl ax,cl + add bx,ax + mov al,[coladdg] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[nggposng] + shl ax,cl + add bx,ax + mov al,[coladdb] + mov cl,[vidbright] + mul cl + mov cl,15 + div cl + xor ah,ah + mov cl,[ngbposng] + shl ax,cl + add bx,ax + mov [ColResult],bx + mov [ColResult+2],bx + pop eax + pop ecx +.samecolor + cmp word[ColResult],0 + je .black + cmp byte[FillSubScr+eax],0 + je .notblack + or byte[FillSubScr+eax],2 + jmp .notblack +.black + cmp byte[scrnon+1],0 + jne .notblack +; mov byte[clinemainsub],1 +; mov byte[scadtng+eax],0 +; mov byte[FillSubScr+eax],0 +.notblack + + + ; fill back area + ; get back window settings + mov dword[ngwinen],0 + push ecx + push edx + cmp byte[winbg1enval+eax+5*256],0 + je .nowindowb + mov bl,[winlogicb] + shr bl,2 + and bl,03h + mov [nglogicval],bl + mov ebx,5*256 + add ebx,eax + call BuildWindow2 +.nowindowb + mov dword[BackAreaAdd],0 + + cmp byte[clinemainsub],1 + jne near .domainscreen + mov ebx,[ColResult] + or ebx,[UnusedBit] + mov edx,[UnusedBit] + mov cl,[scaddset] +.filledscreen + ; get sub-screen colors + test cl,10h + jnz .inside + test cl,20h + jnz .outside +.insideb + mov dword[BackAreaUnFillCol],ebx + mov dword[BackAreaFillCol],ebx + jmp .donesubscreen +.inside + test cl,20h + jnz .filled + mov dword[BackAreaUnFillCol],edx + mov [BackAreaFillCol],ebx + jmp .donesubscreen +.outside + mov [BackAreaUnFillCol],ebx + mov dword[BackAreaFillCol],edx + jmp .donesubscreen +.filled + xor ebx,ebx + mov [BackAreaUnFillCol],edx + mov [BackAreaFillCol],edx + jmp .donesubscreen +.domainscreen + mov ebx,[vbufdptr] + add ebx,dword[cpalptrng] + xor edx,edx + mov cx,[ebx] + shl ecx,16 + mov cx,[ebx] + mov ebx,ecx + mov cl,[scaddset] + shr cl,2 + test byte[scaddtype],20h + jz .notaddbackub + or ebx,[UnusedBit] + mov edx,[UnusedBit] +.notaddbackub + jmp .filledscreen +.donesubscreen + cmp dword[ngwinen],0 + jne .nowinsc2 + mov edx,[BackAreaUnFillCol] + mov [BackAreaFillCol],edx +.nowinsc2 + cmp byte[forceblnk],0 + je .notforceblanked + mov dword[BackAreaUnFillCol],0 + mov dword[BackAreaFillCol],0 +.notforceblanked + call BackAreaFill + test byte[FillSubScr+eax],1 + jz near .nosubscreen2 + mov dword[BackAreaAdd],75036*2 + mov ebx,[ColResult] + mov edx,[UnusedBit] + test byte[scaddset],02h + jz .notbackfixed + or ebx,[UnusedBit] +.notbackfixed + mov cl,[scaddset] + ; get sub-screen colors + test cl,10h + jnz .inside2 + test cl,20h + jnz .outside2 +.inside2b + mov dword[BackAreaUnFillCol],ebx + mov dword[BackAreaFillCol],ebx + jmp .donesubscreen2 +.inside2 + test cl,20h + jnz .filled2 + mov dword[BackAreaUnFillCol],edx + mov [BackAreaFillCol],ebx + jmp .donesubscreen2 +.outside2 + mov [BackAreaUnFillCol],ebx + mov dword[BackAreaFillCol],edx + jmp .donesubscreen2 +.filled2 + xor ebx,ebx + mov [BackAreaUnFillCol],edx + mov [BackAreaFillCol],edx +.donesubscreen2 + cmp dword[ngwinen],0 + jne .nowinsc + mov edx,[BackAreaUnFillCol] + mov [BackAreaFillCol],edx +.nowinsc + call BackAreaFill +.nosubscreen2 + pop edx + pop ecx + + mov byte[SpecialLine+eax],0 + cmp byte[smallscreenon],1 + je .nomode7hr + cmp byte[ScreenScale],1 + je .nomode7hr + cmp byte[scanlines],0 + jne .nomode7hr + cmp byte[bgmode],7 + jb .hrstuff + test byte[interlval],40h + jnz .nomode7hr + cmp byte[Mode7HiRes16b],1 + jne .nomode7hr + jmp .hrstuff +.nomode7hr + jmp .no512 +.hrstuff + cmp byte[res640],0 + je near .no512 + cmp byte[bgmode],5 + jb .no512 + mov byte[SpecialLine+eax],3 + cmp byte[bgmode],7 + je .hires + mov byte[SpecialLine+eax],2 +.hires + mov byte[hiresstuff],1 + push edi + push esi + push eax + push ecx + push eax + mov ebx,eax + mov edi,[vidbuffer] + add edi,16*2 + shl eax,9 + add edi,eax + mov eax,ebx + shl eax,6 + add edi,eax + mov esi,edi + add edi,75036*4 + push esi + mov ecx,128 + rep movsd + pop esi + pop eax + test byte[FillSubScr+eax],1 + jz .nosubscreenhires + add esi,75036*2 + mov edi,esi + add edi,75036*4 + mov ecx,128 + rep movsd +.nosubscreenhires + pop ecx + pop eax + pop esi + pop edi +.no512 + + cmp byte[scanlines],0 + jne .notinterl + test byte[interlval],1 + jz .notinterl + or byte[SpecialLine+eax],4 +.notinterl + + mov ebx,dword[sprleftpr+eax*4] + cmp ebx,00000001h + je .single + cmp ebx,00000100h + je .single + cmp ebx,00010000h + je .single + cmp ebx,01000000h + je .single + or [sprprdrn],ebx + xor ebx,ebx + ret +.single + or [sprprdrn],ebx + or dword[sprleftpr+eax*4],80000000h + xor ebx,ebx + ret + +ALIGN32 +NEWSYM ngwinenval, dd 0 +NEWSYM cdrawbuffer, dd 0 +NEWSYM draw16bnng, dd 0 +NEWSYM scaddsngb, dd 0 +NEWSYM scaddtngb, dd 0 +NEWSYM scaddtngbx, dd 0 +NEWSYM prevbcolng, dd 0 +NEWSYM bcolvalng, dd 0 +NEWSYM cebppos, dd 0 +NEWSYM subscreenonng, dd 0 +NEWSYM cdrawmeth, dd 0 +NEWSYM cpalptrng, dd 0 +NEWSYM prevcoladdrng, dd 0 +NEWSYM prevcolvalng, dd 0 +NEWSYM cbackofsaddr, dd 0 +NEWSYM cbackofsaddrs, dd 0 +NEWSYM cbackofsaddrm, dd 0 +NEWSYM subscrng, dd 0 +NEWSYM ngmsdraw, dd 0 +NEWSYM CMainWinScr, dd 0 +NEWSYM CSubWinScr, dd 0 +NEWSYM Prevcoladdr, dd 0 +NEWSYM ColResult, dd 0 +NEWSYM CPalPtrng, dd 0 +NEWSYM WindowRedraw, dd 0 +NEWSYM mostranspval, dd 0 +NEWSYM mosclineval, dd 0 +NEWSYM startlinet, dd 0 +NEWSYM endlinet, dd 0 +NEWSYM palchanged, dd 0 + +NEWSYM ng16bbgval, dd 0 ; bg # (mov dword[ng16bbgval],%1) +NEWSYM ng16bprval, dd 0 ; 0 = pr0, 2000h = pr1 + +NEWSYM mosjmptab16b, times 15 dd 0 +NEWSYM mosjmptab16bt, times 15 dd 0 +NEWSYM mosjmptab16btms, times 15 dd 0 +NEWSYM mosjmptab16bntms, times 15 dd 0 + +NEWSYM StartDrawNewGfx16b + push edx + push esi + push edi + push ebp + mov byte[WindowRedraw],1 + sub dword[endlinet],8 + + ; Clear video memory +; mov edi,[vidbuffer] +; xor eax,eax +; add edi,32 +; mov dl,[resolutn] +;.loopa +; mov ecx,128 +; rep stosd +; add edi,64 +; dec dl +; jnz .loopa + + cmp dword[scfbl],0 + jne near .dontdraw + + ; Sprite Layering : + ; Mode 0/1 - BG4/BG3pr0 * BG4/BG3pr1 * BG2/BG1pr0 * BG2/BG1pr0 * BG3pr1 + ; Mode 2-6 - BG2pr0 * BG1pr0 * BG2pr1 * BG1pr1 * + ; Mode 7 - * BG1pr0 * BG1pr1 * * + + ; Copy data to sprite table + mov ecx,256 + mov eax,[spritetablea] + mov ebx,sprlefttot + mov edi,sprtbng +.loop + mov [edi],eax + add eax,512 + inc ebx + add edi,4 + dec ecx + jnz .loop + + xor eax,eax + mov edi,sprtlng + mov ecx,64 + rep stosd + + mov byte[firstdrawn],1 + mov dword[bg1totng],0 + mov dword[bg2totng],0 + mov dword[bg3totng],0 + mov dword[bg4totng],0 + mov dword[bg1drwng],0 + mov dword[bg2drwng],0 + mov dword[bg3drwng],0 + mov dword[bg4drwng],0 + + cmp byte[ngmsdraw],0 + je near .skipallsub + + mov dword[CMainWinScr],winbg1envals + mov dword[CSubWinScr],winbg1envals + mov dword[subscrng],1 + + ; Draw SubScreens + test byte[scrndis],8h + jnz near .nodobg4s + test dword[bgcmsung],800h + jz near .nodobg4s + mov dword[mode0ads],60606060h + Procbgpr016b 3, drawbg4line16b, drawbg4tile16b, ngsub, 8h +.nodobg4s + test byte[scrndis],4h + jnz near .nodobg3s + test dword[bgcmsung],400h + jz near .nodobg3s + mov dword[mode0ads],40404040h + Procbg3pr016b 2, drawbg3line16b, drawbg3tile16b, ngsub, 4h +.nodobg3s + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprpra + test dword[modeused],00000101h + jz near .nosprpra + test dword[bgcmsung],1000h + jz near .nosprpra + Procsprng0116b ngsub, 10h +.nosprpra + + test byte[scrndis],8h + jnz near .nodobg4sb + test dword[bgcmsung],800h + jz near .nodobg4sb + mov eax,[bg4totng] + cmp eax,[bg4drwng] + je near .nodobg4sb + mov dword[mode0ads],60606060h + Procbgpr116b 3, drawbg4linepr116b, drawbg4tilepr116b, prdata, ngsub, 8h +.nodobg4sb + test byte[scrndis],4h + jnz near .nodobg3sb + test dword[bgcmsung],400h + jz near .nodobg3sb + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3sb + mov dword[mode0ads],40404040h + Procbg3pr116b 2, drawbg3linepr116b, drawbg3tilepr116b, prdatc, ngsub, 4h +.nodobg3sb + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprprb + test dword[modeused],00000101h + jz near .nosprprb + test dword[bgcmsung],1000h + jz near .nosprprb + Procsprng0116b ngsub, 10h +.nosprprb + + test byte[scrndis],2h + jnz near .nodobg2s + test dword[bgcmsung],200h + jz near .nodobg2s + mov dword[mode0ads],20202020h + Procbgpr016b 1, drawbg2line16b, drawbg2tile16b, ngsub, 2h +.nodobg2s + + ; draw mode 7 extbg pr 0 + cmp byte[ngextbg],0 + je near .noextbgsc + test dword[bgcmsung],300h + jz near .noextbgsc + ProcMode7ngextbg16b ngsub, 1h +.noextbgsc + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprprc + test dword[modeused],01010000h + jnz near .yessprprc + test dword[modeused+4],01010101h + jz near .nosprprc +.yessprprc + test dword[bgcmsung],1000h + jz near .nosprprc + Procsprng23456716b ngsub, 10h +.nosprprc + + test byte[scrndis],1h + jnz near .nodobg1s + test dword[bgcmsung],100h + jz near .nodobg1s + mov dword[mode0ads],00000000h + Procbgpr016b 0, drawbg1line16b, drawbg1tile16b, ngsub, 1h +.nodobg1s + + ; draw mode 7, priority 0 + cmp byte[modeused+7],0 + je near .nomode7 + test dword[bgcmsung],300h + jz near .nomode7 + ProcMode7ng16b ngsub, 1h +.nomode7 + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprd + test dword[bgcmsung],1000h + jz near .nosprprd + Procsprng16b ngsub, 10h +.nosprprd + + test byte[scrndis],2h + jnz near .nodobg2sb + test dword[bgcmsung],200h + jz near .nodobg2sb + mov eax,[bg2totng] + cmp eax,[bg2drwng] + je near .nodobg2sb + mov dword[mode0ads],20202020h + Procbgpr116b 1, drawbg2linepr116b, drawbg2tilepr116b, prdata, ngsub, 2h +.nodobg2sb + + ; draw mode 7 extbg pr 1 + cmp byte[ngextbg],0 + je near .noextbgscb + test dword[bgcmsung],300h + jz near .noextbgscb + ProcMode7ngextbg216b ngsub, 2h +.noextbgscb + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprpre + test dword[modeused],01010000h + jnz near .yessprpre + test dword[modeused+4],01010101h + jz near .nosprpre +.yessprpre + test dword[bgcmsung],1000h + jz near .nosprpre + Procsprng23456716b ngsub, 10h +.nosprpre + + test byte[scrndis],1h + jnz near .nodobg1sb + test dword[bgcmsung],100h + jz near .nodobg1sb + mov eax,[bg1totng] + cmp eax,[bg1drwng] + je near .nodobg1sb + mov dword[mode0ads],00000000h + Procbgpr116b 0, drawbg1linepr116b, drawbg1tilepr116b, prdatb, ngsub, 1h +.nodobg1sb + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprf + test dword[bgcmsung],1000h + jz near .nosprprf + Procsprng16b ngsub, 10h +.nosprprf + + test byte[scrndis],4h + jnz near .nodobg3sb2 + cmp byte[modeused+1],0 + je near .nodobg3sb2 + test dword[bgcmsung],400h + jz near .nodobg3sb2 + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3sb2 + mov dword[mode0ads],40404040h + Procbg3pr1b16b 2, drawbg3linepr116b, drawbg3tilepr116b, prdatc, ngsub, 4h +.nodobg3sb2 + + mov dword[bg1totng],0 + mov dword[bg2totng],0 + mov dword[bg3totng],0 + mov dword[bg4totng],0 + mov dword[bg1drwng],0 + mov dword[bg2drwng],0 + mov dword[bg3drwng],0 + mov dword[bg4drwng],0 + +.skipallsub + mov dword[CMainWinScr],winbg1envalm + mov dword[CSubWinScr],winbg1envals + mov dword[subscrng],0 + + ; Draw MainScreens + test byte[scrndis],8h + jnz near .nodobg4m + test dword[bgcmsung],808h + jz near .nodobg4m + mov dword[mode0ads],60606060h + Procbgpr016b 3, drawbg4line16b, drawbg4tile16b, ngmain, 8h +.nodobg4m + test byte[scrndis],4h + jnz near .nodobg3m + test dword[bgcmsung],404h + jz near .nodobg3m + mov dword[mode0ads],40404040h + Procbg3pr016b 2, drawbg3line16b, drawbg3tile16b, ngmain, 4h +.nodobg3m + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprprma + test dword[modeused],00000101h + jz near .nosprprma + test dword[bgcmsung],1010h + jz near .nosprprma + Procsprng0116b ngmain, 10h +.nosprprma + + test byte[scrndis],8h + jnz near .nodobg4mb + test dword[bgcmsung],808h + jz near .nodobg4mb + mov eax,[bg4totng] + cmp eax,[bg4drwng] + je near .nodobg4mb + mov dword[mode0ads],60606060h + Procbgpr116b 3, drawbg4linepr116b, drawbg4tilepr116b, prdata, ngmain, 8h +.nodobg4mb + test byte[scrndis],4h + jnz near .nodobg3mb + test dword[bgcmsung],4h + jz near .nodobg3mb + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3mb + mov dword[mode0ads],40404040h + Procbg3pr116b 2, drawbg3linepr116b, drawbg3tilepr116b, prdatc, ngmain, 4h +.nodobg3mb + + ; draw sprites mode 0-1 + test byte[scrndis],10h + jnz near .nosprprmb + test dword[modeused],00000101h + jz near .nosprprmb + test dword[bgcmsung],1010h + jz near .nosprprmb + Procsprng0116b ngmain, 10h +.nosprprmb + + test byte[scrndis],2h + jnz near .nodobg2m + test dword[bgcmsung],202h + jz near .nodobg2m + mov dword[mode0ads],20202020h + Procbgpr016b 1, drawbg2line16b, drawbg2tile16b, ngmain, 2h +.nodobg2m + + ; draw mode 7 extbg pr 0 + cmp byte[ngextbg],0 + je near .noextbgmn + test dword[bgcmsung],101h + jz near .noextbgmn + ProcMode7ngextbg16b ngmain ,1h +.noextbgmn + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprprmc + test dword[modeused],01010000h + jnz near .yessprprmc + test dword[modeused+4],01010101h + jz near .nosprprmc +.yessprprmc + test dword[bgcmsung],1010h + jz near .nosprprmc + Procsprng23456716b ngmain ,10h +.nosprprmc + + test byte[scrndis],1h + jnz near .nodobg1m + test dword[bgcmsung],101h + jz near .nodobg1m + mov dword[mode0ads],00000000h + Procbgpr016b 0, drawbg1line16b, drawbg1tile16b, ngmain, 1h +.nodobg1m + + ; draw mode 7, priority 0 + cmp byte[modeused+7],0 + je near .nomode7m + test dword[bgcmsung],101h + jz near .nomode7m + ProcMode7ng16b ngmain ,1h +.nomode7m + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprmd + test dword[bgcmsung],1010h + jz near .nosprprmd + Procsprng16b ngmain ,10h +.nosprprmd + + ; draw mode 7 extbg pr 1 + cmp byte[ngextbg],0 + je near .noextbgmn2 + test dword[bgcmsung],303h + jz near .noextbgmn2 + ProcMode7ngextbg216b ngmain ,2h +.noextbgmn2 + + test byte[scrndis],2h + jnz near .nodobg2mb + test dword[bgcmsung],202h + jz near .nodobg2mb + mov eax,[bg2totng] + cmp eax,[bg2drwng] + je near .nodobg2mb + mov dword[mode0ads],20202020h + Procbgpr116b 1, drawbg2linepr116b, drawbg2tilepr116b, prdata, ngmain, 2h +.nodobg2mb + + ; draw sprites mode 2-7 + test byte[scrndis],10h + jnz near .nosprprme + test dword[modeused],01010000h + jnz near .yessprprme + test dword[modeused+4],01010101h + jz near .nosprprme +.yessprprme + test dword[bgcmsung],1010h + jz near .nosprprme + Procsprng23456716b ngmain ,10h +.nosprprme + + test byte[scrndis],1h + jnz near .nodobg1mb + test dword[bgcmsung],101h + jz near .nodobg1mb + mov eax,[bg1totng] + cmp eax,[bg1drwng] + je near .nodobg1mb + mov dword[mode0ads],00000000h + Procbgpr116b 0, drawbg1linepr116b, drawbg1tilepr116b, prdatb, ngmain, 1h +.nodobg1mb + + ; draw sprites mode 0-7 + test byte[scrndis],10h + jnz near .nosprprmf + test dword[bgcmsung],1010h + jz near .nosprprmf + Procsprng16b ngmain, 10h +.nosprprmf + + test byte[scrndis],4h + jnz near .nodobg3mb2 + cmp byte[modeused+1],0 + je near .nodobg3mb2 + test dword[bgcmsung],404h + jz near .nodobg3mb2 + mov eax,[bg3totng] + cmp eax,[bg3drwng] + je near .nodobg3mb2 + mov dword[mode0ads],40404040h + Procbg3pr1b16b 2, drawbg3linepr116b, drawbg3tilepr116b, prdatc, ngmain, 4h +.nodobg3mb2 + call ProcessTransparencies +.dontdraw + xor ebx,ebx + xor ecx,ecx + xor eax,eax + pop ebp + pop edi + pop esi + pop edx + ret + + +NEWSYM domosaicng16b + mov esi,[pesimpng] + xor eax,eax + mov edi,xtravbuf+32 + mov al,[curmosaicsz] + cmp al,16 + ja .notokay + cmp al,1 + jbe .notokay + push esi + push ebx + mov ebx,[mosclineval] + mov cl,[mostranspval] + test byte[BGMS1+ebx*2],cl + jz .nosubmain + test byte[FillSubScr+ebx],1 + jnz .transpstuff + jmp .main +.nosubmain + test byte[FillSubScr+ebx],1 + jz .main + add esi,75036*2 +.main + pop ebx + jmp [mosjmptab16b+eax*4-8] + pop esi +.notokay + ret +.transpstuff + test byte[BGMS1+ebx*2+1],cl + jnz near .mosaicms + test byte[scadtng+ebx],cl + jz near .main + pop ebx + jmp [mosjmptab16bt+eax*4-8] + pop esi + ret +.mosaicms + test byte[scadtng+ebx],cl + jz near .mosaicmsnt + pop ebx + jmp [mosjmptab16btms+eax*4-8] + pop esi + ret +.mosaicmsnt + pop ebx + jmp [mosjmptab16bntms+eax*4-8] + pop esi + ret + +%macro mosaic2 1 + mov [esi+%1],ax + mov [esi+%1+2],ax +%endmacro +%macro mosaic3 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax +%endmacro +%macro mosaic4 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax +%endmacro +%macro mosaic5 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax +%endmacro +%macro mosaic6 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax +%endmacro +%macro mosaic7 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax +%endmacro +%macro mosaic8 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax +%endmacro +%macro mosaic9 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax +%endmacro +%macro mosaic10 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax +%endmacro +%macro mosaic11 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax + mov [esi+%1+20],ax +%endmacro +%macro mosaic12 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax + mov [esi+%1+20],ax + mov [esi+%1+22],ax +%endmacro +%macro mosaic13 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax + mov [esi+%1+20],ax + mov [esi+%1+22],ax + mov [esi+%1+24],ax +%endmacro +%macro mosaic14 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax + mov [esi+%1+20],ax + mov [esi+%1+22],ax + mov [esi+%1+24],ax + mov [esi+%1+26],ax +%endmacro +%macro mosaic15 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax + mov [esi+%1+20],ax + mov [esi+%1+22],ax + mov [esi+%1+24],ax + mov [esi+%1+26],ax + mov [esi+%1+28],ax +%endmacro +%macro mosaic16 1 + mov [esi+%1],ax + mov [esi+%1+2],ax + mov [esi+%1+4],ax + mov [esi+%1+6],ax + mov [esi+%1+8],ax + mov [esi+%1+10],ax + mov [esi+%1+12],ax + mov [esi+%1+14],ax + mov [esi+%1+16],ax + mov [esi+%1+18],ax + mov [esi+%1+20],ax + mov [esi+%1+22],ax + mov [esi+%1+24],ax + mov [esi+%1+26],ax + mov [esi+%1+28],ax + mov [esi+%1+30],ax +%endmacro + +%macro mosaicproc 3 + mov ecx,%1 +.next + mov ax,[edi] + cmp ax,0FFFFh + je .nodraw + %2 0 + mosender %3 +%endmacro + +%macro mosaicproct 3 + mov ecx,%1 +.next + mov ax,[edi] + cmp ax,0FFFFh + je .nodraw + or ax,[UnusedBit] + %2 0 + mosender %3 +%endmacro + +%macro mosaicprocntms 3 + mov ecx,%1 +.next + mov ax,[edi] + cmp ax,0FFFFh + je near .nodraw + %2 0 + %2 75036*2 + mosender %3 +%endmacro + +%macro mosaicproctms 3 + mov ecx,%1 +.next + mov ax,[edi] + cmp ax,0FFFFh + je near .nodraw + or ax,[UnusedBit] + %2 0 + and ax,[UnusedBit] + %2 75036*2 + mosender %3 +%endmacro + +NEWSYM mosdraw216b + mosaicproc 128,mosaic2,2 +NEWSYM mosdraw316b + mosaicproc 86,mosaic3,3 +NEWSYM mosdraw416b + mosaicproc 64,mosaic4,4 +NEWSYM mosdraw516b + mosaicproc 52,mosaic5,5 +NEWSYM mosdraw616b + mosaicproc 43,mosaic6,6 +NEWSYM mosdraw716b + mosaicproc 37,mosaic7,7 +NEWSYM mosdraw816b + mosaicproc 32,mosaic8,8 +NEWSYM mosdraw916b + mosaicproc 29,mosaic9,9 +NEWSYM mosdraw1016b + mosaicproc 26,mosaic10,10 +NEWSYM mosdraw1116b + mosaicproc 24,mosaic11,11 +NEWSYM mosdraw1216b + mosaicproc 22,mosaic12,12 +NEWSYM mosdraw1316b + mosaicproc 20,mosaic13,13 +NEWSYM mosdraw1416b + mosaicproc 19,mosaic14,14 +NEWSYM mosdraw1516b + mosaicproc 18,mosaic15,15 +NEWSYM mosdraw1616b + mosaicproc 16,mosaic16,16 + +NEWSYM mosdraw216bt + mosaicproct 128,mosaic2,2 +NEWSYM mosdraw316bt + mosaicproct 86,mosaic3,3 +NEWSYM mosdraw416bt + mosaicproct 64,mosaic4,4 +NEWSYM mosdraw516bt + mosaicproct 52,mosaic5,5 +NEWSYM mosdraw616bt + mosaicproct 43,mosaic6,6 +NEWSYM mosdraw716bt + mosaicproct 37,mosaic7,7 +NEWSYM mosdraw816bt + mosaicproct 32,mosaic8,8 +NEWSYM mosdraw916bt + mosaicproct 29,mosaic9,9 +NEWSYM mosdraw1016bt + mosaicproct 26,mosaic10,10 +NEWSYM mosdraw1116bt + mosaicproct 24,mosaic11,11 +NEWSYM mosdraw1216bt + mosaicproct 22,mosaic12,12 +NEWSYM mosdraw1316bt + mosaicproct 20,mosaic13,13 +NEWSYM mosdraw1416bt + mosaicproct 19,mosaic14,14 +NEWSYM mosdraw1516bt + mosaicproct 18,mosaic15,15 +NEWSYM mosdraw1616bt + mosaicproct 16,mosaic16,16 + +NEWSYM mosdraw216btms + mosaicproctms 128,mosaic2,2 +NEWSYM mosdraw316btms + mosaicproctms 86,mosaic3,3 +NEWSYM mosdraw416btms + mosaicproctms 64,mosaic4,4 +NEWSYM mosdraw516btms + mosaicproctms 52,mosaic5,5 +NEWSYM mosdraw616btms + mosaicproctms 43,mosaic6,6 +NEWSYM mosdraw716btms + mosaicproctms 37,mosaic7,7 +NEWSYM mosdraw816btms + mosaicproctms 32,mosaic8,8 +NEWSYM mosdraw916btms + mosaicproctms 29,mosaic9,9 +NEWSYM mosdraw1016btms + mosaicproctms 26,mosaic10,10 +NEWSYM mosdraw1116btms + mosaicproctms 24,mosaic11,11 +NEWSYM mosdraw1216btms + mosaicproctms 22,mosaic12,12 +NEWSYM mosdraw1316btms + mosaicproctms 20,mosaic13,13 +NEWSYM mosdraw1416btms + mosaicproctms 19,mosaic14,14 +NEWSYM mosdraw1516btms + mosaicproctms 18,mosaic15,15 +NEWSYM mosdraw1616btms + mosaicproctms 16,mosaic16,16 + +NEWSYM mosdraw216bntms + mosaicprocntms 128,mosaic2,2 +NEWSYM mosdraw316bntms + mosaicprocntms 86,mosaic3,3 +NEWSYM mosdraw416bntms + mosaicprocntms 64,mosaic4,4 +NEWSYM mosdraw516bntms + mosaicprocntms 52,mosaic5,5 +NEWSYM mosdraw616bntms + mosaicprocntms 43,mosaic6,6 +NEWSYM mosdraw716bntms + mosaicprocntms 37,mosaic7,7 +NEWSYM mosdraw816bntms + mosaicprocntms 32,mosaic8,8 +NEWSYM mosdraw916bntms + mosaicprocntms 29,mosaic9,9 +NEWSYM mosdraw1016bntms + mosaicprocntms 26,mosaic10,10 +NEWSYM mosdraw1116bntms + mosaicprocntms 24,mosaic11,11 +NEWSYM mosdraw1216bntms + mosaicprocntms 22,mosaic12,12 +NEWSYM mosdraw1316bntms + mosaicprocntms 20,mosaic13,13 +NEWSYM mosdraw1416bntms + mosaicprocntms 19,mosaic14,14 +NEWSYM mosdraw1516bntms + mosaicprocntms 18,mosaic15,15 +NEWSYM mosdraw1616bntms + mosaicprocntms 16,mosaic16,16 + + +NEWSYM drawbg1tile16b + mov byte[prdatb+ebx],1 + drawbgtileng16b 0,0 + ret + +NEWSYM drawbg2tile16b + mov byte[prdata+ebx],1 + drawbgtileng16b 1,1 + ret + +NEWSYM drawbg3tile16b + mov byte[prdatc+ebx],1 + drawbgtileng16b 2,2 + ret + +NEWSYM drawbg4tile16b + mov byte[prdata+ebx],1 + drawbgtileng16b 3,1 + ret + +NEWSYM drawbg1tilepr116b + drawbgtilengpr116b 0,0 + ret + +NEWSYM drawbg2tilepr116b + drawbgtilengpr116b 1,1 + ret + +NEWSYM drawbg3tilepr116b + drawbgtilengpr116b 2,2 + ret + +NEWSYM drawbg4tilepr116b + drawbgtilengpr116b 3,1 + ret + +NEWSYM drawbg1line16b + mov byte[prdatb+ebx],0 + drawbglineng16b 0,0 + +NEWSYM drawbg2line16b + mov byte[prdata+ebx],0 + drawbglineng16b 1,1 + +NEWSYM drawbg3line16b + mov byte[prdatc+ebx],0 + drawbglineng16b 2,2 + +NEWSYM drawbg4line16b + mov byte[prdata+ebx],0 + drawbglineng16b 3,1 + +NEWSYM drawbg1linepr116b + drawbglinengpr116b 0,0 + +NEWSYM drawbg2linepr116b + drawbglinengpr116b 1,1 + +NEWSYM drawbg3linepr116b + drawbglinengpr116b 2,2 + +NEWSYM drawbg4linepr116b + drawbglinengpr116b 3,1 + +%macro normalsprng16b 2 + test dword[sprleftpr+ebx*4],80000000h + jnz near .drawsingle + push esi + push ebx + add edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa16b %1 + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov ch,[esi+6] + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf16b %1 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + pop ebx + pop esi + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec cl + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + pop ebx + pop esi + ret + +.drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,ecx + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa16b %2 + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + pop ebx + pop esi + ret +.drawspriteflipx2 + mov bx,[esi] + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf16b %2 + sub edx,8 + mov esi,edx + dec cl + jnz near .loopobj2 + pop ebx + pop esi + ret +%endmacro + + +%macro normalwsprng16b 2 +; cmp byte[winbg1enval+eax+4*256],0 +; je near .skipobjw +;NEWSYM objclineptr, times 256 dd 0 ; l1,r1,l2,r2,en,log,ptr + xor eax,eax + mov [NGNumSpr],cl + mov ecx,[objclineptr+ebx*4] + add ecx,[ngwinptr] + test dword[sprleftpr+ebx*4],80000000h + jnz near .drawsingle + push esi + push ebx + add edi,esi + mov esi,[sprtbng+ebx*4] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push edx + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notprio + mov dh,[esi+6] + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa16b %1 + pop edx +.nodrawspr + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + ret +.drawspriteflipx + mov bx,[esi] + push edx + mov dl,[esi+7] + and edx,03h + cmp edx,[csprival] + jne near .notpriof + mov dh,[esi+6] + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf16b %1 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + pop ebx + pop esi + xor ecx,ecx + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop edx + add edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + pop ebx + pop esi + xor ecx,ecx + xor ecx,ecx + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + pop ebx + pop esi + ret + +.drawsingle + push esi + push ebx + mov edi,esi + mov esi,[sprtbng+ebx*4] + xor edx,edx + mov dl,[NGNumSpr] + and edx,0FFh + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + push edx + mov bx,[esi] + mov dh,[esi+6] + mov esi,[esi+2] + sprdrawa16b %2 + pop edx + sub edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj2 + pop ebx + pop esi + xor ecx,ecx + ret +.drawspriteflipx2 + push edx + mov bx,[esi] + mov dh,[esi+6] + mov esi,[esi+2] + sprdrawaf16b %2 + pop edx + sub edx,8 + mov esi,edx + dec byte[NGNumSpr] + jnz near .loopobj2 + pop ebx + pop esi + xor ecx,ecx + ret +%endmacro + +; FillSubScr bit 0 sets to 1 if there is no subscreen present +; ms,wms,wm,ws +; FillSubScr scadtng +NEWSYM drawsprng16b + test byte[BGMS1+ebx*2],10h + jz .nosubmain + test byte[FillSubScr+ebx],1 + jnz near drawsprng16bt +.nosubmain + mov ebp,[cpalval+ebx*4] + xor eax,eax + mov edi,[CMainWinScr] + test byte[FillSubScr+ebx],1 + jz .main2 + test byte[BGMS1+ebx*2],10h + jnz .main2 + mov edi,[CSubWinScr] +.main2 + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16b + test byte[FillSubScr+ebx],1 + jz .main + test byte[BGMS1+ebx*2],10h + jnz .main + add esi,75036*2 +.main + xor edi,edi + normalsprng16b sprdrawpra16bng,sprdrawprb16bng +NEWSYM drawsprngw16b + xor edi,edi + test byte[FillSubScr+ebx],1 + jz .main + test byte[BGMS1+ebx*2],10h + jnz .main + add esi,75036*2 +.main + normalwsprng16b sprdrawprawb16bng,sprdrawprbwb16bng + +drawsprng16bt: + test byte[scadtng+ebx],10h + jz near drawsprng16bnt + mov ebp,[cpalval+ebx*4] + xor eax,eax + test byte[BGMS1+ebx*2+1],10h + jnz near drawsprng16bmst + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bt + xor edi,edi + normalsprng16b sprdrawpra16bngt,sprdrawprb16bngt +NEWSYM drawsprngw16bt + xor edi,edi + normalwsprng16b sprdrawprawb16bngt,sprdrawprbwb16bngt +drawsprng16bmst: + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmt + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bst + xor edi,edi + normalsprng16b sprdrawpra16bngmst,sprdrawprb16bngmst +drawsprngw16bst: + xor edi,edi + normalwsprng16b sprdrawprawb16bngst,sprdrawprbwb16bngst +drawsprngw16bmt: + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmst + xor edi,edi + normalwsprng16b sprdrawprawb16bngmt,sprdrawprbwb16bngmt +drawsprngw16bmst: + xor edi,edi + normalwsprng16b sprdrawprawb16bngmst,sprdrawprbwb16bngmst + +drawsprng16bnt: + mov ebp,[cpalval+ebx*4] + xor eax,eax + test byte[BGMS1+ebx*2+1],10h + jnz near drawsprng16bmsnt + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16b + xor edi,edi + normalsprng16b sprdrawpra16bngnt,sprdrawprb16bngnt +drawsprngw16bnt + xor edi,edi + normalwsprng16b sprdrawprawb16bngnt,sprdrawprbwb16bngnt +drawsprng16bmsnt: + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmnt + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bsnt + xor edi,edi + normalsprng16b sprdrawpra16bngmsnt,sprdrawprb16bngmsnt +drawsprngw16bsnt: + xor edi,edi + normalwsprng16b sprdrawprawb16bngsnt,sprdrawprbwb16bngsnt +drawsprngw16bmnt: + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmsnt + xor edi,edi + normalwsprng16b sprdrawprawb16bngmnt,sprdrawprbwb16bngmnt +drawsprngw16bmsnt: + xor edi,edi + normalwsprng16b sprdrawprawb16bngmsnt,sprdrawprbwb16bngmsnt + +NEWSYM drawsprng16bhr + test byte[BGMS1+ebx*2],10h + jz .nosubmain + test byte[FillSubScr+ebx],1 + jnz near drawsprng16bthr +.nosubmain + mov ebp,[cpalval+ebx*4] + xor eax,eax + mov edi,[CMainWinScr] + test byte[FillSubScr+ebx],1 + jz .main2 + test byte[BGMS1+ebx*2],10h + jnz .main2 + mov edi,[CSubWinScr] +.main2 + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bhr + test byte[FillSubScr+ebx],1 + jz .main + test byte[BGMS1+ebx*2],10h + jnz .main + add esi,75036*2 +.main + xor edi,edi + normalsprng16b sprdrawpra16bnghr,sprdrawprb16bnghr +NEWSYM drawsprngw16bhr + xor edi,edi + test byte[FillSubScr+ebx],1 + jz .main + test byte[BGMS1+ebx*2],10h + jnz .main + add esi,75036*2 +.main + normalwsprng16b sprdrawprawb16bnghr,sprdrawprbwb16bnghr +drawsprng16bthr: + test byte[scadtng+ebx],10h + jz near drawsprng16bnthr + mov ebp,[cpalval+ebx*4] + xor eax,eax + test byte[BGMS1+ebx*2+1],10h + jnz near drawsprng16bmsthr + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bthr + xor edi,edi + normalsprng16b sprdrawpra16bngthr,sprdrawprb16bngthr +NEWSYM drawsprngw16bthr + xor edi,edi + normalwsprng16b sprdrawprawb16bngthr,sprdrawprbwb16bngthr +drawsprng16bmsthr: + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmthr + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bsthr + xor edi,edi + normalsprng16b sprdrawpra16bngmsthr,sprdrawprb16bngmsthr +drawsprngw16bsthr: + xor edi,edi + normalwsprng16b sprdrawprawb16bngsthr,sprdrawprbwb16bngsthr +drawsprngw16bmthr: + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmsthr + xor edi,edi + normalwsprng16b sprdrawprawb16bngmthr,sprdrawprbwb16bngmthr +drawsprngw16bmsthr: + xor edi,edi + normalwsprng16b sprdrawprawb16bngmsthr,sprdrawprbwb16bngmsthr +drawsprng16bnthr: + mov ebp,[cpalval+ebx*4] + xor eax,eax + test byte[BGMS1+ebx*2+1],10h + jnz near drawsprng16bmsnthr + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bhr + xor edi,edi + normalsprng16b sprdrawpra16bngnthr,sprdrawprb16bngnthr +drawsprngw16bnthr + xor edi,edi + normalwsprng16b sprdrawprawb16bngnthr,sprdrawprbwb16bngnthr +drawsprng16bmsnthr: + mov edi,[CMainWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmnthr + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bsnthr + xor edi,edi + normalsprng16b sprdrawpra16bngmsnthr,sprdrawprb16bngmsnthr +drawsprngw16bsnthr: + xor edi,edi + normalwsprng16b sprdrawprawb16bngsnthr,sprdrawprbwb16bngsnthr +drawsprngw16bmnthr: + mov edi,[CSubWinScr] + cmp byte[edi+ebx+4*256],0 + jne near drawsprngw16bmsnthr + xor edi,edi + normalwsprng16b sprdrawprawb16bngmnthr,sprdrawprbwb16bngmnthr +drawsprngw16bmsnthr: + xor edi,edi + normalwsprng16b sprdrawprawb16bngmsnthr,sprdrawprbwb16bngmsnthr + + +ProcessTransparencies: + cmp byte[NGNoTransp],0 + je .yestransp + ret +.yestransp + cmp byte[FPUCopy],2 + je near ProcessTransparenciesMMX + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,1 +.nextline + test byte[FillSubScr+ebx],1 + jz near .notransp + mov dword[HiResDone],0 +.againtransp + test byte[scadtng+ebx],40h + jz near .fulltransp + test byte[scadtng+ebx],80h + jnz near .subtract + + ; Half Add + push esi + push ebx + ; filter out all fixed color sub-screen + test byte[FillSubScr+ebx],2 + jnz .halfaddcomb + mov ecx,256 + mov ebx,[UnusedBit] + mov edi,[HalfTrans] + xor eax,eax + jmp .next2 +.notranspha + add esi,2 + dec ecx + jz .done +.next2 + mov ax,[esi] + test ax,bx + jz .notranspha + mov dx,[esi+75036*2] + test dx,bx + jnz .notranspha + and eax,edi + and edx,edi + add eax,edx + shr eax,1 + mov [esi],ax + add esi,2 + loop .next2 +.done + pop ebx + pop esi + jmp .donetransp +.halfaddcomb + mov ecx,256 + mov ebx,[UnusedBit] + mov edi,[HalfTrans] + xor eax,eax + xor edx,edx + jmp .next2c +.notransphac + add esi,2 + dec ecx + jz .donec +.next2c + mov ax,[esi] + test ax,bx + jz .notransphac + mov dx,[esi+75036*2] + test dx,bx + jnz .fulladdtranspc + and eax,edi + and edx,edi + add eax,edx + shr eax,1 + mov [esi],ax + add esi,2 + loop .next2c +.donec + pop ebx + pop esi + jmp .donetransp +.fulladdtranspc + and eax,edi + and edx,edi + add eax,edx + shr eax,1 + mov ax,[fulladdtab+eax*2] + mov [esi],ax + add esi,2 + loop .next2c + pop ebx + pop esi + jmp .donetransp + +.subtract + push ebx + push esi + ; half adder + mov ecx,256 + mov ebp,[HalfTrans] + xor edx,edx + mov bx,[UnusedBit] +.nextfshs + mov ax,[esi] + test ax,bx + je .notranspfshs + mov dx,[esi+75036*2] + xor ax,0FFFFh + and edx,ebp + and eax,ebp + add edx,eax + shr edx,1 + mov dx,[fulladdtab+edx*2] + xor dx,0FFFFh + test word[esi+75036*2],bx + jnz .nothalfhs + and edx,ebp + shr edx,1 +.nothalfhs + mov [esi],dx +.notranspfshs + add esi,2 + loop .nextfshs + pop esi + pop ebx + jmp .donetransp +.fulltransp + test byte[scadtng+ebx],80h + jnz near .fullsubtract + push ebx + push esi + mov ecx,256 + mov ebp,[HalfTrans] + xor edx,edx + xor eax,eax + mov bx,[UnusedBit] +.nextfa + mov ax,[esi] + test ax,bx + jz .notranspfa + mov dx,[esi+75036*2] + and eax,ebp + and edx,ebp + add edx,eax + shr edx,1 + mov dx,[fulladdtab+edx*2] + mov [esi],dx +.notranspfa + add esi,2 + loop .nextfa + pop esi + pop ebx + jmp .donetransp +.fullsubtract + push ebx + push esi + ; half adder + mov ecx,256 + mov ebp,[HalfTrans] + xor edx,edx + xor eax,eax + mov bx,[UnusedBit] +.nextfs + mov ax,[esi] + test ax,bx + jz .notranspfs + mov dx,[esi+75036*2] + xor ax,0FFFFh + and edx,ebp + and eax,ebp + add edx,eax + shr edx,1 + mov dx,[fulladdtab+edx*2] + xor dx,0FFFFh + mov [esi],dx +.notranspfs + add esi,2 + loop .nextfs + pop esi + pop ebx +.donetransp + test byte[SpecialLine+ebx],3 + jz .notransp + xor dword[HiResDone],1 + cmp dword[HiResDone],0 + je .okaytransp + add esi,75036*4 + jmp .againtransp +.okaytransp + sub esi,75036*4 +.notransp + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near .nextline + ret + +%macro TranspMMX 3 + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,1 +.nextline + test byte[FillSubScr+ebx],1 + jz near .notransp + mov dword[HiResDone],0 +.againtransp + test byte[scadtng+ebx],40h + jz near .fulltransp + test byte[scadtng+ebx],80h + jnz near .subtract + + ; Half Add + push esi + push ebx + ; filter out all fixed color sub-screen + mov ecx,64 + mov eax,[UnusedBit] +.faddl2h + test dword[esi],eax + jnz near .faddloopbh + test dword[esi+4],eax + jnz near .faddloopbh + add esi,8 + loop .faddl2h + jmp .faddloopdoneh +.prochalfadd + test dword[esi+75036*2],eax + jnz near .faddloopbh + test dword[esi+75036*2+4],eax + jnz near .faddloopbh + mov ebx,[esi] + and ebx,eax + cmp ebx,eax + jne near .faddlooph + mov ebx,[esi+4] + and ebx,eax + cmp ebx,eax + jne near .faddlooph +.prochalfadddo + movq mm0,[esi] + movq mm1,[esi+75036*2] + pand mm0,[HalfTrans] + pand mm1,[HalfTrans] + psrlw mm0,1 + psrlw mm1,1 + paddw mm0,mm1 + movq [esi],mm0 + add esi,8 + loop .prochalfadd + jmp .faddloopdoneh +.procfulladd + mov ebx,[esi] + and ebx,eax + cmp ebx,eax + jne near .faddlooph + mov ebx,[esi+4] + and ebx,eax + cmp ebx,eax + jne near .faddlooph + mov ebx,[esi+75036*2] + and ebx,eax + cmp ebx,eax + jne near .faddlooph + mov ebx,[esi+75036*2+4] + and ebx,eax + cmp ebx,eax + jne near .faddlooph +.procfulladddo + movq mm0,[esi] + movq mm1,[esi+75036*2] + pand mm0,[UnusedBitXor] + movq mm2,mm0 + movq mm4,mm1 + movq mm3,mm0 + %if %1>0 + psllw mm0,%1 + psllw mm1,%1 + %endif + paddusw mm0,mm1 + pand mm0,[FullBitAnd] + movq mm1,mm4 + %if %1>0 + psrlw mm0,%1 + %endif + psllw mm2,%2 + psllw mm1,%2 + paddusw mm2,mm1 + pand mm2,[FullBitAnd] + psrlw mm2,%2 + psllw mm3,%3 + psllw mm4,%3 + paddusw mm3,mm4 + pand mm3,[FullBitAnd] + psrlw mm3,%3 + por mm0,mm3 + por mm0,mm2 + movq [esi],mm0 + add esi,8 + dec ecx + jnz near .procfulladd + jmp .faddloopdoneh +.faddlooph + mov ebx,dword[esi] + test ebx,eax + jz near .faddl2h + and ebx,eax + cmp ebx,eax + jne .faddloopbh + mov ebx,dword[esi+4] + and ebx,eax + cmp ebx,eax + jne .faddloopbh + mov ebx,[esi+75036*2] + and ebx,eax + or ebx,ebx + jz .faddla + cmp ebx,eax + jne .faddloopbh + mov ebx,[esi+75036*2+4] + and ebx,eax + cmp ebx,eax + jne .faddloopbh + jmp .procfulladddo +.faddla + test dword[esi+75036*2+4],eax + jz near .prochalfadddo +.faddloopbh + movq mm0,[esi] + movq mm5,mm0 + movq mm6,mm0 + pand mm5,[UnusedBitXor] + movq mm1,[esi+75036*2] + movq mm7,mm1 + movq mm2,mm0 + pand mm1,[UnusedBitXor] + movq mm3,mm0 + movq mm4,mm1 + %if %1>0 + psllw mm0,%1 + psllw mm1,%1 + %endif + paddusw mm0,mm1 + pand mm0,[FullBitAnd] + movq mm1,mm4 + %if %1>0 + psrlw mm0,%1 + %endif + psllw mm2,%2 + psllw mm1,%2 + paddusw mm2,mm1 + pand mm2,[FullBitAnd] + movq mm1,mm4 + psrlw mm2,%2 + psllw mm3,%3 + psllw mm1,%3 + paddusw mm3,mm1 + pand mm3,[FullBitAnd] + psrlw mm3,%3 + por mm0,mm3 + por mm0,mm2 + pand mm6,[UnusedBit] + pcmpeqw mm6,[UnusedBit] + pand mm0,mm6 + movq mm1,mm5 + pand mm1,mm6 + pand mm4,mm6 + pxor mm6,[UnusedBitXor] + pand mm5,mm6 + pand mm7,[UnusedBit] + pand mm4,[HalfTrans] + pand mm1,[HalfTrans] + psrlw mm1,1 + psrlw mm4,1 + paddw mm1,mm4 + pcmpeqw mm7,[UnusedBit] + pand mm0,mm7 + pxor mm7,[UnusedBitXor] + pand mm1,mm7 + por mm0,mm1 + por mm0,mm5 + movq [esi],mm0 + add esi,8 + dec ecx + jnz near .faddlooph +.faddloopdoneh + pop ebx + pop esi + jmp .donetransp + +.subtract + push ebx + push esi + mov ecx,64 + mov eax,[UnusedBit] +.fsubl2h + test dword[esi],eax + jnz .fsubloopbh + test dword[esi+4],eax + jnz .fsubloopbh + add esi,8 + loop .fsubl2h + jmp .fsubloopdoneh +.fsublooph + test dword[esi],eax + jz .fsubl2h +.fsubloopbh + movq mm0,[esi] + movq mm5,mm0 + movq mm6,mm0 + pxor mm0,[UnusedBitXor] + pand mm5,[UnusedBitXor] + movq mm1,[esi+75036*2] + movq mm7,mm1 + movq mm2,mm0 + pand mm1,[UnusedBitXor] + movq mm3,mm0 + movq mm4,mm1 + %if %1>0 + psllw mm0,%1 + psllw mm1,%1 + %endif + paddusw mm0,mm1 + pand mm0,[FullBitAnd] + movq mm1,mm4 + %if %1>0 + psrlw mm0,%1 + %endif + psllw mm2,%2 + psllw mm1,%2 + paddusw mm2,mm1 + pand mm2,[FullBitAnd] + psrlw mm2,%2 + psllw mm3,%3 + psllw mm4,%3 + paddusw mm3,mm4 + pand mm3,[FullBitAnd] + psrlw mm3,%3 + por mm0,mm3 + por mm0,mm2 + pand mm6,[UnusedBit] + pxor mm0,[UnusedBitXor] + pcmpeqw mm6,[UnusedBit] + pand mm0,mm6 + pxor mm6,[UnusedBitXor] + pand mm5,mm6 + pand mm7,[UnusedBit] + movq mm1,mm0 + pand mm1,[HalfTrans] + psrlw mm1,1 + pcmpeqw mm7,[UnusedBit] + pand mm0,mm7 + pxor mm7,[UnusedBitXor] + pand mm1,mm7 + por mm0,mm1 + por mm0,mm5 + movq [esi],mm0 + add esi,8 + dec ecx + jnz near .fsublooph +.fsubloopdoneh + pop esi + pop ebx + jmp .donetransp + +.fulltransp + test byte[scadtng+ebx],80h + jnz near .fullsubtract + push ebx + push esi + mov ecx,64 + mov eax,[UnusedBit] +.faddl2 + test dword[esi],eax + jnz .faddloopb + test dword[esi+4],eax + jnz .faddloopb + add esi,8 + loop .faddl2 + jmp .faddloopdone +.faddloop + test dword[esi],eax + jz .faddl2 +.faddloopb + movq mm0,[esi] + movq mm1,[esi+75036*2] + movq mm6,mm0 + pand mm0,[UnusedBitXor] + movq mm2,mm0 + movq mm4,mm1 + movq mm3,mm0 + movq mm5,mm0 + %if %1>0 + psllw mm0,%1 + psllw mm1,%1 + %endif + paddusw mm0,mm1 + pand mm0,[FullBitAnd] + movq mm1,mm4 + %if %1>0 + psrlw mm0,%1 + %endif + psllw mm2,%2 + psllw mm1,%2 + paddusw mm2,mm1 + pand mm2,[FullBitAnd] + psrlw mm2,%2 + psllw mm3,%3 + psllw mm4,%3 + paddusw mm3,mm4 + pand mm3,[FullBitAnd] + psrlw mm3,%3 + por mm0,mm3 + por mm0,mm2 + pand mm6,[UnusedBit] + pcmpeqw mm6,[UnusedBit] + pand mm0,mm6 + pxor mm6,[UnusedBitXor] + pand mm5,mm6 + por mm0,mm5 + movq [esi],mm0 + add esi,8 + dec ecx + jnz near .faddloop +.faddloopdone + pop esi + pop ebx + jmp .donetransp +.fullsubtract + push ebx + push esi + mov ecx,64 + mov eax,[UnusedBit] +.fsubl2 + test dword[esi],eax + jnz .fsubloopb + test dword[esi+4],eax + jnz .fsubloopb + add esi,8 + loop .fsubl2 + jmp .fsubloopdone +.fsubloop + test dword[esi],eax + jz .fsubl2 +.fsubloopb + movq mm0,[esi] + movq mm5,mm0 + movq mm6,mm0 + pxor mm0,[UnusedBitXor] + pand mm5,[UnusedBitXor] + movq mm1,[esi+75036*2] + movq mm2,mm0 + pand mm1,[UnusedBitXor] + movq mm3,mm0 + movq mm4,mm1 + %if %1>0 + psllw mm0,%1 + psllw mm1,%1 + %endif + paddusw mm0,mm1 + pand mm0,[FullBitAnd] + movq mm1,mm4 + %if %1>0 + psrlw mm0,%1 + %endif + psllw mm2,%2 + psllw mm1,%2 + paddusw mm2,mm1 + pand mm2,[FullBitAnd] + psrlw mm2,%2 + psllw mm3,%3 + psllw mm4,%3 + paddusw mm3,mm4 + pand mm3,[FullBitAnd] + psrlw mm3,%3 + por mm0,mm3 + por mm0,mm2 + pand mm6,[UnusedBit] + pxor mm0,[UnusedBitXor] + pcmpeqw mm6,[UnusedBit] + pand mm0,mm6 + pxor mm6,[UnusedBitXor] + pand mm5,mm6 + por mm0,mm5 + movq [esi],mm0 + add esi,8 + dec ecx + jnz near .fsubloop +.fsubloopdone + pop esi + pop ebx +.donetransp + test byte[SpecialLine+ebx],3 + jz .notransp + xor dword[HiResDone],1 + cmp dword[HiResDone],0 + je .okaytransp + add esi,75036*4 + jmp .againtransp +.okaytransp + sub esi,75036*4 +.notransp + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near .nextline + emms + ret +%endmacro + +ProcessTransparenciesMMX: + cmp byte[ngrposng],10 + je near ProcessTransparenciesMMXargb + TranspMMX 0,5,11 +ProcessTransparenciesMMXargb + TranspMMX 1,6,11 + +; movq mm0,[esi] +; movq mm1,[esi+75036*2] +; movq mm2,mm0 +; movq mm4,mm1 +; movq mm3,mm0 +; movq mm5,mm0 +; movq mm6,mm0 +; ;psllw mm0,0 +; ;psllw mm1,0 +; paddusw mm0,mm1 +; pand mm6,[UnusedBitXor] +; pand mm0,[FullBitAnd] +; movq mm1,mm4 +; ;psrlw mm0,0 +; psllw mm2,5 +; psllw mm1,5 +; paddusw mm2,mm1 +; pand mm2,[FullBitAnd] +; psrlw mm2,5 +; psllw mm3,11 +; psllw mm4,11 +; paddusw mm3,mm4 +; pand mm3,[FullBitAnd] +; psrlw mm3,11 +; por mm0,mm3 +; por mm0,mm2 +; pand mm6,[UnusedBit] +; pcmpeqw mm6,[UnusedBit] +; pand mm0,mm6 +; pxor mm6,[UnusedBitXor] +; pand mm5,mm6 +; por mm0,mm5 +; movq [esi],mm0 + +; PADDUSW - Add Unsigned with Saturation on Word +; PAND (source can be a memory location) +; PANDN - bitwise AND NOT +; PCMPEQW - packed compare for equal, word +; PSLLW - Shift Left, Logical, Word +; PSRLW - Shirt Right, Logical +; POR + +ALIGN32 +NEWSYM UnusedBit, dd 00000000001000000000000000100000b,00000000001000000000000000100000b +NEWSYM HalfTrans, dd 11110111110111101111011111011110b,11110111110111101111011111011110b,0,0 +NEWSYM UnusedBitXor, dd 11111111110111111111111111011111b,11111111110111111111111111011111b +NEWSYM ngrposng, dd 11,0 +NEWSYM nggposng, dd 6,0 +NEWSYM ngbposng, dd 0,0 +NEWSYM HiResDone, dd 0,0 +NEWSYM FullBitAnd, dd 0F800F800h,0F800F800h +NEWSYM HalfTransB, dd 00001000010000010000100001000001b,00001000010000010000100001000001b +NEWSYM HalfTransC, dd 11110111100111101111011110011110b,11110111100111101111011110011110b +NEWSYM NGNoTransp, dd 0 + \ No newline at end of file diff --git a/zsnes/src/video/newgfx16.mac b/zsnes/src/video/newgfx16.mac new file mode 100644 index 00000000..8c004752 --- /dev/null +++ b/zsnes/src/video/newgfx16.mac @@ -0,0 +1,3762 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM mode7B, mode7D, processmode7hires16b, processmode7hires16bd +EXTSYM drawmode7ngextbg16b,drawmode7ngextbg216b +EXTSYM osm2dis + + + + + + +; drawtileng16b + +%macro ngsub 2 + test dword[BGMS1+ebx*2+1],%1 + jz near %2 + test dword[BGMS1+ebx*2],%1 + jnz near %2 + test byte[FillSubScr+ebx],1 + jnz near %2 +%endmacro + +%macro ngmain 2 + test dword[BGMS1+ebx*2],%1 + jnz %%yesmain + test byte[FillSubScr+ebx],1 + jz near %2 + test dword[BGMS1+ebx*2+1],%1 + jz near %2 +%%yesmain +%endmacro + +%macro sprdrawpra16bng 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bng 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bng 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bng 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpra16bngt 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2+512] + or byte[sprpriodata+ebx-%1+16],dl + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprb16bngt 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2+512] + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngt 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngt 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpra16bngmst 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2+512] + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bngmst 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2+512] + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngmst 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngmst 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngst 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngst 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprawb16bngmt 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + or ax,[UnusedBit] + mov [edi+ebx*2-%1*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngmt 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + or ax,[UnusedBit] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawpra16bngnt 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bngnt 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngnt 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngnt 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpra16bngmsnt 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bngmsnt 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngmsnt 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngmsnt 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngsnt 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2+75036*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngsnt 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2+75036*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprawb16bngmnt 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngmnt 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawpra216bng 1 + or al,al + jz %%skip + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawpra16bnghr 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bnghr 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bnghr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bnghr 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpra16bngthr 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2+512] + or byte[sprpriodata+ebx-%1+16],dl + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprb16bngthr 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2+512] + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngthr 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpra16bngmsthr 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2+512] + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bngmsthr 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2+512] + cmp ch,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngmsthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngmsthr 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngsthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngsthr 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2+512] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + and eax,[UnusedBitXor] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprawb16bngmthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + or ax,[UnusedBit] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngmthr 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + or ax,[UnusedBit] + cmp dh,128+64 + jae %%yestransp + and eax,[UnusedBitXor] +%%yestransp + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawpra16bngnthr 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bngnthr 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngnthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngnthr 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpra16bngmsnthr 1 + or al,al + jz %%skip + add al,ch + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb16bngmsnthr 1 + or al,al + jz %%skip + add al,ch + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngmsnthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbwb16bngmsnthr 1 + or al,al + jz %%skip + add al,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprawb16bngsnthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngsnthr 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprawb16bngmnthr 1 + or al,al + jz %%skip + add al,dh + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + or byte[sprpriodata+ebx-%1+16],dl + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawprbwb16bngmnthr 1 + or al,al + jz %%skip + add al,dh + mov ax,[ebp+eax*2] + mov [edi+ebx*2-%1*2+75036*2],ax + mov [edi+ebx*2-%1*2+75036*6],ax + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx*2-%1*2],ax + mov [edi+ebx*2-%1*2+75036*4],ax +%%skip + xor eax,eax +%endmacro + +%macro sprdrawpra216bnghr 1 + or al,al + jz %%skip + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro Procbgpr016b 5 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2 +; add esi,16*2+288*2 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + %4 %5, %%nogo + ; Check if at a tile alignment + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + test ecx,07h + jz %%tilecheck +%%proclinebyline + ; process line by line + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %2 + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tilecheck + cmp dword[startlinet],ebx + jae %%proclinebyline + cmp dword[endlinet],ebx + jbe %%proclinebyline + test dword[bgwinchange+ebx],0FFFFFF00h + jnz %%linebyline + test dword[bgwinchange+ebx+4],0FFFFFFFFh + jz %%tilebytile +%%linebyline + test dword[winbg1enval+ebx+%1*256],0A0A0A0Ah + jnz %%proclinebyline + test dword[winbg1enval+ebx+%1*256+4],0A0A0A0Ah + jnz %%proclinebyline +%%tilebytile + cmp ebx,[reslbyl] + jae %%proclinebyline + test dword[bgallchange+ebx],0FFFFFF00h + jnz %%proclinebyline + test dword[bgallchange+ebx+4],0FFFFFFFFh + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256],0FFFFFF00h + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256+4],0FFFFFFFFh + jnz near %%proclinebyline + cmp byte[BGMA+ebx],5 + jae near %%proclinebyline + cmp byte[BGMA+ebx],2 + je near %%proclinebyline + test dword[intrlng+ebx],01010101h + jnz near %%proclinebyline + test dword[intrlng+ebx+4],01010101h + jnz near %%proclinebyline + test byte[mosenng+ebx],1 << %1 + jnz %%mosaic +%%nomosaic + mov ax,[resolutn] + sub ax,8 + cmp bx,ax + jae near %%proclinebyline + push esi + call %3 + pop esi + add ebx,8 + add esi,288*2*8 + cmp [resolutn],bx + ja near %%nextline + jmp %%donextbg +%%mosaic + cmp byte[mosszng+ebx],0 + je %%nomosaic + jmp %%proclinebyline +%%donextbg +%endmacro + +%macro Procbg3pr016b 5 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + %4 %5, %%nogo + ; Check if at a tile alignment + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + test ecx,07h + jz %%tilecheck +%%proclinebyline + ; process line by line + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %2 + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tilecheck + cmp dword[startlinet],ebx + jae %%proclinebyline + cmp dword[endlinet],ebx + jbe %%proclinebyline + test dword[bgwinchange+ebx],0FFFFFF00h + jnz %%linebyline + test dword[bgwinchange+ebx+4],0FFFFFFFFh + jz %%tilebytile +%%linebyline + test dword[winbg1enval+ebx+%1*256],0A0A0A0Ah + jnz %%proclinebyline + test dword[winbg1enval+ebx+%1*256+4],0A0A0A0Ah + jnz %%proclinebyline +%%tilebytile + cmp ebx,[reslbyl] + jae %%proclinebyline + test dword[bgallchange+ebx],0FFFFFF00h + jnz %%proclinebyline + test dword[bgallchange+ebx+4],0FFFFFFFFh + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256],0FFFFFF00h + jnz near %%proclinebyline + test dword[bg1change+ebx+%1*256+4],0FFFFFFFFh + jnz near %%proclinebyline + mov eax,[BG3PRI+ebx] + cmp eax,[BG3PRI+ebx+4] + jne near %%proclinebyline + test dword[intrlng+ebx],01010101h + jnz near %%proclinebyline + test dword[intrlng+ebx+4],01010101h + jnz near %%proclinebyline + test byte[mosenng+ebx],1 << %1 + jnz %%mosaic +%%nomosaic + mov ax,[resolutn] + sub ax,8 + cmp bx,ax + jae near %%proclinebyline + push esi + call %3 + pop esi + add ebx,8 + add esi,288*8*2 + cmp [resolutn],bx + ja near %%nextline + jmp %%donextbg +%%mosaic + cmp byte[mosszng+ebx],0 + je %%nomosaic + jmp %%proclinebyline +%%donextbg +%endmacro + +%macro Procbgpr116b 6 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2 +; add esi,16*2+288*2 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + %5 %6, %%nogo + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %2 + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %3 + pop esi + add ebx,8 + add esi,288*2*8 + cmp [resolutn],bx + ja near %%nextline +%%donextbg +%endmacro + +%macro Procbg3pr116b 6 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + %5 %6, %%nogo + cmp byte[BGMA+ebx],1 + jne %%nomode1 + cmp byte[BG3PRI+ebx],0 + jne %%nogo +%%nomode1 + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %2 + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %3 + pop esi + add ebx,8 + add esi,288*2*8 + cmp [resolutn],bx + ja near %%nextline +%%donextbg +%endmacro + +%macro Procbg3pr1b16b 6 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + %5 %6, %%nogo + cmp byte[BGMA+ebx],1 + jne %%nogo + cmp byte[BG3PRI+ebx],0 + je %%nogo + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %2 + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + push esi + mov eax,[cpalval+ebx*4] + mov [CPalPtrng],eax + call %3 + pop esi + add ebx,8 + add esi,288*2*8 + cmp [resolutn],bx + ja near %%nextline +%%donextbg +%endmacro + +%macro Procsprng16b 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + %1 %2, %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + test byte[SpecialLine+ebx],2 + jnz %%hires + push esi + call drawsprng16b + pop esi + jmp %%nogo +%%hires + mov cl,byte[sprlefttot+ebx] + push esi + call drawsprng16bhr + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near %%nextline +%endmacro + +%macro Procsprng0116b 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + %1 %2, %%nogo + cmp byte[BGMA+ebx],1 + ja %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + test byte[SpecialLine+ebx],2 + jnz %%hires + push esi + call drawsprng16b + pop esi + jmp %%nogo +%%hires + mov cl,byte[sprlefttot+ebx] + push esi + call drawsprng16bhr + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near %%nextline +%endmacro + +%macro Procsprng23456716b 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + %1 %2, %%nogo + cmp byte[BGMA+ebx],1 + jbe %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + test byte[SpecialLine+ebx],2 + jnz %%hires + push esi + call drawsprng16b + pop esi + jmp %%nogo +%%hires + mov cl,byte[sprlefttot+ebx] + push esi + call drawsprng16bhr + pop esi +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near %%nextline +%endmacro + +%macro ProcMode7ng16b 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,[mode7A] + mov [Mode7BackA],ebx + mov ebx,[mode7C] + mov [Mode7BackC],ebx + mov ebx,[mode7X0] + mov [Mode7BackX0],ebx + mov bl,[mode7set] + mov [Mode7BackSet],ebx + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + test byte[intrlng+ebx],40h + jnz near %%nogo + %1 %2, %%nogo + push ebx + mov ebp,[cpalval+ebx*4] + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + pop ebx + push eax + push edx + push esi + push ebx + test byte[scadsng+ebx],1 + jnz %%directmode + push esi + push ebx + call drawmode7win16b + pop ebx + pop esi + jmp %%donemode7 +%%directmode + push esi + push ebx + call drawmode7win16bd + pop ebx + pop esi +%%donemode7 + pop ebx + pop esi + pop edx + pop eax + + cmp byte[Mode7HiRes16b],0 + je %%nogoc + cmp byte[scanlines],0 + jne %%nogoc + test byte[scadsng+ebx],1 + jnz %%directmodeb + call processmode7hires16b + jmp %%nogoc +%%directmodeb + call processmode7hires16bd +%%nogoc + +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near %%nextline + mov ebx,[Mode7BackA] + mov [mode7A],ebx + mov ebx,[Mode7BackC] + mov [mode7C],ebx + mov ebx,[Mode7BackX0] + mov [mode7X0],ebx + mov ebx,[Mode7BackSet] + mov [mode7set],bl +%endmacro + + +%macro ProcMode7ngextbg16b 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,[mode7A] + mov [Mode7BackA],ebx + mov ebx,[mode7C] + mov [Mode7BackC],ebx + mov ebx,[mode7X0] + mov [Mode7BackX0],ebx + mov bl,[mode7set] + mov [Mode7BackSet],ebx + mov ebx,1 +%%nextline + mov byte[esi-1],0 + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + %1 %2, %%nogo + test byte[intrlng+ebx],40h + jz near %%nogo + mov byte[esi-1],1 + push ebx + mov ebp,[cpalval+ebx*4] + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + push esi + call drawmode7ngextbg16b + pop esi + pop ebx +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near %%nextline + mov ebx,[Mode7BackA] + mov [mode7A],ebx + mov ebx,[Mode7BackC] + mov [mode7C],ebx + mov ebx,[Mode7BackX0] + mov [mode7X0],ebx + mov ebx,[Mode7BackSet] + mov [mode7set],bl +%endmacro + +%macro ProcMode7ngextbg216b 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16*2+288*2 + mov ebx,[mode7A] + mov [Mode7BackA],ebx + mov ebx,[mode7C] + mov [Mode7BackC],ebx + mov ebx,[mode7X0] + mov [Mode7BackX0],ebx + mov bl,[mode7set] + mov [Mode7BackSet],ebx + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + %1 %2, %%nogo + test byte[intrlng+ebx],40h + jz near %%nogo + + push ebx + mov ebp,[cpalval+ebx*4] + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + push esi + cmp byte[esi-1],1 + je %%drawb + call drawmode7ngextbg16b + jmp %%drawa +%%drawb + call drawmode7ngextbg216b +%%drawa + pop esi + pop ebx +%%nogo + inc ebx + add esi,288*2 + cmp [resolutn],bx + jne near %%nextline + mov ebx,[Mode7BackA] + mov [mode7A],ebx + mov ebx,[Mode7BackC] + mov [mode7C],ebx + mov ebx,[Mode7BackX0] + mov [mode7X0],ebx + mov ebx,[Mode7BackSet] + mov [mode7set],bl +%endmacro + +%macro preparet4ba 0 + shl cx,5 + add ecx,ecx + add ecx,[vcache4b] +%endmacro + +%macro preparet2ba 0 + shl cx,4 + shl ecx,2 + add ecx,[vcache2b] +%endmacro + +%macro preparet8ba 0 + shl cx,6 + add ecx,[vcache8b] +%endmacro + +%macro preparet2batile 0 + shl ecx,8 + add ecx,[vcache2bs] +%endmacro +%macro preparet4batile 0 + shl ecx,8 + add ecx,[vcache4bs] +%endmacro +%macro preparet8batile 0 + shl ecx,8 + add ecx,[vcache8bs] +%endmacro + +%macro test4ba 0 + and ecx,2047 + test dword[vidmemch4+ecx*2],0FFFFh +%endmacro + +%macro test2ba 0 + and ecx,4095 + add edx,dword[mode0add] + test dword[vidmemch2+ecx],0FFh +%endmacro + +%macro test8ba 0 + and ecx,1023 + test dword[vidmemch8+ecx*4],0FFFFFFFFh +%endmacro + +%macro tilenormal 2 + mov ebx,[ecx+%2] + mov [edi+%1],ebx + mov ebx,[ecx+%2+4] + mov [edi+%1+4],ebx + mov ebx,[ecx+%2+8] + mov [edi+%1+8],ebx + mov ebx,[ecx+%2+12] + mov [edi+%1+12],ebx +%endmacro + +%macro tilenormalb 1 + cmp word[ecx+%1],0FFFFh + je %%nott + mov bx,[ecx+%1] + mov [edi+%1],bx +%%nott +%endmacro + +%macro tilenormals 2 + mov ebx,[ecx+%2] + mov [edi+%1+75036*2],ebx + mov ebx,[ecx+%2+4] + mov [edi+%1+4+75036*2],ebx + mov ebx,[ecx+%2+8] + mov [edi+%1+8+75036*2],ebx + mov ebx,[ecx+%2+12] + mov [edi+%1+12+75036*2],ebx +%endmacro + +%macro tilenormalbs 1 + cmp word[ecx+%1],0FFFFh + je %%nott + mov bx,[ecx+%1] + mov [edi+%1+75036*2],bx +%%nott +%endmacro + +%macro tilenormalt 2 + mov ebx,[ecx+%2] + or ebx,[UnusedBit] + mov [edi+%1],ebx + mov ebx,[ecx+%2+4] + or ebx,[UnusedBit] + mov [edi+%1+4],ebx + mov ebx,[ecx+%2+8] + or ebx,[UnusedBit] + mov [edi+%1+8],ebx + mov ebx,[ecx+%2+12] + or ebx,[UnusedBit] + mov [edi+%1+12],ebx +%endmacro + +%macro tilenormalbt 1 + cmp word[ecx+%1],0FFFFh + je %%nott + mov bx,[ecx+%1] + or bx,[UnusedBit] + mov [edi+%1],bx +%%nott +%endmacro + +%macro tilenormalmsnt 2 + mov ebx,[ecx+%2] + mov [edi+%1],ebx + mov [edi+%1+75036*2],ebx + mov ebx,[ecx+%2+4] + mov [edi+%1+4],ebx + mov [edi+%1+4+75036*2],ebx + mov ebx,[ecx+%2+8] + mov [edi+%1+8],ebx + mov [edi+%1+8+75036*2],ebx + mov ebx,[ecx+%2+12] + mov [edi+%1+12],ebx + mov [edi+%1+12+75036*2],ebx +%endmacro + +%macro tilenormalbmsnt 1 + cmp word[ecx+%1],0FFFFh + je %%nott + mov bx,[ecx+%1] + mov [edi+%1],bx + mov [edi+%1+75036*2],bx +%%nott +%endmacro + +%macro tilenormalmst 2 + mov ebx,[ecx+%2] + mov [edi+%1+75036*2],ebx + or ebx,[UnusedBit] + mov [edi+%1],ebx + mov ebx,[ecx+%2+4] + mov [edi+%1+4+75036*2],ebx + or ebx,[UnusedBit] + mov [edi+%1+4],ebx + mov ebx,[ecx+%2+8] + mov [edi+%1+8+75036*2],ebx + or ebx,[UnusedBit] + mov [edi+%1+8],ebx + mov ebx,[ecx+%2+12] + mov [edi+%1+12+75036*2],ebx + or ebx,[UnusedBit] + mov [edi+%1+12],ebx +%endmacro + +%macro tilenormalbmst 1 + cmp word[ecx+%1],0FFFFh + je %%nott + mov bx,[ecx+%1] + mov [edi+%1+75036*2],bx + or bx,[UnusedBit] + mov [edi+%1],bx +%%nott +%endmacro + +%macro drawtileng16b 12 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache + cmp byte[%9+ecx],dl + je %%returnfromcache + mov byte[%9+ecx],dl + call %10 +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],4000h + jz %%noflipxfull + add ecx,128 +%%noflipxfull + test dword[vrama+eax],8000h + jnz near %%flipyfull + %11 0,0 + %11 288*2,16 + %11 288*4,32 + %11 288*6,48 + %11 288*8,64 + %11 288*10,80 + %11 288*12,96 + %11 288*14,112 + jmp %5 +%%flipyfull + %11 288*14,0 + %11 288*12,16 + %11 288*10,32 + %11 288*8,48 + %11 288*6,64 + %11 288*4,80 + %11 288*2,96 + %11 0,112 + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],4000h + jz %%noflipxpart + add ecx,128 +%%noflipxpart + test word[vrama+eax],8000h + jnz near %%flipypart + mov dword[tleftnb],8 +%%nextb + %12 0 + %12 2 + %12 4 + %12 6 + %12 8 + %12 10 + %12 12 + %12 14 + add ecx,16 + add edi,288*2 + dec dword[tleftnb] + jnz near %%nextb + sub edi,288*2*8 + jmp %5 +%%flipypart + add edi,288*2*7 + mov dword[tleftnb],8 +%%nextbm + %12 0 + %12 2 + %12 4 + %12 6 + %12 8 + %12 10 + %12 12 + %12 14 + add ecx,16 + sub edi,288*2 + dec dword[tleftnb] + jnz near %%nextbm + add edi,288*2 +%5 + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,16 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%docache + call %3 + mov byte[%9+ecx],dl + call %10 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawtileng16x1616b 12 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache + cmp byte[%9+ecx],dl + je %%returnfromcache + mov byte[%9+ecx],dl + call %10 +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],4000h + jz %%noflipxfull + add ecx,128 +%%noflipxfull + test dword[vrama+eax],8000h + jnz near %%flipyfull + %11 0,0 + %11 288*2,16 + %11 288*4,32 + %11 288*6,48 + %11 288*8,64 + %11 288*10,80 + %11 288*12,96 + %11 288*14,112 + jmp %%done +%%flipyfull + %11 288*14,0 + %11 288*12,16 + %11 288*10,32 + %11 288*8,48 + %11 288*6,64 + %11 288*4,80 + %11 288*2,96 + %11 0,112 + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],4000h + jz %%noflipxpart + add ecx,128 +%%noflipxpart + test word[vrama+eax],8000h + jnz near %%flipypart + mov dword[tleftnb],8 +%%nextb + %12 0 + %12 2 + %12 4 + %12 6 + %12 8 + %12 10 + %12 12 + %12 14 + add ecx,16 + add edi,288*2 + dec dword[tleftnb] + jnz near %%nextb + sub edi,288*2*8 + jmp %%done +%%flipypart + add edi,288*2*7 + mov dword[tleftnb],8 +%%nextbm + %12 0 + %12 2 + %12 4 + %12 6 + %12 8 + %12 10 + %12 12 + %12 14 + add ecx,16 + sub edi,288*2 + dec dword[tleftnb] + jnz near %%nextbm + add edi,288*2 +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,16 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%5 + add edi,32 + jmp %%ntile +%%docache + call %3 + mov byte[%9+ecx],dl + call %10 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro ProcessBuildWindow 1 + mov dword[ngwinen],0 + test byte[winbg1enval+ebx+%1*256],0Ah + jz %%nowindowing + push eax + push ebx +;NEWSYM winlogicaval, times 256 dw 0 + mov al,[winlogicaval+ebx*2] + shr al,%1*2 + and al,03h + mov [nglogicval],al + mov eax,ebx + add ebx,%1*256 + call BuildWindow + mov eax,edi + sub eax,esi + sar eax,1 + cmp dword[ngwintable],0 + jne %%notzero + sub [ngwintable+4],eax + jmp %%done +%%notzero + sub [ngwintable],eax +%%done + pop ebx + pop eax +%%nowindowing +%endmacro + +%macro drawbgtileng16b 2 + mov dword[ng16bprval],0 + mov dword[ng16bbgval],%1 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + push ebx + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc + lea ecx,[ecx*8] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxinc + add eax,edx + neg dx +.noxinc + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bit + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng4b16b +.no4bit + cmp dl,1 + jne near .no2bit + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + push ebx + mov ebx,[mode0ads] + mov [mode0add],ebx + pop ebx +.nomode0 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng2b16b +.no2bit + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng8b16b +.no8bit + pop ebx + ret + +.tiles16x16 + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + push ebx + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2 + lea ecx,[ecx*4] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2 + add eax,edx + neg dx +.noxinc2 + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bit2 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng16x164b16b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + push ebx + mov ebx,[mode0ads] + mov [mode0add],ebx + pop ebx +.nomode02 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng16x162b16b +.no2bit2 + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng16x168b16b +.no8bit2 + pop ebx + ret +%endmacro + +%macro drawbgtilengpr116b 2 + mov dword[ng16bprval],2000h + mov dword[ng16bbgval],%1 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + push ebx + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng4b16b +.no4bit + cmp dl,1 + jne near .no2bit + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + push ebx + mov ebx,[mode0ads] + mov [mode0add],ebx + pop ebx +.nomode0 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng2b16b +.no2bit + cmp dl,3 + jne near .no8bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng8b16b +.no8bit + pop ebx + ret +.tiles16x16 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + mov dword[taddnfy16x16],0 + add ecx,ebx + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + push ebx + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng16x164b16b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + push ebx + mov ebx,[mode0ads] + mov [mode0add],ebx + pop ebx +.nomode02 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng16x162b16b +.no2bit2 + cmp dl,3 + jne near .no8bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawtileng16x168b16b +.no8bit2 + pop ebx + ret +%endmacro + +%macro procpixels 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2] + shl ebx,16 + mov bx,[eax+ecx*2] + mov [edi+%3],ebx + xor ebx,ebx +%endmacro + +%macro procpixelst 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelstr 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2+512] + shl ebx,16 + mov bx,[eax+ecx*2+512] + mov [edi+%3],ebx + xor ebx,ebx +%endmacro + +%macro procpixelstt 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelsnt 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2] + shl ebx,16 + mov bx,[eax+ecx*2] + mov [edi+%3],ebx + xor ebx,ebx +%endmacro + +%macro procpixelstnt 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx +%%nodraw +%endmacro + +%macro procpixelsmst 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2+512] + shl ebx,16 + mov bx,[eax+ecx*2+512] + and ebx,[UnusedBitXor] + mov [edi+%3],ebx + mov [edi+%3+75036*2],ebx + xor ebx,ebx +%endmacro + +%macro procpixelstmst 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2+512] + mov [edi+%2],cx + and cx,[UnusedBitXor] + mov [edi+%2+75036*2],cx +%%nodraw +%endmacro + +%macro procpixelsmsnt 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2] + shl ebx,16 + mov bx,[eax+ecx*2] + mov [edi+%3],ebx + mov [edi+%3+75036*2],ebx + xor ebx,ebx +%endmacro + +%macro procpixelstmsnt 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2],cx + mov [edi+%2+75036*2],cx +%%nodraw +%endmacro + +%macro procpixelss 3 + mov bl,[esi+%2] + mov cl,[esi+%1] + add bl,dl + add cl,dl + mov bx,[eax+ebx*2] + shl ebx,16 + mov bx,[eax+ecx*2] + mov [edi+%3+75036*2],ebx + xor ebx,ebx +%endmacro + +%macro procpixelsts 3 + mov bl,[esi+%1] + add bl,dl + test bl,%3 + jz %%nodraw + mov cx,[eax+ebx*2] + mov [edi+%2+75036*2],cx +%%nodraw +%endmacro + +%macro drawlineng16b 10 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + jmp %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jz %%notflipyfull + add ecx,[flipyposng] + jmp %%yesflipyfull +%%notflipyfull + add ecx,[yposng] +%%yesflipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 0,1,0 + %9 2,3,4 + %9 4,5,8 + %9 6,7,12 + pop eax + jmp %5 +%%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 7,6,0 + %9 5,4,4 + %9 3,2,8 + %9 1,0,12 + pop eax + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jz %%noflipypart + add ecx,[flipyposng] + jmp %%yesflipypart +%%noflipypart + add ecx,[yposng] +%%yesflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 0,0,%8 + %10 1,2,%8 + %10 2,4,%8 + %10 3,6,%8 + %10 4,8,%8 + %10 5,10,%8 + %10 6,12,%8 + %10 7,14,%8 + pop eax + jmp %5 +%%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 7,0,%8 + %10 6,2,%8 + %10 5,4,%8 + %10 4,6,%8 + %10 3,8,%8 + %10 2,10,%8 + %10 1,12,%8 + %10 0,14,%8 + pop eax +%5 + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,16 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlineng16x1616b 10 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test word[vrama+eax],8000h + jz %%noflipyfull + add ecx,[flipyposng] + jmp %%yesflipyfull +%%noflipyfull + add ecx,[yposng] +%%yesflipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 0,1,0 + %9 2,3,4 + %9 4,5,8 + %9 6,7,12 + pop eax + jmp %%done +%%flipxfull + push eax + mov esi,ecx + xor ecx,ecx + xor ebx,ebx + mov eax,[CPalPtrng] + %9 7,6,0 + %9 5,4,4 + %9 3,2,8 + %9 1,0,12 + pop eax + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jz %%noflipypart + add ecx,[flipyposng] + jmp %%yesflipypart +%%noflipypart + add ecx,[yposng] +%%yesflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 0,0,%8 + %10 1,2,%8 + %10 2,4,%8 + %10 3,6,%8 + %10 4,8,%8 + %10 5,10,%8 + %10 6,12,%8 + %10 7,14,%8 + pop eax + jmp %%done +%%flipxpart + push eax + mov eax,[CPalPtrng] + mov esi,ecx + xor ebx,ebx + %10 7,0,%8 + %10 6,2,%8 + %10 5,4,%8 + %10 4,6,%8 + %10 3,8,%8 + %10 2,10,%8 + %10 1,12,%8 + %10 0,14,%8 + pop eax +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,16 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng16b + ret +%5 + add edi,32 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawbglineng16b 2 + mov dword[ng16bprval],0 + mov [pesimpng],esi + mov dword[ng16bbgval],%1 + cmp byte[bgmode],5 + jb %%nointerl + test byte[intrlng+ebx],01h + jz %%nointerl + add ecx,ebx + add ecx,[cfieldad] +%%nointerl + push ebx + mov byte[curmosaicsz],1 + xor eax,eax + test byte[mosenng+ebx],1 << %1 + jz %%nomosaic + mov al,[mosszng+ebx] + or al,al + jz %%nomosaic + inc al + mov byte[curmosaicsz],al + mov cl,al + mov al,bl + div cl + mul cl + mov ebx,eax + mov edi,xtravbuf+32 + mov ecx,128 + mov eax,0FFFFFFFFh + mov esi,xtravbuf+32 + rep stosd + or ebx,ebx + jnz %%nozeroline + inc ebx +%%nozeroline + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + jmp %%yesmosaic +%%nomosaic +%%yesmosaic + cmp byte[BGMA+ebx],5 + jae near .tiles16x8 + cmp byte[osm2dis],1 + je .nooffsetm + cmp byte[BGMA+ebx],2 + je near .offsetm + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 +; cmp byte[BGMA+ebx],4 +; je near .offsetm +.nooffsetm + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxinc + add eax,edx + neg dx +.noxinc + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bit + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + add ecx,%2*256 + mov dl,1 << %2 + jmp drawlineng4b16b +.no4bit + cmp dl,1 + jne near .no2bit + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ecx,[mode0ads] + mov [mode0add],ecx +.nomode0 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng2b16b +.no2bit + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng8b16b +.no8bit + pop ebx + ret + +.tiles16x16 + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2 + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2 + add eax,edx + neg dx +.noxinc2 + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bit2 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x164b16b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + push ebx + mov ebx,[mode0ads] + mov [mode0add],ebx + pop ebx +.nomode02 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x162b16b +.no2bit2 + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x168b16b +.no8bit2 + pop ebx + ret + +.tiles16x8 + cmp byte[t16x161+ebx+%1*256],1 + je .tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],0 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc2c + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2c + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + jmp .tiles16x8hr +.tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy2 + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy2 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2b + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2b + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h +.tiles16x8hr + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + add ecx,ecx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2b + add eax,edx + neg dx +.noxinc2b + mov edi,ecx + sub dx,64 + and ecx,01F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + shr edi,1 + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bit2b + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[cbgval],%1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x84b16b +.no4bit2b + cmp dl,1 + jne near .no2bit2b + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov dword[cbgval],%1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x82b16b +.no2bit2b + pop ebx + ret + + +.offsetm16x16 + pushad + xor edx,edx + mov dx,[BG3SYl+ebx*2] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma16x16 + and dx,0F000h + shr dx,5 + add ax,dx +.nooma16x16 + cmp byte[BGMA+ebx],4 + je .offsetm416x16 + add eax,40h +.offsetm416x16 + mov edx,eax + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincd16x16 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyincd16x16 + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + mov [yposngom],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov [flipyposngom],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincd16x16 + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincd16x16 + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + popad + + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy16om + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy16om + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc216om + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc216om + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov [flipyposngom],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc216om + add eax,edx + add [ofsmtptr],edx + neg dx +.noxinc216om + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bitom16x16 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[ofsmval],2000h << %1 + mov dword[ofsmvalh],2000h << %1 + cmp byte[hdmaearlstart],0 + je .ofsmvalhack16x16 + mov dword[ofsmvalh],0 +.ofsmvalhack16x16 + mov dword[cbgval],%1 + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlinengom16x164b16b +.no4bitom16x16 + pop ebx + ret + + ; Offsetmode calculation : *1024+*32+ +.offsetm + cmp byte[t16x161+ebx+%1*256],1 + je near .offsetm16x16 + xor edx,edx + mov dx,[BG3SYl+ebx*2] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma + and dx,0F000h + shr dx,5 + add ax,dx +.nooma + cmp byte[BGMA+ebx],4 + je .offsetm4 + add eax,40h +.offsetm4 + mov edx,eax + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincd + add eax,[BGPT1Y+ebx*2+%1*512] +.noyincd + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + mov [yposngom],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov [flipyposngom],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincd + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincd + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + add edi,edi + cmp dl,2 + jne near .no4bitd + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[ofsmval],2000h << %1 + mov dword[ofsmvalh],2000h << %1 + cmp byte[hdmaearlstart],0 + je .ofsmvalhack + mov dword[ofsmvalh],0 +.ofsmvalhack + mov dword[cbgval],%1 + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlinengom4b16b +.no4bitd + cmp dl,1 + jne near .no2bitdn + ; eax = pointer to beginning of tile area + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov byte[tleftn],33 +.loopdn + mov cx,[vrama+eax] + test cx,2000h + jnz near .fintiledn + drawlinengom216b tltype2b, preparet2ba, cachesingle2bng,.loopdn,.fintiledn,ngpalcon2b,test2ba,03h,%1 +.no2bitdn + cmp dl,3 + jne near .no8bitdn + ; eax = pointer to beginning of tile area + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn2 + mov cx,[vrama+eax] + test cx,2000h + jnz near .fintiledn2 + drawlinengom216b tltype8b, preparet8ba, cachesingle8bng,.loopdn2,.fintiledn2,ngpalcon8b,test8ba,0FFh,%1 +.no8bitdn + pop ebx + ret +%endmacro + +%macro mosender 1 +.nodraw + add edi,%1*2 + add esi,%1*2 + dec ecx + jnz near .next + pop esi + mov dword[ignor512],0 + ret +%endmacro + +%macro drawbglinengpr116b 2 + mov dword[ng16bprval],2000h + mov [pesimpng],esi + mov dword[ng16bbgval],%1 + push ebx + mov byte[curmosaicsz],1 + xor eax,eax + test byte[mosenng+ebx],1 << %1 + jz %%nomosaic + mov al,[mosszng+ebx] + or al,al + jz %%nomosaic + inc al + mov byte[curmosaicsz],al + mov cl,al + mov al,bl + div cl + mul cl + mov ebx,eax + mov edi,xtravbuf+32 + mov ecx,128 + mov eax,0FFFFFFFFh + mov esi,xtravbuf+32 + rep stosd + or ebx,ebx + jnz %%nomosaic + inc ebx + jmp %%yesmosaic +%%nomosaic +%%yesmosaic + cmp byte[BGMA+ebx],5 + jae near .tiles16x8 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + cmp byte[osm2dis],1 + je .nooffsetm + cmp byte[BGMA+ebx],2 + je near .offsetm +; cmp byte[BGMA+ebx],4 +; je near .offsetm +.nooffsetm + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng4b16b +.no4bit + cmp dl,1 + jne near .no2bit + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ecx,[mode0ads] + mov [mode0add],ecx +.nomode0 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng2b16b +.no2bit + cmp dl,3 + jne near .no8bit + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng8b16b +.no8bit + pop ebx + ret + +.tiles16x16 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + mov dword[taddnfy16x16],0 + add ecx,ebx + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + + lea eax,[ecx*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x164b16b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + ProcessBuildWindow %1 + cmp byte[BGMA+ebx],0 + jne .nomode02 + push ebx + mov ebx,[mode0ads] + mov [mode0add],ebx + pop ebx +.nomode02 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x162b16b +.no2bit2 + cmp dl,3 + jne near .no8bit2 + ; eax = pointer to beginning of tile area + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x168b16b +.no8bit2 + pop ebx + ret + +.tiles16x8 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomyb + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomyb + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],0 +.tiles16x16hr + + lea eax,[ecx*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2b + ; eax = pointer to beginning of tile area + mov dword[cbgval],%1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x84b16b +.no4bit2b + cmp dl,1 + jne near .no2bit2b + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov dword[cbgval],%1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlineng16x82b16b +.no2bit2b + pop ebx + ret + +.offsetm + xor edx,edx + mov dx,[BG3SYl+ebx*2] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma + and dx,0F000h + shr dx,5 + add ax,dx +.nooma + mov edx,eax + cmp byte[BGMA+ebx],4 + je .offsetm4 + add edx,40h +.offsetm4 + and edx,0FFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincdd + add [ofsmtptr],edx +.noxincdd + and ecx,0F8h + shr ecx,2 + add [ofsmtptr],ecx + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + mov [yposngom],eax + xor eax,38h + mov [flipyposng],eax + mov [flipyposngom],eax + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + cmp dl,2 + jne near .no4bitd + ; eax = pointer to beginning of tile area + mov dword[ofsmval],2000h << %1 + mov dword[ofsmvalh],2000h << %1 + cmp byte[hdmaearlstart],0 + je .ofsmvalhack + mov dword[ofsmvalh],0 +.ofsmvalhack + mov dword[cbgval],%1 + ProcessBuildWindow %1 + mov ecx,ebx + mov dl,1 << %2 + add ecx,%2*256 + jmp drawlinengom4b16b +.no4bitd + cmp dl,1 + jne near .no2bitdn + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiledn + drawlinengom216b tltype2b, preparet2ba, cachesingle2bng,.loopdn,.fintiledn,ngpalcon2b,test2ba,03h,%1 +.no2bitdn + cmp dl,3 + jne near .no8bitdn + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn2 + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiledn2 + drawlinengom216b tltype8b, preparet8ba, cachesingle8bng,.loopdn2,.fintiledn2,ngpalcon8b,test8ba,0FFh,%1 +.no8bitdn + pop ebx + ret +%endmacro + \ No newline at end of file diff --git a/zsnes/src/video/newgfx2.asm b/zsnes/src/video/newgfx2.asm new file mode 100644 index 00000000..82eaf7bf --- /dev/null +++ b/zsnes/src/video/newgfx2.asm @@ -0,0 +1,674 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM ngwintable,ngwinen,ngcwinptr,ngcpixleft,ngcwinmode +EXTSYM tleftn, ng16bprval, vrama, bg1drwng, ng16bbgval, bg1totng +EXTSYM bgtxadd, taddnfy16x16, taddfy16x16, switch16x16, curmosaicsz, domosaicng +EXTSYM vidmemch4,vidmemch2,vidmemch8,mode0add,vcache4b,vcache2b,vcache8b +EXTSYM cachesingle2bng,cachesingle8bng,ngpalcon4b,ngpalcon8b +EXTSYM ngpalcon2b,tleftnb,tltype2b,tltype4b,tltype8b,yposng,flipyposng +EXTSYM ofsmcptr,ofsmtptr,ofsmmptr,ofsmcyps,ofsmady,ofsmadx +EXTSYM yposngom,flipyposngom,cbgval,ofsmval,ofsmvalh,vram + +%include "video/vidmacro.mac" +%include "video/newgfx2.mac" +%include "video/newgfx.mac" +%include "video/newgfxwn.mac" + + + + + + + + + +;****************************************** +; 8x8 tiles - tile engine +;****************************************** + +%macro WinClipMacro 1 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + add ax,2 + mov ebx,[ng16bbgval] + add edi,8 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jnz .notileadd + add ax,[bgtxadd] +.notileadd + dec byte[tleftn] + jnz .winclipped + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline +%endmacro + +NEWSYM drawtileng2b + cmp byte[ngwinen],1 + je near drawtileng2bwin + mov byte[tleftn],33 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h + ret +drawtileng2bwin: + WinClipMacro Processwinclip2bt + drawtileng tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +Processwinclip2bt: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawtilengwin tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawtileng2bwin.winclipped + jmp drawtileng2bwin.loop + + +NEWSYM drawtileng4b + cmp byte[ngwinen],1 + je near drawtileng4bwin + mov byte[tleftn],33 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh + ret +drawtileng4bwin: + WinClipMacro Processwinclip4bt + drawtileng tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +Processwinclip4bt: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawtilengwin tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawtileng4bwin.winclipped + jmp drawtileng4bwin.loop + +NEWSYM drawtileng8b + cmp byte[ngwinen],1 + je near drawtileng8bwin + mov byte[tleftn],33 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh + ret + +drawtileng8bwin: + WinClipMacro Processwinclip8bt + drawtileng tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +Processwinclip8bt: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawtilengwin tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawtileng8bwin.winclipped + jmp drawtileng8bwin.loop + +;****************************************** +; 16x16 tiles - tile engine +;****************************************** + +%macro WinClipMacro16x16 1 + mov byte[tleftn],17 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %1 + sub dword[ebx],16 + add ax,2 + mov ebx,[ng16bbgval] + add edi,16 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jnz .notileadd + add ax,[bgtxadd] +.notileadd + dec byte[tleftn] + jnz .winclipped + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],16 + jbe near %1 + sub dword[ebx],16 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline +%endmacro + +NEWSYM drawtileng16x162b + cmp byte[ngwinen],1 + je near drawtileng16x162bwin + mov byte[tleftn],17 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng16x16 tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h + ret +drawtileng16x162bwin: + WinClipMacro16x16 Processwinclip16x162bt + drawtileng16x16 tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +Processwinclip16x162bt: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawtileng16x16win tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawtileng16x162bwin.winclipped + jmp drawtileng16x162bwin.loop + +NEWSYM drawtileng16x164b + cmp byte[ngwinen],1 + je near drawtileng16x164bwin + mov byte[tleftn],17 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng16x16 tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh + ret +drawtileng16x164bwin: + WinClipMacro16x16 Processwinclip16x164bt + drawtileng16x16 tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +Processwinclip16x164bt: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawtileng16x16win tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawtileng16x164bwin.winclipped + jmp drawtileng16x164bwin.loop + +NEWSYM drawtileng16x168b + mov byte[tleftn],17 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawtileng16x16 tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh + ret +drawtileng16x168bwin: + WinClipMacro16x16 Processwinclip16x168bt + drawtileng16x16 tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +Processwinclip16x168bt: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawtileng16x16win tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawtileng16x168bwin.winclipped + jmp drawtileng16x168bwin.loop + +;****************************************** +; 8x8 tiles - line by line engine +;****************************************** + +NEWSYM drawlineng2b + cmp byte[ngwinen],1 + je near drawlineng2bwin + mov byte[tleftn],33 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h + ret +drawlineng2bwin: + WinClipMacro Processwinclip2b + drawlineng tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +Processwinclip2b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawlinengwin tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlineng2bwin.winclipped + jmp drawlineng2bwin.loop + +NEWSYM drawlineng4b + cmp byte[ngwinen],1 + je near drawlineng4bwin + mov byte[tleftn],33 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh + ret +drawlineng4bwin: + WinClipMacro Processwinclip4b + drawlineng tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +Processwinclip4b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawlinengwin tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlineng4bwin.winclipped + jmp drawlineng4bwin.loop + +NEWSYM drawlineng8b + cmp byte[ngwinen],1 + je near drawlineng8bwin + mov byte[tleftn],33 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh + ret +drawlineng8bwin: + WinClipMacro Processwinclip8b + drawlineng tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +Processwinclip8b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawlinengwin tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlineng8bwin.winclipped + jmp drawlineng8bwin.loop + +;****************************************** +; 16x16 tiles - line by line engine +;****************************************** + +NEWSYM drawlineng16x162b + cmp byte[ngwinen],1 + je near drawlineng16x162bwin + mov byte[tleftn],17 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng16x16 tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h + ret +drawlineng16x162bwin: + WinClipMacro16x16 Processwinclip16x162b + drawlineng16x16 tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +Processwinclip16x162b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawlineng16x16win tltype2b, preparet2ba, cachesingle2bng,.loop,.finline,ngpalcon2b,test2ba,03h +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlineng16x162bwin.winclipped + jmp drawlineng16x162bwin.loop + +NEWSYM drawlineng16x164b + cmp byte[ngwinen],1 + je near drawlineng16x164bwin + mov byte[tleftn],17 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng16x16 tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh + ret +drawlineng16x164bwin: + WinClipMacro16x16 Processwinclip16x164b + drawlineng16x16 tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +Processwinclip16x164b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawlineng16x16win tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlineng16x164bwin.winclipped + jmp drawlineng16x164bwin.loop + +NEWSYM drawlineng16x168b + cmp byte[ngwinen],1 + je near drawlineng16x168bwin + mov byte[tleftn],17 +.loop + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline + drawlineng16x16 tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh + ret +drawlineng16x168bwin: + WinClipMacro16x16 Processwinclip16x168b + drawlineng16x16 tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +Processwinclip16x168b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .finline + drawlineng16x16win tltype8b, preparet8ba, cachesingle8bng,.loop,.finline,ngpalcon8b,test8ba,0FFh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlineng16x168bwin.winclipped + jmp drawlineng16x168bwin.loop + +NEWSYM drawlineng16x84b + mov byte[tleftn],33 +.loop2b + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .fintile2b + drawlineng16x8 tltype4b, preparet4ba, cachesingle4bng,.loop2b,.fintile2b,ngpalcon4b,test4ba,0Fh + +NEWSYM drawlineng16x82b + mov byte[tleftn],33 +.loopb2b + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .fintileb2b + drawlineng16x8 tltype2b, preparet2ba, cachesingle2bng,.loopb2b,.fintileb2b,ngpalcon2b,test2ba,03h + +%macro WinClipMacroom 1 + mov byte[tleftn],33 + mov dword[ngcwinptr],ngwintable + mov dword[ngcwinmode],0 + cmp dword[ngwintable],0 + jne near .loop + add dword[ngcwinptr],4 + mov dword[ngcwinmode],1 +.winclipped + mov ebx,[ngcwinptr] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,8 + test eax,03Fh + jnz .next + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx +.next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz .noofsm2 + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz .noupper2 + add ax,[ofsmady] +.noupper2 + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +.noofsm2 + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmvalh] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz .noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz .noleft + add ax,[ofsmadx] +.noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +.noofsmh + + dec byte[tleftn] + jnz near .winclipped + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +.loop + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + cmp dword[ebx],8 + jbe near %1 + sub dword[ebx],8 + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .finline +%endmacro + +NEWSYM drawlinengom4b + cmp byte[ngwinen],1 + je near drawlinengom4bwin + mov byte[tleftn],33 +.loopd + mov cx,[vrama+eax] + xor ecx,[ng16bprval] + test ecx,2000h + jnz near .fintiled + drawlinengom tltype4b, preparet4ba, cachesingle4bng,.loopd,.fintiled,ngpalcon4b,test4ba,0Fh +drawlinengom4bwin: + WinClipMacroom Processwinclipom4b + drawlinengom tltype4b, preparet4ba, cachesingle4bng,.loop,.finline,ngpalcon4b,test4ba,0Fh +Processwinclipom4b: + mov ebx,[ngcwinptr] + mov cx,[vrama+eax] + mov ebx,[ebx] + xor ecx,[ng16bprval] + mov [ngcpixleft],ebx + test ecx,2000h + jnz near .fintiled + drawlinengomwin tltype4b, preparet4ba, cachesingle4bng,.loop,.fintiled,ngpalcon4b,test4ba,0Fh +.loop + push eax + mov ebx,[ngcwinptr] + mov eax,[ngcpixleft] + mov [ebx],eax + pop eax + cmp dword[ngcwinmode],1 + je near drawlinengom4bwin.winclipped + jmp drawlinengom4bwin.loop + \ No newline at end of file diff --git a/zsnes/src/video/newgfx2.mac b/zsnes/src/video/newgfx2.mac new file mode 100644 index 00000000..cc408c78 --- /dev/null +++ b/zsnes/src/video/newgfx2.mac @@ -0,0 +1,1009 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +; Finish up parttile + +%macro drawlineng16x8 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],bl + mov [edi+75036],bh + shr ebx,16 + mov [edi+1],bl + mov [edi+75037],bh + mov ebx,[ecx+4] + add ebx,edx + mov [edi+2],bl + mov [edi+75038],bh + shr ebx,16 + mov [edi+3],bl + mov [edi+75039],bh + jmp %%done +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],bl + mov [edi+75036],bh + shr ebx,16 + mov [edi+1],bl + mov [edi+75037],bh + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+2],bl + mov [edi+75038],bh + shr ebx,16 + mov [edi+3],bl + mov [edi+75039],bh + jmp %%done +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],bl + mov [edi+75036],bh + shr ebx,16 + mov [edi+1],bl + mov [edi+75037],bh + mov ebx,[ecx+4] + add ebx,edx + mov [edi+2],bl + mov [edi+75038],bh + shr ebx,16 + mov [edi+3],bl + mov [edi+75039],bh + jmp %%done +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],bl + mov [edi+75036],bh + shr ebx,16 + mov [edi+1],bl + mov [edi+75037],bh + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+2],bl + mov [edi+75038],bh + shr ebx,16 + mov [edi+3],bl + mov [edi+75039],bh + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+75036],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+1],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+75037],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+2],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+75038],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+3],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+75039],bh +%%drawd2 + jmp %%done + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+75039],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+3],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+75038],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+2],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+75037],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+1],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+75036],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %%done + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+75036],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+1],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+75037],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+2],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+75038],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+3],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+75039],bh +%%drawd2m + jmp %%done + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+75039],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+3],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+75038],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+2],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+75037],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+1],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+75036],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,4 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[cbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%5 + add edi,8 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlinengom2 9 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov dl,ch + inc dword[bg1drwng+%9*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + jmp %5 + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %5 + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + jmp %5 + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%5 + inc dword[bg1totng+%9*4] + add word[ofsmmptr],2 + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,8 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofshvaladd],8 + test dword[ebx-40h],8000h + jz near %%noofsm + test dword[ebx-40h],2000h << %9 + jz %%noofsm + mov ebx,[ebx-40h] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],8000h + jnz near %%noofsmh + test dword[ebx-40h],2000h << %9 + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + + +%macro drawlinengom 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + jmp %5 + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %5 + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + jmp %5 + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%5 + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,8 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz .noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz .noupper + add ax,[ofsmady] +.noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +.noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmvalh] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/video/newgfxb.mac b/zsnes/src/video/newgfxb.mac new file mode 100644 index 00000000..1da6db10 --- /dev/null +++ b/zsnes/src/video/newgfxb.mac @@ -0,0 +1,3298 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +%macro Procbgpr0 5 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%4 + jz %%nogo + test dword[BGMS1+ebx*2],%5 + jnz %%nogo + ; Check if at a tile alignment + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + test ecx,07h + jz %%tilecheck +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tilecheck + mov eax,[BG1SXl+ebx*2+%1*512] + cmp ax,[BG1SXl+ebx*2+2+%1*512] + jne %%proclinebyline + cmp eax,[BG1SXl+ebx*2+4+%1*512] + jne %%proclinebyline + cmp eax,[BG1SXl+ebx*2+8+%1*512] + jne %%proclinebyline + cmp eax,[BG1SXl+ebx*2+12+%1*512] + jne %%proclinebyline + mov eax,[BG1SYl+ebx*2+%1*512] + cmp ax,[BG1SYl+ebx*2+2+%1*512] + jne %%proclinebyline + cmp eax,[BG1SYl+ebx*2+4+%1*512] + jne %%proclinebyline + cmp eax,[BG1SYl+ebx*2+8+%1*512] + jne %%proclinebyline + cmp eax,[BG1SYl+ebx*2+12+%1*512] + jne %%proclinebyline + test dword[BGMS1+ebx*2+14],%4 + jz near %%proclinebyline + test dword[BGMS1+ebx*2+14],%5 + jnz near %%proclinebyline + cmp ebx,[reslbyl] + jae near %%proclinebyline + mov eax,[BGMA+ebx] + cmp eax,[BGMA+ebx+4] + jne near %%proclinebyline + mov eax,[BGOPT1+ebx*2+%1*512] + cmp ax,[BGOPT1+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGOPT1+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGOPT1+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGOPT1+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGPT1+ebx*2+%1*512] + cmp ax,[BGPT1+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGPT1X+ebx*2+%1*512] + cmp ax,[BGPT1X+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1X+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1X+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1X+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGPT1Y+ebx*2+%1*512] + cmp ax,[BGPT1Y+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1Y+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1Y+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1Y+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGMS1+ebx] + cmp eax,[BGMS1+ebx+4] + jne near %%proclinebyline + cmp eax,[BGMS1+ebx+8] + jne near %%proclinebyline + cmp eax,[BGMS1+ebx+12] + jne near %%proclinebyline + mov eax,[BGFB+ebx] + cmp eax,[BGFB+ebx+4] + jne near %%proclinebyline + mov eax,[t16x161+ebx+%1*256] + cmp eax,[t16x161+ebx+4+%1*256] + jne near %%proclinebyline + cmp byte[BGMA+ebx],5 + jae near %%proclinebyline + cmp byte[BGMA+ebx],2 + je near %%proclinebyline + test dword[intrlng+ebx],01010101h + jnz near %%proclinebyline + test dword[intrlng+ebx+4],01010101h + jnz near %%proclinebyline + test byte[mosenng+ebx],1 << %1 + jnz %%mosaic +%%nomosaic + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja near %%nextline + jmp %%donextbg +%%mosaic + cmp byte[mosszng+ebx],0 + je %%nomosaic + jmp %%proclinebyline +%%donextbg +%endmacro + +%macro Procbg3pr0 5 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%4 + jz %%nogo + test dword[BGMS1+ebx*2],%5 + jnz %%nogo + ; Check if at a tile alignment + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + test ecx,07h + jz %%tilecheck +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tilecheck + mov eax,[BG1SXl+ebx*2+%1*512] + cmp ax,[BG1SXl+ebx*2+2+%1*512] + jne %%proclinebyline + cmp eax,[BG1SXl+ebx*2+4+%1*512] + jne %%proclinebyline + cmp eax,[BG1SXl+ebx*2+8+%1*512] + jne %%proclinebyline + cmp eax,[BG1SXl+ebx*2+12+%1*512] + jne %%proclinebyline + mov eax,[BG1SYl+ebx*2+%1*512] + cmp ax,[BG1SYl+ebx*2+2+%1*512] + jne %%proclinebyline + cmp eax,[BG1SYl+ebx*2+4+%1*512] + jne %%proclinebyline + cmp eax,[BG1SYl+ebx*2+8+%1*512] + jne %%proclinebyline + cmp eax,[BG1SYl+ebx*2+12+%1*512] + jne %%proclinebyline + test dword[BGMS1+ebx*2+14],%4 + jz near %%proclinebyline + test dword[BGMS1+ebx*2+14],%5 + jnz near %%proclinebyline + cmp ebx,[reslbyl] + jae near %%proclinebyline + mov eax,[BGMA+ebx] + cmp eax,[BGMA+ebx+4] + jne near %%proclinebyline + mov eax,[BGOPT1+ebx*2+%1*512] + cmp ax,[BGOPT1+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGOPT1+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGOPT1+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGOPT1+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGPT1+ebx*2+%1*512] + cmp ax,[BGPT1+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGPT1X+ebx*2+%1*512] + cmp ax,[BGPT1X+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1X+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1X+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1X+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGPT1Y+ebx*2+%1*512] + cmp ax,[BGPT1Y+ebx*2+2+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1Y+ebx*2+4+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1Y+ebx*2+8+%1*512] + jne near %%proclinebyline + cmp eax,[BGPT1Y+ebx*2+12+%1*512] + jne near %%proclinebyline + mov eax,[BGMS1+ebx] + cmp eax,[BGMS1+ebx+4] + jne near %%proclinebyline + cmp eax,[BGMS1+ebx+8] + jne near %%proclinebyline + cmp eax,[BGMS1+ebx+12] + jne near %%proclinebyline + mov eax,[BG3PRI+ebx] + cmp eax,[BG3PRI+ebx+4] + jne near %%proclinebyline + mov eax,[BGFB+ebx] + cmp eax,[BGFB+ebx+4] + jne near %%proclinebyline + mov eax,[t16x161+ebx+%1*256] + cmp eax,[t16x161+ebx+4+%1*256] + jne near %%proclinebyline + test dword[intrlng+ebx],01010101h + jnz near %%proclinebyline + test dword[intrlng+ebx+4],01010101h + jnz near %%proclinebyline + test byte[mosenng+ebx],1 << %1 + jnz %%mosaic +%%nomosaic + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja near %%nextline +%%mosaic + cmp byte[mosszng+ebx],0 + je %%nomosaic + jmp %%proclinebyline +%%donextbg +%endmacro + +%macro Procbgpr1 6 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 +; add esi,16+288 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%5 + jz %%nogo + test dword[BGMS1+ebx*2],%6 + jnz %%nogo + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja %%nextline +%%donextbg +%endmacro + +%macro Procbg3pr1 6 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%5 + jz %%nogo + test dword[BGMS1+ebx*2],%6 + jnz %%nogo + cmp byte[BGMA+ebx],1 + jne %%nomode1 + cmp byte[BG3PRI+ebx],0 + jne %%nogo +%%nomode1 + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja %%nextline +%%donextbg +%endmacro + +%macro Procbg3pr1b 6 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16 + xor ebx,ebx +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%5 + jz %%nogo + test dword[BGMS1+ebx*2],%6 + jnz %%nogo + cmp byte[BGMA+ebx],1 + jne %%nogo + cmp byte[BG3PRI+ebx],0 + je %%nogo + ; Check if at a tile alignment + cmp byte[%4+ebx],1 + je %%tile +%%proclinebyline + ; process line by line + call %2 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne %%nextline + jmp %%donextbg +%%tile + call %3 + add ebx,8 + add esi,288*8 + cmp [resolutn],bx + ja %%nextline +%%donextbg +%endmacro + +%macro Procsprng 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%1 + jz %%nogo + test dword[BGMS1+ebx*2],%2 + jnz %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + call drawsprng + cmp byte[BGMA+ebx],5 + jb %%nogo + cmp byte[res640],0 + je %%nogo + add esi,75036 + mov cl,byte[sprlefttot+ebx] + call drawsprng + sub esi,75036 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne near %%nextline +%endmacro + +%macro Procsprng01 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%1 + jz %%nogo + test dword[BGMS1+ebx*2],%2 + jnz %%nogo + cmp byte[BGMA+ebx],1 + ja %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + call drawsprng + cmp byte[BGMA+ebx],5 + jb %%nogo + cmp byte[res640],0 + je %%nogo + add esi,75036 + mov cl,byte[sprlefttot+ebx] + call drawsprng + sub esi,75036 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne near %%nextline +%endmacro + +%macro Procsprng234567 2 + ; Draw BG 2 + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne %%nogo + test dword[BGMS1+ebx*2],%1 + jz %%nogo + test dword[BGMS1+ebx*2],%2 + jnz %%nogo + cmp byte[BGMA+ebx],1 + jbe %%nogo + xor eax,eax + mov al,[sprtlng+ebx] + mov cl,byte[sprlefttot+ebx] + mov [csprival],eax + inc byte[sprtlng+ebx] + test byte[sprleftpr+ebx*4+eax],1 + jz %%nogo + or cl,cl + jz %%nogo + call drawsprng + cmp byte[BGMA+ebx],5 + jb %%nogo + cmp byte[res640],0 + je %%nogo + add esi,75036 + mov cl,byte[sprlefttot+ebx] + call drawsprng + sub esi,75036 +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne near %%nextline +%endmacro + +%macro ProcMode7ng 2 + mov byte[winon],0 + ; Draw BG + ; Start line by line drawing/check + mov esi,[vidbuffer] + add esi,16+288 + mov ebx,1 +%%nextline + cmp byte[BGFB+ebx],0 + jne near %%nogo + cmp byte[BGMA+ebx],7 + jne near %%nogo + test dword[BGMS1+ebx*2],%1 + jz near %%nogo + test dword[BGMS1+ebx*2],%2 + jnz near %%nogo + push ebx + ; Process mosaic + mov byte[curmosaicsz],1 + xor ecx,ecx + test byte[mosenng+ebx],1 + jz %%nomosaic + mov cl,[mosszng+ebx] + or cl,cl + jz %%nomosaic + inc cl + mov byte[curmosaicsz],cl + xor edx,edx + mov eax,ebx + div cl + xor edx,edx + mul cl + mov ebx,eax +%%nomosaic + ; process line by line + mov edx,[mode7ab+ebx*4] + mov [mode7A],edx + mov edx,[mode7cd+ebx*4] + mov [mode7C],edx + mov edx,[mode7xy+ebx*4] + mov [mode7X0],edx + mov edx,[mode7st+ebx] + mov [mode7set],dl + xor edx,edx + mov eax,ebx + test byte[mode7set],02h + jz %%noflip + mov eax,261 + sub eax,ebx +%%noflip + mov dx,[BG1SXl+ebx*2] + add ax,[BG1SYl+ebx*2] + mov [curvidoffset],esi + push esi + call drawmode7 + pop esi + pop ebx +%%nogo + inc ebx + add esi,288 + cmp [resolutn],bx + jne near %%nextline +%endmacro + + +%macro preparet4ba 0 + shl cx,5 + add ecx,ecx + add ecx,[vcache4b] +%endmacro + +%macro preparet2ba 0 + shl cx,4 + shl ecx,2 + add ecx,[vcache2b] +%endmacro + +%macro preparet8ba 0 + shl cx,6 + add ecx,[vcache8b] +%endmacro + +%macro test4ba 0 + and ecx,2047 + test dword[vidmemch4+ecx*2],0FFFFh +%endmacro + +%macro test2ba 0 + and ecx,4095 + add edx,dword[mode0add] + test dword[vidmemch2+ecx],0FFh +%endmacro + +%macro test8ba 0 + and ecx,1023 + test dword[vidmemch8+ecx*4],0FFFFFFFFh +%endmacro + +%macro drawtileng 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + mov ebx,[ecx+8] + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+12] + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+16] + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+20] + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+24] + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+28] + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+32] + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+36] + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+40] + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+44] + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+48] + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+52] + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+56] + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx+60] + add ebx,edx + mov [edi+288*7+4],ebx + jmp %5 +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + mov ebx,[ecx+12] + bswap ebx + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+8] + bswap ebx + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+20] + bswap ebx + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+16] + bswap ebx + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+28] + bswap ebx + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+24] + bswap ebx + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+36] + bswap ebx + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+32] + bswap ebx + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+44] + bswap ebx + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+40] + bswap ebx + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+52] + bswap ebx + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+48] + bswap ebx + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+60] + bswap ebx + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx+56] + bswap ebx + add ebx,edx + mov [edi+288*7+4],ebx + jmp %5 +%%flipyfull + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+288*7+4],ebx + mov ebx,[ecx+8] + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+12] + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+16] + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+20] + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+24] + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+28] + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+32] + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+36] + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+40] + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+44] + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+48] + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+52] + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+56] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+60] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi+288*7],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+288*7+4],ebx + mov ebx,[ecx+12] + bswap ebx + add ebx,edx + mov [edi+288*6],ebx + mov ebx,[ecx+8] + bswap ebx + add ebx,edx + mov [edi+288*6+4],ebx + mov ebx,[ecx+20] + bswap ebx + add ebx,edx + mov [edi+288*5],ebx + mov ebx,[ecx+16] + bswap ebx + add ebx,edx + mov [edi+288*5+4],ebx + mov ebx,[ecx+28] + bswap ebx + add ebx,edx + mov [edi+288*4],ebx + mov ebx,[ecx+24] + bswap ebx + add ebx,edx + mov [edi+288*4+4],ebx + mov ebx,[ecx+36] + bswap ebx + add ebx,edx + mov [edi+288*3],ebx + mov ebx,[ecx+32] + bswap ebx + add ebx,edx + mov [edi+288*3+4],ebx + mov ebx,[ecx+44] + bswap ebx + add ebx,edx + mov [edi+288*2],ebx + mov ebx,[ecx+40] + bswap ebx + add ebx,edx + mov [edi+288*2+4],ebx + mov ebx,[ecx+52] + bswap ebx + add ebx,edx + mov [edi+288],ebx + mov ebx,[ecx+48] + bswap ebx + add ebx,edx + mov [edi+288+4],ebx + mov ebx,[ecx+60] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+56] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov dword[tleftnb],8 +%%nextb + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextb + sub edi,288*8 + jmp %5 +%%flipxpart + mov dword[tleftnb],8 +%%nextbf + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextbf + sub edi,288*8 + jmp %5 +%%flipypart + add edi,288*7 + test word[vrama+eax],4000h + jnz near %%flipxypart + mov dword[tleftnb],8 +%%nextbm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbm + add edi,288 + jmp %5 +%%flipxypart + mov dword[tleftnb],8 +%%nextbfm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbfm + add edi,288 +%5 + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,8 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawtileng16x16 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + push eax + mov ebx,[ecx] + mov eax,[ecx+4] + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + mov ebx,[ecx+8] + mov eax,[ecx+12] + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+16] + mov eax,[ecx+20] + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+24] + mov eax,[ecx+28] + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+32] + mov eax,[ecx+36] + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+40] + mov eax,[ecx+44] + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+48] + mov eax,[ecx+52] + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+56] + mov eax,[ecx+60] + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + pop eax + jmp %%done +%%flipxfull + push eax + mov ebx,[ecx+4] + mov eax,[ecx] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + mov ebx,[ecx+12] + mov eax,[ecx+8] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+20] + mov eax,[ecx+16] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+28] + mov eax,[ecx+24] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+36] + mov eax,[ecx+32] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+44] + mov eax,[ecx+40] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+52] + mov eax,[ecx+48] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+60] + mov eax,[ecx+56] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + pop eax + jmp %%done +%%flipyfull + test word[vrama+eax],4000h + jnz near %%flipxyfull + push eax + mov ebx,[ecx] + mov eax,[ecx+4] + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + mov ebx,[ecx+8] + mov eax,[ecx+12] + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+16] + mov eax,[ecx+20] + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+24] + mov eax,[ecx+28] + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+32] + mov eax,[ecx+36] + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+40] + mov eax,[ecx+44] + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+48] + mov eax,[ecx+52] + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+56] + mov eax,[ecx+60] + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + pop eax + jmp %%done +%%flipxyfull + push eax + mov ebx,[ecx+4] + mov eax,[ecx] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*7],ebx + mov [edi+288*7+4],eax + mov ebx,[ecx+12] + mov eax,[ecx+8] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*6],ebx + mov [edi+288*6+4],eax + mov ebx,[ecx+20] + mov eax,[ecx+16] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*5],ebx + mov [edi+288*5+4],eax + mov ebx,[ecx+28] + mov eax,[ecx+24] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*4],ebx + mov [edi+288*4+4],eax + mov ebx,[ecx+36] + mov eax,[ecx+32] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*3],ebx + mov [edi+288*3+4],eax + mov ebx,[ecx+44] + mov eax,[ecx+40] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288*2],ebx + mov [edi+288*2+4],eax + mov ebx,[ecx+52] + mov eax,[ecx+48] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi+288],ebx + mov [edi+288+4],eax + mov ebx,[ecx+60] + mov eax,[ecx+56] + bswap ebx + bswap eax + add ebx,edx + add eax,edx + mov [edi],ebx + mov [edi+4],eax + pop eax + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov dword[tleftnb],8 +%%nextb + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextb + sub edi,288*8 + jmp %%done +%%flipxpart + mov dword[tleftnb],8 +%%nextbf + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + add ecx,8 + add edi,288 + dec dword[tleftnb] + jnz %%nextbf + sub edi,288*8 + jmp %%done +%%flipypart + add edi,288*7 + test word[vrama+eax],4000h + jnz near %%flipxypart + mov dword[tleftnb],8 +%%nextbm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbm + add edi,288 + jmp %%done +%%flipxypart + mov dword[tleftnb],8 +%%nextbfm + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm + add ecx,8 + sub edi,288 + dec dword[tleftnb] + jnz %%nextbfm + add edi,288 +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%5 + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawbgtileng 2 + mov dword[ng16bprval],0 + mov dword[ng16bbgval],%1 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + push ebx + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc + lea ecx,[ecx*8] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxinc + add eax,edx + neg dx +.noxinc + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawtileng4b +.no4bit + cmp dl,1 + jne near .no2bit + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawtileng2b +.no2bit + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawtileng8b +.no8bit + pop ebx + ret + +.tiles16x16 + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + push ebx + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2 + lea ecx,[ecx*4] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2 + add eax,edx + neg dx +.noxinc2 + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit2 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawtileng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawtileng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawtileng16x168b +.no8bit2 + pop ebx + ret +%endmacro + +%macro drawbgtilengpr1 2 + mov dword[ng16bprval],2000h + mov dword[ng16bbgval],%1 + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + push ebx + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit + ; eax = pointer to beginning of tile area + jmp drawtileng4b +.no4bit + cmp dl,1 + jne near .no2bit + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawtileng2b +.no2bit + cmp dl,3 + jne near .no8bit + ; eax = pointer to beginning of tile area + jmp drawtileng8b +.no8bit + pop ebx + ret +.tiles16x16 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + mov dword[taddnfy16x16],0 + add ecx,ebx + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + push ebx + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2 + ; eax = pointer to beginning of tile area + jmp drawtileng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawtileng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit2 + ; eax = pointer to beginning of tile area + jmp drawtileng16x168b +.no8bit2 + pop ebx + ret +%endmacro + +%macro drawlineng 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %5 +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + jmp %5 + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %5 + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + jmp %5 + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%5 + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,8 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlineng16x16 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%done + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + add ecx,[yposng] + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%flipxfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%flipyfull + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov ebx,[ecx] + add ebx,edx + mov [edi],ebx + mov ebx,[ecx+4] + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%flipxyfull + mov ebx,[ecx+4] + bswap ebx + add ebx,edx + mov [edi],ebx + mov ebx,[ecx] + bswap ebx + add ebx,edx + mov [edi+4],ebx + jmp %%done +%%parttile + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawd + add ebx,edx + test bl,%8 + jz %%drawa + mov [edi],bl +%%drawa + test bh,%8 + jz %%drawb + mov [edi+1],bh +%%drawb + shr ebx,16 + test bl,%8 + jz %%drawc + mov [edi+2],bl +%%drawc + test bh,%8 + jz %%drawd + mov [edi+3],bh +%%drawd + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2 + add ebx,edx + test bl,%8 + jz %%drawa2 + mov [edi+4],bl +%%drawa2 + test bh,%8 + jz %%drawb2 + mov [edi+5],bh +%%drawb2 + shr ebx,16 + test bl,%8 + jz %%drawc2 + mov [edi+6],bl +%%drawc2 + test bh,%8 + jz %%drawd2 + mov [edi+7],bh +%%drawd2 + jmp %%done + +%%flipxpart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdf + add ebx,edx + test bl,%8 + jz %%drawaf + mov [edi+7],bl +%%drawaf + test bh,%8 + jz %%drawbf + mov [edi+6],bh +%%drawbf + shr ebx,16 + test bl,%8 + jz %%drawcf + mov [edi+5],bl +%%drawcf + test bh,%8 + jz %%drawdf + mov [edi+4],bh +%%drawdf + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2f + add ebx,edx + test bl,%8 + jz %%drawa2f + mov [edi+3],bl +%%drawa2f + test bh,%8 + jz %%drawb2f + mov [edi+2],bh +%%drawb2f + shr ebx,16 + test bl,%8 + jz %%drawc2f + mov [edi+1],bl +%%drawc2f + test bh,%8 + jz %%drawd2f + mov [edi],bh +%%drawd2f + jmp %%done + +%%flipypart + add ecx,[flipyposng] + test word[vrama+eax],4000h + jnz near %%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdm + add ebx,edx + test bl,%8 + jz %%drawam + mov [edi],bl +%%drawam + test bh,%8 + jz %%drawbm + mov [edi+1],bh +%%drawbm + shr ebx,16 + test bl,%8 + jz %%drawcm + mov [edi+2],bl +%%drawcm + test bh,%8 + jz %%drawdm + mov [edi+3],bh +%%drawdm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2m + add ebx,edx + test bl,%8 + jz %%drawa2m + mov [edi+4],bl +%%drawa2m + test bh,%8 + jz %%drawb2m + mov [edi+5],bh +%%drawb2m + shr ebx,16 + test bl,%8 + jz %%drawc2m + mov [edi+6],bl +%%drawc2m + test bh,%8 + jz %%drawd2m + mov [edi+7],bh +%%drawd2m + jmp %%done + +%%flipxypart + mov ebx,[ecx] + or ebx,ebx + jz %%drawdfm + add ebx,edx + test bl,%8 + jz %%drawafm + mov [edi+7],bl +%%drawafm + test bh,%8 + jz %%drawbfm + mov [edi+6],bh +%%drawbfm + shr ebx,16 + test bl,%8 + jz %%drawcfm + mov [edi+5],bl +%%drawcfm + test bh,%8 + jz %%drawdfm + mov [edi+4],bh +%%drawdfm + mov ebx,[ecx+4] + or ebx,ebx + jz %%drawd2fm + add ebx,edx + test bl,%8 + jz %%drawa2fm + mov [edi+3],bl +%%drawa2fm + test bh,%8 + jz %%drawb2fm + mov [edi+2],bh +%%drawb2fm + shr ebx,16 + test bl,%8 + jz %%drawc2fm + mov [edi+1],bl +%%drawc2fm + test bh,%8 + jz %%drawd2fm + mov [edi],bh +%%drawd2fm +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%5 + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawbglineng 2 + mov dword[ng16bprval],0 + mov dword[ng16bbgval],%1 + cmp byte[bgmode],5 + jb %%nointerl + test byte[intrlng+ebx],01h + jz %%nointerl + add ecx,ebx + add ecx,[cfieldad] +%%nointerl + push ebx + mov byte[curmosaicsz],1 + xor eax,eax + test byte[mosenng+ebx],1 << %1 + jz %%nomosaic + mov al,[mosszng+ebx] + or al,al + jz %%nomosaic + inc al + mov byte[curmosaicsz],al + mov cl,al + mov al,bl + div cl + mul cl + mov ebx,eax + mov [pesimpng],esi + mov edi,xtravbuf+16 + mov ecx,64 + xor eax,eax + mov esi,xtravbuf+16 + rep stosd + or ebx,ebx + jnz %%nozeroline + inc ebx +%%nozeroline + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + jmp %%yesmosaic +%%nomosaic + cmp byte[BGMA+ebx],5 + jae near .tiles16x8 +%%yesmosaic + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + cmp byte[BGMA+ebx],2 + je near .offsetm +; cmp byte[BGMA+ebx],4 +; je near .offsetm2 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxinc + add eax,edx + neg dx +.noxinc + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawlineng4b +.no4bit + cmp dl,1 + jne near .no2bit + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawlineng2b +.no2bit + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawlineng8b +.no8bit + pop ebx + ret + +.tiles16x16 + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2 + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2 + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2 + add eax,edx + neg dx +.noxinc2 + mov edi,ecx + sub dx,64 + and ecx,1F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit2 + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawlineng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawlineng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + jmp drawlineng16x168b +.no8bit2 + pop ebx + ret + +.tiles16x8 + cmp byte[t16x161+ebx+%1*256],1 + je .tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],0 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,100h + jz .noyinc2c + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2c + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + jmp .tiles16x8hr +.tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy2 + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy2 + mov eax,[BGPT1+ebx*2+%1*512] + test ecx,200h + jz .noyinc2b + add eax,[BGPT1Y+ebx*2+%1*512] +.noyinc2b + lea edx,[ecx*8] + lea ecx,[ecx*4] + and edx,38h + and ecx,07C0h ; 1Fh*40h +.tiles16x8hr + mov [yposng],edx + xor edx,38h + add eax,ecx + mov [flipyposng],edx + mov ecx,[BG1SXl+ebx*2+%1*512] + add ecx,ecx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,200h + jz .noxinc2b + add eax,edx + neg dx +.noxinc2b + mov edi,ecx + sub dx,64 + and ecx,01F0h + and eax,0FFFFh + shr ecx,3 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,0Fh + and edx,07h + and ecx,0FFFFh + shr edi,1 + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bit2b + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loop2b + mov cx,[vrama+eax] + test ecx,2000h + jnz near .fintile2b + drawlineng16x8 tltype4b, preparet4ba, cachesingle4bng,.loop2b,.fintile2b,ngpalcon4b,test4ba,0Fh,%1 +.no4bit2b + cmp dl,1 + jne near .no2bit2b + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov byte[tleftn],33 +.loopb2b + mov cx,[vrama+eax] + test ecx,2000h + jnz near .fintileb2b + drawlineng16x8 tltype2b, preparet2ba, cachesingle2bng,.loopb2b,.fintileb2b,ngpalcon2b,test2ba,03h,%1 +.no2bit2b + pop ebx + ret + + ; Offsetmode calculation : *1024+*32+ +.offsetm + xor edx,edx + mov dx,[BG3SYl+ebx*2] + and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + add eax,40h + mov edx,eax + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincd + add eax,[BGPT1Y+ebx*2+%1*512] +.noyincd + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + mov [yposngom],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov [flipyposngom],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincd + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincd + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,2 + jne near .no4bitd + shr ecx,5 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopd + mov cx,[vrama+eax] + test ecx,2000h + jnz near .fintiled + drawlinengom tltype4b, preparet4ba, cachesingle4bng,.loopd,.fintiled,ngpalcon4b,test4ba,0Fh,%1 +.no4bitd + pop ebx + ret + +.offsetm2 + xor edx,edx + mov dx,[BG3SYl+ebx*2] + and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + add eax,40h + mov edx,eax + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincdn + add eax,[BGPT1Y+ebx*2+%1*512] +.noyincdn + lea ecx,[ecx*8] + mov edx,ecx + and ecx,07C0h ; 1Fh*40h + and edx,38h + add eax,ecx + mov [yposng],edx + mov [yposngom],edx + xor edx,38h + mov ecx,[BG1SXl+ebx*2+%1*512] + mov [flipyposng],edx + mov [flipyposngom],edx + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincdn + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincdn + mov edi,ecx + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + mov [bgtxad+ebx*2+%2*512],dx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + mov ecx,[BGOPT1+ebx*2+%1*512] + mov edx,[BGMA+ebx] + and edi,07h + and edx,07h + and ecx,0FFFFh + mov edx,[colormodedef+edx*4+%1] + neg edi + cmp dl,1 + jne near .no2bitdn + ; eax = pointer to beginning of tile area + shr ecx,4 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov byte[tleftn],33 +.loopdn + mov cx,[vrama+eax] + test cx,2000h + jnz near .fintiledn + drawlinengom2 tltype2b, preparet2ba, cachesingle2bng,.loopdn,.fintiledn,ngpalcon2b,test2ba,03h,%1 +.no2bitdn + cmp dl,3 + jne near .no8bitdn + ; eax = pointer to beginning of tile area + shr ecx,6 + add edi,esi + mov [ngptrdat+%2*1024+ebx*4],ecx + mov [ngptrdat2],ecx + mov [ngceax+%2*1024+ebx*4],eax + mov [ngcedi+%2*1024+ebx*4],edi + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn2 + mov cx,[vrama+eax] + test cx,2000h + jnz near .fintiledn2 + drawlinengom2 tltype8b, preparet8ba, cachesingle8bng,.loopdn2,.fintiledn2,ngpalcon8b,test8ba,0FFh,%1 +.no8bitdn + pop ebx + ret +%endmacro + +%macro mosender 1 +.nodraw + add edi,%1 + add esi,%1 + dec ecx + jnz .next + pop esi + mov dword[ignor512],0 + ret +%endmacro + +%macro drawbglinengpr1 2 + mov dword[ng16bprval],2000h + mov dword[ng16bbgval],%1 + push ebx + mov byte[curmosaicsz],1 + xor eax,eax + test byte[mosenng+ebx],1 << %1 + jz %%nomosaic + mov al,[mosszng+ebx] + or al,al + jz %%nomosaic + inc al + mov byte[curmosaicsz],al + mov cl,al + mov al,bl + div cl + mul cl + mov ebx,eax + mov [pesimpng],esi + mov edi,xtravbuf+16 + mov ecx,64 + xor eax,eax + mov esi,xtravbuf+16 + rep stosd + or ebx,ebx + jnz %%nomosaic + inc ebx + jmp %%yesmosaic +%%nomosaic + cmp byte[BGMA+ebx],5 + jae near .tiles16x8 +%%yesmosaic + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16 + cmp byte[BGMA+ebx],2 + je near .offsetm +; cmp byte[BGMA+ebx],4 +; je near .offsetm2 + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit + ; eax = pointer to beginning of tile area + jmp drawlineng4b +.no4bit + cmp dl,1 + jne near .no2bit + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode0 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode0 + jmp drawlineng2b +.no2bit + cmp dl,3 + jne near .no8bit + ; eax = pointer to beginning of tile area + jmp drawlineng8b +.no8bit + pop ebx + ret + +.tiles16x16 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + mov dword[taddnfy16x16],0 + add ecx,ebx + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomy + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomy + + lea eax,[ecx*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2 + ; eax = pointer to beginning of tile area + jmp drawlineng16x164b +.no4bit2 + cmp dl,1 + jne near .no2bit2 + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + cmp byte[BGMA+ebx],0 + jne .nomode02 + mov ebx,[mode0ads] + mov [mode0add],ebx +.nomode02 + jmp drawlineng16x162b +.no2bit2 + cmp dl,3 + jne near .no8bit2 + ; eax = pointer to beginning of tile area + jmp drawlineng16x168b +.no8bit2 + pop ebx + ret + +.tiles16x8 + mov ecx,[BG1SYl+ebx*2+%1*512] + and ecx,0FFFFh + add ecx,ebx + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],16 + test ecx,08h + jz .nobottomyb + mov dword[taddnfy16x16],16 + mov dword[taddfy16x16],-16 +.nobottomyb + cmp byte[t16x161+ebx+%1*256],1 + je near .tiles16x16hr + mov dword[taddnfy16x16],0 + mov dword[taddfy16x16],0 +.tiles16x16hr + + lea eax,[ecx*8] + and eax,38h + mov [yposng],eax + xor eax,38h + mov [flipyposng],eax + + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + cmp dl,2 + jne near .no4bit2b + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loop2b + mov cx,[vrama+eax] + test cx,2000h + jz near .fintile2b + drawlineng16x8 tltype4b, preparet4ba, cachesingle4bng,.loop2b,.fintile2b,ngpalcon4b,test4ba,0Fh,%1 + pop ebx + ret +.no4bit2b + cmp dl,1 + jne near .no2bit2b + ; eax = pointer to beginning of tile area + mov dword[mode0add],0 + mov byte[tleftn],33 +.loopb2b + mov cx,[vrama+eax] + test ecx,2000h + jz near .fintileb2b + drawlineng16x8 tltype2b, preparet2ba, cachesingle2bng,.loopb2b,.fintileb2b,ngpalcon2b,test2ba,03h,%1 + pop ebx + ret +.no2bit2b + pop ebx + ret + +.offsetm + xor edx,edx + mov dx,[BG3SYl+ebx*2] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov edx,eax + add edx,40h + and edx,0FFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincdd + add [ofsmtptr],edx +.noxincdd + and ecx,0F8h + shr ecx,2 + add [ofsmtptr],ecx + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + mov [yposngom],eax + xor eax,38h + mov [flipyposng],eax + mov [flipyposngom],eax + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + cmp dl,2 + jne near .no4bitd + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopd + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiled + drawlinengom tltype4b, preparet4ba, cachesingle4bng,.loopd,.fintiled,ngpalcon4b,test4ba,0Fh,%1 +.no4bitd + pop ebx + ret + +.offsetm2 + xor edx,edx + mov dx,[BG3SYl+ebx*2] + and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[BGPT3+ebx*2] + add ax,dx + xor edx,edx + mov dx,[BG3SXl+ebx*2] + and dx,0F8h + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov edx,eax + add edx,40h + and edx,0FFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[BGPT1Y+ebx*2+%1*512] + mov [ofsmady],eax + mov eax,[BGPT1X+ebx*2+%1*512] + mov [ofsmadx],eax + mov eax,[BGPT1+ebx*2+%1*512] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + mov ecx,[BG1SXl+ebx*2+%1*512] + mov edx,[BGPT1X+ebx*2+%1*512] + test ecx,100h + jz .noxincddn + add [ofsmtptr],edx +.noxincddn + and ecx,0F8h + shr ecx,2 + add [ofsmtptr],ecx + mov eax,[BG1SYl+ebx*2+%1*512] + and eax,0FFFFh + add eax,ebx + lea eax,[eax*8] + and eax,38h + mov [yposng],eax + mov [yposngom],eax + xor eax,38h + mov [flipyposng],eax + mov [flipyposngom],eax + mov edx,[BGMA+ebx] + mov ecx,[bgtxad+ebx*2+%2*512] + and edx,07h + mov [bgtxadd],cx + mov ecx,[ngptrdat+%2*1024+ebx*4] + mov edx,[colormodedef+edx*4+%1] + mov [ngptrdat2],ecx + mov eax,[ngceax+%2*1024+ebx*4] + mov edi,[ngcedi+%2*1024+ebx*4] + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + cmp dl,1 + jne near .no2bitdn + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiledn + drawlinengom2 tltype2b, preparet2ba, cachesingle2bng,.loopdn,.fintiledn,ngpalcon2b,test2ba,03h,%1 +.no2bitdn + cmp dl,3 + jne near .no8bitdn + ; eax = pointer to beginning of tile area + mov byte[tleftn],33 +.loopdn2 + mov cx,[vrama+eax] + test cx,2000h + jz near .fintiledn2 + drawlinengom2 tltype8b, preparet8ba, cachesingle8bng,.loopdn2,.fintiledn2,ngpalcon8b,test8ba,0FFh,%1 +.no8bitdn + pop ebx + ret +%endmacro + \ No newline at end of file diff --git a/zsnes/src/video/newgfxwn.mac b/zsnes/src/video/newgfxwn.mac new file mode 100644 index 00000000..4cd87347 --- /dev/null +++ b/zsnes/src/video/newgfxwn.mac @@ -0,0 +1,1048 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + + + + + + +Nextwinmode: + push ebx + mov ebx,[ngcwinptr] + xor dword[ngcwinmode],1 + mov ebx,[ebx+4] + add dword[ngcwinptr],4 + mov [ngcpixleft],ebx + pop ebx + ret + +%macro processnextdrawwin 3 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + test %1,%3 + jz %%nodraw + mov [edi+%2],%1 +%%nodraw +%endmacro + +%macro processwinpixel 0 + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + dec dword[ngcpixleft] + jnz %%notzero2 + call Nextwinmode +%%notzero2 +%endmacro + +%macro drawlinengwin 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jz %%noflipypart + add ecx,[flipyposng] + jmp %%flipypart +%%noflipypart + add ecx,[yposng] +%%flipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + add ebx,edx + processnextdrawwin bl,0,%8 + processnextdrawwin bh,1,%8 + shr ebx,16 + processnextdrawwin bl,2,%8 + processnextdrawwin bh,3,%8 + mov ebx,[ecx+4] + add ebx,edx + processnextdrawwin bl,4,%8 + processnextdrawwin bh,5,%8 + shr ebx,16 + processnextdrawwin bl,6,%8 + processnextdrawwin bh,7,%8 + jmp .fin +%%flipxpart + mov ebx,[ecx+4] + add ebx,edx + rol ebx,16 + processnextdrawwin bh,0,%8 + processnextdrawwin bl,1,%8 + shr ebx,16 + processnextdrawwin bh,2,%8 + processnextdrawwin bl,3,%8 + mov ebx,[ecx] + add ebx,edx + rol ebx,16 + processnextdrawwin bh,4,%8 + processnextdrawwin bl,5,%8 + shr ebx,16 + processnextdrawwin bh,6,%8 + processnextdrawwin bl,7,%8 + jmp .fin +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +.fin + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,8 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlineng16x16win 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz %%flipypart + add ecx,[yposng] + jmp %%noflipypart +%%flipypart + add ecx,[flipyposng] +%%noflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + add ebx,edx + processnextdrawwin bl,0,%8 + processnextdrawwin bh,1,%8 + shr ebx,16 + processnextdrawwin bl,2,%8 + processnextdrawwin bh,3,%8 + mov ebx,[ecx+4] + add ebx,edx + processnextdrawwin bl,4,%8 + processnextdrawwin bh,5,%8 + shr ebx,16 + processnextdrawwin bl,6,%8 + processnextdrawwin bh,7,%8 + jmp %%done +%%flipxpart + mov ebx,[ecx+4] + add ebx,edx + rol ebx,16 + processnextdrawwin bh,0,%8 + processnextdrawwin bl,1,%8 + shr ebx,16 + processnextdrawwin bh,2,%8 + processnextdrawwin bl,3,%8 + mov ebx,[ecx] + add ebx,edx + rol ebx,16 + processnextdrawwin bh,4,%8 + processnextdrawwin bl,5,%8 + shr ebx,16 + processnextdrawwin bh,6,%8 + processnextdrawwin bl,7,%8 +%%done + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz near %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawlinengomwin 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[cbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + %2 + ; start drawing from ecx to edi + test word[vrama+eax],8000h + jnz near %%flipypart + add ecx,[yposng] + jmp %%notflipypart +%%flipypart + add ecx,[flipyposng] +%%notflipypart + test word[vrama+eax],4000h + jnz near %%flipxpart + mov ebx,[ecx] + add ebx,edx + processnextdrawwin bl,0,%8 + processnextdrawwin bh,1,%8 + shr ebx,16 + processnextdrawwin bl,2,%8 + processnextdrawwin bh,3,%8 + mov ebx,[ecx+4] + add ebx,edx + processnextdrawwin bl,4,%8 + processnextdrawwin bh,5,%8 + shr ebx,16 + processnextdrawwin bl,6,%8 + processnextdrawwin bh,7,%8 + jmp %%endokay + +%%flipxpart + mov ebx,[ecx+4] + add ebx,edx + rol ebx,16 + processnextdrawwin bh,0,%8 + processnextdrawwin bl,1,%8 + shr ebx,16 + processnextdrawwin bh,2,%8 + processnextdrawwin bl,3,%8 + mov ebx,[ecx] + add ebx,edx + rol ebx,16 + processnextdrawwin bh,4,%8 + processnextdrawwin bl,5,%8 + shr ebx,16 + processnextdrawwin bh,6,%8 + processnextdrawwin bl,7,%8 + jmp %%endokay +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%endokay + mov ebx,[cbgval] + add word[ofsmmptr],2 + inc dword[bg1totng+ebx*4] + add word[ofsmtptr],2 + mov ax,[ofsmmptr] + mov ebx,[yposngom] + mov edx,[flipyposngom] + mov [yposng],ebx + mov [flipyposng],edx + add edi,8 + test eax,03Fh + jz near %%tileadd +%%next + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov ecx,[ofsmval] + add dword[ofshvaladd],8 + test dword[ebx],ecx + jz .noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz .noupper + add ax,[ofsmady] +.noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yposng],edx + xor edx,38h + mov [flipyposng],edx +.noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofsmcptr2],2 + mov ecx,[ofsmval] + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],ecx + jz %%noofsmh + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx +%%noofsmh + dec byte[tleftn] + jnz near %4 +%%fin + pop ebx + cmp byte[curmosaicsz],1 + jne near domosaicng + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add word[ofsmtptr],bx + jmp %%next +%endmacro + +%macro parttilewin 2 + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[ecx+%1*8] + or bl,bl + jz %%nodraw + add bl,dl + mov [edi+%2*288],bl +%%nodraw +%endmacro + +%macro drawtilengwin 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %5 + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov dword[tleftnb],8 +%%loopfa + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[ecx] + add bl,dl + mov [edi],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx+8*7] + add bl,dl + mov [edi+288*7],bl +%%nodraw + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfa + sub edi,8 + jmp %%end +%%flipxfull + mov dword[tleftnb],8 + add ecx,7 +%%loopfb + dec dword[ngcpixleft] + jnz %%notzerob + call Nextwinmode +%%notzerob + cmp dword[ngcwinmode],1 + je %%nodrawb + mov bl,[ecx] + add bl,dl + mov [edi],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx+8*7] + add bl,dl + mov [edi+288*7],bl +%%nodrawb + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfb + sub edi,8 + jmp %%end +%%flipyfull + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov dword[tleftnb],8 +%%loopfc + dec dword[ngcpixleft] + jnz %%notzeroc + call Nextwinmode +%%notzeroc + cmp dword[ngcwinmode],1 + je %%nodrawc + mov bl,[ecx+8*7] + add bl,dl + mov [edi],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx] + add bl,dl + mov [edi+288*7],bl +%%nodrawc + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfc + sub edi,8 + jmp %%end +%%flipxyfull + mov dword[tleftnb],8 + add ecx,7 +%%loopfd + dec dword[ngcpixleft] + jnz %%notzerod + call Nextwinmode +%%notzerod + cmp dword[ngcwinmode],1 + je %%nodrawd + mov bl,[ecx+8*7] + add bl,dl + mov [edi],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx] + add bl,dl + mov [edi+288*7],bl +%%nodrawd + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfd + sub edi,8 + jmp %%end +%%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfullp + test dword[vrama+eax],4000h + jnz near %%flipxfullp + mov dword[tleftnb],8 +%%loopfap + dec dword[ngcpixleft] + jnz %%notzerop + call Nextwinmode +%%notzerop + parttilewin 0,0 + parttilewin 1,1 + parttilewin 2,2 + parttilewin 3,3 + parttilewin 4,4 + parttilewin 5,5 + parttilewin 6,6 + parttilewin 7,7 + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfap + sub edi,8 + jmp %%end +%%flipxfullp + mov dword[tleftnb],8 + add ecx,7 +%%loopfbp + dec dword[ngcpixleft] + jnz %%notzerobp + call Nextwinmode +%%notzerobp + parttilewin 0,0 + parttilewin 1,1 + parttilewin 2,2 + parttilewin 3,3 + parttilewin 4,4 + parttilewin 5,5 + parttilewin 6,6 + parttilewin 7,7 + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfbp + sub edi,8 + jmp %%end +%%flipyfullp + test word[vrama+eax],4000h + jnz near %%flipxyfullp + mov dword[tleftnb],8 +%%loopfcp + dec dword[ngcpixleft] + jnz %%notzerocp + call Nextwinmode +%%notzerocp + parttilewin 7,0 + parttilewin 6,1 + parttilewin 5,2 + parttilewin 4,3 + parttilewin 3,4 + parttilewin 2,5 + parttilewin 1,6 + parttilewin 0,7 + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfcp + sub edi,8 + jmp %%end +%%flipxyfullp + mov dword[tleftnb],8 + add ecx,7 +%%loopfdp + dec dword[ngcpixleft] + jnz %%notzerodp + call Nextwinmode +%%notzerodp + parttilewin 7,0 + parttilewin 6,1 + parttilewin 5,2 + parttilewin 4,3 + parttilewin 3,4 + parttilewin 2,5 + parttilewin 1,6 + parttilewin 0,7 + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfdp + sub edi,8 + jmp %%end +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%end + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + add edi,8 + test eax,03Fh + jz %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + +%macro drawtileng16x16win 8 + ; tile value : bit 15 = flipy, bit 14 = flipx, bit 13 = priority value + ; bit 10-12 = palette, 0-9=tile# + mov ebx,[ng16bbgval] + mov dl,ch + inc dword[bg1drwng+ebx*4] + and ecx,3FFh + and edx,1Fh + add ecx,[ngptrdat2] + add cx,[taddnfy16x16] + test dword[vrama+eax],8000h + jz %%noflipy + add cx,[taddfy16x16] +%%noflipy + test dword[vrama+eax],4000h + jz %%noflipx + inc cx +%%noflipx +%%nexttile + push ecx + push edx + mov edx,[%6+edx*4] + %7 + jnz near %%docache +%%returnfromcache + cmp byte[%1+ecx],2 + je near %%skip + cmp byte[%1+ecx],0 + je near %%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfull + test dword[vrama+eax],4000h + jnz near %%flipxfull + mov dword[tleftnb],8 +%%loopfa + dec dword[ngcpixleft] + jnz %%notzero + call Nextwinmode +%%notzero + cmp dword[ngcwinmode],1 + je %%nodraw + mov bl,[ecx] + add bl,dl + mov [edi],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx+8*7] + add bl,dl + mov [edi+288*7],bl +%%nodraw + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfa + sub edi,8 + jmp %%end +%%flipxfull + mov dword[tleftnb],8 + add ecx,7 +%%loopfb + dec dword[ngcpixleft] + jnz %%notzerob + call Nextwinmode +%%notzerob + cmp dword[ngcwinmode],1 + je %%nodrawb + mov bl,[ecx] + add bl,dl + mov [edi],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx+8*7] + add bl,dl + mov [edi+288*7],bl +%%nodrawb + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfb + sub edi,8 + jmp %%end +%%flipyfull + test word[vrama+eax],4000h + jnz near %%flipxyfull + mov dword[tleftnb],8 +%%loopfc + dec dword[ngcpixleft] + jnz %%notzeroc + call Nextwinmode +%%notzeroc + cmp dword[ngcwinmode],1 + je %%nodrawc + mov bl,[ecx+8*7] + add bl,dl + mov [edi],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx] + add bl,dl + mov [edi+288*7],bl +%%nodrawc + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfc + sub edi,8 + jmp %%end +%%flipxyfull + mov dword[tleftnb],8 + add ecx,7 +%%loopfd + dec dword[ngcpixleft] + jnz %%notzerod + call Nextwinmode +%%notzerod + cmp dword[ngcwinmode],1 + je %%nodrawd + mov bl,[ecx+8*7] + add bl,dl + mov [edi],bl + mov bl,[ecx+8*6] + add bl,dl + mov [edi+288],bl + mov bl,[ecx+8*5] + add bl,dl + mov [edi+288*2],bl + mov bl,[ecx+8*4] + add bl,dl + mov [edi+288*3],bl + mov bl,[ecx+8*3] + add bl,dl + mov [edi+288*4],bl + mov bl,[ecx+8*2] + add bl,dl + mov [edi+288*5],bl + mov bl,[ecx+8] + add bl,dl + mov [edi+288*6],bl + mov bl,[ecx] + add bl,dl + mov [edi+288*7],bl +%%nodrawd + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfd + sub edi,8 + jmp %%end +%%parttile + %2 + ; start drawing from ecx + test dword[vrama+eax],8000h + jnz near %%flipyfullp + test dword[vrama+eax],4000h + jnz near %%flipxfullp + mov dword[tleftnb],8 +%%loopfap + dec dword[ngcpixleft] + jnz %%notzerop + call Nextwinmode +%%notzerop + parttilewin 0,0 + parttilewin 1,1 + parttilewin 2,2 + parttilewin 3,3 + parttilewin 4,4 + parttilewin 5,5 + parttilewin 6,6 + parttilewin 7,7 + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfap + sub edi,8 + jmp %%end +%%flipxfullp + mov dword[tleftnb],8 + add ecx,7 +%%loopfbp + dec dword[ngcpixleft] + jnz %%notzerobp + call Nextwinmode +%%notzerobp + parttilewin 0,0 + parttilewin 1,1 + parttilewin 2,2 + parttilewin 3,3 + parttilewin 4,4 + parttilewin 5,5 + parttilewin 6,6 + parttilewin 7,7 + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfbp + sub edi,8 + jmp %%end +%%flipyfullp + test word[vrama+eax],4000h + jnz near %%flipxyfullp + mov dword[tleftnb],8 +%%loopfcp + dec dword[ngcpixleft] + jnz %%notzerocp + call Nextwinmode +%%notzerocp + parttilewin 7,0 + parttilewin 6,1 + parttilewin 5,2 + parttilewin 4,3 + parttilewin 3,4 + parttilewin 2,5 + parttilewin 1,6 + parttilewin 0,7 + inc ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfcp + sub edi,8 + jmp %%end +%%flipxyfullp + mov dword[tleftnb],8 + add ecx,7 +%%loopfdp + dec dword[ngcpixleft] + jnz %%notzerodp + call Nextwinmode +%%notzerodp + parttilewin 7,0 + parttilewin 6,1 + parttilewin 5,2 + parttilewin 4,3 + parttilewin 3,4 + parttilewin 2,5 + parttilewin 1,6 + parttilewin 0,7 + dec ecx + inc edi + dec dword[tleftnb] + jnz near %%loopfdp + sub edi,8 + jmp %%end +%%skip + processwinpixel + processwinpixel + processwinpixel + processwinpixel +%%end + pop edx + pop ecx + inc cx + test dword[vrama+eax],4000h + jz %%noflipxb + sub cx,2 +%%noflipxb + add edi,8 + xor dword[switch16x16],1 + jnz near %%nexttile +%%ntile + mov ebx,[ng16bbgval] + add ax,2 + inc dword[bg1totng+ebx*4] + test eax,03Fh + jz near %%tileadd +%%next + dec byte[tleftn] + jnz near %4 + pop ebx + ret +%%done +%5 + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + processwinpixel + add edi,16 + jmp %%ntile +%%docache + call %3 + jmp %%returnfromcache +%%tileadd + add ax,[bgtxadd] + jmp %%next +%endmacro + + \ No newline at end of file diff --git a/zsnes/src/video/procvid.asm b/zsnes/src/video/procvid.asm new file mode 100644 index 00000000..c6554e26 --- /dev/null +++ b/zsnes/src/video/procvid.asm @@ -0,0 +1,3605 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM BGMA,DSPMem,INTEnab,V8Mode,antienab,cacheud,cbitmode +EXTSYM ccud,cfield,cgfxmod,cgram,coladdb,coladdg,coladdr,cpalval,curblank +EXTSYM curfps,cvidmode,delay,draw16bnng,extlatch,fnamest,fulladdtab,En2xSaI +EXTSYM gammalevel,hirestiledat,ignor512,latchx,latchy,maxbr,ForceNewGfxOff +EXTSYM newengen,nextframe,objptr,pressed,prevpal,res512switch,res640 +EXTSYM resolutn,romispal,sbpmofs,sbselec,scaddtype,scadtng,scanlines +EXTSYM scbcong,selcA000,snesmouse,t1cc,vcache4b,vesa2_bpos,spritetablea +EXTSYM vesa2_clbit,vesa2_gpos,vesa2_rpos,vesa2red10,vesa2selec,vidbuffer +EXTSYM vidbufferm,vram,vsyncon,vbufdptr,KeyStateSelct,forceblnk,soundon +EXTSYM Open_File,Read_File,Close_File,Create_File,Write_File,Get_File_Date +EXTSYM Triplebufen,makepal,changepal,saveselectpal,displayfpspal,superscopepal +EXTSYM DrawScreen +EXTSYM Get_MouseData,Get_MousePositionDisplacement +EXTSYM GUIEnableTransp +EXTSYM GUIFontData +EXTSYM StopSound,StartSound +EXTSYM PrevPicture,File_Seek,File_Seek_End,nggposng +EXTSYM OSPort +EXTSYM Palette0 +EXTSYM GetTimeInSeconds +EXTSYM scaddset,scrnon,spcRam,nmiprevline,bgmode,ofsmcptr +EXTSYM interlval,bg3ptr,bg3scroly,bg3scrolx,C4Ram,SprValAdd,SA1IRQEn,SA1IRQV +EXTSYM winbg1en,winlogica,wincolen,winlogicb,dsp1ptr,dsp1array,bg3objptr +EXTSYM cnetptrhead,cnetptrtail,JoyBOrig,pl2neten,Voice6Ptr,HIRQLoc,SA1DoIRQ +EXTSYM mode7A,mode7B,mode7C,mode7D,mode7set,winbg3en,winl1,winr1,SA1DMAInfo +EXTSYM winl2,winr2,VIRQLoc,SA1Enable,mode7X0,mode7Y0,SA1Temp +EXTSYM SA1IRQTemp,SA1IRQEnable,SA1DMADest,SA1DMAChar,SA1DMASource,SA1DMACount +EXTSYM objptrn,Voice0State,TempValueSnd,nglogicval,bgtilesz,C4values +EXTSYM curexecstate,TempVidInfo,LatestBank,C4ObjSelec +EXTSYM BGMS1,scadsng,winenabm,winenabs,vidbright +EXTSYM genfulladdtab,genfulladdtabng +EXTSYM KeyQuickChat,CNetType,WritetochatBuffer,NetAddChar,TimerEnable,ShowTimer +EXTSYM ClearScreenSkip,debugdisble,cmovietimeint +EXTSYM ChatNick +EXTSYM StringLength +EXTSYM chatstrLt + + +NEWSYM ScreenScale, db 0 ; If horizontal is scaled or not +NEWSYM TempDebugV, dw 0 ; Temporary Debugging variable + +%macro MMXStuff 0 +%%1 + movq mm0,[esi] + movq [es:edi],mm0 + movq mm1,[esi+8] + movq [es:edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz %%1 +%endmacro + +%macro FPUStuff 1 + FILD QWORD [ESI+%1*16] + FILD QWORD [ESI+8+%1*16] + FISTP QWORD [ES:EDI+8+%1*16] + FISTP QWORD [ES:EDI+%1*16] +%endmacro + +%MACRO CopyFPU 0 +%ENDMACRO + +%include "video/copyvid.inc" + +NEWSYM FPUZero + mov [.Zero],eax + mov [.Zero+4],eax + mov [.Zero2],eax + mov [.Zero2+4],eax +.TopOfLoop + FILD QWORD [.Zero] + FILD QWORD [.Zero2] + FXCH + FISTP QWORD [EDI] + FISTP QWORD [EDI+8] + ADD EDI,16 + DEC ECX + JNZ .TopOfLoop + ret + +.Zero dd 0,0 +.Zero2 dd 0,0 + +NEWSYM FPUCopy, db 0 + +;******************************************************* +; ShowVideo Processes & displays video +;******************************************************* + +NEWSYM showvideo + push esi + push edi + push edx + push ebx + push ebp + inc byte[ccud] + mov bl,byte[ccud] + cmp byte[cacheud],bl + je .noinc + mov byte[ccud],0 +.noinc + call copyvid + mov eax,[KeyStateSelct] + test byte[pressed+eax],1 + jz .nosavesel + call saveselect +.nosavesel + xor ecx,ecx + pop ebp + pop ebx + pop edx + pop edi + pop esi + ret + + + +NEWSYM processmouse + push esi + push edi + push edx + push ebx + call Get_MouseData + mov [mousebuttons],bx + cmp byte[snesmouse],3 + jne .ss + cmp byte[pressed+13],0 + je .noautosw + cmp byte[ssautoswb],1 + je .ss + xor byte[ssautosw],20h + mov byte[ssautoswb],1 + mov dword[Msgptr],.ssautoen + cmp byte[ssautosw],0 + jne .nononauto + mov dword[Msgptr],.ssautodi +.nononauto + mov eax,[MsgCount] + mov [MessageOn],eax + jmp .ss +.noautosw + mov byte[ssautoswb],0 +.ss + call Get_MousePositionDisplacement + cmp byte[snesmouse],4 + je .le + cmp byte[snesmouse],3 + jne .ss2 +.le + add word[mousexloc],cx + test word[mousexloc],8000h + jz .nowrapleft + mov word[mousexloc],0 +.nowrapleft + cmp word[mousexloc],255 + jbe .nowrapright + mov word[mousexloc],255 +.nowrapright + mov ax,[mousexloc] + add ax,40 + mov [latchx],ax + mov byte[extlatch],40h +.ss2 + mov word[mousexpos],0 + cmp cx,0 + je .noxchange + mov byte[mousexdir],0 + cmp cx,0 + jge .noneg + mov byte[mousexdir],1 + neg cx +.noneg + mov [mousexpos],cx +.noxchange + cmp byte[snesmouse],4 + je .le2 + cmp byte[snesmouse],3 + jne .ss3 +.le2 + add word[mouseyloc],dx + test word[mouseyloc],8000h + jz .nowrapup + mov word[mouseyloc],0 +.nowrapup + cmp word[mouseyloc],223 + jbe .nowrapdown + mov word[mouseyloc],223 +.nowrapdown + mov ax,[mouseyloc] + mov [latchy],ax +.ss3 + mov word[mouseypos],0 + cmp dx,0 + je .noychange + mov byte[mouseydir],0 + cmp dx,0 + jge .noneg2 + mov byte[mouseydir],1 + neg dx +.noneg2 + mov [mouseypos],dx +.noychange + xor ecx,ecx + pop ebx + pop edx + pop edi + pop esi + ret + +.ssautoen db 'AUTOFIRE ENABLED.',0 +.ssautodi db 'AUTOFIRE DISABLED.',0 + +NEWSYM ssautosw, db 20h +NEWSYM ssautoswb, db 0 +NEWSYM mousebuttons, dw 0 +NEWSYM mousexpos, dw 0 +NEWSYM mousexdir, db 0 +NEWSYM mouseypos, dw 0 +NEWSYM mouseydir, db 0 +NEWSYM mousechan, db 0 +NEWSYM mousexloc, dw 128 +NEWSYM mouseyloc, dw 112 + +;******************************************************* +; Output Hex Outputs the hex in al @ esi +;******************************************************* + +NEWSYM outputhex + push edi + push esi + push eax + push ebx + push ecx + push esi + mov edi,FontData + xor ebx,ebx + mov bl,al + shr bl,4 + shl ebx,3 + add edi,ebx + add edi,8 + mov cl,8 +.loopa + mov ah,[edi] + mov ch,8 +.loopb + test ah,80h + jz .nowrite + mov byte[esi],128 + mov byte[esi+289],192 +.nowrite + shl ah,1 + inc esi + dec ch + jnz .loopb + add esi,280 + inc edi + dec cl + jnz .loopa + pop esi + add esi,8 + mov edi,FontData + xor ebx,ebx + mov bl,al + and bl,0Fh + shl ebx,3 + add edi,ebx + add edi,8 + mov cl,8 +.loopa2 + mov ah,[edi] + mov ch,8 +.loopb2 + test ah,80h + jz .nowrite2 + mov byte[esi],128 + mov byte[esi+289],192 +.nowrite2 + shl ah,1 + inc esi + dec ch + jnz .loopb2 + add esi,280 + inc edi + dec cl + jnz .loopa2 + pop ecx + pop ebx + pop eax + pop esi + pop edi + ret + +OutputText16b: + cmp byte[ForceNonTransp],1 + je near OutText16bnt + cmp byte[GUIEnableTransp],0 + je near OutText16bnt + ; output text in edi to esi + push ebx + push eax + mov cl,9 +.loopa + mov ch,9 + xor eax,eax + cmp cl,1 + je .not1 + mov al,[edi] + shl eax,1 +.not1 + xor ebx,ebx + cmp cl,9 + je .loopb + mov bl,[edi-1] +.loopb + test ax,100h + jz .nowrite + push eax + and word[esi],dx + shr word[esi],1 + and word[esi+75036*4],dx + shr word[esi+75036*4],1 + ror edx,16 + add word[esi],dx + add word[esi+75036*4],dx + ror edx,16 + pop eax + jmp .nowrite2 +.nowrite + test bx,100h + jz .nowrite2 + and word[esi],dx + shr word[esi],1 + and word[esi+75036*4],dx + shr word[esi+75036*4],1 +.nowrite2 + shl ax,1 + shl bx,1 + add esi,2 + dec ch + jnz .loopb + add esi,279*2 + inc edi + dec cl + jnz .loopa + pop eax + pop ebx + ret + +OutText16bnt: + ; output text in edi to esi + push ebx + push eax + mov cl,9 +.loopa + mov ch,9 + xor eax,eax + cmp cl,1 + je .not1 + mov al,[edi] + shl eax,1 +.not1 + xor ebx,ebx + cmp cl,9 + je .loopb + mov bl,[edi-1] +.loopb + test ax,100h + jz .nowrite + mov word[esi],0FFFFh + mov word[esi+75036*4],0FFFFh + jmp .nowrite2 +.nowrite + test bx,100h + jz .nowrite2 + and word[esi],dx + and word[esi+75036*4],dx + shr word[esi],1 + shr word[esi+75036*4],1 +.nowrite2 + shl ax,1 + shl bx,1 + add esi,2 + dec ch + jnz .loopb + add esi,279*2 + inc edi + dec cl + jnz .loopa + pop eax + pop ebx + ret + +NEWSYM outputhex16 + push edi + push esi + push eax + push ebx + push ecx + push edx + push esi + mov dx,[vesa2_clbitng] + ror edx,16 + mov dx,[vesa2_clbitng] + shr dx,1 + ror edx,16 + + mov edi,FontData + xor ebx,ebx + mov bl,al + shr bl,4 + shl ebx,3 + add edi,ebx + add edi,8 + call OutputText16b + pop esi + add esi,16 + mov edi,FontData + xor ebx,ebx + mov bl,al + and bl,0Fh + shl ebx,3 + add edi,ebx + add edi,8 + call OutputText16b + pop edx + pop ecx + pop ebx + pop eax + pop esi + pop edi + ret + +NEWSYM ASCII2Font + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,30h,00h,00h,00h,00h,00h,00h + db 00h,3Eh,33h,31h,3Fh,37h,2Fh,3Dh,3Ah,3Bh,35h,38h,39h,25h,28h,29h + db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0Ah,2Eh,40h,2Ah,32h,2Bh,36h + db 3Ch,0Bh,0Ch,0Dh,0Eh,0Fh,10h,11h,12h,13h,14h,15h,16h,17h,18h,19h + db 1Ah,1Bh,1Ch,1Dh,1Eh,1Fh,20h,21h,22h,23h,24h,2Ch,34h,2Dh,42h,26h + db 41h,0Bh,0Ch,0Dh,0Eh,0Fh,10h,11h,12h,13h,14h,15h,16h,17h,18h,19h + db 1Ah,1Bh,1Ch,1Dh,1Eh,1Fh,20h,21h,22h,23h,24h,43h,00h,44h,27h,00h + db 0Dh,1Fh,0Fh,0Bh,0Bh,0Bh,0Bh,0Dh,0Fh,0Fh,0Fh,13h,13h,13h,0Bh,0Bh + db 0Fh,0Bh,0Bh,19h,19h,19h,1Fh,1Fh,23h,19h,1Fh,0Dh,10h,23h,1Ah,10h + db 0Bh,13h,19h,1Fh,18h,18h,0Bh,19h,00h,00h,00h,00h,00h,00h,00h,00h + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h + db 00h,00h,00h,00h,00h,00h,00h,00h,00h,4Bh,4Ah,45h,46h,47h,48h,49h + +NEWSYM FontData + db 0,0,0,0,0,0,0,0 + db 01111100b,11000110b,11001110b,11010110b ; 0, 1 + db 11100110b,11000110b,01111100b,00000000b + db 00011000b,00111000b,01111000b,00011000b ; 1, 2 + db 00011000b,00011000b,01111110b,00000000b + db 01111100b,11000110b,00001100b,00011000b ; 2, 3 + db 00110000b,01100110b,11111110b,00000000b + db 01111100b,11000110b,00000110b,00111100b ; 3, 4 + db 00000110b,11000110b,01111100b,00000000b + db 00111100b,01101100b,11001100b,11111110b ; 4, 5 + db 00001100b,00001100b,00001100b,00000000b + db 11111110b,11000000b,11000000b,11111100b ; 5, 6 + db 00000110b,11000110b,01111100b,00000000b + db 00111100b,01100000b,11000000b,11111100b ; 6, 7 + db 11000110b,11000110b,01111100b,00000000b + db 11111110b,11000110b,00000110b,00001100b ; 7, 8 + db 00011000b,00011000b,00011000b,00000000b + db 01111100b,11000110b,11000110b,01111100b ; 8, 9 + db 11000110b,11000110b,01111100b,00000000b + db 01111100b,11000110b,11000110b,01111110b ; 9, A + db 00000110b,11000110b,01111100b,00000000b + db 00111000b,01101100b,11000110b,11111110b ; A, B + db 11000110b,11000110b,11000110b,00000000b + db 11111100b,11000110b,11000110b,11111100b ; B, C + db 11000110b,11000110b,11111100b,00000000b + db 01111100b,11000110b,11000000b,11000000b ; C, D + db 11000000b,11000110b,01111100b,00000000b + db 11111100b,11000110b,11000110b,11000110b ; D, E + db 11000110b,11000110b,11111100b,00000000b + db 11111110b,11000000b,11000000b,11111000b ; E, F + db 11000000b,11000000b,11111110b,00000000b + db 11111110b,11000000b,11000000b,11111000b ; F, 10 + db 11000000b,11000000b,11000000b,00000000b + db 01111100b,11000110b,11000000b,11000000b ; G, 11 + db 11001110b,11000110b,01111100b,00000000b + db 11000110b,11000110b,11000110b,11111110b ; H, 12 + db 11000110b,11000110b,11000110b,00000000b + db 00111100b,00011000b,00011000b,00011000b ; I, 13 + db 00011000b,00011000b,00111100b,00000000b + db 00011110b,00001100b,00001100b,00001100b ; J, 14 + db 00001100b,11001100b,00111100b,00000000b + db 11001100b,11011000b,11110000b,11100000b ; K, 15 + db 11110000b,11011000b,11001100b,00000000b + db 11000000b,11000000b,11000000b,11000000b ; L, 16 + db 11000000b,11000000b,11111110b,00000000b + db 11000110b,11101110b,11111110b,11010110b ; M, 17 + db 11000110b,11000110b,11000110b,00000000b + db 11000110b,11100110b,11110110b,11011110b ; N, 18 + db 11001110b,11000110b,11000110b,00000000b + db 01111100b,11000110b,11000110b,11000110b ; O, 19 + db 11000110b,11000110b,01111100b,00000000b + db 11111100b,11000110b,11000110b,11111100b ; P, 1A + db 11000000b,11000000b,11000000b,00000000b + db 01111100b,11000110b,11000110b,11000110b ; Q, 1B + db 11010110b,11001110b,01111110b,00000000b + db 11111100b,11000110b,11000110b,11111100b ; R, 1C + db 11001100b,11000110b,11000110b,00000000b + db 01111100b,11000110b,11000000b,01111100b ; S, 1D + db 00000110b,11000110b,01111100b,00000000b + db 01111110b,00011000b,00011000b,00011000b ; T, 1E + db 00011000b,00011000b,00011000b,00000000b + db 11000110b,11000110b,11000110b,11000110b ; U, 1F + db 11000110b,11000110b,01111100b,00000000b + db 11000110b,11000110b,11000110b,11000110b ; V, 20 + db 01101100b,00111000b,00010000b,00000000b + db 11000110b,11000110b,11000110b,11010110b ; W, 21 + db 11010110b,11111110b,01101100b,00000000b + db 11000110b,01101100b,00111000b,00010000b ; X, 22 + db 00111000b,01101100b,11000110b,00000000b + db 11001100b,11001100b,01111000b,00110000b ; Y, 23 + db 00110000b,00110000b,00110000b,00000000b + db 11111100b,10001100b,00011000b,00110000b ; Z, 24 + db 01100000b,11000100b,11111100b,00000000b + db 00000000b,00000000b,00000000b,11111110b ; -, 25 + db 00000000b,00000000b,00000000b,00000000b + db 00000000b,00000000b,00000000b,00000000b ; _, 26 + db 00000000b,00000000b,11111110b,00000000b + db 01110000b,11011100b,00000110b,00000000b ; ~, 27 + db 00000000b,00000000b,00000000b,00000000b + db 00000000b,00000000b,00000000b,00000000b ; ., 28 + db 00000000b,00110000b,00110000b,00000000b + db 00000010b,00000100b,00001000b,00010000b ; /, 29 + db 00100000b,01000000b,10000000b,00000000b + db 00001100b,00011000b,00110000b,01100000b ; <, 2A + db 00110000b,00011000b,00001100b,00000000b + db 01100000b,00110000b,00011000b,00001100b ; >, 2B + db 00011000b,00110000b,01100000b,00000000b + db 00111000b,00100000b,00100000b,00100000b ; [, 2C + db 00100000b,00100000b,00111000b,00000000b + db 00111000b,00001000b,00001000b,00001000b ; ], 2D + db 00001000b,00001000b,00111000b,00000000b + db 00000000b,00011000b,00011000b,00000000b ; :, 2E + db 00011000b,00011000b,00000000b,00000000b + db 00011000b + db 00100100b + db 00011000b + db 00111010b ; &, 2F + db 01000100b + db 01000110b + db 00111010b + db 00000000b + ; Arrow, 30 + ; #, 31 (, 3A {, 43 + ; =, 32 ), 3B }, 44 + ; ", 33 @, 3C Up,45 + ; \, 34 ', 3D Dn,46 + ; *, 35 !, 3E Lt,47 + ; ?, 36 $, 3F Rt,48 + ; %, 37 ;, 40 Bk,49 + ; +, 38 `, 41 .5,4A + ; ,, 39 ^, 42 + +;******************************************************* +; Output Char Outputs char in al @ esi +;******************************************************* + +NEWSYM outputchar + push edi + push esi + push eax + mov edi,FontData + xor ebx,ebx + mov bl,al + shl ebx,3 + add edi,ebx + mov cl,8 +.loopa + mov ah,[edi] + mov ch,8 +.loopb + test ah,80h + jz .nowrite + mov al,[textcolor] + mov byte[esi],al + mov byte[esi+289],192 +.nowrite + shl ah,1 + inc esi + dec ch + jnz .loopb + add esi,280 + inc edi + dec cl + jnz .loopa + pop eax + pop esi + pop edi + ret + +NEWSYM outputchar16b + push edi + push esi + push eax + push edx + push ecx + mov dx,[vesa2_clbitng] + ror edx,16 + mov dx,[vesa2_clbitng] + shr dx,1 + ror edx,16 + + mov edi,FontData + xor ebx,ebx + mov bl,al + shl ebx,3 + add edi,ebx + call OutputText16b + pop ecx + pop edx + pop eax + pop esi + pop edi + ret + +NEWSYM textcolor, db 128 +NEWSYM textcolor16b, dw 0FFFFh + +NEWSYM outputchar5x5 + push edi + push esi + push eax + mov edi,GUIFontData + xor ebx,ebx + mov bl,al + shl ebx,2 + add edi,ebx + xor ebx,ebx + mov bl,al + add edi,ebx + mov cl,5 +.loopa + mov ah,[edi] + mov ch,5 +.loopb + test ah,80h + jz .nowrite + mov al,[textcolor] + mov byte[esi],al +.nowrite + shl ah,1 + inc esi + dec ch + jnz .loopb + add esi,283 + inc edi + dec cl + jnz .loopa + pop eax + pop esi + pop edi + ret + +NEWSYM outputchar16b5x5 + push edi + push esi + push eax + mov edi,GUIFontData + xor ebx,ebx + mov bl,al + shl ebx,2 + add edi,ebx + xor ebx,ebx + mov bl,al + add edi,ebx + mov cl,5 +.loopa + mov ah,[edi] + mov ch,5 +.loopb + test ah,80h + jz .nowrite + push eax + mov ax,[textcolor16b] + mov word[esi],ax + mov word[esi+75036*4],ax + pop eax +.nowrite + shl ah,1 + add esi,2 + dec ch + jnz .loopb + add esi,283*2 + inc edi + dec cl + jnz .loopa + pop eax + pop esi + pop edi + ret + +NEWSYM outputchar16b5x52 + push edi + push esi + push eax + mov edi,GUIFontData + xor ebx,ebx + mov bl,al + shl ebx,2 + add edi,ebx + xor ebx,ebx + mov bl,al + add edi,ebx + mov word[esi-288*2],0 + mov word[esi+2-288*2],0 + mov word[esi+4-288*2],0 + mov word[esi+6-288*2],0 + mov word[esi+8-288*2],0 + mov word[esi+10-288*2],0 + mov word[esi-288*2+75036*4],0 + mov word[esi+2-288*2+75036*4],0 + mov word[esi+4-288*2+75036*4],0 + mov word[esi+6-288*2+75036*4],0 + mov word[esi+8-288*2+75036*4],0 + mov word[esi+10-288*2+75036*4],0 + mov cl,5 +.loopa + mov ah,[edi] + mov ch,5 +.loopb + mov word[esi],0 + mov word[esi+2],0 + mov word[esi+75036*4],0 + mov word[esi+2+75036*4],0 + test ah,80h + jz .nowrite + push eax + mov ax,[textcolor16b] + mov word[esi],ax + mov word[esi+75036*4],ax + pop eax +.nowrite + shl ah,1 + add esi,2 + dec ch + jnz .loopb + add esi,283*2 + inc edi + dec cl + jnz .loopa + mov word[esi],0 + mov word[esi+2],0 + mov word[esi+4],0 + mov word[esi+6],0 + mov word[esi+8],0 + mov word[esi+10],0 + mov word[esi+75036*4],0 + mov word[esi+2+75036*4],0 + mov word[esi+4+75036*4],0 + mov word[esi+6+75036*4],0 + mov word[esi+8+75036*4],0 + mov word[esi+10+75036*4],0 + pop eax + pop esi + pop edi + ret + +;******************************************************* +; Output Graphic String Outputs String from edi to esi +;******************************************************* + +NEWSYM OutputGraphicString + cmp byte[cbitmode],1 + je .do16b +.no16bit + xor eax,eax +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar + add esi,8 + inc edi + jmp .nextstr +.nomore + ret + +.do16b + sub esi,[vidbuffer] + shl esi,1 + add esi,[vidbuffer] + cmp byte[textcolor],128 + jne .no128 + mov word[textcolor16b],0FFFFh +.no128 + cmp byte[textcolor],129 + jne .no129 + mov word[textcolor16b],0 +.no129 + cmp byte[textcolor],130 + jne .no130 + xor ax,ax + xor bx,bx + mov cl,[vesa2_rpos] + mov bx,20 + shl bx,cl + add ax,bx + mov cl,[vesa2_gpos] + mov bx,20 + shl bx,cl + add ax,bx + mov cl,[vesa2_bpos] + mov bx,20 + shl bx,cl + add ax,bx + mov word[textcolor16b],ax +.no130 + ; Color #131, Red + cmp byte[textcolor],131 + jne .no131 + xor ax,ax + xor bx,bx + mov cl,[vesa2_rpos] + mov bx,22 + shl bx,cl + add ax,bx + mov cl,[vesa2_gpos] + mov bx,5 + shl bx,cl + add ax,bx + mov cl,[vesa2_bpos] + mov bx,5 + shl bx,cl + add ax,bx + mov word[textcolor16b],ax +.no131 + jmp OutputGraphicString16b + +NEWSYM OutputGraphicString16b + xor eax,eax +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar16b + add esi,16 + inc edi + jmp .nextstr +.nomore + ret + +NEWSYM OutputGraphicString5x5 + cmp byte[cbitmode],1 + je .do16b +.no16bit + xor eax,eax +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar5x5 + add esi,6 + inc edi + jmp .nextstr +.nomore + ret + +.do16b + sub esi,[vidbuffer] + shl esi,1 + add esi,[vidbuffer] + cmp byte[textcolor],128 + jne .no128 + mov word[textcolor16b],0FFFFh +.no128 + cmp byte[textcolor],129 + jne .no129 + mov word[textcolor16b],0 +.no129 + cmp byte[textcolor],130 + jne .no130 + xor ax,ax + xor bx,bx + mov cl,[vesa2_rpos] + mov bx,20 + shl bx,cl + add ax,bx + mov cl,[vesa2_gpos] + mov bx,20 + shl bx,cl + add ax,bx + mov cl,[vesa2_bpos] + mov bx,20 + shl bx,cl + add ax,bx + mov word[textcolor16b],ax +.no130 + ; Color #131, Red + cmp byte[textcolor],131 + jne .no131 + xor ax,ax + xor bx,bx + mov cl,[vesa2_rpos] + mov bx,22 + shl bx,cl + add ax,bx + mov cl,[vesa2_gpos] + mov bx,5 + shl bx,cl + add ax,bx + mov cl,[vesa2_bpos] + mov bx,5 + shl bx,cl + add ax,bx + mov word[textcolor16b],ax +.no131 + jmp OutputGraphicString16b5x5 + +NEWSYM OutputGraphicString16b5x5 + xor eax,eax +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar16b5x5 + add esi,12 + inc edi + jmp .nextstr +.nomore + ret + +NEWSYM OutputGraphicString16b5x52 + xor eax,eax +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar16b5x52 + add esi,12 + inc edi + jmp .nextstr +.nomore + ret + +NEWSYM OutputGraphicStringb + cmp byte[cbitmode],1 + je near .do16b + xor eax,eax + cmp byte[edi-1],1 + je .dir + cmp byte[edi-1],2 + je near .drive + sub esi,8 +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar + add esi,8 + inc edi + jmp .nextstr +.nomore + ret +.dir + sub esi,8 + mov al,'<' + mov al,[ASCII2Font+eax] + call outputchar + add esi,8 +.nextstr2 + mov al,[edi] + cmp al,0 + je .nomore2 + mov al,[ASCII2Font+eax] + call outputchar + add esi,8 + inc edi + jmp .nextstr2 +.nomore2 + mov al,'>' + mov al,[ASCII2Font+eax] + call outputchar + ret +.drive + sub esi,8 + mov al,'[' + mov al,[ASCII2Font+eax] + call outputchar + add esi,8 +.nextstr3 + mov al,[edi] + cmp al,0 + je .nomore3 + mov al,[ASCII2Font+eax] + call outputchar + add esi,8 + inc edi + jmp .nextstr3 +.nomore3 + mov al,']' + mov al,[ASCII2Font+eax] + call outputchar + ret +.do16b + sub esi,[vidbuffer] + shl esi,1 + add esi,[vidbuffer] + cmp byte[textcolor],128 + jne .no128 + mov word[textcolor16b],0FFFFh +.no128 + cmp byte[textcolor],129 + jne .no129 + mov word[textcolor16b],0 +.no129 + cmp byte[textcolor],130 + jne .no130 + xor ax,ax + xor bx,bx + mov cl,[vesa2_rpos] + mov bx,20 + shl bx,cl + add ax,bx + mov cl,[vesa2_gpos] + mov bx,20 + shl bx,cl + add ax,bx + mov cl,[vesa2_bpos] + mov bx,20 + shl bx,cl + add ax,bx + mov word[textcolor16b],ax +.no130 + ; Color #131, Red + cmp byte[textcolor],131 + jne .no131 + xor ax,ax + xor bx,bx + mov cl,[vesa2_rpos] + mov bx,22 + shl bx,cl + add ax,bx + mov cl,[vesa2_gpos] + mov bx,5 + shl bx,cl + add ax,bx + mov cl,[vesa2_bpos] + mov bx,5 + shl bx,cl + add ax,bx + mov word[textcolor16b],ax +.no131 +NEWSYM OutputGraphicString16bb + xor eax,eax + cmp byte[edi-1],1 + je .dir + cmp byte[edi-1],2 + je near .drive + xor eax,eax + sub esi,16 +.nextstr + mov al,[edi] + cmp al,0 + je .nomore + mov al,[ASCII2Font+eax] + call outputchar16b + add esi,16 + inc edi + jmp .nextstr +.nomore + ret +.dir + sub esi,16 + mov al,'<' + mov al,[ASCII2Font+eax] + call outputchar16b + add esi,16 +.nextstr2 + mov al,[edi] + cmp al,0 + je .nomore2 + mov al,[ASCII2Font+eax] + call outputchar16b + add esi,16 + inc edi + jmp .nextstr2 +.nomore2 + mov al,'>' + mov al,[ASCII2Font+eax] + call outputchar16b + ret +.drive + sub esi,16 + mov al,'[' + mov al,[ASCII2Font+eax] + call outputchar16b + add esi,16 +.nextstr3 + mov al,[edi] + cmp al,0 + je .nomore3 + mov al,[ASCII2Font+eax] + call outputchar16b + add esi,16 + inc edi + jmp .nextstr3 +.nomore3 + mov al,']' + mov al,[ASCII2Font+eax] + call outputchar16b + ret + +;******************************************************* +; Save Select Allows user to select save state slot +;******************************************************* +; For Save State + +NEWSYM csounddisable, db 0 +NEWSYM statefileloc, dd 0 +newestfileloc db 0 +newestfiledate dd 0 +f3menuen db 0 +PrevPictureVal db 0 +CurPictureVal db 0 + +NEWSYM drawhline +.loop + mov byte[esi],al + inc esi + loop .loop + ret + +NEWSYM drawhline16b +.loop + mov [esi],ax + add esi,2 + loop .loop + ret + +NEWSYM drawvline +.loop + mov byte[esi],al + add esi,288 + loop .loop + ret + +NEWSYM drawvline16b +.loop + mov [esi],ax + add esi,288*2 + loop .loop + ret + +%macro determinenewhelp 2 + mov bl,%1 + mov byte[fnamest+eax],%2 + call DetermineNew +%endmacro + +DetermineNew: + push eax + push ebx + mov edx,fnamest+1 + call Open_File + jc near .nodraw + mov bx,ax + mov edx,fnamest+1 + call Get_File_Date + shl edx,16 + mov dx,cx + push edx + call Close_File + pop edx + pop ebx + pop eax + ; date = edx, position = bl + cmp edx,[newestfiledate] + jbe .notlatest + mov [newestfiledate],edx + mov [newestfileloc],bl +.notlatest + ret +.nodraw + pop ebx + pop eax + ret + +DetermineNewest: + mov dword[newestfiledate],0 + mov byte[newestfileloc],0 + + determinenewhelp 0,'T' + determinenewhelp 1,'1' + determinenewhelp 2,'2' + determinenewhelp 3,'3' + determinenewhelp 4,'4' + determinenewhelp 5,'5' + determinenewhelp 6,'6' + determinenewhelp 7,'7' + determinenewhelp 8,'8' + determinenewhelp 9,'9' + ret + +NEWSYM CapturePicture + pushad + mov esi,[vidbuffer] + add esi,288*2+16*2 + mov edi,PrevPicture + mov edx,56 +.next + push esi + push edx + mov dx,1111011111011110b + cmp byte[newengen],0 + je .noneweng2 + cmp byte[nggposng],5 + jne .noneweng2 + mov dx,0111101111011110b +.noneweng2 + mov ecx,64 +.loop + mov ax,[esi] + mov bx,[esi+4] + and ax,dx + and bx,dx + shr ax,1 + shr bx,1 + add ax,bx + push ax + mov ax,[esi+288*2] + mov bx,[esi+4+288*2] + and ax,dx + and bx,dx + shr ax,1 + shr bx,1 + add bx,ax + pop ax + and ax,dx + and bx,dx + shr ax,1 + shr bx,1 + add ax,bx + mov [edi],ax + add esi,8 + add edi,2 + loop .loop + pop edx + pop esi + add esi,288*2*4 + dec edx + jnz near .next + cmp byte[newengen],0 + je .noneweng + cmp byte[nggposng],5 + jne .noneweng + mov edx,PrevPicture + mov ecx,64*56 +.loop2 + mov ax,[edx] + mov bx,ax + and ax,0111111111100000b + and bx,0000000000011111b + shl ax,1 + or bx,ax + mov [edx],bx + add edx,2 + loop .loop2 +.noneweng + popad + ret + +GetPicture: + mov cl,[CurPictureVal] + cmp [PrevPictureVal],cl + jne .notskip + ret +.notskip + mov [PrevPictureVal],cl + mov edx,PrevPicture + mov ecx,64*56*2 +.loop + mov byte[edx],0 + inc edx + loop .loop + mov edx,fnamest+1 + call Open_File + jc near .nodraw2 + mov bx,ax + xor cx,cx + xor dx,dx + call File_Seek_End + shl edx,16 + mov dx,ax + cmp edx,266879+64*56*2 + je .draw + cmp edx,398643+64*56*2 + je .draw + cmp edx,400692+64*56*2 + je .draw + cmp edx,275071+64*56*2 + je .draw + jmp .nodraw +.draw + sub edx,64*56*2 + mov ax,dx + shr edx,16 + mov cx,dx + mov dx,ax + call File_Seek + mov ecx,64*56*2 + mov edx,PrevPicture + call Read_File +.nodraw + call Close_File +.nodraw2 + ; convert to 1:5:5:5 + cmp byte[newengen],0 + je .noneweng + cmp byte[nggposng],5 + jne .noneweng + mov edx,PrevPicture + mov ecx,64*56 +.loop2 + mov ax,[edx] + mov bx,ax + and ax,1111111111000000b + and bx,0000000000011111b + shr ax,1 + or bx,ax + mov [edx],bx + add edx,2 + loop .loop2 +.noneweng + ; draw border + mov esi,75*2+9*288*2 + add esi,[vidbuffer] + mov edx,58 +.ploopa + mov ecx,66 + push esi +.ploopb + mov word[esi],0FFFFh + add esi,2 + loop .ploopb + pop esi + add esi,288*2 + dec edx + jnz .ploopa + ; draw picture + mov esi,76*2+10*288*2 + add esi,[vidbuffer] + mov edx,56 + mov edi,PrevPicture +.ploopa2 + mov ecx,64 + push esi +.ploopb2 + mov ax,[edi] + mov word[esi],ax + add esi,2 + add edi,2 + loop .ploopb2 + pop esi + add esi,288*2 + dec edx + jnz .ploopa2 + ret + +NEWSYM drawfillboxsc + push eax + push ebx + mov edx,fnamest+1 + call Open_File + jc near .nodraw + mov bx,ax + call Close_File + pop ebx + ; draws a 10x10 filled box according to position bl and color dl + xor eax,eax + mov al,11 + mul bl + mov esi,76+94*288 + add esi,[vidbuffer] + add esi,eax + mov ecx,10 + mov al,176 + cmp [newestfileloc],bl + jne .next + mov al,208 +.next + push esi + push ecx + mov ecx,10 + call drawhline + pop ecx + pop esi + add esi,288 + dec ecx + jnz .next + pop eax + ret +.nodraw + pop ebx + pop eax + ret + +NEWSYM drawfillboxsc16b + push eax + push ebx + mov edx,fnamest+1 + call Open_File + jc near .nodraw + mov bx,ax + call Close_File + pop ebx + ; draws a 10x10 filled box according to position bl and color dl + xor eax,eax + mov al,11 + mul bl + mov esi,76*2+94*288*2 + add esi,[vidbuffer] + add esi,eax + add esi,eax + mov ecx,10 + mov ax,[saveselect.allgrn] + cmp [newestfileloc],bl + jne .next + mov ax,[saveselect.allgrnb] +.next + push esi + push ecx + mov ecx,10 + call drawhline16b + pop ecx + pop esi + add esi,288*2 + dec ecx + jnz .next + pop eax + ret +.nodraw + pop ebx + pop eax + ret + +NEWSYM drawbox + ; draws a box according to position bl and color dl + xor eax,eax + mov al,11 + mul bl + mov esi,75+93*288 + add esi,[vidbuffer] + add esi,eax + mov al,dl + push esi + mov ecx,12 + call drawhline + pop esi + push esi + mov ecx,12 + call drawvline + pop esi + push esi + add esi,11 + mov ecx,12 + call drawvline + pop esi + add esi,11*288 + mov ecx,12 + call drawhline + ret + +NEWSYM drawbox16b + ; draws a box according to position bl and color dx + xor eax,eax + mov al,11 + mul bl + mov esi,75*2+93*288*2 + add esi,[vidbuffer] + add esi,eax + add esi,eax + mov ax,dx + push esi + mov ecx,12 + call drawhline16b + pop esi + push esi + mov ecx,12 + call drawvline16b + pop esi + push esi + add esi,11*2 + mov ecx,12 + call drawvline16b + pop esi + add esi,11*288*2 + mov ecx,12 + call drawhline16b + ret + +%macro drawfillboxhelp 2 + mov bl,%1 + mov byte[fnamest+eax],%2 + call drawfillboxsc +%endmacro + +%macro drawfillboxhelp16b 2 + mov bl,%1 + mov byte[fnamest+eax],%2 + call drawfillboxsc16b +%endmacro + + +NEWSYM saveselect + mov byte[f3menuen],1 + mov byte[ForceNonTransp],1 + cmp byte[ForceNewGfxOff],0 + jne .nong16b + cmp byte[cbitmode],0 + je .nong16b + call GetScreen +.nong16b + cmp dword[MessageOn],0 + je .nochangem + mov dword[MessageOn],1 +.nochangem + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + call StopSound + cmp byte[soundon],0 + je .nosound + mov byte[csounddisable],1 + cmp byte[OSPort],1 + ja .nosound + push es + mov es,[sbselec] + mov edi,[sbpmofs] + mov ecx,320 +.loopa + mov dword[es:edi],0 + add edi,4 + dec ecx + jnz .loopa + pop es +.nosound + cmp byte[cbitmode],1 + je near .16b + call saveselectpal + ; draw a small blue box with a white border + mov esi,70+70*288 + add esi,[vidbuffer] + mov ecx,150 + mov al,70 +.loop + mov byte[esi],144 + inc esi + loop .loop + add esi,288-150 + dec al + mov ecx,150 + jnz .loop + ; draw filled boxes for existing files + mov eax,[statefileloc] + mov bl,byte[fnamest+eax] + push ebx + call DetermineNewest + drawfillboxhelp 0,'T' + drawfillboxhelp 1,'1' + drawfillboxhelp 2,'2' + drawfillboxhelp 3,'3' + drawfillboxhelp 4,'4' + drawfillboxhelp 5,'5' + drawfillboxhelp 6,'6' + drawfillboxhelp 7,'7' + drawfillboxhelp 8,'8' + drawfillboxhelp 9,'9' + pop ebx + mov eax,[statefileloc] + mov byte[fnamest+eax],bl + + mov esi,75+73*288 + add esi,[vidbuffer] + mov edi,.stringa + call OutputGraphicString + mov esi,75+83*288 + add esi,[vidbuffer] + mov edi,.stringb + call OutputGraphicString + mov esi,75+108*288 + add esi,[vidbuffer] + mov edi,.stringc + call OutputGraphicString + mov esi,75+118*288 + add esi,[vidbuffer] + mov edi,.stringd + call OutputGraphicString + mov esi,75+128*288 + add esi,[vidbuffer] + mov edi,.stringe + call OutputGraphicString + mov al,128 + mov esi,70+70*288 + add esi,[vidbuffer] + mov ecx,150 + call drawhline + mov esi,70+70*288 + add esi,[vidbuffer] + mov ecx,70 + call drawvline + mov esi,70+139*288 + add esi,[vidbuffer] + mov ecx,150 + call drawhline + mov esi,219+70*288 + add esi,[vidbuffer] + mov ecx,70 + call drawvline + mov esi,75+93*288 + add esi,[vidbuffer] + mov ecx,111 + call drawhline + mov esi,75+104*288 + add esi,[vidbuffer] + mov ecx,111 + call drawhline + mov esi,75+94*288 + add esi,[vidbuffer] + mov bl,11 +.nextvline + mov ecx,10 + push esi + push ebx + call drawvline + pop ebx + pop esi + add esi,11 + dec bl + jnz .nextvline + mov esi,78+96*288 + add esi,[vidbuffer] + mov al,1 + call outputchar + mov bl,9 +.nextnumchar + add esi,11 + inc al + push ebx + call outputchar + pop ebx + dec bl + jnz .nextnumchar + mov byte[curblank],0h + mov bl,0 + mov ebx,[statefileloc] + mov al,byte[fnamest+ebx] + cmp al,'T' + jne .noT + mov bl,0 + jmp .nexter +.noT + mov bl,al + sub bl,48 +.nexter + mov dl,160 + call drawbox + push ebx + call copyvid + pop ebx + ; wait until esc/enter is pressed +.noesc + mov dl,128 + call drawbox + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc + test byte[pressed+28],1 + jnz near .enter + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc + test byte[pressed+28],1 + jnz near .enter + push ebx + call copyvid + pop ebx + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc + test byte[pressed+28],1 + jnz near .enter + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc + test byte[pressed+28],1 + jnz near .enter + mov dl,160 + call drawbox + push ebx + call copyvid + pop ebx + jmp .noesc +.enter + mov byte[pressed+28],0 + cmp bl,0 + jne .nozero + mov al,'T' + jmp .save +.nozero + add bl,48 + mov al,bl +.save + mov ebx,[statefileloc] + mov byte[fnamest+ebx],al +.esc + mov byte[pressed+1],0 + mov byte[pressed+28],0 + cmp byte[OSPort],1 + jbe .notpr28b + cmp byte[pressed+1],1 + jne .notpr1b + mov byte[pressed+1],2 +.notpr1b + cmp byte[pressed+28],1 + jne .notpr28b + mov byte[pressed+28],2 +.notpr28b + mov word[t1cc],0 + mov byte[csounddisable],0 + call StartSound + + call makepal + mov byte[f3menuen],0 + mov byte[ForceNonTransp],0 + ret + +.allred dw 0 +.allgrn dw 0 +.allgrnb dw 0 +.blue dw 0 +.stepb dw 0 + +; Start 16-bit stuff here +.16b + cmp byte[newengen],0 + je .notng + mov byte[GUIOn],1 +.notng + ; draw shadow behind box + mov esi,80*2+80*288*2 + add esi,[vidbuffer] + mov ecx,150 + mov al,70 + mov ah,5 +.loop16b2 + mov dx,[esi] + and dx,[vesa2_clbit] + shr dx,1 + mov [esi],dx + add esi,2 + loop .loop16b2 + add esi,288*2-150*2 + dec al + mov ecx,150 + jnz .loop16b2 + + mov ax,018h + mov cl,[vesa2_rpos] + shl ax,cl + mov [.allgrn],ax + + mov ax,25 + mov cl,[vesa2_rpos] + shl ax,cl + mov [.allgrnb],ax + mov ax,12 + mov cl,[vesa2_gpos] + shl ax,cl + or [.allgrnb],ax + + mov ax,01Fh + mov cl,[vesa2_rpos] + shl ax,cl + mov [.allred],ax + mov ax,012h + mov cl,[vesa2_bpos] + shl ax,cl + mov dx,ax + mov ax,01h + mov cl,[vesa2_gpos] + shl ax,cl + mov bx,ax + mov ax,01h + mov cl,[vesa2_rpos] + shl ax,cl + or bx,ax + + ; draw a small blue box with a white border + mov esi,70*2+70*288*2 + add esi,[vidbuffer] + mov ecx,150 + mov al,70 + mov ah,5 +.loop16b + mov [esi],dx + add esi,2 + loop .loop16b + add esi,288*2-150*2 + dec ah + jnz .nocolinc16b + add dx,bx + mov ah,5 +.nocolinc16b + dec al + mov ecx,150 + jnz .loop16b + + ; draw filled boxes for existing files + mov eax,[statefileloc] + mov bl,byte[fnamest+eax] + push ebx + call DetermineNewest + drawfillboxhelp16b 0,'T' + drawfillboxhelp16b 1,'1' + drawfillboxhelp16b 2,'2' + drawfillboxhelp16b 3,'3' + drawfillboxhelp16b 4,'4' + drawfillboxhelp16b 5,'5' + drawfillboxhelp16b 6,'6' + drawfillboxhelp16b 7,'7' + drawfillboxhelp16b 8,'8' + drawfillboxhelp16b 9,'9' + pop ebx + mov eax,[statefileloc] + mov byte[fnamest+eax],bl + + mov esi,75*2+73*288*2 + add esi,[vidbuffer] + mov edi,.stringa + call OutputGraphicString16b + mov esi,75*2+83*288*2 + add esi,[vidbuffer] + mov edi,.stringb + call OutputGraphicString16b + mov esi,75*2+108*288*2 + add esi,[vidbuffer] + mov edi,.stringc + call OutputGraphicString16b + mov esi,75*2+118*288*2 + add esi,[vidbuffer] + mov edi,.stringd + call OutputGraphicString16b + mov esi,75*2+128*288*2 + add esi,[vidbuffer] + mov edi,.stringe + call OutputGraphicString16b + mov ax,0FFFFh + mov esi,70*2+70*288*2 + add esi,[vidbuffer] + mov ecx,150 + call drawhline16b + mov esi,70*2+70*288*2 + add esi,[vidbuffer] + mov ecx,70 + call drawvline16b + mov esi,70*2+139*288*2 + add esi,[vidbuffer] + mov ecx,150 + call drawhline16b + mov esi,219*2+70*288*2 + add esi,[vidbuffer] + mov ecx,70 + call drawvline16b + mov esi,75*2+93*288*2 + add esi,[vidbuffer] + mov ecx,111 + call drawhline16b + mov esi,75*2+104*288*2 + add esi,[vidbuffer] + mov ecx,111 + call drawhline16b + mov esi,75*2+94*288*2 + add esi,[vidbuffer] + mov bl,11 +.nextvline16b + mov ecx,10 + push esi + push ebx + call drawvline16b + pop ebx + pop esi + add esi,22 + dec bl + jnz .nextvline16b + mov esi,78*2+96*288*2 + add esi,[vidbuffer] + mov al,1 + call outputchar16b + mov bl,9 +.nextnumchar16b + add esi,22 + inc al + push ebx + call outputchar16b + pop ebx + dec bl + jnz .nextnumchar16b + + mov byte[curblank],0h + mov bl,0 + mov ebx,[statefileloc] + mov al,byte[fnamest+ebx] + cmp al,'T' + jne .noT16b + mov bl,0 + jmp .nexter16b +.noT16b + mov bl,al + sub bl,48 +.nexter16b + mov dx,[.allred] + call drawbox16b + push ebx + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + pop ebx + ; wait until esc/enter is pressed + + mov byte[PrevPictureVal],0FFh +.noesc16b + mov [CurPictureVal],bl + pushad + mov eax,[statefileloc] + mov cl,byte[fnamest+eax] + push ecx + cmp bl,0 + jne .nozero16b2 + mov cl,'T' + jmp .save16b2 +.nozero16b2 + mov cl,bl + add cl,48 +.save16b2 + mov byte[fnamest+eax],cl + call GetPicture + pop ecx + mov eax,[statefileloc] + mov byte[fnamest+eax],cl + popad + + mov dx,0FFFFh + call drawbox16b + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc16b + test byte[pressed+28],1 + jnz near .enter16b + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc16b + test byte[pressed+28],1 + jnz near .enter16b + push ebx + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + pop ebx + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc16b + test byte[pressed+28],1 + jnz near .enter16b + mov ecx,2500 + call delay + call testpressed8b + test byte[pressed+1],1 + jnz near .esc16b + test byte[pressed+28],1 + jnz near .enter16b + mov dx,[.allred] + call drawbox16b + push ebx + mov al,[newengen] + mov byte[newengen],0 + push eax + call copyvid + pop eax + mov [newengen],al + pop ebx + jmp .noesc16b +.enter16b + mov byte[pressed+28],0 + cmp bl,0 + jne .nozero16b + mov al,'T' + jmp .save16b +.nozero16b + add bl,48 + mov al,bl +.save16b + mov ebx,[statefileloc] + mov byte[fnamest+ebx],al +.esc16b + cmp byte[OSPort],1 + jbe .notprwin + cmp byte[pressed+1],1 + jne .notpr1 + mov byte[pressed+1],2 +.notpr1 + cmp byte[pressed+28],1 + jne .notpr28 + mov byte[pressed+28],2 +.notpr28 + jmp .prwin +.notprwin + mov byte[pressed+1],0 + mov byte[pressed+28],0 +.prwin + mov word[t1cc],0 + mov byte[csounddisable],0 + call StartSound + mov byte[f3menuen],0 + mov byte[ForceNonTransp],0 + mov byte[GUIOn],0 + call Clear2xSaIBuffer + ret + +.stringa db 'PLEASE SELECT',0 +.stringb db 'SAVE STATE SLOT',0 +.stringc db 'USE CURSOR KEYS',0 +.stringd db 'TO MOVE AND',0 +.stringe db 'ENTER TO SELECT',0 + +NEWSYM ForceNonTransp, db 0 + +NEWSYM testpressed8b + test byte[pressed+2],1 + jz .no1 + mov bl,1 +.no1 + test byte[pressed+3],1 + jz .no2 + mov bl,2 +.no2 + test byte[pressed+4],1 + jz .no3 + mov bl,3 +.no3 + test byte[pressed+5],1 + jz .no4 + mov bl,4 +.no4 + test byte[pressed+6],1 + jz .no5 + mov bl,5 +.no5 + test byte[pressed+7],1 + jz .no6 + mov bl,6 +.no6 + test byte[pressed+8],1 + jz .no7 + mov bl,7 +.no7 + test byte[pressed+9],1 + jz .no8 + mov bl,8 +.no8 + test byte[pressed+10],1 + jz .no9 + mov bl,9 +.no9 + test byte[pressed+11],1 + jz .no0 + mov bl,0 +.no0 + test byte[pressed+75],1 + jz .noleft + cmp bl,0 + je .noleft + dec bl + mov byte[pressed+75],2 +.noleft + test byte[pressed+77],1 + jz .noright + cmp bl,9 + je .noright + inc bl + mov byte[pressed+77],2 +.noright + cmp byte[OSPort],3 + jne near .nowin32 + test byte[pressed+0CBh],1 + jz .noleft2 + cmp bl,0 + je .noleft2 + dec bl + mov byte[pressed+0CBh],2 +.noleft2 + test byte[pressed+0CDh],1 + jz .noright2 + cmp bl,9 + je .noright2 + inc bl + mov byte[pressed+0CDh],2 +.noright2 +.nowin32 + ret + +;******************************************************* +; MakePal Changes the entire palette +;******************************************************* +; set the brightness with [maxbr] +NEWSYM doveg + pushad + xor eax,eax + mov al,[coladdr] + add al,[coladdg] + add al,[coladdb] + xor dx,dx + mov bx,3 + div bx + and ax,011111b + mov [coladdr],al + mov [coladdg],al + mov [coladdb],al + xor eax,eax +.next + push eax + mov ax,[cgram+eax] + mov bx,ax + mov cx,ax + and bx,011111b + and cx,1111100000b + shr cx,5 + add bx,cx + mov cx,ax + and cx,111110000000000b + shr cx,10 + add bx,cx + mov ax,bx + xor dx,dx + mov bx,3 + div bx + and ax,011111b + mov cx,ax + mov bx,ax + shl bx,5 + or ax,bx + shl cx,10 + or ax,cx + mov bx,ax + pop eax + mov word[cgram+eax],bx + add eax,2 + cmp eax,200h + jne .next + popad + ret + +blahblahblah dw 0 + +NEWSYM dosmakepal + cmp byte[V8Mode],1 + jne .noveg + call doveg +.noveg + mov ax,[cgram] + mov [tempco0],ax + test byte[scaddtype],00100000b + jz near .noaddition + test byte[scaddtype],10000000b + jnz near .noaddition + mov cx,[cgram] + mov ax,cx + and ax,001Fh + add al,[coladdr] + cmp al,01Fh + jb .noadd + mov al,01Fh +.noadd + mov bx,ax + mov ax,cx + shr ax,5 + and ax,001Fh + add al,[coladdg] + cmp al,01Fh + jb .noaddb + mov al,01Fh +.noaddb + shl ax,5 + add bx,ax + mov ax,cx + shr ax,10 + and ax,001Fh + add al,[coladdb] + cmp al,01Fh + jb .noaddc + mov al,01Fh +.noaddc + shl ax,10 + add bx,ax + mov [cgram],bx +.noaddition + cmp byte[Palette0],0 + je .nocol0mod + mov word[cgram],0 +.nocol0mod +NEWSYM makepalb + mov edi,cgram + mov ebx,prevpal + xor ah,ah +.loopa + mov cx,[edi] + push eax + push ebx + mov [ebx],cx + mov al,ah + mov dx,03C8h + out dx,al + mov ax,cx + and al,01Fh + mov bh,[maxbr] + mov bl,bh + mul bl + mov bl,15 + div bl + shl al,1 + mov dx,03C9h + add al,[gammalevel] + cmp al,63 + jbe .nor + mov al,63 +.nor + out dx,al + mov ax,cx + shr ax,5 + and al,01Fh + mov bl,bh + mul bl + mov bl,15 + div bl + shl al,1 + add al,[gammalevel] + cmp al,63 + jbe .nog + mov al,63 +.nog + out dx,al + mov ax,cx + shr ax,10 + and al,01Fh + mov bl,bh + mul bl + mov bl,15 + div bl + shl al,1 + add al,[gammalevel] + cmp al,63 + jbe .nob + mov al,63 +.nob + out dx,al + pop ebx + pop eax + add edi,2 + add ebx,2 + inc ah + jnz near .loopa + mov al,[maxbr] + mov [prevbright],al + mov ax,[tempco0] + mov [cgram],ax + cmp byte[MessageOn],0 + je .nochange128 + mov dx,03C8h + mov al,128 + out dx,al + mov al,63 + inc dx + out dx,al + out dx,al + out dx,al + mov dx,03C8h + mov al,128+64 + out dx,al + mov al,0 + inc dx + out dx,al + out dx,al + out dx,al +.nochange128 + ret +NEWSYM tempco0, dw 0 + +;******************************************************* +; ChangePal Sets up the palette +;******************************************************* + +NEWSYM doschangepal + cmp byte[V8Mode],1 + jne .noveg + call doveg +.noveg + mov ax,[cgram] + mov [tempco0],ax + test byte[scaddtype],00100000b + jz near .noaddition + test byte[scaddtype],10000000b + jnz near .noaddition + mov cx,[cgram] + mov ax,cx + and ax,001Fh + add al,[coladdr] + cmp al,01Fh + jb .noadd + mov al,01Fh +.noadd + mov bx,ax + mov ax,cx + shr ax,5 + and ax,001Fh + add al,[coladdg] + cmp al,01Fh + jb .noaddb + mov al,01Fh +.noaddb + shl ax,5 + add bx,ax + mov ax,cx + shr ax,10 + and ax,001Fh + add al,[coladdb] + cmp al,01Fh + jb .noaddc + mov al,01Fh +.noaddc + shl ax,10 + add bx,ax + mov [cgram],bx +.noaddition + cmp byte[Palette0],0 + je .nocol0mod + mov word[cgram],0 +.nocol0mod + ; check if brightness differs + mov al,[maxbr] + cmp al,[prevbright] + jne near makepalb + ; check for duplicate palette (Compare prevpal with cgram) + mov ebx,prevpal + mov edi,cgram + xor ah,ah +.loopa + mov cx,[edi] + cmp cx,[ebx] + je .nochange + push eax + push ebx + push eax + pop eax + mov [ebx],cx + mov al,ah + mov dx,03C8h + out dx,al + mov ax,cx + and al,01Fh + mov bh,[maxbr] + mov bl,bh + mul bl + mov bl,15 + div bl + shl al,1 + add al,[gammalevel] + cmp al,63 + jbe .nor + mov al,63 +.nor + inc dx + out dx,al + mov ax,cx + shr ax,5 + and al,01Fh + mov bl,bh + mul bl + mov bl,15 + div bl + shl al,1 + add al,[gammalevel] + cmp al,63 + jbe .nog + mov al,63 +.nog + out dx,al + mov ax,cx + shr ax,10 + and al,01Fh + mov bl,bh + mul bl + mov bl,15 + div bl + shl al,1 + add al,[gammalevel] + cmp al,63 + jbe .nob + mov al,63 +.nob + out dx,al + pop ebx + pop eax +.nochange + add edi,2 + add ebx,2 + inc ah + jnz near .loopa + mov ax,[tempco0] + mov [cgram],ax + cmp byte[MessageOn],0 + je .nochange128 + mov dx,03C8h + mov al,128 + out dx,al + mov al,63 + inc dx + out dx,al + out dx,al + out dx,al +.nochange128 + ret + +NEWSYM prevbright, db 0 ; previous brightness + +;******************************************************* +; CopyVid Copies buffer into video +;******************************************************* + +NEWSYM showfps + mov cl,50 + cmp byte[romispal],0 + jne .nontsc + mov cl,60 +.nontsc + inc byte[curfps] + cmp byte[nextframe],cl + jb .nofrc + mov al,[curfps] + mov [lastfps],al + mov al,[curfps2] + mov [lastfps2],al + mov byte[curfps],0 + mov byte[curfps2],0 + sub byte[nextframe],cl +.nofrc + + cmp byte[cbitmode],1 + je near .do16b + + call displayfpspal + + mov al,[lastfps] + mov bl,10 + xor ah,ah + div bl + shl al,4 + add ah,al + mov al,ah + mov esi,208*288+32 + add esi,[vidbuffer] + push ecx + call outputhex + + mov esi,208*288+48 + add esi,[vidbuffer] + mov al,29h + call outputchar + pop ecx + + mov al,cl + mov bl,10 + xor ah,ah + div bl + shl al,4 + add ah,al + mov al,ah + mov esi,208*288+56 + add esi,[vidbuffer] + call outputhex + ret + +.do16b + mov al,[lastfps] + mov bl,10 + xor ah,ah + div bl + shl al,4 + add ah,al + mov al,ah + mov esi,208*288*2+32*2 + add esi,[vidbuffer] + push ecx + call outputhex16 + + mov esi,208*288*2+48*2 + add esi,[vidbuffer] + mov al,29h + call outputchar16b + pop ecx + + mov al,cl + mov bl,10 + xor ah,ah + div bl + shl al,4 + add ah,al + mov al,ah + mov esi,208*288*2+56*2 + add esi,[vidbuffer] + call outputhex16 + ret + +.ng16b + mov byte[ngfont],1 + + mov al,[lastfps] + mov bl,10 + xor ah,ah + div bl + shl al,4 + add ah,al + mov al,ah + mov esi,208*288+32 + add esi,[vidbuffer] + push ecx + call outputhex + + mov esi,208*288+48 + add esi,[vidbuffer] + mov al,29h + call outputchar + pop ecx + + mov al,cl + mov bl,10 + xor ah,ah + div bl + shl al,4 + add ah,al + mov al,ah + mov esi,208*288+56 + add esi,[vidbuffer] + call outputhex + ret + +NEWSYM spcdebugaddr, dd 0 +NEWSYM tempoffset, dw 0 + +NEWSYM Testval, dd 0 + + +NEWSYM ClockOutput + cmp byte[cbitmode],1 + je near .do16b3 +.no16b3 + mov byte[ngfont],1 + call displayfpspal + mov esi,215*288+32+192 + add esi,[vidbuffer] + mov ebx,7 +.loop2 + mov ecx,12 + mov byte[esi-1],0C0h +.loop + mov dword[esi],0C0C0C0C0h + add esi,4 + loop .loop + add esi,288-48 + dec ebx + jnz .loop2 + jmp .do8b +.do16b3 + mov esi,215*288*2+32*2+192*2 + add esi,[vidbuffer] + mov ebx,7 +.loop2b + mov ecx,24 + mov word[esi-2],0 + mov word[esi-2+75036*4],0 +.loopb + mov dword[esi],0 + mov dword[esi+75036*4],0 + add esi,4 + loop .loopb + add esi,288*2-48*2 + dec ebx + jnz .loop2b +.do8b + call GetTimeInSeconds + xor edx,edx + mov ebx,60 + div ebx + push eax + ; edx = seconds + mov eax,edx + xor edx,edx + mov ebx,10 + div ebx + mov esi,216*288+32+228 + call .output + pop eax + mov ebx,60 + xor edx,edx + div ebx + push eax + ; edx = minutes + mov eax,edx + xor edx,edx + mov ebx,10 + div ebx + mov esi,216*288+32+210 + call .output + pop eax + ; eax = hours + xor edx,edx + mov ebx,10 + div ebx + mov esi,216*288+32+192 + call .output + cmp byte[cbitmode],1 + je .do16b2 +.no16b4 + mov esi,216*288+32+222 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar5x5 + popad + mov esi,216*288+32+204 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar5x5 + popad + ret + +.do16b2 + mov esi,216*288*2+32*2+222*2 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar16b5x5 + popad + mov esi,216*288*2+32*2+204*2 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar16b5x5 + popad + ret +.output + ; output char value at al and dl + cmp byte[cbitmode],1 + je .do16b +.no16b5 + add esi,[vidbuffer] + and eax,0FFh + add al,48 + mov al,[ASCII2Font+eax] + pushad + call outputchar5x5 + popad + xor eax,eax + mov al,dl + add al,48 + mov al,[ASCII2Font+eax] + add esi,6 + pushad + call outputchar5x5 + popad + ret +.do16b + add esi,esi + add esi,[vidbuffer] + and eax,0FFh + add al,48 + mov al,[ASCII2Font+eax] + pushad + call outputchar16b5x5 + popad + xor eax,eax + mov al,dl + add al,48 + mov al,[ASCII2Font+eax] + add esi,12 + pushad + call outputchar16b5x5 + popad + ret + +NEWSYM ClockOutputB + cmp byte[cbitmode],1 + je near .do16b3 +.no16b3 + mov byte[ngfont],1 + call displayfpspal + mov esi,208*288+32+192 + add esi,[vidbuffer] + mov ebx,7 +.loop2 + mov ecx,12 + mov byte[esi-1],0C0h +.loop + mov dword[esi],0C0C0C0C0h + add esi,4 + loop .loop + add esi,288-48 + dec ebx + jnz .loop2 + jmp .do8b +.do16b3 + mov esi,208*288*2+32*2+192*2 + add esi,[vidbuffer] + mov ebx,7 +.loop2b + mov ecx,24 + mov word[esi-2],0 + mov word[esi-2+75036*4],0 +.loopb + mov dword[esi],0 + mov dword[esi+75036*4],0 + add esi,4 + loop .loopb + add esi,288*2-48*2 + dec ebx + jnz .loop2b +.do8b + call GetTimeInSeconds + xor edx,edx + mov ebx,60 + div ebx + push eax + ; edx = seconds + mov eax,edx + xor edx,edx + mov ebx,10 + div ebx + mov esi,209*288+32+228 + call .output + pop eax + mov ebx,60 + xor edx,edx + div ebx + push eax + ; edx = minutes + mov eax,edx + xor edx,edx + mov ebx,10 + div ebx + mov esi,209*288+32+210 + call .output + pop eax + ; eax = hours + xor edx,edx + mov ebx,10 + div ebx + mov esi,209*288+32+192 + call .output + cmp byte[cbitmode],1 + je .do16b2 +.no16b4 + mov esi,209*288+32+222 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar5x5 + popad + mov esi,209*288+32+204 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar5x5 + popad + ret +.do16b2 + mov esi,209*288*2+32*2+222*2 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar16b5x5 + popad + mov esi,209*288*2+32*2+204*2 + add esi,[vidbuffer] + xor eax,eax + add al,':' + mov al,[ASCII2Font+eax] + pushad + call outputchar16b5x5 + popad + ret +.output + ; output char value at al and dl + cmp byte[cbitmode],1 + je .do16b +.no16b5 + add esi,[vidbuffer] + and eax,0FFh + add al,48 + mov al,[ASCII2Font+eax] + pushad + call outputchar5x5 + popad + xor eax,eax + mov al,dl + add al,48 + mov al,[ASCII2Font+eax] + add esi,6 + pushad + call outputchar5x5 + popad + ret +.do16b + add esi,esi + add esi,[vidbuffer] + and eax,0FFh + add al,48 + mov al,[ASCII2Font+eax] + pushad + call outputchar16b5x5 + popad + xor eax,eax + mov al,dl + add al,48 + mov al,[ASCII2Font+eax] + add esi,12 + pushad + call outputchar16b5x5 + popad + ret + + +hextestfilen db 'DSP1DUMP.DAT',0 + +NEWSYM SoundTest, db 0 + + +NEWSYM hextestoutput + + mov dx,[bg3scroly] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[bg3ptr] + add ax,dx + xor edx,edx + mov dx,[bg3scrolx] + and dx,0F8h + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma + and dx,0F000h + shr dx,5 + add ax,dx +.nooma + add eax,40h + mov edx,eax + mov [Testval],edx + + cmp byte[pressed+25],1 + jne .nopress25 + jmp .nopress25 + pushad + mov edx,hextestfilen + call Create_File + jc .failed + mov bx,ax + mov edx,dsp1array + mov ecx,4096 + call Write_File + call Close_File +.failed + popad + mov byte[pressed+25],2 +.nopress25 + call displayfpspal + mov esi,216*288+32 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + mov al,[eax+224h] + mov al,[scrnon] + call outputhex + mov esi,216*288+32+16 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + mov al,[eax+225h] + mov al,[scrnon+1] + mov al,[scrnon+1] + call outputhex + mov esi,216*288+70 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + mov al,[eax+226h] + mov al,[scaddset] + mov al,byte[bgmode] + call outputhex + mov esi,216*288+70+16 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + mov al,[eax+227h] + mov al,[C4values+2] + mov al,[scaddset] + mov al,[blahblahblah] + call outputhex + mov esi,216*288+108 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + add eax,[C4Ram] + mov al,[eax+228h] + mov al,[coladdr] + call outputhex + mov esi,216*288+108+16 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + add eax,[C4Ram] + mov al,[eax+229h] + mov al,[coladdr+1] + call outputhex + mov esi,216*288+146 + add esi,[vidbuffer] + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + add eax,[C4Ram] + mov al,[eax+22Ah] + mov al,[coladdr+2] + call outputhex + xor eax,eax + mov al,[C4ObjSelec] + shl eax,4 + add eax,[C4Ram] + mov al,[eax+22Bh] + mov esi,216*288+146+16 + add esi,[vidbuffer] + mov al,[C4values+6] + mov al,[vidbright] + or al,[forceblnk] + call outputhex + ret + +NEWSYM SoundPlayed0, db 0 +NEWSYM SoundPlayed1, db 0 +NEWSYM SoundPlayed2, db 0 +NEWSYM SoundPlayed3, db 0 +NEWSYM SoundPlayed4, db 0 +NEWSYM SoundPlayed5, db 0 +NEWSYM SoundPlayed6, db 0 +NEWSYM SoundPlayed7, db 0 +NEWSYM ngfont, db 0 + +NEWSYM ShowSound + add esi,[vidbuffer] +.next + mov [esi],ebx + mov [esi+4],ebx + mov [esi+8],bx + sub esi,288 + dec al + jnz .next + ret + +NEWSYM sounddisplay + call displayfpspal + + push esi + push ebx + push eax + mov ebx,80808080h + cmp byte[SoundPlayed0],0 + je .nosnd0 + mov al,[SoundPlayed0] + mov esi,223*288+16 + call ShowSound + sub byte[SoundPlayed0],2 +.nosnd0 + cmp byte[SoundPlayed1],0 + je .nosnd1 + mov al,[SoundPlayed1] + mov esi,223*288+28 + call ShowSound + sub byte[SoundPlayed1],2 +.nosnd1 + cmp byte[SoundPlayed2],0 + je .nosnd2 + mov al,[SoundPlayed2] + mov esi,223*288+40 + call ShowSound + sub byte[SoundPlayed2],2 +.nosnd2 + cmp byte[SoundPlayed3],0 + je .nosnd3 + mov al,[SoundPlayed3] + mov esi,223*288+52 + call ShowSound + sub byte[SoundPlayed3],2 +.nosnd3 + cmp byte[SoundPlayed4],0 + je .nosnd4 + mov al,[SoundPlayed4] + mov esi,223*288+64 + call ShowSound + sub byte[SoundPlayed4],2 +.nosnd4 + cmp byte[SoundPlayed5],0 + je .nosnd5 + mov al,[SoundPlayed5] + mov esi,223*288+76 + call ShowSound + sub byte[SoundPlayed5],2 +.nosnd5 + cmp byte[SoundPlayed6],0 + je .nosnd6 + mov al,[SoundPlayed6] + mov esi,223*288+88 + call ShowSound + sub byte[SoundPlayed6],2 +.nosnd6 + cmp byte[SoundPlayed7],0 + je .nosnd7 + mov al,[SoundPlayed7] + mov esi,223*288+100 + call ShowSound + sub byte[SoundPlayed7],2 +.nosnd7 + pop eax + pop esi + pop ebx + ret + +NEWSYM waitvsync + mov dx,3DAh ;VGA status port +;.loop +; in al,dx +; test al,8 ;check VR bit +; jnz .loop ;in middle of VR, better wait for next one +.loop2 + in al,dx + test al,8 + jz .loop2 ;updating the screen + ret + +NEWSYM prevengval, db 10 +NEWSYM chaton, db 0 +NEWSYM chatstrL, times 140 db 0 +NEWSYM chatLpos, dd 0 +NEWSYM chatstrR, times 140 db 0 +NEWSYM chatstrR2, times 140 db 0 +NEWSYM chatstrR3, times 140 db 0 +NEWSYM chatstrR4, times 140 db 0 +NEWSYM chatstrR5, times 140 db 0 +NEWSYM chatRTL, dd 0 +NEWSYM chatRTL2, dd 0 +NEWSYM chatRTL3, dd 0 +NEWSYM chatRTL4, dd 0 +NEWSYM chatRTL5, dd 0 +NEWSYM chatTL, dd 0 +NEWSYM chatreqtable + db 0 ,2 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,0 + db 'Q','W','E','R','T','Y','U','I','O','P','[',']',13 ,0 ,'A','S' + db 'D','F','G','H','J','K','L',';',27h,'`',1 ,'\','Z','X','C','V' + db 'B','N','M',',','.','/',1 ,0 ,0 ,' ',0 ,0 ,0 ,0 ,0 ,0 + ; Shift Key Presses + db 0 ,2 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,0 + db 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S' + db 'D','F','G','H','J','K','L',':','"','~',1 ,'|','Z','X','C','V' + db 'B','N','M','<','>','?',1 ,0 ,0 ,' ',0 ,0 ,0 ,0 ,0 ,0 + + +; Letters transferred & string cleared when chatstrL[0]!=0 and chaton=0 +; Disable all transfers when chaton=1 (except joysticks and upper keyboard +; in input devices) + +NEWSYM ChatType2 + jmp ChatType.skipchatdisp +NEWSYM ChatType + cmp dword[chatTL],0 + jne near .chatdisplayed + cmp byte[chatstrL],0 + jne near .processchat + jmp .skipchatdisp +.chatdisplayed + dec dword[chatTL] + cmp dword[chatTL],0 + jne .skipchatdisp + mov dword[chatstrL],0 +.skipchatdisp + + mov eax,[KeyQuickChat] + cmp byte[chaton],0 + jne .nosendchats + cmp byte[chatstrL],0 + je .nosendchats + cmp dword[chatTL],0 + jne .nosendchats + mov byte[pressed+eax],0 +.nosendchats + + cmp byte[pressed+eax],1 + jne .noqchat + + mov dword[chatTL],0 + mov byte[pressed+eax],2 + mov byte[chaton],1 + mov dword[chatLpos],0 + mov byte[chatstrL],'>' + mov byte[chatstrL+1],'_' + mov byte[chatstrL+2],0 +.noqchat + jmp .skipall +.processchat + cmp byte[chaton],0 + je near .skipall + mov eax,63 +.notof + cmp byte[chatreqtable+eax],1 + jbe near .skipthis + cmp byte[pressed+eax],1 + jne near .skipthis + mov byte[pressed+eax],2 + push eax + cmp byte[pressed+42],1 + je .shift + cmp byte[pressed+54],1 + je .shift + mov al,[chatreqtable+eax] + jmp .noshift +.shift + mov al,[chatreqtable+eax+64] +.noshift + cmp al,8 + je .delete + cmp al,13 + je .enter + cmp al,2 + je near .cancel + cmp dword[chatLpos],32+30 + jae near .skipoutput + mov ebx,[chatLpos] + mov [chatstrL+ebx+1],al + mov byte[chatstrL+ebx+2],'_' + mov byte[chatstrL+ebx+3],0 + inc dword[chatLpos] + jmp .skipoutput +.delete + mov byte[pressed+0Eh],2 + cmp dword[chatLpos],0 + je near .skipoutput + dec dword[chatLpos] + mov ebx,[chatLpos] + mov byte[chatstrL+ebx+1],'_' + mov byte[chatstrL+ebx+2],0 + jmp .skipoutput +.enter + mov byte[pressed+1Ch],2 + mov byte[chaton],0 + cmp dword[chatLpos],0 + jne .noskipoutput + mov byte[chatstrL],0 + jmp .skipoutput +.noskipoutput + mov ebx,[chatLpos] + mov byte[chatstrL+ebx+1],0 + pushad + mov dl,'L' +; call NetAddChar + cmp byte[OSPort],2 + jb .dos + cmp dword[chatstrL+1],'/ME ' + je .action +.dos + mov esi,ChatNick + call WritetochatBuffer + mov esi,chatstrL + call WritetochatBuffer + jmp .noaction +.action + mov dl,'*' + call NetAddChar + mov esi,ChatNick + call WritetochatBuffer + mov dl,' ' + call NetAddChar + mov esi,chatstrL+5 + call WritetochatBuffer +.noaction + mov dl,13 + call NetAddChar + mov dl,10 + call NetAddChar + popad + jmp .skipoutput +.cancel + mov byte[chatstrL],0 + mov byte[chaton],0 + mov byte[pressed+1],2 +.skipoutput + pop eax +.skipthis + dec eax + jns near .notof +.skipall + ret + +%macro RemoteStringPrint 1 + cmp byte[%1],0 + je %%nostringremote + mov edi,%1 + mov esi,[vidbuffer] + cmp byte[cbitmode],1 + je %%do16b3 + mov byte[ngfont],1 + add esi,194*288+20 + add esi,[.sdrawptr] + cmp byte[%1],' ' + jne %%nospace + inc edi + add esi,6 +%%nospace + add dword[.sdrawptr],288*6 + call OutputGraphicString5x5.no16bit + jmp %%nostringremote +%%do16b3 + add esi,194*288*2+20*2 + add esi,[.sdrawptr] + cmp byte[%1],' ' + jne %%nospaceb + inc edi + add esi,6 +%%nospaceb + add dword[.sdrawptr],288*6*2 + call OutputGraphicString16b5x52 +%%nostringremote +%endmacro + + +NEWSYM copyvid + cmp byte[CNetType],20 + jne .nonet + call ChatType +.nonet + mov byte[ngfont],0 + cmp byte[chatstrL],0 + je .nostringlocal + mov eax,chatstrL + call StringLength + sub ecx,42 + cmp ecx,0 + jge .notover + xor ecx,ecx +.notover + mov edi,chatstrL + add edi,ecx + mov esi,[vidbuffer] + cmp byte[cbitmode],1 + je .do16b2 +.no16b2 + mov byte[ngfont],1 + add esi,188*288+20 + call OutputGraphicString5x5.no16bit + jmp .nostringlocal +.do16b2 + add esi,188*288*2+20*2 + call OutputGraphicString16b5x52 +.nostringlocal + + cmp byte[chatstrLt],0 + je .nostringtemp + mov edi,chatstrLt + mov esi,[vidbuffer] + cmp byte[cbitmode],1 + je .do16b2temp +.no16b2temp + mov byte[ngfont],1 + add esi,182*288+20 + call OutputGraphicString5x5.no16bit + jmp .nostringtemp +.do16b2temp + add esi,182*288*2+20*2 + call OutputGraphicString16b5x52 +.nostringtemp + + mov dword[.sdrawptr],0 + RemoteStringPrint chatstrR5 + RemoteStringPrint chatstrR4 + RemoteStringPrint chatstrR3 + RemoteStringPrint chatstrR2 + RemoteStringPrint chatstrR + + cmp dword[chatRTL],0 + je .nortl + dec dword[chatRTL] + cmp dword[chatRTL],0 + jne .nortl + mov dword[chatstrR],0 +.nortl + cmp dword[chatRTL2],0 + je .nortl2 + dec dword[chatRTL2] + cmp dword[chatRTL2],0 + jne .nortl2 + mov dword[chatstrR2],0 +.nortl2 + cmp dword[chatRTL3],0 + je .nortl3 + dec dword[chatRTL3] + cmp dword[chatRTL3],0 + jne .nortl3 + mov dword[chatstrR3],0 +.nortl3 + cmp dword[chatRTL4],0 + je .nortl4 + dec dword[chatRTL4] + cmp dword[chatRTL4],0 + jne .nortl4 + mov dword[chatstrR4],0 +.nortl4 + cmp dword[chatRTL5],0 + je .nortl5 + dec dword[chatRTL5] + cmp dword[chatRTL5],0 + jne .nortl5 + mov dword[chatstrR5],0 +.nortl5 + + + ; Test if add table needs updating + cmp byte[cbitmode],0 + je .notatud + cmp byte[vesa2red10],0 + je .notatud + mov al,[newengen] + cmp [prevengval],al + je .notatud + mov [prevengval],al + call genfulladdtab + jmp .notatud +.redadd + call genfulladdtabng +.notatud + cmp dword[MessageOn],0 + je near .nomsg + cmp byte[cbitmode],1 + je .do16b +.no16b + mov byte[ngfont],1 + mov edi,[Msgptr] + mov esi,200*288+32 + add esi,[vidbuffer] + call OutputGraphicString.no16bit + dec dword[MessageOn] + jnz .nomsg + cmp byte[cbitmode],1 + je .nomsg + call makepal + jmp .nomsg +.do16b + mov edi,[Msgptr] + mov esi,200*288*2+32*2 + add esi,[vidbuffer] + call OutputGraphicString16b + dec dword[MessageOn] +.nomsg + jmp vidpaste +.sdrawptr dd 0 + +NEWSYM vidpaste + cmp byte[vsyncon],0 + je .novsync + cmp byte[Triplebufen],0 + jne .novsync + cmp byte[curblank],0h + jne .novsync + cmp byte[OSPort],1 + ja .novsync + call waitvsync +.novsync + cmp byte[cbitmode],1 + je .nopal + cmp byte[curblank],0 + jne .nopal + call changepal +.nopal + cmp byte[FPSOn],0 + je .nofps + cmp byte[curblank],0 + jne .nofps + call showfps +.nofps +; call ClockOutputB + + cmp byte[TimerEnable],0 + je .noclock + cmp byte[ShowTimer],0 + je .noclock +; cmp byte[OSPort],2 +; jae .noclock + call ClockOutput +.noclock + cmp byte[snesmouse],3 + je near .drawss +; cmp byte[snesmouse],4 +; je near .drawss +.returnfromdraw + mov ax,[resolutn] + cmp [prevresolutn],ax + je .noclear + mov [prevresolutn],ax + call ClearScreen +.noclear + jmp DrawScreen + +.drawss + cmp byte[cbitmode],1 + je .noss8b + call superscopepal +.noss8b + xor eax,eax + mov al,[mouseyloc] + mov ebx,288 + mul ebx + mov esi,[vidbuffer] + mov edi,SScopeCursor + xor ebx,ebx + mov bl,[mousexloc] + add ebx,6 + cmp byte[cbitmode],1 + je near .ss16b + mov cl,20 +.ssloop + mov ch,20 +.ssloop2 + cmp byte[edi],0 + je .nodraw + mov edx,eax + add edx,ebx + sub edx,288*10 + jb .nodraw + mov byte[esi+edx],128+16 +.nodraw + inc ebx + inc edi + dec ch + jnz .ssloop2 + sub ebx,20 + add eax,288 + dec cl + jnz .ssloop + jmp .returnfromdraw + +.ss16b + push ebx + mov cl,[vesa2_rpos] + mov bx,31 + shl bx,cl + mov [.SSRedCo],bx + pop ebx + shl eax,1 + shl ebx,1 + mov cl,20 +.ssloopb + mov ch,20 +.ssloopb2 + cmp byte[edi],0 + je .nodrawb + mov edx,eax + add edx,ebx + sub edx,288*10*2 + jb .nodrawb + push eax + mov ax,[.SSRedCo] + mov [esi+edx],ax + pop eax +.nodrawb + add ebx,2 + inc edi + dec ch + jnz .ssloopb2 + sub ebx,40 + add eax,288*2 + dec cl + jnz .ssloopb + jmp .returnfromdraw + +.SSRedCo dw 0 + +NEWSYM lastfps, db 0 ; stores the last fps encountered +NEWSYM lastfps2, db 0 ; stores the last fps encountered +NEWSYM curfps2, db 0 ; current video refresh fps +NEWSYM Msgptr, dd 0 ; Pointer to message +NEWSYM MessageOn, dd 0 ; Message On Countdown +NEWSYM MsgCount, dd 120 ; How long message will stay (PAL = 100) +NEWSYM FPSOn, db 0 +prevresolutn dd 224 + +NEWSYM SScopeCursor +db 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 +db 0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0 +db 0,0,0,0,0,1,1,0,0,1,0,0,1,1,0,0,0,0,0,0 +db 0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0 +db 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0 +db 0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0 +db 0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0 +db 0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0 +db 0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0 +db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 +db 0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0 +db 0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0 +db 0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0 +db 0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0 +db 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0 +db 0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0 +db 0,0,0,0,0,1,1,0,0,1,0,0,1,1,0,0,0,0,0,0 +db 0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0 +db 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 +db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + \ No newline at end of file diff --git a/zsnes/src/video/vidmacrb.mac b/zsnes/src/video/vidmacrb.mac new file mode 100644 index 00000000..37b58f95 --- /dev/null +++ b/zsnes/src/video/vidmacrb.mac @@ -0,0 +1,1759 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM OMBGTestVal,ngptrdat2,cachesingle4bng,ofshvaladd,ofsmtptrs,ofsmcptr2 +EXTSYM Testval + + + + + + +; makev16t macros + +%macro procwindowback 0 + mov byte[winon],0 + mov bl,[wincolen] + and bl,00001010b + cmp bl,00001010b + je near .dualwin + mov bl,[scaddset] + shr bl,4 + and bl,00000011b + + cmp bl,0 + je near .finishwin + cmp bl,3 + je near .clearwin + test byte[wincolen],00001010b + jz near .finishwin + + mov al,[wincolen] + and al,00000101b + + mov esi,windowdata + mov byte[winon],1 + mov byte[numwin],0 + mov cl,[winl2] + mov ch,[winr2] + test byte[wincolen],00000010b + jz .nowin1 + mov cl,[winl1] + mov ch,[winr1] + shl al,2 +.nowin1 + cmp ch,255 + je .noinc + inc ch +.noinc + test al,04h + jnz near .wininside + cmp cl,ch + jae .noinsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[esi+2],cl + mov byte[esi+3],0FFh + mov byte[esi+4],ch + mov byte[esi+5],01h + mov byte[numwin],3 + jmp .finishwin +.noinsidemask + mov byte[winon],2 + jmp .finishwin +.wininside + cmp cl,ch + ja .nooutsidemask +.nonotoutside + cmp ch,254 + jb .skipnodraw + cmp cl,1 + jbe .noinsidemask +.skipnodraw + mov byte[esi],cl + mov byte[esi+1],01h + mov byte[esi+2],ch + mov byte[esi+3],0FFh + mov byte[numwin],2 + jmp .finishwin +.nooutsidemask + mov byte[winon],5 + jmp .finishwin +.dualwin + mov al,[wincolen] + mov bl,[scaddset] + and bl,30h + cmp bl,30h + je .clearwin + cmp bl,00h + je .finishwin + call makedualwincol + mov byte[winon],3 + jmp .finishwin +.clearwin + mov byte[winon],4 +.finishwin +%endmacro + + +%macro procwindowback2 0 + mov byte[winon],0 + mov al,[wincolen] + test al,00001010b + jz near .finishwin + mov esi,windowdata + mov bl,al + mov byte[winon],1 + and bl,00001010b + and al,00000101b + mov byte[numwin],0 + cmp bl,00001010b + je near .multiwin + test bl,00000010b + jnz .win1 + mov cl,[winl2] + mov ch,[winr2] + shr al,2 + jmp .okaywin +.win1 + mov cl,[winl1] + mov ch,[winr1] + and al,01h +.okaywin + test al,01h + jz near .wininside + cmp cl,ch + jae .noinsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[esi+2],cl + mov byte[esi+3],0FFh + mov byte[esi+4],ch + mov byte[esi+5],01h + mov byte[numwin],3 + jmp .finishwin +.noinsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[numwin],1 + jmp .finishwin +.wininside + cmp cl,ch + ja .nooutsidemask +.nonotoutside + cmp ch,254 + jb .skipnodraw + cmp cl,1 + jbe .noinsidemask +.skipnodraw + mov byte[esi],cl + mov byte[esi+1],01h + mov byte[esi+2],ch + mov byte[esi+3],0FFh + mov byte[numwin],2 + jmp .finishwin +.nooutsidemask + mov byte[winon],0 + jmp .finishwin +.multiwin + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[numwin],1 +.finishwin +%endmacro + + +;******************************************************* +; Processes & Draws 4-bit sprites for both main & sub +;******************************************************* + +%macro drawspr16bt 2 + mov al,[esi+%1] + test al,0Fh + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi-%2],dx + mov [ebp-%2],dx +%%skip +%endmacro + + +%macro drawspr16btwo 3 + mov al,[esi+%1] + test al,0Fh + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi-%2],dx + mov [ebp-%2],dx +%%skip +%endmacro + + +%macro sprpriorityinit 1 + cmp byte[sprclprio+ebp],0 + je near .endobj + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near %1 +.drawnowin +%endmacro + +%macro sprprioritydrawbt 2 + cmp dword[sprsingle],1 + je near .drawsingle + mov [csprprlft],cl + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notprio + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notpriof + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + xor eax,eax + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +%endmacro + +%macro sprdrawpra16bt 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + mov [transpbuf+32+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16bt 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + mov [transpbuf+32+ebx*2-%1*2],dx +%%skip +%endmacro + + +;******************************************************* +; Processes & Draws 4-bit sprites w/ transparency +;******************************************************* + +%macro drawspr16ta 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-%2],dx +%%skip +%endmacro + +%macro drawspr16tb 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov ebx,[ebp-%2] + mov edx,[pal16b+eax*4] + cmp bx,0 + je %%noadd + and edx,[vesa2_clbit] + and ebx,[vesa2_clbit] + add edx,ebx + shr edx,1 +%%noadd + mov [edi-%2],dx +%%skip +%endmacro + + +%macro drawspr16tc 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov ebx,[ebp-%2] + mov edx,[pal16bcl+eax*4] + and ebx,[vesa2_clbit] + add edx,ebx + shr edx,1 + mov edx,[fulladdtab+edx*2] + mov [edi-%2],dx +%%skip +%endmacro + + +%macro drawspr16td 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov ebx,[ebp-%2] + mov edx,[pal16bxcl+eax*4] + and ebx,[vesa2_clbit] + add edx,ebx + shr edx,1 + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi-%2],dx +%%skip +%endmacro + +%macro drawspr16tawinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%2],dx +%%skip +%endmacro + +%macro drawspr16tbwinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[ebp-%2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and eax,[vesa2_clbit] + and edx,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi-%2],ax + xor eax,eax +%%skip +%endmacro + +%macro drawspr16tcwinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[ebp-%2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add eax,edx + shr eax,1 + mov eax,[fulladdtab+eax*2] + mov [edi-%2],ax + xor eax,eax +%%skip +%endmacro + +%macro drawspr16tdwinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[ebp-%2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add eax,edx + shr eax,1 + mov eax,[fulladdtab+eax*2] + xor eax,0FFFFh + mov [edi-%2],ax + xor eax,eax +%%skip +%endmacro + +%macro drawsprgrp 1 + %1 0, 16 + %1 1, 14 + %1 2, 12 + %1 3, 10 + %1 4, 8 + %1 5, 6 + %1 6, 4 + %1 7, 2 +%endmacro + +%macro drawsprgrpf 1 + %1 7, 16 + %1 6, 14 + %1 5, 12 + %1 4, 10 + %1 3, 8 + %1 2, 6 + %1 1, 4 + %1 0, 2 +%endmacro + +%macro drawsprgrpwin 1 + %1 0, 16, 0 + %1 1, 14, 1 + %1 2, 12, 2 + %1 3, 10, 3 + %1 4, 8, 4 + %1 5, 6, 5 + %1 6, 4, 6 + %1 7, 2, 7 +%endmacro + +%macro drawsprgrpfwin 1 + %1 7, 16, 0 + %1 6, 14, 1 + %1 5, 12, 2 + %1 4, 10, 3 + %1 3, 8, 4 + %1 2, 6, 5 + %1 1, 4, 6 + %1 0, 2, 7 +%endmacro + + +%macro sprprioritydrawt16b 4 + cmp dword[sprsingle],1 + je near .drawsingle + mov [csprprlft],cl + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notprio + cmp ch,12*16 + jae near .transpobj + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b %3 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.transpobj + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notpriof + cmp ch,12*16 + jae near .transpobjf + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b %3 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.transpobjf + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + xor eax,eax + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transpobj2 + sprdrawa16b %4 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.transpobj2 + sprdrawa16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transpobj2f + sprdrawaf16b %4 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.transpobj2f + sprdrawaf16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +%endmacro + +%macro sprdrawpra16bha 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + or byte[sprpriodata+ebx-%1+16],cl + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprb16bha 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpraw16bha 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + or byte[sprpriodata+ebx-%1+16],cl + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbw16bha 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + + +%macro sprdrawpra16bfa 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16bfa 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpraw16bfa 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprbw16bfa 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpra16bfs 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16bfs 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpraw16bfs 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprbw16bfs 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +;******************************************************* +; Processes & Draws 8x8 tiles for both main & sub screen +;******************************************************* + +%macro draw8x816bta 2 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%2],cx + mov [ebp+%2],cx +%%loop +%endmacro + +%macro draw8x816btawinon 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[ecx+%1],0FFh + jnz %%loop + add al,dh + mov eax,[pal16b+eax*4] + mov [esi+%2],ax + mov [ebp+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816btawinonb 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[ecx+7-%1],0FFh + jnz %%loop + add al,dh + mov eax,[pal16b+eax*4] + mov [esi+%2],ax + mov [ebp+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro drawtilegrp 1 + cmp dword[ebx],0 + je near %%loop + %1 0, 0 + %1 1, 2 + %1 2, 4 + %1 3, 6 +%%loop + cmp dword[ebx+4],0 + je near %%loop2 + %1 4, 8 + %1 5, 10 + %1 6, 12 + %1 7, 14 +%%loop2 +%endmacro + +%macro drawtilegrpf 1 + cmp dword[ebx+4],0 + je near %%loop + %1 7, 0 + %1 6, 2 + %1 5, 4 + %1 4, 6 +%%loop + cmp dword[ebx],0 + je near %%loop2 + %1 3, 8 + %1 2, 10 + %1 1, 12 + %1 0, 14 +%%loop2 +%endmacro + +%macro drawtilegrpfull 1 + cmp dword[edi],0 + je near %%loop + %1 0, 0 + %1 1, 2 + %1 2, 4 + %1 3, 6 +%%loop + cmp dword[edi+4],0 + je near %%loop2 + %1 4, 8 + %1 5, 10 + %1 6, 12 + %1 7, 14 +%%loop2 +%endmacro + +%macro drawtilegrpfullf 1 + cmp dword[edi+4],0 + je near %%loop + %1 7, 0 + %1 6, 2 + %1 5, 4 + %1 4, 6 +%%loop + cmp dword[edi],0 + je near %%loop2 + %1 3, 8 + %1 2, 10 + %1 1, 12 + %1 0, 14 +%%loop2 +%endmacro + + +;******************************************************* +; Processes & Draws 8x8 tiles in 2, 4, & 8 bit mode +;******************************************************* + +%macro draw8x816ta 2 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816ta2 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16b+eax*4] + test ebx,0FFFFh + je %%noadd + and ecx,1111011111011110b ; [vesa2_clbit] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 +%%noadd + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tb 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tc 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinon 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbwinon 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinon 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinon2 3 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%3],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov ebx,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and ebx,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add ebx,ecx + shr ebx,1 +%%noadd + mov [esi+%2],bx +%%loop +%endmacro + +%macro draw8x816tbwinon2 3 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%3],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinon2 3 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%3],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinonb 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbwinonb 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinonb 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + + +; end makev16t +; **************************************************** +; **************************************************** + +%macro Draw16x1616bwin 3 + mov al,[ebx+%1] + test al,0FFh + jz %%loop + test byte[ebp+%3],0FFh + jnz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%2],cx +%%loop +%endmacro + +;******************************************************* +; Processes & Draws 16x16 tiles in 2, 4, & 8 bit mode +;******************************************************* +%macro Draw16x1616b 2 + mov al,[ebx+%1] + test al,0FFh + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%2],cx +%%loop +%endmacro + +%macro drawpixel16b8x8winon 4 + mov al,[ebx+%1] + test al,0FFh + jz %2 + test byte[ebp+%4],0FFh + jnz %2 + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%3],cx +%2 +%endmacro + +%macro drawpixel16b8x8 3 + mov al,[ebx+%1] + test al,0FFh + jz %2 + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%3],cx +%2 +%endmacro + +%macro Draw8x816bwinmacro 1 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[ebp+%1],0FFh + jnz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +%macro Draw8x816bwinflipmacro 1 + mov al,[ebx+7-%1] + or al,al + jz %%loop + test byte[ebp+%1],0FFh + jnz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +;******************************************************* +; DrawLine 16bit Draws the current line +;******************************************************* +; use curypos+bg1scroly for y location and bg1scrolx for x location +; use bg1ptr(b,c,d) for the pointer to the tile number contents +; use bg1objptr for the pointer to the object tile contents + +%macro procmode716b 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,%1 + mov dx,%2 + call drawmode716b +%endmacro + + +%macro sprdrawpra16b 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16b 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpraw16b 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprbw16b 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +;******************************************************* +; Processes & Draws 8x8 tiles in 2, 4, & 8 bit mode +;******************************************************* + +%macro Draw8x816bmacro 1 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +%macro Draw8x816bflipmacro 1 + mov al,[ebx+7-%1] + or al,al + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +%macro sprdrawa16b 1 + mov al,[esi] + %1 8 + mov al,[esi+1] + %1 7 + mov al,[esi+2] + %1 6 + mov al,[esi+3] + %1 5 + mov al,[esi+4] + %1 4 + mov al,[esi+5] + %1 3 + mov al,[esi+6] + %1 2 + mov al,[esi+7] + %1 1 +%endmacro + +%macro sprdrawaf16b 1 + mov al,[esi] + %1 1 + mov al,[esi+1] + %1 2 + mov al,[esi+2] + %1 3 + mov al,[esi+3] + %1 4 + mov al,[esi+4] + %1 5 + mov al,[esi+5] + %1 6 + mov al,[esi+6] + %1 7 + mov al,[esi+7] + %1 8 +%endmacro + + +%macro sprdrawa 1 + mov eax,[esi] + %1 8, al + %1 7, ah + mov eax,[esi+2] + %1 6, al + %1 5, ah + mov eax,[esi+4] + %1 4, al + %1 3, ah + mov eax,[esi+6] + %1 2, al + %1 1, ah +%endmacro + +%macro sprdrawpra 2 + or %2,%2 + jz %%skip + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + add %2,ch + mov [edi+ebx-%1],%2 + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb 2 + or %2,%2 + jz %%skip + add %2,ch + mov [edi+ebx-%1],%2 +%%skip +%endmacro + +%macro sprdrawpra2 2 + or %2,%2 + jz %%skip + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawpraw 2 + or %2,%2 + jz %%skip + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add %2,ch + mov [edi+ebx-%1],%2 + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprbw 2 + or %2,%2 + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add %2,ch + mov [edi+ebx-%1],%2 +%%skip +%endmacro + +%macro sprdrawaf 1 + mov eax,[esi] + %1 1, al + %1 2, ah + mov eax,[esi+2] + %1 3, al + %1 4, ah + mov eax,[esi+4] + %1 5, al + %1 6, ah + mov eax,[esi+6] + %1 7, al + %1 8, ah +%endmacro + +%macro procoffsetmode 0 + push ebx + push edx + add word[ofsmmptr],2 + add word[ofsmtptr],2 + mov ebx,[yposngom] + mov eax,[flipyposngom] + mov [yadder],ebx + mov [yrevadder],eax + mov ax,[ofsmmptr] + test eax,03Fh + jnz %%next + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add [ofsmtptr],bx +%%next + add eax,[vram] + mov edi,eax + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov eax,[OMBGTestVal] + test dword[ebx],eax + jz %%noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yadder],edx + xor edx,38h + mov [yrevadder],edx + add eax,[vram] + mov edi,eax +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofshvaladd],8 + mov eax,[OMBGTestVal] + add dword[ofsmcptr2],2 + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],eax + jz %%noofsmh + mov eax,edi + sub eax,[vram] + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx + add eax,[vram] + mov edi,eax +%%noofsmh + pop edx + pop ebx +%endmacro + +;******************************************************* +; Processes & Draws 8x8 offset mode in Mode 2/4 +;******************************************************* + +%macro initoffsetmode 0 + push ebx + push ecx + mov ebx,2000h + mov ecx,ebp + shl ebx,cl + mov [OMBGTestVal],ebx + mov ecx,[bg1scroly+ebp*2] + and ecx,0FFFFh + add ecx,ebx + push eax + push edx + xor edx,edx + mov dx,[bg3scroly] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[bg3ptr] + add ax,dx + xor edx,edx + mov dx,[bg3scrolx] + and dx,0F8h + xor ebx,ebx + mov ebx,[curypos] + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + add eax,40h + mov edx,eax + mov [Testval],edx + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[bg1ptry+ebp*4] + mov [ofsmady],eax + mov eax,[bg1ptrx+ebp*4] + mov [ofsmadx],eax + mov eax,[bg1ptr+ebp*2] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincd + add eax,[bg1ptry+ebp*4] +.noyincd + lea ecx,[ecx*8] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov edx,[yadder] + mov [yposngom],edx + mov edx,[yrevadder] + mov [flipyposngom],edx + mov ecx,[bg1scrolx+ebp*2] + mov edx,[bg1ptrx+ebp*4] + test ecx,100h + jz .noxincd + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincd + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + xor eax,eax + mov ax,[bg1objptr+ebp*2] + shr eax,5 + mov [ngptrdat2],eax + mov eax,edi + sub eax,[vram] + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + pop edx + pop eax + pop ecx + pop ebx +%endmacro + +%macro offsetmcachechk 0 + ; Cache check + push ecx + mov ecx,eax + add ecx,[ngptrdat2] + and ecx,2047 + cmp word[vidmemch4+ecx*2],0 + je %%nocache + call cachesingle4bng +%%nocache + pop ecx +%endmacro + \ No newline at end of file diff --git a/zsnes/src/video/vidmacro.mac b/zsnes/src/video/vidmacro.mac new file mode 100644 index 00000000..afa89c08 --- /dev/null +++ b/zsnes/src/video/vidmacro.mac @@ -0,0 +1,1791 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +EXTSYM OMBGTestVal,ngptrdat2,cachesingle4bng,ofshvaladd,ofsmtptrs,ofsmcptr2 +EXTSYM Testval + + + + + + +; makev16t macros + +%macro procwindowback 0 + mov byte[winon],0 + mov bl,[wincolen] + and bl,00001010b + cmp bl,00001010b + je near .dualwin + mov bl,[scaddset] + shr bl,4 + and bl,00000011b + + cmp bl,0 + je near .finishwin + cmp bl,3 + je near .clearwin + test byte[wincolen],00001010b + jz near .finishwin + + mov al,[wincolen] + and al,00000101b + + mov esi,windowdata + mov byte[winon],1 + mov byte[numwin],0 + mov cl,[winl2] + mov ch,[winr2] + test byte[wincolen],00000010b + jz .nowin1 + mov cl,[winl1] + mov ch,[winr1] + shl al,2 +.nowin1 + cmp ch,255 + je .noinc + inc ch +.noinc + test al,04h + jnz near .wininside + cmp cl,ch + jae .noinsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[esi+2],cl + mov byte[esi+3],0FFh + mov byte[esi+4],ch + mov byte[esi+5],01h + mov byte[numwin],3 + jmp .finishwin +.noinsidemask + mov byte[winon],2 + jmp .finishwin +.wininside + cmp cl,ch + ja .nooutsidemask +.nonotoutside + cmp ch,254 + jb .skipnodraw + cmp cl,1 + jbe .noinsidemask +.skipnodraw + mov byte[esi],cl + mov byte[esi+1],01h + mov byte[esi+2],ch + mov byte[esi+3],0FFh + mov byte[numwin],2 + jmp .finishwin +.nooutsidemask + mov byte[winon],5 + jmp .finishwin +.dualwin + mov al,[wincolen] + mov bl,[scaddset] + and bl,30h + cmp bl,30h + je .clearwin + cmp bl,00h + je .finishwin + call makedualwincol + mov byte[winon],3 + jmp .finishwin +.clearwin + mov byte[winon],4 +.finishwin +%endmacro + + +%macro procwindowback2 0 + mov byte[winon],0 + mov al,[wincolen] + test al,00001010b + jz near .finishwin + mov esi,windowdata + mov bl,al + mov byte[winon],1 + and bl,00001010b + and al,00000101b + mov byte[numwin],0 + cmp bl,00001010b + je near .multiwin + test bl,00000010b + jnz .win1 + mov cl,[winl2] + mov ch,[winr2] + shr al,2 + jmp .okaywin +.win1 + mov cl,[winl1] + mov ch,[winr1] + and al,01h +.okaywin + test al,01h + jz near .wininside + cmp cl,ch + jae .noinsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[esi+2],cl + mov byte[esi+3],0FFh + mov byte[esi+4],ch + mov byte[esi+5],01h + mov byte[numwin],3 + jmp .finishwin +.noinsidemask + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[numwin],1 + jmp .finishwin +.wininside + cmp cl,ch + ja .nooutsidemask +.nonotoutside + cmp ch,254 + jb .skipnodraw + cmp cl,1 + jbe .noinsidemask +.skipnodraw + mov byte[esi],cl + mov byte[esi+1],01h + mov byte[esi+2],ch + mov byte[esi+3],0FFh + mov byte[numwin],2 + jmp .finishwin +.nooutsidemask + mov byte[winon],0 + jmp .finishwin +.multiwin + mov byte[esi],0 + mov byte[esi+1],01h + mov byte[numwin],1 +.finishwin +%endmacro + + +;******************************************************* +; Processes & Draws 4-bit sprites for both main & sub +;******************************************************* + +%macro drawspr16bt 2 + mov al,[esi+%1] + test al,0Fh + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi-%2],dx + mov [ebp-%2],dx +%%skip +%endmacro + + +%macro drawspr16btwo 3 + mov al,[esi+%1] + test al,0Fh + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi-%2],dx + mov [ebp-%2],dx +%%skip +%endmacro + + +%macro sprpriorityinit 1 + cmp byte[sprclprio+ebp],0 + je near .endobj + test byte[cwinenabm],10h + jz .drawnowin + cmp byte[winonsp],0 + jne near %1 +.drawnowin +%endmacro + +%macro sprprioritydrawbt 2 + cmp dword[sprsingle],1 + je near .drawsingle + mov [csprprlft],cl + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notprio + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notpriof + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + xor eax,eax + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawa16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + sprdrawaf16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +%endmacro + +%macro sprdrawpra16bt 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + mov [transpbuf+32+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16bt 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + mov [transpbuf+32+ebx*2-%1*2],dx +%%skip +%endmacro + + +;******************************************************* +; Processes & Draws 4-bit sprites w/ transparency +;******************************************************* + +%macro drawspr16ta 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx-%2],dx +%%skip +%endmacro + +%macro drawspr16tb 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov ebx,[ebp-%2] + mov edx,[pal16b+eax*4] + cmp bx,0 + je %%noadd + and edx,[vesa2_clbit] + and ebx,[vesa2_clbit] + add edx,ebx + shr edx,1 +%%noadd + mov [edi-%2],dx +%%skip +%endmacro + + +%macro drawspr16tc 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov ebx,[ebp-%2] + mov edx,[pal16bcl+eax*4] + and ebx,[vesa2_clbit] + add edx,ebx + shr edx,1 + mov edx,[fulladdtab+edx*2] + mov [edi-%2],dx +%%skip +%endmacro + + +%macro drawspr16td 2 + mov al,[esi+%1] + or al,al + jz %%skip + add al,ch + mov ebx,[ebp-%2] + mov edx,[pal16bxcl+eax*4] + and ebx,[vesa2_clbit] + add edx,ebx + shr edx,1 + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi-%2],dx +%%skip +%endmacro + +%macro drawspr16tawinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%2],dx +%%skip +%endmacro + +%macro drawspr16tbwinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[ebp-%2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and eax,[vesa2_clbit] + and edx,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi-%2],ax + xor eax,eax +%%skip +%endmacro + +%macro drawspr16tcwinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[ebp-%2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add eax,edx + shr eax,1 + mov eax,[fulladdtab+eax*2] + mov [edi-%2],ax + xor eax,eax +%%skip +%endmacro + +%macro drawspr16tdwinon 3 + mov al,[esi+%1] + or al,al + jz %%skip + cmp byte[winspdata+ebx-8+%3+16],0 + jne %%skip + add al,ch + mov edx,[ebp-%2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add eax,edx + shr eax,1 + mov eax,[fulladdtab+eax*2] + xor eax,0FFFFh + mov [edi-%2],ax + xor eax,eax +%%skip +%endmacro + +%macro drawsprgrp 1 + %1 0, 16 + %1 1, 14 + %1 2, 12 + %1 3, 10 + %1 4, 8 + %1 5, 6 + %1 6, 4 + %1 7, 2 +%endmacro + +%macro drawsprgrpf 1 + %1 7, 16 + %1 6, 14 + %1 5, 12 + %1 4, 10 + %1 3, 8 + %1 2, 6 + %1 1, 4 + %1 0, 2 +%endmacro + +%macro drawsprgrpwin 1 + %1 0, 16, 0 + %1 1, 14, 1 + %1 2, 12, 2 + %1 3, 10, 3 + %1 4, 8, 4 + %1 5, 6, 5 + %1 6, 4, 6 + %1 7, 2, 7 +%endmacro + +%macro drawsprgrpfwin 1 + %1 7, 16, 0 + %1 6, 14, 1 + %1 5, 12, 2 + %1 4, 10, 3 + %1 3, 8, 4 + %1 2, 6, 5 + %1 1, 4, 6 + %1 0, 2, 7 +%endmacro + + +%macro sprprioritydrawt16b 4 + cmp dword[sprsingle],1 + je near .drawsingle + mov [csprprlft],cl + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,esi + xor ebx,ebx +.loopobj + test byte[esi+7],20h + jnz near .drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notprio + cmp ch,12*16 + jae near .transpobj + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b %3 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.transpobj + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawa16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notprio + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawa sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.drawspriteflipx + mov bx,[esi] + push esi + mov ch,[esi+6] + mov dl,[esi+7] + xor eax,eax + and edx,03h + cmp edx,ebp + jne near .notpriof + cmp ch,12*16 + jae near .transpobjf + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b %3 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem +.endobj + ret +.transpobjf + mov esi,[esi+2] + mov cl,[csprbit] + sprdrawaf16b %1 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.notpriof + mov esi,[esi+2] + mov dl,[csprbit] + sprdrawaf sprdrawpra2 + pop esi + add esi,8 + dec byte[csprprlft] + jnz near .loopobj + rol byte[csprbit],1 + cmp byte[csprbit],1 + je near .clearcsprmem + ret +.clearcsprmem + xor eax,eax + mov ecx,64 + mov edi,sprpriodata+16 + rep stosd + ret +.drawsingle + mov esi,[currentobjptr] + mov edi,[curvidoffset] + mov edx,ecx + and edx,0FFh + xor eax,eax + shl edx,3 + sub edx,8 + add edx,esi + mov esi,edx + xor ebx,ebx +.loopobj2 + test byte[esi+7],20h + jnz near .drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transpobj2 + sprdrawa16b %4 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.transpobj2 + sprdrawa16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.drawspriteflipx2 + mov bx,[esi] + push esi + mov ch,[esi+6] + mov esi,[esi+2] + cmp ch,12*16 + jae near .transpobj2f + sprdrawaf16b %4 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +.transpobj2f + sprdrawaf16b %2 + pop esi + sub esi,8 + dec cl + jnz near .loopobj2 + ret +%endmacro + +%macro sprdrawpra16bha 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + or byte[sprpriodata+ebx-%1+16],cl + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprb16bha 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + +%macro sprdrawpraw16bha 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + or byte[sprpriodata+ebx-%1+16],cl + xor eax,eax +%%skip +%endmacro + +%macro sprdrawprbw16bha 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16b+eax*4] + cmp dx,0 + je %%noadd + and edx,[vesa2_clbit] + and eax,[vesa2_clbit] + add eax,edx + shr eax,1 +%%noadd + mov [edi+ebx*2-%1*2],ax + xor eax,eax +%%skip +%endmacro + + +%macro sprdrawpra16bfa 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16bfa 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpraw16bfa 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprbw16bfa 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpra16bfs 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16bfs 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpraw16bfs 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprbw16bfs 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[transpbuf+32+ebx*2-%1*2] + mov eax,[pal16bxcl+eax*4] + and edx,[vesa2_clbit] + add edx,eax + shr edx,1 + xor eax,eax + mov edx,[fulladdtab+edx*2] + xor edx,0FFFFh + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +;******************************************************* +; Processes & Draws 8x8 tiles for both main & sub screen +;******************************************************* + +%macro draw8x816bta 2 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%2],cx + mov [ebp+%2],cx +%%loop +%endmacro + +%macro draw8x816btawinon 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[ecx+%1],0FFh + jnz %%loop + add al,dh + mov eax,[pal16b+eax*4] + mov [esi+%2],ax + mov [ebp+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816btawinonb 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[ecx+7-%1],0FFh + jnz %%loop + add al,dh + mov eax,[pal16b+eax*4] + mov [esi+%2],ax + mov [ebp+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro drawtilegrp 1 + cmp dword[ebx],0 + je near %%loop + %1 0, 0 + %1 1, 2 + %1 2, 4 + %1 3, 6 +%%loop + cmp dword[ebx+4],0 + je near %%loop2 + %1 4, 8 + %1 5, 10 + %1 6, 12 + %1 7, 14 +%%loop2 +%endmacro + +%macro drawtilegrpf 1 + cmp dword[ebx+4],0 + je near %%loop + %1 7, 0 + %1 6, 2 + %1 5, 4 + %1 4, 6 +%%loop + cmp dword[ebx],0 + je near %%loop2 + %1 3, 8 + %1 2, 10 + %1 1, 12 + %1 0, 14 +%%loop2 +%endmacro + +%macro drawtilegrpfull 1 + cmp dword[edi],0 + je near %%loop + %1 0, 0 + %1 1, 2 + %1 2, 4 + %1 3, 6 +%%loop + cmp dword[edi+4],0 + je near %%loop2 + %1 4, 8 + %1 5, 10 + %1 6, 12 + %1 7, 14 +%%loop2 +%endmacro + +%macro drawtilegrpfullf 1 + cmp dword[edi+4],0 + je near %%loop + %1 7, 0 + %1 6, 2 + %1 5, 4 + %1 4, 6 +%%loop + cmp dword[edi],0 + je near %%loop2 + %1 3, 8 + %1 2, 10 + %1 1, 12 + %1 0, 14 +%%loop2 +%endmacro + + +;******************************************************* +; Processes & Draws 8x8 tiles in 2, 4, & 8 bit mode +;******************************************************* + +%macro draw8x816ta 2 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816ta2 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16b+eax*4] + test ebx,0FFFFh + je %%noadd + and ecx,1111011111011110b ; [vesa2_clbit] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 +%%noadd + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tb 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tc 2 + mov al,[edi+%1] + or al,al + jz %%loop + add al,dh + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinon 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbwinon 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinon 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinon2 3 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%3],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov ebx,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and ebx,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add ebx,ecx + shr ebx,1 +%%noadd + mov [esi+%2],bx +%%loop +%endmacro + +%macro draw8x816tbwinon2 3 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%3],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinon2 3 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+%3],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tawinonb 2 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ecx,[ebp+%2] + mov eax,[pal16b+eax*4] + test ecx,0FFFFh + je %%noadd + and eax,1111011111011110b ; [vesa2_clbit] + and ecx,1111011111011110b ; [vesa2_clbit] + add eax,ecx + shr eax,1 +%%noadd + mov [esi+%2],ax + xor eax,eax +%%loop +%endmacro + +%macro draw8x816tbwinonb 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + mov [esi+%2],cx +%%loop +%endmacro + +%macro draw8x816tcwinonb 2 + mov al,[edi+%1] + or al,al + jz %%loop + test byte[edx+7-%1],0FFh + jnz %%loop + add al,[coadder16] + mov ebx,[ebp+%2] + mov ecx,[pal16bxcl+eax*4] + and ebx,1111011111011110b ; [vesa2_clbit] + add ecx,ebx + shr ecx,1 + mov ecx,[fulladdtab+ecx*2] + xor ecx,0FFFFh + mov [esi+%2],cx +%%loop +%endmacro + + +; end makev16t +; **************************************************** +; **************************************************** + +%macro Draw16x1616bwin 3 + mov al,[ebx+%1] + test al,0FFh + jz %%loop + test byte[ebp+%3],0FFh + jnz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%2],cx +%%loop +%endmacro + +;******************************************************* +; Processes & Draws 16x16 tiles in 2, 4, & 8 bit mode +;******************************************************* +%macro Draw16x1616b 2 + mov al,[ebx+%1] + test al,0FFh + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%2],cx +%%loop +%endmacro + +%macro drawpixel16b8x8winon 4 + mov al,[ebx+%1] + test al,0FFh + jz %2 + test byte[ebp+%4],0FFh + jnz %2 + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%3],cx +%2 +%endmacro + +%macro drawpixel16b8x8 3 + mov al,[ebx+%1] + test al,0FFh + jz %2 + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%3],cx +%2 +%endmacro + +%macro Draw8x816bwinmacro 1 + mov al,[ebx+%1] + or al,al + jz %%loop + test byte[ebp+%1],0FFh + jnz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +%macro Draw8x816bwinflipmacro 1 + mov al,[ebx+7-%1] + or al,al + jz %%loop + test byte[ebp+%1],0FFh + jnz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +;******************************************************* +; DrawLine 16bit Draws the current line +;******************************************************* +; use curypos+bg1scroly for y location and bg1scrolx for x location +; use bg1ptr(b,c,d) for the pointer to the tile number contents +; use bg1objptr for the pointer to the object tile contents + +%macro procmode716b 3 + xor eax,eax + xor edx,edx + mov ax,[curypos] + test byte[mode7set],02h + jz .noflip + mov ax,261 + sub ax,[curypos] + dec ax +.noflip + mov byte[curmosaicsz],1 + test byte[mosaicon],%3 + jz .nomos + mov bl,[mosaicsz] + cmp bl,0 + je .nomos + inc bl + mov [curmosaicsz],bl + xor bh,bh + div bx + xor edx,edx + mul bx +.nomos + add ax,%1 + mov dx,%2 + call drawmode716b +%endmacro + + +%macro sprdrawpra16b 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprb16b 1 + or eax,eax + jz %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +%macro sprdrawpraw16b 1 + or eax,eax + jz %%skip + test byte[sprpriodata+ebx-%1+16],cl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx + or byte[sprpriodata+ebx-%1+16],cl +%%skip +%endmacro + +%macro sprdrawprbw16b 1 + or eax,eax + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add al,ch + mov edx,[pal16b+eax*4] + mov [edi+ebx*2-%1*2],dx +%%skip +%endmacro + +;******************************************************* +; Processes & Draws 8x8 tiles in 2, 4, & 8 bit mode +;******************************************************* + +%macro Draw8x816bmacro 1 + mov al,[ebx+%1] + or al,al + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +%macro Draw8x816bflipmacro 1 + mov al,[ebx+7-%1] + or al,al + jz %%loop + add al,dh + mov ecx,[pal16b+eax*4] + mov [esi+%1*2],cx +%%loop +%endmacro + +%macro sprdrawa16b 1 + xor eax,eax + mov al,[esi] + %1 8 + mov al,[esi+1] + %1 7 + mov al,[esi+2] + %1 6 + mov al,[esi+3] + %1 5 + mov al,[esi+4] + %1 4 + mov al,[esi+5] + %1 3 + mov al,[esi+6] + %1 2 + mov al,[esi+7] + %1 1 +%endmacro + +%macro sprdrawaf16b 1 + xor eax,eax + mov al,[esi] + %1 1 + mov al,[esi+1] + %1 2 + mov al,[esi+2] + %1 3 + mov al,[esi+3] + %1 4 + mov al,[esi+4] + %1 5 + mov al,[esi+5] + %1 6 + mov al,[esi+6] + %1 7 + mov al,[esi+7] + %1 8 +%endmacro + + +%macro sprdrawa 1 + mov ax,[esi] + %1 8, al + %1 7, ah + mov ax,[esi+2] + %1 6, al + %1 5, ah + mov ax,[esi+4] + %1 4, al + %1 3, ah + mov ax,[esi+6] + %1 2, al + %1 1, ah +%endmacro + +%macro sprdrawpra 2 + or %2,%2 + jz %%skip + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + add %2,ch + mov [edi+ebx-%1],%2 + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprawb 2 + or %2,%2 + jz %%skip + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[ecx+ebx-%1],1 + je %%skip + add %2,dh + mov [edi+ebx-%1],%2 + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprb 2 + or %2,%2 + jz %%skip + add %2,ch + mov [edi+ebx-%1],%2 +%%skip +%endmacro + +%macro sprdrawprbwb 2 + or %2,%2 + jz %%skip + add %2,dh + cmp byte[ecx+ebx-%1],1 + je %%skip + mov [edi+ebx-%1],%2 +%%skip +%endmacro + +%macro sprdrawpra2 2 + or %2,%2 + jz %%skip + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawpraw 2 + or %2,%2 + jz %%skip + test byte[sprpriodata+ebx-%1+16],dl + jnz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add %2,ch + mov [edi+ebx-%1],%2 + or byte[sprpriodata+ebx-%1+16],dl +%%skip +%endmacro + +%macro sprdrawprbw 2 + or %2,%2 + jz %%skip + cmp byte[winspdata+ebx-%1+16],0 + jne %%skip + add %2,ch + mov [edi+ebx-%1],%2 +%%skip +%endmacro + +%macro sprdrawaf 1 + mov ax,[esi] + %1 1, al + %1 2, ah + mov ax,[esi+2] + %1 3, al + %1 4, ah + mov ax,[esi+4] + %1 5, al + %1 6, ah + mov ax,[esi+6] + %1 7, al + %1 8, ah +%endmacro + +%macro procoffsetmode 0 + push ebx + push edx + add word[ofsmmptr],2 + add word[ofsmtptr],2 + mov ebx,[yposngom] + mov eax,[flipyposngom] + mov [yadder],ebx + mov [yrevadder],eax + mov ax,[ofsmmptr] + test eax,03Fh + jnz %%next + mov bx,[bgtxadd] + add ax,bx + add [ofsmmptr],bx + add [ofsmtptr],bx +%%next + add eax,[vram] + mov edi,eax + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + mov eax,[OMBGTestVal] + test dword[ebx],eax + jz %%noofsm + mov ebx,[ebx] + mov ax,[ofsmtptr] + and ebx,3FFh + add ebx,[ofsmcyps] + test ebx,100h + jz %%noupper + add ax,[ofsmady] +%%noupper + and ebx,0FFh + mov edx,ebx + shr ebx,3 + and edx,07h + shl ebx,6 + shl edx,3 + add ax,bx + mov [yadder],edx + xor edx,38h + mov [yrevadder],edx + add eax,[vram] + mov edi,eax +%%noofsm + mov ebx,[ofsmcptr] + add ebx,[ofsmcptr2] + add dword[ofshvaladd],8 + mov eax,[OMBGTestVal] + add dword[ofsmcptr2],2 + and dword[ofsmcptr2],3Fh + test dword[ebx-40h],eax + jz %%noofsmh + mov eax,edi + sub eax,[vram] + mov ebx,[ebx-40h] + sub ax,[ofsmtptr] + add ax,[ofsmtptrs] + add ebx,[ofshvaladd] + test ebx,100h + jz %%noleft + add ax,[ofsmadx] +%%noleft + and ebx,0F8h + shr ebx,2 + add ax,bx + add eax,[vram] + mov edi,eax +%%noofsmh + pop edx + pop ebx +%endmacro + +;******************************************************* +; Processes & Draws 8x8 offset mode in Mode 2/4 +;******************************************************* + +%macro initoffsetmode 0 + push ebx + push ecx + mov ebx,2000h + mov ecx,ebp + shl ebx,cl + mov [OMBGTestVal],ebx + mov ecx,[bg1scroly+ebp*2] + and ecx,0FFFFh + add ecx,ebx + push eax + push edx + xor edx,edx + mov dx,[bg3scroly] +; and dx,0F8h + shr edx,3 + shl edx,6 + xor eax,eax + mov ax,[bg3ptr] + add ax,dx + xor edx,edx + mov dx,[bg3scrolx] + and dx,0F8h + xor ebx,ebx + mov ebx,[curypos] + mov [ofsmcyps],ebx + shr edx,3 + shl edx,1 + add ax,dx + mov dx,[bg3scrolx] + test dx,8000h + jz .nooma + and dx,0F000h + shr dx,5 + add ax,dx +.nooma + add eax,40h + mov edx,eax + mov [Testval],edx + and edx,0FFFFFFC0h + add edx,[vram] + mov [ofsmcptr],edx + and eax,3Fh + mov [ofsmcptr2],eax + mov eax,[bg1ptry+ebp*4] + mov [ofsmady],eax + mov eax,[bg1ptrx+ebp*4] + mov [ofsmadx],eax + mov eax,[bg1ptr+ebp*2] + mov [ofsmtptr],eax + mov [ofsmtptrs],eax + test ecx,100h + jz .noyincd + add eax,[bg1ptry+ebp*4] +.noyincd + lea ecx,[ecx*8] + and ecx,07C0h ; 1Fh*40h + add eax,ecx + mov edx,[yadder] + mov [yposngom],edx + mov edx,[yrevadder] + mov [flipyposngom],edx + mov ecx,[bg1scrolx+ebp*2] + mov edx,[bg1ptrx+ebp*4] + test ecx,100h + jz .noxincd + add eax,edx + add [ofsmtptr],edx + neg dx +.noxincd + sub dx,64 + and ecx,0F8h + and eax,0FFFFh + shr ecx,2 + mov [bgtxadd],edx + add eax,ecx + add [ofsmtptr],ecx + mov [ofsmmptr],eax + xor eax,eax + mov ax,[bg1objptr+ebp*2] + shr eax,5 + mov [ngptrdat2],eax + mov eax,edi + sub eax,[vram] + mov [ofsmmptr],eax + mov dword[ofshvaladd],0 + pop edx + pop eax + pop ecx + pop ebx +%endmacro + +%macro offsetmcachechk 0 + ; Cache check + push ecx + mov ecx,eax + add ecx,[ngptrdat2] + and ecx,2047 + cmp word[vidmemch4+ecx*2],0 + je %%nocache + call cachesingle4bng +%%nocache + pop ecx +%endmacro + \ No newline at end of file diff --git a/zsnes/src/water.c b/zsnes/src/water.c new file mode 100644 index 00000000..d4a54ee8 --- /dev/null +++ b/zsnes/src/water.c @@ -0,0 +1,338 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include +#include + +#include "fixsin.h" + +extern char *vidbuffer; + +#define SCRW 288 +#define SCRH 224 + +static unsigned char vscr[SCRW*SCRH]; + + +static int Height[2][SCRW*SCRH]; + + +static void DrawWaterNoLight(int *ptr); +void DrawWaterWithLight(int *ptr,int light); +static void SineBlob(int x, int y, int radius, int height, int page); +static void CalcWater(int *nptr,int *optr,int density); + +static int x,y; +static int ox=80,oy=60; +static int xang,yang; +static int density=4; +static int Hpage=0; +static int mode=0x0001; +static int offset; +static int pheight=400; +static int radius=30; + +void DrawWater(void) +{ + // tslast=tscurrent; +// tscurrent=time(NULL); + + DrawWaterNoLight(Height[Hpage]); +// DrawWaterWithLight(Height[Hpage],1); + if(mode&2) // && (tscurrent-tslast)) + { + int x,y; + x=rand()%(SCRW-2)+1; + y=rand()%(SCRH-2)+1; + Height[Hpage][y*SCRW+x]=rand()%(pheight<<2); + } + + /* the surfer */ + if(mode&1) + { + int x,y; + x = (SCRW/2) + + ((((FSin( (xang* 65) >>8) >>8) + * (FSin( (xang*349) >>8) >>8)) + * ((SCRW-8)/2)) >> 16); + + y = (SCRH/2) + + ((((FSin( (yang*377) >>8) >>8) + *(FSin( (yang* 84) >>8) >>8)) + * ((SCRH-8)/2)) >> 16); + xang += 13; + yang += 12; + + if(mode & 0x4000) + { + offset = (oy+y)/2*SCRW + (ox+x)/2; + Height[Hpage][offset] = pheight; + Height[Hpage][offset + 1] = + Height[Hpage][offset - 1] = + Height[Hpage][offset + SCRW] = + Height[Hpage][offset - SCRW] = pheight >> 1; + + offset = y*SCRW + x; + Height[Hpage][offset] = pheight<<1; + Height[Hpage][offset + 1] = + Height[Hpage][offset - 1] = + Height[Hpage][offset + SCRW] = + Height[Hpage][offset - SCRW] = pheight; + } + else + { + SineBlob((ox+x)/2, (oy+y)/2, 3, -1200, Hpage); + SineBlob(x, y, 4, -2000, Hpage); + + } + + ox = x; + oy = y; + + } + + if(mode&4) + { + if(rand()%20 == 0) + { +/* + if(mode & 0x4000) +// HeightBlob(-1, -1, radius/2, pheight, Hpage); + else +*/ + SineBlob(-1, -1, radius, -pheight*6, Hpage); + } + } + CalcWater(Height[Hpage^1], Height[Hpage], density); + Hpage ^= 1; /* flip flop */ + +} + + +void DrawWaterNoLight(int *ptr) +{ + int dx,dy; + int x,y; + int c; + int p; + + int offset = SCRW+1; + if(ptr == NULL) + { + return; + } + + for(y=((SCRH-1)*SCRW); offset < y; offset+=2) + { + for(x = offset+SCRW-2;offset>3)+(dx>>3); +/* if(p>(SCRH*SCRW)) + { + for(;p<(SCRH*SCRW);p-=SCRW); + } + if(p<0) + { + for(;p>0;p+=SCRW); + } +*/ + if(p >= (SCRW*SCRH) ) + { + p=(SCRW*SCRH)-1; + } + else + { + if(p < 0) + { + p=0; + } + } + c=vidbuffer[p]; + (c<1) ? c=1 : (c > 31) ? c=31 : 0; + vscr[offset]=c; + offset++; + dx=ptr[offset]-ptr[offset+1]; + dy=ptr[offset]-ptr[offset+SCRW]; + p=offset+SCRW*(dy>>3)+(dx>>3); +/* + if(p>(SCRH*SCRW)) + { + for(;p<(SCRH*SCRW);p-=SCRW); + } + if(p<0) + { + for(;p>=0;p+=SCRW); + } +*/ + if(p >= (SCRW*SCRH) ) + { + p=(SCRW*SCRH)-1; + } + else + { + if(p < 0) + { + p=0; + } + } + + c=vidbuffer[p]; + (c<1) ? c=1 : (c > 31) ? c=31 : 0; + vscr[offset]=c; + } + } + + memcpy( vidbuffer,vscr,SCRW*SCRH); +// frames++; + +} + + +void DrawWaterWithLight(int *ptr,int light) +{ + int dx,dy; + int x,y; + int c; + int p; + + int offset = SCRW+1; + if(ptr == NULL) + { + return; + } + + for(y=((SCRH-1)*SCRW); offset < y; offset+=2) + { + for(x = offset+SCRW-2;offset>3)+(dx>>3); + if(p>(SCRH*SCRW)) + { + for(;p<(SCRH*SCRW);p-=SCRW); + } + if(p<0) + { + for(;p>=0;p+=SCRW); + } + c=vidbuffer[p]; + c-=(dx>>light); + (c<0) ? c=0 : (c > 255) ? c=255 : 0; + vscr[offset]=c; + offset++; + dx=ptr[offset]-ptr[offset+1]; + dy=ptr[offset]-ptr[offset+SCRW]; + p=offset+SCRW*(dy>>3)+(dx>>3); + if(p>(SCRH*SCRW)) + { + for(;p<(SCRH*SCRW);p-=SCRW); + } + if(p<0) + { + for(;p>=0;p+=SCRW); + } + c=vidbuffer[p]; + + c-=(dx>>light); + (c<0) ? c=0 : (c > 255) ? c=255 : 0; + vscr[offset]=c; + } + } + + memcpy( vidbuffer,vscr,SCRW*SCRH); +// memcpy( VGLDisplay->Bitmap,vscr,SCRW*SCRH); +// frames++; + + +} + + +void CalcWater(int *nptr,int *optr,int density) +{ + int newh; + int count = SCRW+1; + int x,y; + + for(y = (SCRH-1) * SCRW;count> 2) + - nptr[count]; + + nptr[count] = newh - (newh >> density); + } + } + +} + +void SineBlob(int x, int y, int radius, int height, int page) +{ + int cx, cy; + int left,top,right,bottom; + int square, dist; + int radsquare = radius * radius; + float length = (1024.0/(float)radius)*(1024.0/(float)radius); + + if(x<0) x = 1+radius+ rand()%(SCRW-2*radius-1); + if(y<0) y = 1+radius+ rand()%(SCRH-2*radius-1); + + +// radsquare = (radius*radius) << 8; + radsquare = (radius*radius); + +// height /= 8; + + left=-radius; right = radius; + top=-radius; bottom = radius; + + + // Perform edge clipping... + if(x - radius < 1) left -= (x-radius-1); + if(y - radius < 1) top -= (y-radius-1); + if(x + radius > SCRW-1) right -= (x+radius-SCRW+1); + if(y + radius > SCRH-1) bottom-= (y+radius-SCRH+1); + + for(cy = top; cy < bottom; cy++) + { + for(cx = left; cx < right; cx++) + { + square = cy*cy + cx*cx; + if(square < radsquare) + { + dist = sqrt(square*length); + Height[page][SCRW*(cy+y) + cx+x] + += (int)((FCos(dist)+0xffff)*(height)) >> 19; + } + } + } +} + \ No newline at end of file diff --git a/zsnes/src/win/copyvwin.asm b/zsnes/src/win/copyvwin.asm new file mode 100644 index 00000000..c9295003 --- /dev/null +++ b/zsnes/src/win/copyvwin.asm @@ -0,0 +1,1527 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM vesa2selec,vidbuffer,GUIOn,FPUCopy,resolutn,En2xSaI,antienab,scanlines +EXTSYM hirestiledat,res512switch,curblank,spritetablea +EXTSYM lineleft,_2xSaILineW,_2xSaISuperEagleLineW +EXTSYM newengen,cfield,HalfTrans +EXTSYM GUIOn2 +EXTSYM SpecialLine +EXTSYM vidbufferofsb +EXTSYM Super2xSaI +EXTSYM HalfTransB,HalfTransC + + + +NEWSYM AddEndBytes, dd 0 ; Number of bytes between each line +NEWSYM NumBytesPerLine, dd 0 ; Total number of bytes per line (1024+AddEndBytes) +NEWSYM WinVidMemStart, dd 0 + +NEWSYM copy640x480x16bwin + cmp byte[curblank],40h + jne .startcopy + ret +.startcopy + push es + mov ax,ds + mov es,ax + mov esi,[vidbuffer] + mov edi,[WinVidMemStart] + add esi,16*2+256*2+32*2 + xor eax,eax + ; Check if interpolation mode + cmp byte[GUIOn2],1 + je .nointerp + cmp byte[FPUCopy],2 + jne .nommx + cmp byte[En2xSaI],0 + jne near Process2xSaIwin +.nommx + cmp byte[antienab],1 + je near interpolate640x480x16bwin +.nointerp + mov dl,[resolutn] + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quartscanlines + + mov ebx,hirestiledat+1 + cmp byte[newengen],0 + je .loopa + mov ebx,SpecialLine+1 +.loopa + mov ecx,256 + cmp byte[ebx],1 + je near .yeshires + cmp byte[GUIOn],1 + je .ignorehr + cmp byte[ebx],1 + ja near .yeshiresng +.ignorehr + cmp byte[FPUCopy],2 + je near .mmx +.a + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + sub esi,256*2 + add edi,[AddEndBytes] + mov ecx,256 +.a2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 +.return + add esi,64 + add edi,[AddEndBytes] + inc ebx + dec dl + jnz near .loopa + pop es + xor byte[res512switch],1 + cmp byte[FPUCopy],2 + je .mmx2 + ret +.mmx2 + emms + ret +.yeshires + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightside + push ebx + mov ebx,[NumBytesPerLine] +.b + mov ax,[esi] + mov [edi],ax + mov [edi+ebx],ax + add esi,2 + add edi,4 + dec ecx + jnz .b + pop ebx + add edi,[NumBytesPerLine] + jmp .return +.rightside + push ebx + mov ebx,[NumBytesPerLine] +.c + mov ax,[esi] + mov [edi+2],ax + mov [edi+2+ebx],ax + add esi,2 + add edi,4 + dec ecx + jnz .c + pop ebx + add edi,[NumBytesPerLine] + jmp .return +.mmx + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.mmxr + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + movq [edi],mm0 + punpckhwd mm1,mm1 + movq [edi+8],mm1 + movq [eax],mm0 + movq [eax+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxr + mov eax,[spritetablea] + mov ecx,32 + add eax,512 + add edi,[AddEndBytes] +.mmxr2 + movq mm0,[eax] + movq [edi],mm0 + movq mm1,[eax+8] + movq [edi+8],mm1 + movq mm2,[eax+16] + movq [edi+16],mm2 + movq mm3,[eax+24] + movq [edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2 + jmp .return +.yeshiresng + call HighResProc + jmp .return + +.bng + mov eax,[esi+75036*4-2] + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .bng + add edi,[AddEndBytes] + sub esi,256*2 + mov ecx,256 +.bngb + mov eax,[esi+75036*4-2] + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .bngb + jmp .return + +.scanlines + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopab + cmp byte[newengen],0 + je .loopab + mov ebx,SpecialLine+1 +.loopab + mov ecx,256 + cmp byte[ebx],1 + je .yeshiresb + cmp byte[ebx],1 + jbe .ignorehrb + call HighResProc + jmp .returnb +.ignorehrb + cmp byte[FPUCopy],2 + je near .mmxsl +.ab + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .ab +.returnb + add esi,64 + add edi,[AddEndBytes] + add edi,[NumBytesPerLine] + inc ebx + dec dl + jnz .loopab + pop es + xor byte[res512switch],1 + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.yeshiresb + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightsideb +.bb + mov ax,[esi] + mov [edi],ax + add esi,2 + add edi,4 + dec ecx + jnz .bb + jmp .returnb +.rightsideb +.cb + mov ax,[esi] + mov [edi+2],ax + add esi,2 + add edi,4 + dec ecx + jnz .cb + jmp .returnb +.mmxsl + mov ecx,64 +.mmxrsl + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + punpckhwd mm1,mm1 + movq [edi],mm0 + movq [edi+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrsl + jmp .returnb + +.halfscanlines + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabh + cmp byte[newengen],0 + je .loopabh + mov ebx,SpecialLine+1 +.loopabh + cmp byte[ebx],1 + jbe .ignorehrbh + call HighResProc + jmp .returnbh +.ignorehrbh + cmp byte[FPUCopy],2 + je near .mmxslh + mov ecx,256 +.abh + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abh + mov ecx,256 + sub esi,512 + add edi,[AddEndBytes] +.abhs + mov ax,[esi] + shl eax,16 + mov ax,[esi] + and eax,[HalfTrans] + shr eax,1 + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs +.returnbh + add esi,64 + add edi,[AddEndBytes] + inc ebx + dec dl + jnz near .loopabh + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxslh + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.mmxrslh + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + punpckhwd mm1,mm1 + movq [edi],mm0 + movq [edi+8],mm1 + movq [eax],mm0 + movq [eax+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrslh + mov eax,[spritetablea] + mov ecx,32 + add eax,512 + add edi,[AddEndBytes] + movq mm4,[HalfTrans] +.mmxr2h + movq mm0,[eax] + movq mm1,[eax+8] + movq mm2,[eax+16] + movq mm3,[eax+24] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + movq [edi],mm0 + movq [edi+8],mm1 + movq [edi+16],mm2 + movq [edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2h + jmp .returnbh + +.quartscanlines + mov [lineleft],dl + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabh2 + cmp byte[newengen],0 + je .loopabh2 + mov ebx,SpecialLine+1 +.loopabh2 + cmp byte[ebx],1 + jbe .ignorehrbh2 + call HighResProc + jmp .returnbh2 +.ignorehrbh2 + cmp byte[FPUCopy],2 + je near .mmxslh2 + mov ecx,256 +.abh2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abh2 + mov ecx,256 + sub esi,512 + add edi,[AddEndBytes] +.abhs2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + and eax,[HalfTrans] + shr eax,1 + mov edx,eax + and edx,[HalfTrans] + shr edx,1 + add eax,edx + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs2 +.returnbh2 + add esi,64 + add edi,[AddEndBytes] + inc ebx + dec byte[lineleft] + jnz near .loopabh2 + pop es + cmp byte[FPUCopy],2 + je near .mmx2 + ret +.mmxslh2 + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.mmxrslh2 + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + punpckhwd mm1,mm1 + movq [edi],mm0 + movq [edi+8],mm1 + movq [eax],mm0 + movq [eax+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrslh2 + mov eax,[spritetablea] + mov ecx,64 + add eax,512 + add edi,[AddEndBytes] + movq mm4,[HalfTrans] +.mmxr2h2 + movq mm0,[eax] + movq mm1,[eax+8] + pand mm0,mm4 + pand mm1,mm4 + psrlw mm0,1 + psrlw mm1,1 + movq mm2,mm0 + movq mm3,mm1 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm2 + paddd mm1,mm3 + movq [edi],mm0 + movq [edi+8],mm1 + add eax,16 + add edi,16 + dec ecx + jnz .mmxr2h2 + jmp .returnbh2 + +HighResProc: + mov ecx,256 + cmp byte[ebx],3 + je near .hiresmode7 + cmp byte[ebx],7 + je near .hiresmode7 + test byte[ebx],4 + jz .nofield + cmp byte[scanlines],0 + jne .nofield + test byte[cfield],1 + jz .nofield + add edi,[NumBytesPerLine] +.nofield + test byte[ebx],3 + jnz near .hires +.a + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a + cmp byte[scanlines],0 + jne .nofield + test byte[cfield],1 + jnz .nofielde + add edi,[NumBytesPerLine] +.nofielde + ret +.hiresmode7 + cmp byte[FPUCopy],2 + je .yeshiresngmmxmode7 +.a2 + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2 + add edi,[AddEndBytes] + sub esi,512 + mov ecx,256 + add esi,75036*4 +.a2b + mov ax,[esi] + shl eax,16 + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .a2b + sub esi,75036*4 + ret +.yeshiresngmmxmode7 + mov ecx,64 +.mmxr + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + movq [edi],mm0 + punpckhwd mm1,mm1 + movq [edi+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxr + add edi,[AddEndBytes] + sub esi,512 + add esi,75036*4 + mov ecx,64 +.mmxrb + movq mm0,[esi] + movq mm1,mm0 + punpcklwd mm0,mm1 + movq [edi],mm0 + punpckhwd mm1,mm1 + movq [edi+8],mm1 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .mmxrb + sub esi,75036*4 + ret +.hires + cmp byte[FPUCopy],2 + je near .yeshiresngmmx +.bng + mov eax,[esi+75036*4-2] + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .bng + test byte[ebx],4 + jz .nofieldb + cmp byte[scanlines],0 + jne .nofieldb + test byte[cfield],1 + jnz .lowerfield + add edi,[NumBytesPerLine] +.lowerfield + ret +.nofieldb + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlines + cmp byte[scanlines],2 + je near .quartscanlines + add edi,[AddEndBytes] + sub esi,256*2 + mov ecx,256 +.bngb + mov eax,[esi+75036*4-2] + mov ax,[esi] + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .bngb + ret +.scanlines + ret +.yeshiresngmmx + mov eax,[spritetablea] + mov ecx,64 + add eax,512 +.ngal + movq mm0,[esi] + movq mm1,[esi+75036*4] + movq mm2,mm0 + punpcklwd mm0,mm1 + movq [edi],mm0 + punpckhwd mm2,mm1 + movq [edi+8],mm2 + movq [eax],mm0 + movq [eax+8],mm2 + add esi,8 + add edi,16 + add eax,16 + dec ecx + jnz .ngal + test byte[ebx],4 + jz .nofieldc + cmp byte[scanlines],0 + jne .nofieldc + test byte[cfield],1 + jnz .lowerfieldb + add edi,[NumBytesPerLine] +.lowerfieldb + ret +.nofieldc + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],3 + je near .halfscanlinesmmx + cmp byte[scanlines],2 + je near .quartscanlinesmmx + test byte[ebx+1],3 + jz .noaa + cmp byte[En2xSaI],0 + jne near .antialias + cmp byte[antienab],0 + jne near .antialias +.noaa + add edi,[AddEndBytes] + mov eax,[spritetablea] + mov ecx,32 + add eax,512 +.mmxr2 + movq mm0,[eax] + movq [edi],mm0 + movq mm1,[eax+8] + movq [edi+8],mm1 + movq mm2,[eax+16] + movq [edi+16],mm2 + movq mm3,[eax+24] + movq [edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2 + ret +.antialias + add edi,[AddEndBytes] + mov eax,[spritetablea] + mov ecx,64 + add eax,512 + movq mm4,[HalfTrans] + sub esi,256*2 +.mmxr2aa + movq mm0,[esi+288*2] + movq mm1,[esi+288*2+75036*4] + movq mm2,mm0 + punpcklwd mm0,mm1 + punpckhwd mm2,mm1 + movq mm1,[eax] + movq mm3,[eax+8] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm1 + paddd mm2,mm3 + movq [edi],mm0 + movq [edi+8],mm2 + add eax,16 + add edi,16 + add esi,8 + dec ecx + jnz .mmxr2aa + ret +.halfscanlines + add edi,[AddEndBytes] + sub esi,256*2 + mov ecx,256 +.abhs + mov eax,[esi+75036*4-2] + mov ax,[esi] + and eax,[HalfTrans] + shr eax,1 + mov edx,eax + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs + ret +.quartscanlines + add edi,[AddEndBytes] + sub esi,256*2 + mov ecx,256 +.abhs2 + mov eax,[esi+75036*4-2] + mov ax,[esi] + and eax,[HalfTrans] + shr eax,1 + mov edx,eax + and edx,[HalfTrans] + shr edx,1 + add eax,edx + mov [edi],eax + add esi,2 + add edi,4 + dec ecx + jnz .abhs2 + ret +.halfscanlinesmmx + mov eax,[spritetablea] + mov ecx,32 + add eax,512 + add edi,[AddEndBytes] + movq mm4,[HalfTrans] +.mmxr2h + movq mm0,[eax] + movq mm1,[eax+8] + movq mm2,[eax+16] + movq mm3,[eax+24] + pand mm0,mm4 + pand mm1,mm4 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + movq [edi],mm0 + movq [edi+8],mm1 + movq [edi+16],mm2 + movq [edi+24],mm3 + add eax,32 + add edi,32 + dec ecx + jnz .mmxr2h + ret +.quartscanlinesmmx + mov eax,[spritetablea] + mov ecx,64 + add eax,512 + add edi,[AddEndBytes] + movq mm4,[HalfTransC] +.mmxr2h2 + movq mm0,[eax] + movq mm1,[eax+8] + pand mm0,mm4 + pand mm1,mm4 + psrlw mm0,1 + psrlw mm1,1 + movq mm2,mm0 + movq mm3,mm1 + pand mm2,mm4 + pand mm3,mm4 + psrlw mm2,1 + psrlw mm3,1 + paddd mm0,mm2 + paddd mm1,mm3 + movq [edi],mm0 + movq [edi+8],mm1 + add eax,16 + add edi,16 + dec ecx + jnz .mmxr2h2 + ret + +Process2xSaIwin: + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabi + cmp byte[newengen],0 + je .loopabi + mov ebx,SpecialLine+1 +.loopabi + mov [InterPtr],ebx + +; add edi,[VESAAddr] + mov dl,[resolutn] + sub dl,2 ; Compensate for top/bottom line + 2 lines in 2xSaI + mov byte[lineleft],dl + mov dword[esi+512],0 + mov dword[esi+512+576*2],0 + mov ebx,[vidbufferofsb] + add ebx,288*2 + +.next + mov dword[esi+512+576*3],0 + + mov eax,[InterPtr] + cmp byte[eax],1 + jbe .ignorehr + push ebx + mov ebx,[InterPtr] + call HighResProc + pop ebx + push ebx + mov ecx,144 +.nextb + mov dword[ebx],0FFFFFFFFh + add ebx,4 + loop .nextb + pop ebx + jmp .returninterp +.ignorehr + +;srcPtr equ 8 +;deltaPtr equ 12 +;srcPitch equ 16 +;width equ 20 +;dstOffset equ 24 +;dstPitch equ 28 +;dstSegment equ 32 + + + push ebx + mov eax,[NumBytesPerLine] + push eax + mov eax,edi ; destination offset + push eax + mov eax,256 ; width + push eax + mov eax,576 ; source pitch + push eax + push ebx + mov eax,esi ; source pointer + push eax + cmp byte[En2xSaI],2 + je .supereagle + cmp byte[En2xSaI],3 + je .super2xSaI + call _2xSaILineW + jmp .normal +.supereagle + call _2xSaISuperEagleLineW + jmp .normal +.super2xSaI + call Super2xSaI +.normal + add esp,24 + pop ebx + add esi,576 + add edi,[NumBytesPerLine] + add edi,[NumBytesPerLine] + add ebx,576 + inc dword[InterPtr] + dec dword[lineleft] + jnz near .next + mov ecx,256 + sub edi,[NumBytesPerLine] +.loop + mov dword[es:edi],0 + add edi,4 + loop .loop + pop es + emms + ret +.returninterp + add esi,64 + inc dword[InterPtr] + add edi,[AddEndBytes] + add ebx,576 + dec byte[lineleft] + jnz near .next + emms + pop es + ret + +MMXInterpolwin: + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopab + cmp byte[newengen],0 + je .loopab + mov ebx,SpecialLine+1 +.loopab + + mov dl,[resolutn] + dec dl + dec dl + dec dl + movq mm2,[HalfTransC] + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],2 + je near .scanlinesquart + cmp byte[scanlines],3 + je near .scanlineshalf + inc ebx + mov [lineleft],dl + ; do scanlines + mov edx,[spritetablea] + mov ecx,64 + mov eax,[esi+510] + add edx,512 + mov [esi+512],eax +.a2 + movq mm0,[esi] + movq mm3,mm0 + movq mm4,mm0 + movq mm1,[esi+2] + pand mm3,mm1 + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + pand mm3,[HalfTransB] + paddw mm0,mm3 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edi],mm4 + movq [edi+8],mm5 + movq [edx],mm4 + movq [edx+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .a2 + add esi,64 + add edi,[AddEndBytes] +.a5 + cmp byte[ebx],1 + jbe .ignorehr + call HighResProc + movq mm2,[HalfTransC] + jmp .returninterp +.ignorehr + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 + ; Process next line +.a3 + movq mm0,[esi] + movq mm3,mm0 + movq mm4,mm0 + movq mm1,[esi+2] + pand mm3,mm1 + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + pand mm3,[HalfTransB] + paddw mm0,mm3 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + movq mm6,[edx] + movq mm7,[edx+8] + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edx],mm4 + movq [edx+8],mm5 + pand mm0,mm4 + movq mm0,mm6 + pand mm4,mm2 + pand mm6,mm2 + psrlw mm4,1 + psrlw mm6,1 + pand mm0,[HalfTransB] + paddd mm4,mm6 + paddw mm4,mm0 + movq mm0,mm5 + pand mm0,mm7 + pand mm5,mm2 + pand mm7,mm2 + psrlw mm5,1 + pand mm0,[HalfTransB] + psrlw mm7,1 + paddd mm5,mm7 + paddw mm5,mm0 + movq [edi],mm4 + movq [edi+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz near .a3 + add edi,[AddEndBytes] + mov edx,[spritetablea] + add edx,512 + mov ecx,64 +.a4 + movq mm0,[edx] + movq mm1,[edx+8] + movq [edi],mm0 + movq [edi+8],mm1 + add edi,16 + add edx,16 + dec ecx + jnz .a4 +.returninterp + add esi,64 + add edi,[AddEndBytes] + inc ebx + dec byte[lineleft] + jnz near .a5 + emms + pop es + ret + +.scanlines + inc dl + mov [lineleft],dl + ; do scanlines + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax +.asl + cmp byte[ebx],1 + jbe .ignorehrs + call HighResProc + movq mm2,[HalfTrans] + jmp .returninterps +.ignorehrs +.a + movq mm0,[esi] + movq mm4,mm0 + movq mm1,[esi+2] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edi],mm4 + movq [edi+8],mm5 + add esi,8 + add edi,16 + dec ecx + jnz .a + mov eax,[esi+510] + mov [esi+512],eax +.returninterps + add esi,64 + add edi,[AddEndBytes] + add edi,[NumBytesPerLine] + inc ebx + mov ecx,64 + dec byte[lineleft] + jnz near .asl + emms + pop es + ret + +.scanlineshalf + inc dl + mov [lineleft],dl + ; do scanlines +.ahb + cmp byte[ebx],1 + jbe .ignorehrhs + call HighResProc + movq mm2,[HalfTrans] + jmp .returninterphs +.ignorehrhs + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 +.ah + movq mm0,[esi] + movq mm4,mm0 + movq mm1,[esi+2] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edx],mm4 + movq [edx+8],mm5 + movq [edi],mm4 + movq [edi+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .ah + add edi,[AddEndBytes] + sub edx,16*64 + mov ecx,64 +.ahc + movq mm0,[edx] + movq mm1,[edx+8] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + movq [edi],mm0 + movq [edi+8],mm1 + add edi,16 + add edx,16 + dec ecx + jnz .ahc +.returninterphs + add edi,[AddEndBytes] + add esi,64 + inc ebx + dec byte[lineleft] + jnz near .ahb + emms + pop es + ret + +.scanlinesquart + inc dl + mov [lineleft],dl + ; do scanlines +.ahb2 + cmp byte[ebx],1 + jbe .ignorehrqs + call HighResProc + movq mm2,[HalfTransC] + jmp .returninterpqs +.ignorehrqs + mov eax,[esi+510] + mov ecx,64 + mov [esi+512],eax + mov edx,[spritetablea] + add edx,512 +.ah2 + movq mm0,[esi] + movq mm3,mm0 + movq mm4,mm0 + movq mm1,[esi+2] + pand mm3,mm1 + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + paddd mm0,mm1 + pand mm3,[HalfTransB] + paddw mm0,mm3 + movq mm5,mm4 + ; mm4/mm5 contains original values, mm0 contains mixed values + punpcklwd mm4,mm0 + punpckhwd mm5,mm0 + movq [edx],mm4 + movq [edx+8],mm5 + movq [edi],mm4 + movq [edi+8],mm5 + add esi,8 + add edi,16 + add edx,16 + dec ecx + jnz .ah2 + add edi,[AddEndBytes] + sub edx,16*64 + mov ecx,64 +.ahc2 + movq mm0,[edx] + movq mm1,[edx+8] + pand mm0,mm2 + pand mm1,mm2 + psrlw mm0,1 + psrlw mm1,1 + movq mm4,mm0 + movq mm5,mm1 + pand mm4,mm2 + pand mm5,mm2 + psrlw mm4,1 + psrlw mm5,1 + paddd mm0,mm4 + paddd mm1,mm5 + movq [edi],mm0 + movq [edi+8],mm1 + add edi,16 + add edx,16 + dec ecx + jnz .ahc2 +.returninterpqs + add esi,64 + add edi,[AddEndBytes] + inc ebx + dec byte[lineleft] + jnz near .ahb2 + emms + pop es + ret + +NEWSYM interpolate640x480x16bwin + cmp byte[FPUCopy],2 + je near MMXInterpolwin + + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabi + cmp byte[newengen],0 + je .loopabi + mov ebx,SpecialLine+1 +.loopabi + mov [InterPtr],ebx + + mov dl,[resolutn] + dec dl + dec dl + dec dl + cmp byte[scanlines],1 + je near .scanlines + cmp byte[scanlines],2 + je near .scanlinesquart + cmp byte[scanlines],3 + je near .scanlineshalf + inc dword[InterPtr] + mov [lineleft],dl + ; do first line + mov ecx,255 + mov edx,[spritetablea] +.a + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [edi],ebx + mov [edx],ebx + add esi,2 + add edi,4 + add edx,4 + loop .a + add esi,66 + add edi,[AddEndBytes] + add edi,4 +.loopb + mov ebx,[InterPtr] + cmp byte[ebx],1 + jbe .ignorehr + call HighResProc + jmp .returninterp +.ignorehr + mov ecx,255 + mov edx,[spritetablea] +.c + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov eax,[edx] + mov bx,[esi] + and eax,[HalfTrans] + mov [edx],ebx + and ebx,[HalfTrans] + shr eax,1 + shr ebx,1 + add eax,ebx + mov [edi],eax + add esi,2 + add edi,4 + add edx,4 + loop .c + add edi,4 + add edi,[AddEndBytes] + mov edx,[spritetablea] + mov ecx,255 +.d + mov eax,[edx] + mov [edi],eax + add edx,4 + add edi,4 + loop .d + add esi,66 + inc dword[InterPtr] + add edi,[AddEndBytes] + add edi,4 + dec byte[lineleft] + jnz near .loopb + pop es + ret +.returninterp + add esi,64 + inc dword[InterPtr] + add edi,[AddEndBytes] + dec byte[lineleft] + jnz near .loopb + pop es + ret + +.scanlines + xor eax,eax + mov ebx,hirestiledat+1 + cmp byte[GUIOn],1 + je .loopabis + cmp byte[newengen],0 + je .loopabis + mov ebx,SpecialLine+1 +.loopabis +.loopab + mov ecx,255 + cmp byte[ebx],1 + jbe .ignorehrs + call HighResProc + jmp .returninterps +.ignorehrs + cmp byte[ebx],1 + je .yeshiresb +.ignorehrb + push ebx +.ab + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [edi],ebx + add esi,2 + add edi,4 + dec ecx + jnz .ab + pop ebx +.returnb + add esi,66 + add edi,4 + add edi,[AddEndBytes] + add edi,[NumBytesPerLine] + inc ebx + dec dl + jnz .loopab + pop es + xor byte[res512switch],1 + ret +.yeshiresb + mov byte[ebx],0 + test byte[res512switch],1 + jnz .rightsideb +.bb + mov ax,[esi] + mov [edi],ax + add esi,2 + add edi,4 + dec ecx + jnz .bb + jmp .returnb +.rightsideb +.cb + mov ax,[esi] + mov [edi+2],ax + add esi,2 + add edi,4 + dec ecx + jnz .cb + jmp .returnb +.returninterps + add esi,64 + inc dword[InterPtr] + add edi,[AddEndBytes] + add edi,[NumBytesPerLine] + dec byte[lineleft] + jnz near .loopab + pop es + ret + +.scanlineshalf + xor eax,eax + mov [lineleft],dl +.loopab2 + mov ebx,[InterPtr] + cmp byte[ebx],1 + jbe .ignorehrhs + call HighResProc + jmp .returninterphs +.ignorehrhs + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab2 + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [edx],ebx + mov [edi],ebx + add esi,2 + add edi,4 + add edx,4 + dec ecx + jnz .ab2 + add edi,4 + add edi,[AddEndBytes] + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab2b + mov eax,[edx] + and eax,[HalfTrans] + shr eax,1 + mov [edi],eax + add edi,4 + add edx,4 + dec ecx + jnz .ab2b + inc dword[InterPtr] + add esi,66 + add edi,4 + add edi,[AddEndBytes] + dec byte[lineleft] + jnz near .loopab2 + pop es + ret +.returninterphs + add esi,64 + inc dword[InterPtr] + add edi,[AddEndBytes] + dec byte[lineleft] + jnz near .loopab2 + pop es + ret + +.scanlinesquart + xor eax,eax + mov [lineleft],dl +.loopab3 + mov ebx,[InterPtr] + cmp byte[ebx],1 + jbe .ignorehrqs + call HighResProc + jmp .returninterpqs +.ignorehrqs + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab3 + mov ax,[esi] + mov bx,[esi+2] + and ebx,[HalfTrans+6] + and eax,[HalfTrans+6] + add ebx,eax + shl ebx,15 + mov bx,[esi] + mov [edx],ebx + mov [edi],ebx + add esi,2 + add edi,4 + add edx,4 + dec ecx + jnz .ab3 + add edi,AddEndBytes + add edi,4 + mov ecx,255 + mov edx,[spritetablea] + add edx,512 +.ab3b + mov eax,[edx] + and eax,[HalfTrans] + shr eax,1 + mov ebx,eax + and ebx,[HalfTrans] + shr ebx,1 + add eax,ebx + mov [edi],eax + add edi,4 + add edx,4 + dec ecx + jnz .ab3b + inc dword[InterPtr] + add esi,66 + add edi,4 + add edi,[AddEndBytes] + dec byte[lineleft] + jnz near .loopab3 + pop es + ret +.returninterpqs + add esi,64 + inc dword[InterPtr] + add edi,[AddEndBytes] + dec byte[lineleft] + jnz near .loopab3 + pop es + ret + +ALIGN32 +InterPtr dd 0 + + \ No newline at end of file diff --git a/zsnes/src/win/resource.h b/zsnes/src/win/resource.h new file mode 100644 index 00000000..784b7b3e --- /dev/null +++ b/zsnes/src/win/resource.h @@ -0,0 +1,34 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by zloader.rc +// +#define IDI_ICON1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif \ No newline at end of file diff --git a/zsnes/src/win/winintrf.asm b/zsnes/src/win/winintrf.asm new file mode 100644 index 00000000..47f2373a --- /dev/null +++ b/zsnes/src/win/winintrf.asm @@ -0,0 +1,2078 @@ +;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later +;version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +%include "macros.mac" + +EXTSYM dssel, selcA000, selcB800, selc0040, previdmode, DosExit, ZFileSystemInit +EXTSYM getcmdline,GUIRestoreVars,getcfg,obtaindir,ConvertJoyMap,tparms +EXTSYM preparedir,getblaster,Force8b,SBHDMA +EXTSYM ccmdline +EXTSYM FilenameStart +EXTSYM spcon +EXTSYM cfgsoundon +EXTSYM pl1selk +EXTSYM pl1startk +EXTSYM pl1upk +EXTSYM pl1downk +EXTSYM pl1leftk +EXTSYM pl1rightk +EXTSYM pl1Xk +EXTSYM pl1Ak +EXTSYM pl1Lk +EXTSYM pl1Yk +EXTSYM pl1Bk +EXTSYM pl1Rk +EXTSYM cfgcvidmode +EXTSYM pl1contrl,pl2contrl +EXTSYM InitDir,InitDrive +EXTSYM DOScreatenewcfg,ExecGUISaveVars +EXTSYM allocptr +extsym putchar +EXTSYM getch +EXTSYM exit +EXTSYM FPUCopy +EXTSYM ZOpenFile,ZOpenMode,CurrentHandle,ZFileSeek,ZOpenFileName,ZFileSeekMode +EXTSYM ZFileSeekPos,ZFileSeekHandle +EXTSYM ZFileWriteHandle,ZFileWriteSize,ZFileWriteBlock,ZFileWrite +EXTSYM ZFileReadHandle,ZFileReadSize,ZFileReadBlock,ZFileRead +EXTSYM ZFileDelFName,ZFileDelete +EXTSYM ZCloseFileHandle,ZCloseFile +EXTSYM ZFileTellHandle,ZFileTell +EXTSYM ZFFTimeFName,ZFTime,ZFDate,ZFileGetFTime +extsym kbhit +extsym keyboardhit +extsym GUIkeydelay2 +;extsym _kbhit +;EXTSYM _getch +extsym _chdrive +EXTSYM ZFileMKDir,ZFileCHDir,ZFileRMDir,CHPath,MKPath,RMPath +EXTSYM ZFileGetDir,DriveNumber,DirName +EXTSYM _getdrive +EXTSYM DTALoc,DTALocPos,ZFileFindATTRIB,ZFileFindFirst,ZFileFindNext,ZFileFindPATH +EXTSYM oldhand9s,oldhand9o,interror,oldhand8s,oldhand8o,oldhandSBs,oldhandSBo +EXTSYM NoSoundReinit,soundon,DSPDisable,SBInt,NoSoundReinit,PICMaskP,SBIrq +EXTSYM SBHandler,InitSB,handler8h,handler9h,init60hz,Interror,init18_2hz,DeInitSPC +EXTSYM Start60HZ +EXTSYM pressed +EXTSYM RaisePitch,AdjustFrequency +EXTSYM vidbufferofsb,vidbuffer +EXTSYM clearwin +EXTSYM Stop60HZ +EXTSYM dosmakepal +EXTSYM doschangepal +EXTSYM dosinitvideo,dosinitvideo2 +EXTSYM initwinvideo +EXTSYM vesa2_rpos +EXTSYM vesa2_gpos +EXTSYM vesa2_bpos +EXTSYM vesa2_rposng +EXTSYM vesa2_gposng +EXTSYM vesa2_bposng +EXTSYM vesa2_usbit +EXTSYM vesa2_clbit +EXTSYM vesa2_clbitng +EXTSYM vesa2_clbitng2 +EXTSYM vesa2_clbitng3 +EXTSYM genfulladdtabng +EXTSYM vesa2red10 +EXTSYM res640 +EXTSYM res480 +EXTSYM AddSub256,InitVesa2,cbitmode,cvidmode +EXTSYM scanlines,vesa2_bits +EXTSYM vesa2_x,vesa2_y +EXTSYM vesa2selec,InitVesa12,videotroub +EXTSYM genfulladdtab +EXTSYM DosDrawScreen,dosvidpastecopyscr,GUICPC +EXTSYM drawscreenwin +EXTSYM ConvertToAFormat +EXTSYM UnusedBit,HalfTrans,UnusedBitXor,UnusedBit,UnusedBitXor +EXTSYM ngrposng,nggposng,ngbposng,HalfTransB,HalfTransC +EXTSYM DOSClearScreen +EXTSYM DosUpdateDevices +EXTSYM WinUpdateDevices +EXTSYM DOSJoyRead +EXTSYM UpdateVFrame +EXTSYM GetMouseX +EXTSYM GetMouseY +EXTSYM GetMouseMoveX +EXTSYM GetMouseMoveY +EXTSYM GetMouseButton +EXTSYM SetMouseMinX,SetMouseMaxX +EXTSYM SetMouseMinY,SetMouseMaxY +EXTSYM SetMouseX,SetMouseY +EXTSYM T36HZEnabled +EXTSYM MouseButton +EXTSYM GUIinit36_4hz,GUIoldhand9s,GUIoldhand9o,GUIoldhand8s,GUIoldhand8o +EXTSYM GUIhandler9h,GUIhandler8h,GUIinit18_2hz +EXTSYM Start36HZ +EXTSYM Stop36HZ +EXTSYM BufferSizeW,BufferSizeB,ProcessSoundBuffer +EXTSYM CheckTimers +EXTSYM vesa2_rfull,vesa2_rtrcl,vesa2_rtrcla +EXTSYM vesa2_gfull,vesa2_gtrcl,vesa2_gtrcla +EXTSYM vesa2_bfull,vesa2_btrcl,vesa2_btrcla +EXTSYM Init_2xSaIMMXW +EXTSYM TCPIPPortNum +EXTSYM InitTCP +EXTSYM StartServerCycle +EXTSYM ServerCheckNewClient +EXTSYM acceptzuser +EXTSYM GUINetTextk2 +EXTSYM ConnectServer +EXTSYM WaitForServer +EXTSYM SendData +EXTSYM SendDataUDP +EXTSYM GetData +EXTSYM DeInitTCP +EXTSYM StopServer +EXTSYM Disconnect +EXTSYM UDPDisableMode,UDPEnableMode,UDPClearVars,UDPWait1Sec +EXTSYM WinErrorA2,WinErrorB2,WinErrorC2 +EXTSYM ZsnesPage +EXTSYM _imp__GetLocalTime@4 + + +; NOTE: For timing, Game60hzcall should be called at 50hz or 60hz (depending +; on romispal) after a call to InitPreGame and before DeInitPostGame are +; made. GUI36hzcall should be called at 36hz after a call GUIInit and +; before GUIDeInit. + + +SECTION .data +NEWSYM OSPort, db 3 ; 0 = DOS (C), 1 = DOS (ASM), 2 = Linux, 3 = Win95 +SECTION .text + +NEWSYM StartUp + call ZFileSystemInit + ret + +; SystemInit - Initialize all Joystick stuff, load in all configuration data, +; parse commandline data, obtain current directory (One time initialization) + +NEWSYM SystemInit + ; Be sure to set SBHDMA to a value other than 0 if 16bit sound exists + push es + mov byte[cfgcvidmode],2 + mov byte[cvidmode],2 + call getcmdline + + mov byte[esi],'Z' + mov byte[esi+1],'S' + mov byte[esi+2],'N' + mov byte[esi+3],'E' + mov byte[esi+4],'S' + mov byte[esi+5],'W' + mov byte[esi+6],'.' + mov byte[esi+7],'C' + mov byte[esi+8],'F' + mov byte[esi+9],'G' + mov byte[esi+10],0 + mov byte[esi+256],'Z' + mov byte[esi+1+256],'G' + mov byte[esi+2+256],'U' + mov byte[esi+3+256],'I' + mov byte[esi+4+256],'C' + mov byte[esi+5+256],'F' + mov byte[esi+6+256],'G' + mov byte[esi+7+256],'W' + mov byte[esi+8+256],'.' + mov byte[esi+9+256],'D' + mov byte[esi+10+256],'A' + mov byte[esi+11+256],'T' + mov byte[esi+12+256],0 + + mov byte[pl1selk],54 + mov byte[pl1startk],28 ; 1START = ENTER + mov byte[pl1upk],200 ; 1UP = up + mov byte[pl1downk],208 ; 1DOWN = down + mov byte[pl1leftk],203 ; 1LEFT = left + mov byte[pl1rightk],205 ; 1RIGHT = right + mov byte[pl1Xk],31 ; 1X = INS + mov byte[pl1Ak],45 ; 1A = HOME + mov byte[pl1Lk],32 ; 1L = PAGE UP + mov byte[pl1Yk],30 ; 1Y = DELETE + mov byte[pl1Bk],44 ; 1B = END + mov byte[pl1Rk],46 ; 1R = PAGE DOWN + mov byte[pl1contrl],1 + mov byte[pl2contrl],1 + + mov byte[spcon],1 + mov byte[soundon],1 + mov byte[cfgsoundon],1 + + ; Get and set the initial directory + mov ebx,InitDir + mov edx,InitDrive + call Get_Dir + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + + call GUIRestoreVars ; Load GUI stuff + call getcfg ; Load cfg stuff + call obtaindir ; Get Save/Init Directories + call ConvertJoyMap ; Mini joystick init + call ccmdline + call tparms + call preparedir + mov byte[soundon],0 +; call getblaster ; get set blaster environment +; cmp byte[Force8b],1 +; jne .noforce8b + mov byte[SBHDMA],1 +;.noforce8b + pop es + ret + +; Configuration save re-routing functions. You can comment these out +; for debugging purposes or change it if you're using a different +; configuration format +NEWSYM createnewcfg + call DOScreatenewcfg + ret +NEWSYM GUISaveVars + call ExecGUISaveVars + ret + +; Allocate memory - see allocptr in ui.asm for details on what to allocate +NEWSYM allocmem + call allocptr + ret + + +NEWSYM PrintChar + ret + ; print character at dl, push all modified registers + pushad + push eax + push edx + call putchar + pop edx +; mov ah,02h +; int 21h + pop eax + popad + ret + +NEWSYM PrintStr ; Print ASCIIZ string + + pushad + +.next + mov al,[edx] + or al,al + jz .finish + push edx + mov dl,al + push edx + call putchar + pop edx +; mov ah,02h +; int 21h + pop edx + inc edx + jmp .next +.finish + popad + ret + + +NEWSYM wfkey, db 0 + +NEWSYM WaitForKey ; Wait for a key to be pressed + pushad + call getch + mov [wfkey],al + popad + mov al,[wfkey] + ;mov ah,7 + ;int 21h + ; return key in al + ret + + +NEWSYM OsExit +NEWSYM OSExit + call exit + int 3h + jmp DosExit + +NEWSYM MMXCheck + ; Check for cpu that doesn't support CPUID + mov edx,cpuidfname + call Open_File + jc .skipcheck + mov bx,ax + call Close_File + jmp .nommx2 +.skipcheck + + ; Create file + mov edx,cpuidfname + call Create_File + mov bx,ax + call Close_File + + mov edx,cpuidtext + call PrintStr + + ; MMX support + mov byte[FPUCopy],0 + mov eax,1 + CPUID + + push edx + mov edx,cpuidtext2 + call PrintStr + pop edx + + test edx,1 << 23 + jz .nommx + mov byte[FPUCopy],2 + mov edx,YesMMX + call PrintStr +.nommx + ; Delete file + mov edx,cpuidfname + call Delete_File +.nommx2 + ret + +NEWSYM TempHandle, dd 0 + +NEWSYM Open_File + pushad + mov dword[ZOpenMode],0 + mov dword[ZOpenFileName],edx + call ZOpenFile + cmp eax,0FFFFFFFFh + je .error + mov [TempHandle],eax + mov dword[ZFileSeekMode],0 + mov dword[ZFileSeekPos],0 + mov dword[ZFileSeekHandle],eax + call ZFileSeek + popad + mov ax,[TempHandle] + clc + ret +.error + popad + stc + ret + mov ax,3D00h + int 21h + ; return bx = file handle, carry = error + ret + +NEWSYM Open_File_Write + pushad + mov dword[ZOpenMode],2 + mov dword[ZOpenFileName],edx + call ZOpenFile + cmp eax,0FFFFFFFFh + je .error + mov [TempHandle],eax + mov dword[ZFileSeekMode],0 + mov dword[ZFileSeekPos],0 + mov dword[ZFileSeekHandle],eax + call ZFileSeek + popad + mov ax,[TempHandle] + clc + ret +.error + popad + stc + ret + mov ax,3D01h + int 21h + ; return bx = file handle, carry = error + ret + +NEWSYM Create_File + pushad + mov dword[ZOpenMode],1 + mov dword[ZOpenFileName],edx + call ZOpenFile + cmp eax,0FFFFFFFFh + je .error + mov [TempHandle],eax + popad + mov ax,[TempHandle] + clc + ret +.error + popad + stc + ret + mov ah,3Ch + mov cx,0 + int 21h + ; return bx = file handle + ret + +NEWSYM Write_File + mov dword[ZFileWriteHandle],0 + mov [ZFileWriteHandle],bx + mov [ZFileWriteSize],ecx + mov [ZFileWriteBlock],edx + pushad + call ZFileWrite + cmp eax,0FFFFFFFFh + je .fail + popad + mov eax,1 + clc + ret +.fail + popad + mov eax,0 + stc + ret + mov ah,40h + int 21h + ret + +NEWSYM Read_File + mov dword[ZFileReadHandle],0 + mov [ZFileReadHandle],bx + mov [ZFileReadSize],ecx + mov [ZFileReadBlock],edx + pushad + call ZFileRead + mov [TempVarSeek],eax + popad + mov eax,[TempVarSeek] + clc + ret + mov ah,3Fh + int 21h + ret + +NEWSYM Delete_File + mov [ZFileDelFName],edx + pushad + call ZFileDelete + popad + ret + mov ah,41h + int 21h + ret + +NEWSYM Close_File + mov dword[ZCloseFileHandle],0 + mov [ZCloseFileHandle],bx + pushad + call ZCloseFile + popad + clc + ret + mov ah,3Eh + int 21h + ret + +NEWSYM File_Seek + mov word[ZFileSeekPos+2],cx + mov word[ZFileSeekPos],dx + mov dword[ZFileSeekMode],0 + mov dword[ZFileSeekHandle],0 + mov word[ZFileSeekHandle],bx + pushad + call ZFileSeek + popad + mov ax,dx + mov dx,cx + ret + ; seek to cx:dx from 0 position, return carry as error + mov ax,4200h + int 21h + ret + +NEWSYM File_Seek_End + mov word[ZFileSeekPos+2],cx + mov word[ZFileSeekPos],dx + mov dword[ZFileSeekHandle],0 + mov word[ZFileSeekHandle],bx + mov dword[ZFileSeekMode],1 + mov dword[ZFileTellHandle],0 + mov word[ZFileTellHandle],bx + pushad + call ZFileSeek + call ZFileTell + mov [TempVarSeek],eax + popad + mov ax,[TempVarSeek] + mov dx,[TempVarSeek+2] + ret + ; seek to cx:dx from end position, and return file location in dx:ax + mov ax,4202h + int 21h + ret + +NEWSYM Get_Time + pushad +; call GetTime + mov [TempVarSeek],eax + popad + mov eax,[TempVarSeek] + ret +NEWSYM Get_TimeDate + pushad +; call GetDate + mov [TempVarSeek],eax + popad + mov eax,[TempVarSeek] + ret + +NEWSYM Get_Date + ; dl = day, dh = month, cx = year + mov dx,0 + mov cx,0 +; mov ah,2Ah +; int 21h + ret + +NEWSYM Get_File_Date + mov [ZFFTimeFName],edx + pushad + call ZFileGetFTime + popad + mov dx,[ZFDate] + mov cx,[ZFTime] + ret + ; return packed date in dx:cx + mov ah,57h + mov al,00h + int 21h + ret + + +RefreshKeybBuffer: + call JoyRead + mov ebx,[HoldKey] + cmp byte[pressed+ebx],0 + jne .holding + mov dword[HoldKey],0 +.holding + xor eax,eax + xor ebx,ebx +.loop + cmp byte[PKeyBuf+eax],0 + jne .not1 + cmp byte[pressed+eax],0 + je .not1 + mov byte[PKeyBuf+eax],1 + mov ebx,eax +.not1 + cmp byte[pressed+eax],0 + jne .not0 + mov byte[PKeyBuf+eax],0 +.not0 + inc eax + cmp eax,100h + jne .loop + or ebx,ebx + jz .notpressed + mov [HoldKey],ebx + mov byte[GUIkeydelay2],14 + call .processkey +.notpressed + ; Execute the following at 36hz + cmp dword[HoldKey],0 + je .noholder + cmp byte[GUIkeydelay2],0 + jne .noholder + mov byte[GUIkeydelay2],3 + call .processkey +.noholder + ret +.processkey + mov ebx,[HoldKey] + cmp ebx,0A8h + jb .skipdecval + sub ebx,80h +.skipdecval + cmp ebx,58h + jae .none + xor eax,eax + mov al,[Keybtail] + inc al + and al,0Fh + cmp al,[Keybhead] + je .none + mov al,[Keybtail] + mov cl,[KeyConvTable+ebx] + cmp byte[pressed+2Ah],0 + jne .shift + cmp byte[pressed+36h],0 + je .noshift +.shift + mov cl,[KeyConvTableS+ebx] +.noshift + mov [HoldKeyBuf+eax],cl + inc al + and al,0Fh + mov [Keybtail],al +.none + ret +Keybhead db 0 +Keybtail db 0 +HoldKey dd 0 +HoldKeyBuf times 16 db 0 +PKeyBuf times 100h db 0 + +NEWSYM CurKeyPos, dd 0 +NEWSYM CurKeyReadPos, dd 0 +NEWSYM KeyBuffer, times 16 dd 0 + +NEWSYM Check_Key + mov al,[CurKeyPos] + cmp al,[CurKeyReadPos] + jne .yeskey + xor al,al + ret +.yeskey + mov al,0FFh + ret + ; returns 0 if there are no keys in the keyboard buffer, 0xFF otherwise +; mov al,byte [keyboardhit] +; push eax +; xor eax,eax +; mov byte [keyboardhit],al +; pop eax + pushad +; call kbhit + call RefreshKeybBuffer + mov byte[wfkey],0 + mov al,[Keybhead] + cmp al,[Keybtail] + je .nokeys + mov byte[wfkey],0FFh +.nokeys + popad + mov al,[wfkey] +; mov ah,0Bh +; int 21h + ret + +NEWSYM Get_Key + ; wait if there are no keys in buffer, then return key in al + ; for extended keys, return a 0, then the extended key afterwards + xor eax,eax +.nokey + pushad + call JoyRead + popad + mov al,[CurKeyReadPos] + cmp al,[CurKeyPos] + je .nokey + test word[KeyBuffer+eax*4],100h + jnz .upper + mov al,[KeyBuffer+eax*4] + inc dword[CurKeyReadPos] + and dword[CurKeyReadPos],0Fh + ret +.upper + sub word[KeyBuffer+eax*4],100h + xor al,al + ret + + pushad +.nonewkey + call RefreshKeybBuffer + xor eax,eax + mov al,[Keybhead] + cmp al,[Keybtail] + je .nonewkey + mov bl,[HoldKeyBuf+eax] + test bl,80h + jz .notupperkey + xor bl,bl + sub byte[HoldKeyBuf+eax],80h + jmp .yesupperkey +.notupperkey + inc al + and al,0Fh + mov [Keybhead],al +.yesupperkey +; call getch + mov [wfkey],bl + popad + mov al,[wfkey] + ;mov ah,7 + ;int 21h + ; return key in al + ret + +KeyConvTable + db 255,27 ,'1','2','3','4','5','6' ; 00h + db '7','8','9','0','-','=',8 ,9 + db 'Q','W','E','R','T','Y','U','I' ; 10h + db 'O','P','[',']',13 ,255,'A','S' + db 'D','F','G','H','J','K','L',';' ; 20h + db 39 ,'`',255,'\','Z','X','C','V' + db 'B','N','M',',','.','/',255,'*' ; 30h + db 255,32 ,255,255,255,255,255,255 + db 255,255,255,255,255,255,255,255 ; 40h + db 200,201,202,203,204,205,206,207 + db 208,209,210,211,255,255,255,255 ; 50h +KeyConvTableS + db 255,27 ,'!','@','#','$','%','^' ; 00h + db '&','*','(',')','_','+',8 ,9 + db 'Q','W','E','R','T','Y','U','I' ; 10h + db 'O','P','{','}',13 ,255,'A','S' + db 'D','F','G','H','J','K','L',':' ; 20h + db '"','~',255,'|','Z','X','C','V' + db 'B','N','M','<','>','?',255,'*' ; 30h + db 255,32 ,255,255,255,255,255,255 + db 255,255,255,255,255,255,255,255 ; 40h + db 200,201,202,203,204,205,206,207 + db 208,209,210,211,255,255,255,255 ; 50h + +; mov dl,[SRAMDrive] +; mov ebx,SRAMDir +; call Change_Dir + +NEWSYM Change_Drive + ; change to drive in dl (0 = A, 1 = B, etc.) + and edx,0FFh + add edx,1 + push edx + call _chdrive + pop edx +; mov ah,0Eh +; int 21h + ret + +NEWSYM Change_Single_Dir + mov [CHPath],edx + pushad + call ZFileCHDir + or eax,eax + jnz .notokay + popad + clc + ret +.notokay + popad + stc + ret + ; Dir in edx, return error in carry flag + mov ah,3Bh + int 21h + ret + +NEWSYM Create_Dir + ; change to dir in edx + mov [MKPath],edx + pushad + call ZFileMKDir + or eax,eax + jnz .notokay + popad + clc + ret +.notokay + popad + stc + ret + mov ah,39h + int 21h + ret + +NEWSYM Remove_Dir + ; remove dir in edx + mov [RMPath],edx + pushad + call ZFileRMDir + or eax,eax + jnz .notokay + popad + clc + ret +.notokay + popad + stc + ret + mov ah,3Ah + int 21h + ret + +; mov dl,[LoadDrive] +; mov ebx,LoadDir +; call Change_Dir +NEWSYM Change_Dir + pushad + + and edx,0FFh + add edx,1 + push edx + call _chdrive + pop edx + +; mov ah,0Eh +; int 21h +; jc .fail + mov dword[CHPath],gotoroot + call ZFileCHDir + or eax,eax + jnz .fail + popad + mov [CHPath],ebx + cmp byte[ebx],0 + je .nocdir + pushad + call ZFileCHDir + or eax,eax + jnz .fail + popad +.nocdir + clc + ret +.fail + popad + stc + ret + + ; dl = drive, ebx = dir + push ebx + mov ah,0Eh + int 21h + mov ah,3Bh + mov edx,gotoroot + int 21h + pop ebx + mov edx,ebx + cmp byte[edx],0 + je .nodir + mov ah,3Bh + int 21h +.nodir + ret + +; mov ebx,LoadDir +; mov edx,LoadDrive +; call Get_Dir +NEWSYM Get_Dir + mov [DirName],ebx + pushad + call ZFileGetDir + mov eax,[DirName] + mov ebx,eax + mov ecx,125 +.loop + mov dl,[eax+3] + cmp dl,'/' + jne .noslash + mov dl,'\' +.noslash + mov [eax],dl + inc eax + loop .loop + popad + push edx + call _getdrive +; mov ah,19h +; int 21h + sub al,1 + pop edx + mov [edx],al + ret + + push edx + mov ah,47h + mov dl,0 + mov esi,ebx + int 21h + mov ah,19h + int 21h + pop edx + mov [edx],al + ret + +NEWSYM Get_First_Entry + ; cx = attributes, edx = pointer to wildcard + ; returns : DTALoc+15h, bit 4 = Dir (1) or File (0) + ; DTALoc+1Eh = filename, carry flag set = no more entry + mov [ZFileFindPATH],edx + mov dword[ZFileFindATTRIB],0 + mov [ZFileFindATTRIB],cx + mov dword[DTALocPos],DTALoc + pushad + call ZFileFindFirst + or eax,eax + jnz .end + popad + clc + ret +.end + popad + stc + ret + mov ah,4Eh + mov al,0 + int 21h + ret + +NEWSYM Get_Next_Entry + mov dword[DTALocPos],DTALoc + pushad + call ZFileFindNext + or eax,eax + jnz .end + popad + clc + ret +.end + popad + stc + ret + mov ah,04Fh + int 21h + ret + +NEWSYM Set_DTA_Address + ; Only needed for dos stuff +; mov edx,DTALoc +; mov ah,1Ah +; int 21h + ret + +NEWSYM Get_Memfree + mov eax,02000000h +; mov ax,0500h +; mov edi,edx +; int 31h + ret + +NEWSYM Output_Text ; Output character (ah=02h) or string (ah=09h) + pushad + + ; This function usually displays an error message on-screen + cmp ah,02h + je .char + cmp ah,09h + je .string + ret +.char + push edx + call putchar + pop edx +; int 21h ; print dl + popad + ret +.string + pushad + call PrintStr ; print edx + popad + popad + ret + + + +NEWSYM InitPreGame ; Executes before starting/continuing a game + mov byte[pressed+1],2 + pushad + call Start60HZ + popad + pushad + call initwinvideo + popad + + mov byte[RaisePitch],1 + pushad + call AdjustFrequency + popad + + pushad + xor eax,eax + mov edi,[vidbufferofsb] + mov ecx,228*120 + rep stosd + popad + + pushad + call clearwin + popad + ret + + ; set up interrupt handler + ; get old handler pmode mode address + ; Process stuff such as sound init, interrupt initialization + ret + +NEWSYM SetupPreGame ; Executes after pre-game init, can execute multiple + ; times after a single InitPreGame + mov byte[pressed+1],2 + ret + + +NEWSYM DeInitPostGame ; Called after game is ended + pushad + call Stop60HZ + popad + ret + +; **************************** +; Video Stuff +; **************************** + +; ** Palette Functions ** +NEWSYM makepal ; 8-bit palette set + ret +; jmp dosmakepal +NEWSYM changepal ; 8-bit palette set (changes only) + ret +; jmp doschangepal +NEWSYM displayfpspal + ret + + mov al,128 + mov dx,03C8h + out dx,al + inc dx + mov al,63 + out dx,al + out dx,al + out dx,al + mov al,128+64 + mov dx,03C8h + out dx,al + inc dx + mov al,0 + out dx,al + out dx,al + out dx,al + ret + +NEWSYM superscopepal + ret + + mov al,128+16 + mov dx,03C8h + out dx,al + inc dx + mov al,63 + out dx,al + xor al,al + out dx,al + out dx,al + ret + +NEWSYM saveselectpal + ret + + ; set palette of colors 128,144, and 160 to white, blue, and red + mov al,128 + mov dx,03C8h + out dx,al + inc dx + mov al,63 + out dx,al + out dx,al + out dx,al + mov al,144 + mov dx,03C8h + out dx,al + inc dx + xor al,al + out dx,al + out dx,al + mov al,50 + out dx,al + mov al,160 + mov dx,03C8h + out dx,al + inc dx + mov al,45 + out dx,al + xor al,al + out dx,al + out dx,al + mov al,176 + mov dx,03C8h + out dx,al + inc dx + mov al,47 + out dx,al + xor al,al + out dx,al + out dx,al + mov al,208 + mov dx,03C8h + out dx,al + inc dx + mov al,50 + out dx,al + mov al,25 + out dx,al + xor al,al + out dx,al + ret + +; ** init video mode functions ** +NEWSYM firstvideo, dd 1 + + +NEWSYM initvideo ; Returns 1 in videotroub if trouble occurs + mov byte[res640],1 + mov byte[res480],1 + mov byte[cbitmode],1 + mov word[vesa2_x],512 + mov word[vesa2_y],480 + mov byte[vesa2_bits],16 + mov dword [vesa2_bits],16 + mov dword [vesa2_rpos],11 + mov dword [vesa2_gpos],5 + mov dword [vesa2_bpos],0 + mov byte[vesa2red10],0 + mov byte[vesa2_rposng],11 + mov byte[vesa2_gposng],5 + mov byte[vesa2_bposng],0 + mov dword[vesa2_clbitng],1111011111011110b + mov dword[vesa2_clbitng2],11110111110111101111011111011110b + mov dword[vesa2_clbitng2+4],11110111110111101111011111011110b + mov dword[vesa2_clbitng3],0111101111101111b + + pushad + call initwinvideo + popad + + cmp dword[firstvideo],1 + je .skipinitgfx + pushad + call InitializeGfxStuff + popad + +.skipinitgfx + mov dword[firstvideo],0 + + pushad + call InitializeGfxStuff + popad + + ret + + +; pushad +; call genfulladdtabng +; popad +; jmp dosinitvideo +NEWSYM initvideo2 ; ModeQ scanline re-init (Keep blank on non-dos ports) + ret +; jmp dosinitvideo2 +NEWSYM deinitvideo +; mov al,[previdmode] +; mov ah,0 +; int 10h + ret + +; ** copy video mode functions ** +NEWSYM converta, dd 0 +NEWSYM DrawScreen ; In-game screen render w/ triple buffer check + cmp dword [converta],1 + jne near .skipconv + pushad + mov dword[UnusedBit], 10000000000000001000000000000000b + mov dword[HalfTrans], 01111011110111100111101111011110b + mov dword[UnusedBitXor], 01111111111111110111111111111111b + mov dword[UnusedBit+4], 10000000000000001000000000000000b + mov dword[HalfTrans+4], 01111011110111100111101111011110b + mov dword[UnusedBitXor+4],01111111111111110111111111111111b + mov dword[HalfTransB], 00000100001000010000010000100001b + mov dword[HalfTransB+4], 00000100001000010000010000100001b + mov dword[HalfTransC], 01111011110111100111101111011110b + mov dword[HalfTransC+4], 01111011110111100111101111011110b + mov dword[ngrposng],10 + mov dword[nggposng],5 + mov dword[ngbposng],0 + + call ConvertToAFormat + + popad + +.skipconv + pushad + call drawscreenwin + popad + + ret +; jmp DosDrawScreen + +NEWSYM vidpastecopyscr ; GUI screen render + pushad + xor eax,eax + mov al,[cvidmode] + cmp byte[GUI16VID+eax],1 + jne .no16bconv + mov eax,[vidbuffer] + mov ecx,224*288 + mov edx,ecx + sub ecx,288 + dec edx +.loop + xor ebx,ebx + mov bl,[eax+edx] + mov bx,[GUICPC+ebx*2] + mov [eax+edx*2],bx + dec edx + loop .loop +.no16bconv + popad + jmp DrawScreen + + +; ** Clear Screen function ** +NEWSYM ClearScreen + ret + + +; ** Video Mode Variables ** +SECTION .data + +; Total Number of Video Modes +NEWSYM NumVideoModes, dd 18 + +; GUI Video Mode Names - Make sure that all names are of the same length +; and end with a NULL terminator +NEWSYM GUIVideoModeNames +db '64x56 R WIN ',0 ;0 +db '128x112 R WIN ',0 ;1 +db '256X224 R WIN ',0 ;2 +db '256x224 R FULL',0 ;3 +db '512X448 R WIN ',0 ;4 +db '512X448 DR WIN ',0 ;5 +db '640x480 S WIN ',0 ;6 +db '640x480 DR FULL',0 ;7 +db '640X480 DS FULL',0 ;8 +db '640X480 S FULL',0 ;9 +db '800x600 S WIN ',0 ;10 +db '800x600 DS WIN ',0 ;11 +db '800x600 S FULL',0 ;12 +db '800x600 DS FULL',0 ;13 +db '1024X768 S WIN ',0 ;14 +db '1024X768 DS WIN ',0 ;15 +db '1024x768 S FULL',0 ;16 +db '1024x768 DS FULL',0 ;17 + + +; Video Mode Feature Availability (1 = Available, 0 = Not Available) +; Left side starts with Video Mode 0 +NEWSYM GUI16VID, db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ; 16-bit mode +NEWSYM GUINGVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; New Graphics Mode Available +NEWSYM GUISLVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Scanlines +NEWSYM GUIINVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Interpolation +NEWSYM GUII2VID, db 0,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,1 ; Interpolation(w) +NEWSYM GUIEAVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Eagle +NEWSYM GUIIEVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; (Interp | Eagle) +NEWSYM GUIFSVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Full Screen +NEWSYM GUISSVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Small Screen +NEWSYM GUITBVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Triple Buffering +NEWSYM GUIHSVID, db 0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0 ; Half/Quarter Scanlines +NEWSYM GUI2xVID, db 0,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,1 ; 2xSaI/Super Eagle Engines +NEWSYM GUIM7VID, db 0,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,1 ; ?Mode 7 video thing? +NEWSYM GUIWFVID, db 0,0,0,1,0,0,0,1,1,1,0,0,1,1,0,0,1,1 ; If Windows Full Screen +NEWSYM GUIDSIZE, db 0,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,1 +NEWSYM GUIRATIO, db 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + +SECTION .text + +; **************************** +; Input Device Stuff +; **************************** + +; Variables related to Input Device Routines: +; pl1selk,pl1startk,pl1upk,pl1downk,pl1leftk,pl1rightk,pl1Xk, +; pl1Ak,pl1Lk,pl1Yk,pl1Bk,pl1Rk +; (Change 1 to 2,3,4 for other players) +; Each of these variables contains the corresponding key pressed value +; for the key data +; pressed[] +; - This is an array of pressed/released data (bytes) where the +; corresponding key pressed value is used as the index. The value +; for each entry is 0 for released and 1 for pressed. Also, when +; writing keyboard data to this array, be sure to first check if +; the value of the array entry is 2 or not. If it is 2, do not write 1 +; to that array entry. (however, you can write 0 to it) +; As an example, to access Player 1 L button press data, it is +; done like : pressed[pl1Lk] +; The 3 character key description of that array entry is accessed by the +; GUI through ScanCodeListing[pl1Lk*3] + +; Note: When storing the input device configuration of a dynamic input +; device system (ie. Win9x) rather than a static system (ie. Dos), it +; is best to store in the name of the device and relative button +; assignments in the configuration file, then convert it to ZSNES' +; numerical corresponding key format after reading from it. And then +; convert it back when writing to it back. + +NEWSYM UpdateDevices ; One-time input device init + call WinUpdateDevices +; call DosUpdateDevices + ret + +NEWSYM JoyRead +; call SoundProcess ; Put the sound stuff here since it's + ; called 60 times per second +; call DOSJoyRead + pushad + call UpdateVFrame + popad + ret + +SECTION .data + +; Total Number of Input Devices +NEWSYM NumInputDevices, dd 2 + +; Input Device Names +NEWSYM GUIInputNames +db 'NONE ',0 +db 'KEYB/JOYSTICK ',0 +db ' ',0 +db ' ',0 +db ' ',0 +db ' ',0 +db 'SIDEWINDERPAD1 ',0 +db 'SIDEWINDERPAD2 ',0 +db 'SIDEWINDERPAD3 ',0 +db 'SIDEWINDERPAD4 ',0 +db 'GAMEPAD PRO P0 ',0 +db 'GAMEPAD PRO P1 ',0 +db 'PARALLEL LPT1 P1',0 +db 'PARALLEL LPT1 P2',0 +db 'PARALLEL LPT2 P1',0 +db 'PARALLEL LPT2 P2',0 + +; GUI Description codes for each corresponding key pressed value +NEWSYM ScanCodeListing + db '---','ESC',' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 ' ; 00h + db ' 7 ',' 8 ',' 9 ',' 0 ',' - ',' = ','BKS','TAB' + db ' Q ',' W ',' E ',' R ',' T ',' Y ',' U ',' I ' ; 10h + db ' O ',' P ',' [ ',' ] ','RET','LCT',' A ',' S ' + db ' D ',' F ',' G ',' H ',' J ',' K ',' L ',' : ' ; 20h + db ' " ',' ~ ','LSH',' \ ',' Z ',' X ',' C ',' V ' + db ' B ',' N ',' M ',' , ',' . ',' / ','RSH',' * ' ; 30h + db 'LAL','SPC','CAP','F1 ','F2 ','F3 ','F4 ','F5 ' + db 'F6 ','F7 ','F8 ','F9 ','F10','NUM','SCR','N 7' ; 40h + db 'N 8','N 9','N -','N 4','N 5','N 6','N +','N 1' + db 'N 2','N 3','N 0','N .',' ',' ','OEM','F11' ; 50h + db 'F12','59h','5Ah','5BH','5CH','5DH','5EH','5FH' + db '60H','61H','62H','63H','64H','65H','66H','67H' ; 80h + db '68H','69H','6AH','6BH','6CH','6DH','6EH','6FH' + db '70H','71H','72H','73H','74H','75H','76H','77H' ; 90h + db '78H','79H','7AH','7BH','7CH','7DH','7EH','7FH' + ; Keyboard continued (Direct Input) + db '80H','81H','82H','83H','84H','85H','86H','87H' ; 80h + db '88H','89H','8AH','8BH','8CH','8DH','8EH','8FH' + db '90H','91H','92H','93H','94H','95H','96H','97H' ; 90h + db '98H','99H','9AH','9BH','9CH','9DH','9EH','9FH' + db 'A0H','A1H','A2H','A3H','A4H','A5H','A6H','A7H' ; A0h + db 'A8H','A9H','AAH','ABH','ACH','ADH','AEH','AFH' + db 'B0H','B1H','B2H','B3H','B4H','B5H','B6H','B7H' ; B0h + db 'B8H','B9H','BAH','BBH','BCH','BDH','BEH','BFH' + db 'C0H','C1H','C2H','C3H','C4H','C5H','C6H','C7H' ; C0h + db 'C8H','C9H','CAH','CBH','CCH','CDH','CEH','CFH' + db 'D0H','D1H','D2H','D3H','D4H','D5H','D6H','D7H' ; D0h + db 'D8H','D9H','DAH','DBH','DCH','DDH','DEH','DFH' + db 'E0H','E1H','E2H','E3H','E4H','E5H','E6H','E7H' ; E0h + db 'E8H','E9H','EAH','EBH','ECH','EDH','EEH','EFH' + db 'F0H','F1H','F2H','F3H','F4H','F5H','F6H','F7H' ; F0h + db 'F8H','F9H','FAH','FBH','FCH','FDH','FEH','FFH' + ; Joystick Stuff (Direct Input) + db 'J00','J01','J02','J03','J04','J05','J06','J07' + db 'J08','J09','J0A','J0B','J0C','J0D','J0E','J0F' + db 'J10','J11','J12','J13','J14','J15','J16','J17' + db 'J18','J19','J1A','J1B','J1C','J1D','J1E','J1F' + db 'J20','J21','J22','J23','J24','J25','J26','J27' + db 'J28','J29','J2A','J2B','J2C','J2D','J2E','J2F' + db 'J30','J31','J32','J33','J34','J35','J36','J37' + db 'J38','J39','J3A','J3B','J3C','J3D','J3E','J3F' + db 'J40','J41','J42','J43','J44','J45','J46','J47' + db 'J48','J49','J4A','J4B','J4C','J4D','J4E','J4F' + db 'J50','J51','J52','J53','J54','J55','J56','J57' + db 'J58','J59','J5A','J5B','J5C','J5D','J5E','J5F' + db 'J60','J61','J62','J63','J64','J65','J66','J67' + db 'J68','J69','J6A','J6B','J6C','J6D','J6E','J6F' + db 'J70','J71','J72','J73','J74','J75','J76','J77' + db 'J78','J79','J7A','J7B','J7C','J7D','J7E','J7F' + ; Extra Stuff (180h) (Parallel Port) + db 'PPB','PPY','PSL','PST','PUP','PDN','PLT','PRT' + db 'PPA','PPX','PPL','PPR',' ',' ',' ',' ' + db 'P2B','P2Y','P2S','P2T','P2U','P2D','P2L','P2R' + db 'P2A','P2X','P2L','P2R',' ',' ',' ',' ' + db 'PPB','PPY','PSL','PST','PUP','PDN','PLT','PRT' + db 'PPA','PPX','PPL','PPR',' ',' ',' ',' ' + db 'P2B','P2Y','P2S','P2T','P2U','P2D','P2L','P2R' + db 'P2A','P2X','P2L','P2R',' ',' ',' ',' ' + +SECTION .text + +SECTION .data +NEWSYM ZSNESBase, dd 0 +cpuidfname db 'nocpuzid.dat',0 +cpuidtext db 'NOTE: If ZSNES crashes here, then please re-run. ',0 +cpuidtext2 db 13,' ',13,0 +YesMMX db 'MMX support enabled.',13,10,13,10,0 +TempVarSeek dd 0 +gotoroot db '\',0 +SECTION .text + +; **************************** +; Mouse Stuff +; **************************** + +NEWSYM Init_Mouse + ; return non-zero if successful + mov eax,01h + ret + +NEWSYM WMouseX, dd 0 +NEWSYM WMouseY, dd 0 +NEWSYM WMouseMoveX, dd 0 +NEWSYM WMouseMoveY, dd 0 +NEWSYM WMouseButton, dd 0 + + + + +NEWSYM Get_MouseData ; Returns both pressed and coordinates + ; bx : bit 0 = left button, bit 1 = right button + ; cx = Mouse X Position, dx = Mouse Y Position + pushad + call GetMouseX + mov [WMouseX],eax + call GetMouseY + mov [WMouseY],eax + call GetMouseButton + mov [WMouseButton],eax + popad + mov cx,[WMouseX] + mov dx,[WMouseY] + mov bx,[WMouseButton] + ret + +NEWSYM Set_MouseXMax ; Sets the X boundaries (ecx = left, edx = right) + pushad + or ecx,0FFFh + push ecx + call SetMouseMinX + pop ecx + or edx,0FFFh + push edx + call SetMouseMaxX + pop edx + popad + ret + +NEWSYM Set_MouseYMax ; Sets the Y boundaries (ecx = left, edx = right) + pushad + or ecx,0FFFh + push ecx + call SetMouseMinY + pop ecx + or edx,0FFFh + push edx + call SetMouseMaxY + pop edx + popad + ret + +NEWSYM Set_MousePosition ; Sets Mouse Position (x:cx,y:dx) + pushad + or ecx,0FFFFh + push ecx + call SetMouseX + pop ecx + push edx + or edx,0FFFFh + call SetMouseY + pop edx + popad + ret + +NEWSYM Get_MousePositionDisplacement + ; returns x,y displacement in pixel in cx,dx + pushad + call GetMouseMoveX + mov [WMouseMoveX],eax + call GetMouseMoveY + mov [WMouseMoveY],eax + popad + mov cx,[WMouseMoveX] + mov dx,[WMouseMoveY] + ret + + +NEWSYM MouseWindow + pushad + or byte[MouseButton],2 + mov byte[T36HZEnabled],1 + call GetMouseButton + and byte[MouseButton],0FDh + popad + ret + +NEWSYM GUIInit + pushad + call Start36HZ + popad + ret + +NEWSYM GUIDeInit + pushad + call Stop36HZ + popad + ret + +; **************************** +; Sound Stuff +; **************************** + +NEWSYM StopSound + call Start36HZ + call JoyRead + ret + +NEWSYM StartSound + call Start60HZ + call JoyRead + ret + + +NEWSYM SoundProcess ; This function is called ~60 times/s at full speed + pushad +; cmp byte[OSPort],1 ; Do not call in the dos port +; ja .notdos +;.notdos + cmp byte[soundon],0 + je .nosound + cmp byte[DSPDisable],1 + je .nosound + mov eax,256 ; Size + mov dword[BufferSizeB],eax + add eax,eax + mov dword[BufferSizeW],eax + pushad + call ProcessSoundBuffer + popad + ; DSPBuffer should contain the processed buffer in the specified size + ; You will have to convert/clip it to 16-bit for actual sound process +.nosound + popad + ret + +NEWSYM delay + ret + +NEWSYM Check60hz + ; Call the timer update function here + pushad + call CheckTimers + popad + ret + +BitPosR db 11 +BitPosG db 5 +BitPosB db 0 +BitSizeR db 5 +BitSizeG db 6 +BitSizeB db 5 + + +InitializeGfxStuff: + ; Process Red Stuff + mov al,[BitPosR] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[BitSizeR],6 + jne .no6bit + mov [vesa2_usbit],bx + inc al +.no6bit + or [vesa2_clbit],bx + mov [vesa2_rpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrr + shl bx,cl + jmp .shlr +.shrr + shr bx,1 +.shlr + mov word[vesa2_rfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_rtrcl],bx + xor bx,0FFFFh + mov word[vesa2_rtrcla],bx + + ; Process Green Stuff + mov al,[BitPosG] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[BitSizeG],6 + jne .no6bitb + mov [vesa2_usbit],bx + inc al +.no6bitb + or [vesa2_clbit],bx + mov [vesa2_gpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrg + shl bx,cl + jmp .shlg +.shrg + shr bx,1 +.shlg + mov word[vesa2_gfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_gtrcl],bx + xor bx,0FFFFh + mov word[vesa2_gtrcla],bx + + ; Process Blue Stuff + mov al,[BitPosB] + mov cl,al + mov bx,1 + shl bx,cl + cmp byte[BitSizeB],6 + jne .no6bitc + mov [vesa2_usbit],bx + inc al +.no6bitc + or [vesa2_clbit],bx + mov [vesa2_bpos],al + dec al + mov cl,al + mov bx,001Fh + cmp cl,0FFh + je .shrb + shl bx,cl + jmp .shlb +.shrb + shr bx,1 +.shlb + mov word[vesa2_bfull],bx + add al,5 + mov bx,1 + mov cl,al + shl bx,cl + mov word[vesa2_btrcl],bx + xor bx,0FFFFh + mov word[vesa2_btrcla],bx + + xor word[vesa2_clbit],0FFFFh + call genfulladdtab + cmp byte[converta],1 + je .red10 + mov eax,565 + jmp .red11 + .red10 + mov eax,555 + .red11 + push eax + call Init_2xSaIMMXW + pop eax + + + ret + + +NEWSYM SetInputDevice + ; eax = pointer to devices, bl = device #, bh = player # (0-4) + ; Sets keys according to input device selected + cmp bl,0 + jne near .nozero + mov dword[eax],0 + mov dword[eax+4],0 + mov dword[eax+8],0 + mov dword[eax+12],0 + mov dword[eax+16],0 + mov dword[eax+20],0 + mov dword[eax+24],0 + mov dword[eax+28],0 + mov dword[eax+32],0 + mov dword[eax+36],0 + mov dword[eax+40],0 + mov dword[eax+44],0 + ret +.nozero + cmp bh,1 + je near .input2 + mov dword[eax],54 + mov dword[eax+4],28 + mov dword[eax+8],200 + mov dword[eax+12],208 + mov dword[eax+16],203 + mov dword[eax+20],205 + mov dword[eax+24],31 + mov dword[eax+28],45 + mov dword[eax+32],32 + mov dword[eax+36],30 + mov dword[eax+40],44 + mov dword[eax+44],46 + ret +.input2 + mov dword[eax],56 + mov dword[eax+4],29 + mov dword[eax+8],37 + mov dword[eax+12],50 + mov dword[eax+16],49 + mov dword[eax+20],51 + mov dword[eax+24],31 + mov dword[eax+28],32 + mov dword[eax+32],33 + mov dword[eax+36],44 + mov dword[eax+40],45 + mov dword[eax+44],46 + ret + +; **************************** +; TCP/IP Stuff +; **************************** + +; TCPIPPortNum +NEWSYM TCPIPStatus, db 0 +NEWSYM PacketSendSize, dd 0 +NEWSYM PacketRecvSize, dd 0 +NEWSYM PacketRecvPtr, dd 0 +NEWSYM PacketSendArray, times 2048+256 db 0 +NEWSYM PacketRecvArray, times 2048+256 db 0 +NEWSYM IPAddrStr, times 20 db 0 +NEWSYM RemoteDisconnect, db 0 + +NEWSYM TCPIPStartServer + mov byte[RemoteDisconnect],0 + pushad + mov dword[PacketSendSize],0 + mov dword[PacketRecvSize],0 + call InitTCP + or eax,eax + jnz .failed + mov byte[TCPIPStatus],1 +; StartServer(unsigned short port) + xor eax,eax + mov ax,[TCPIPPortNum] + push eax + call StartServerCycle + add esp,4 + or eax,eax + jnz .failed + mov byte[TCPIPStatus],2 + popad + xor eax,eax + ret +.failed + popad + mov eax,-1 + ret + +NEWSYM TCPIPWaitForConnection + mov byte[RemoteDisconnect],0 + pushad + call ServerCheckNewClient + mov [.temp],eax + cmp eax,1 + jne .notwaiting + call acceptzuser + or eax,eax + jnz .failed +.notwaiting + popad + mov eax,[.temp] + ret +.failed + popad + mov eax,-1 + ret +.temp dd 0 + +NEWSYM TCPIPInitConnectToServer + pushad + mov dword[PacketSendSize],0 + mov dword[PacketRecvSize],0 + call InitTCP + or eax,eax + jnz .failed + mov byte[TCPIPStatus],1 + ; Convert GUINetTextk2 to IPAddrStr + mov ebx,GUINetTextk2 + mov edx,IPAddrStr +.notend + mov al,[ebx] + cmp al,' ' + je .dontinclude + mov [edx],al + inc edx +.dontinclude + inc ebx + cmp al,0 + jne .notend + popad + xor eax,eax + ret +.failed + popad + mov eax,1 + ret + +NEWSYM TCPIPConnectToServer +; int ConnectServer(char *servername, unsigned short port) + pushad + xor eax,eax + mov ax,[TCPIPPortNum] + push eax + mov eax,IPAddrStr + push eax + xor eax,eax + call ConnectServer + add esp,8 + or eax,eax + jnz .noclient + mov byte[TCPIPStatus],3 + popad + xor eax,eax + ret +.noclient + mov [.temp],eax + popad + mov eax,[.temp] + ret +.temp dd 0 + +NEWSYM TCPIPConnectToServerW +; int ConnectServer(char *servername, unsigned short port) + pushad + xor eax,eax + call WaitForServer + or eax,eax + jnz .foundclient + mov byte[TCPIPStatus],3 + popad + xor eax,eax + ret +.foundclient + mov [.temp],eax + popad + mov eax,[.temp] + ret +.temp dd 0 + +NEWSYM TCPIPStoreByte + ; Store al into the array +; cmp dword[PacketSendSize],2048 +; je .packeterror + push ebx + mov ebx,[PacketSendSize] + mov [PacketSendArray+ebx],al + pop ebx + inc dword[PacketSendSize] + ret +.packeterror + mov byte[RemoteDisconnect],1 + ret + +NEWSYM TCPIPGetByte + ; dh = 0 : No bytes in buffer + ; dl = resulting character + cmp dword[PacketRecvSize],0 + jne .bytereceived + mov dword[PacketRecvPtr],0 + call TCPIPRecvPacket + cmp dword[PacketRecvSize],0 + jne .bytereceived + xor dh,dh + ret +.bytereceived + push eax + mov eax,[PacketRecvPtr] + mov dl,[PacketRecvArray+eax] + mov dh,1 + inc dword[PacketRecvPtr] + mov eax,[PacketRecvPtr] + cmp [PacketRecvSize],eax + jne .notequal + mov dword[PacketRecvSize],0 +.notequal + pop eax + ret + +NEWSYM TCPIPSendPacket + cmp dword[PacketSendSize],0 + je .nopacket + pushad + ; Send PacketSendArray with size of PacketSendSize + ; SendData(int dsize,char *dptr) + mov eax,PacketSendArray + push eax + mov eax,[PacketSendSize] + push eax + call SendData + or eax,eax + jnz .failed + add esp,8 + popad +.nopacket + ret +.failed + add esp,8 + popad + call TCPIPDisconnect + mov byte[RemoteDisconnect],1 + ret + +NEWSYM TCPIPSendPacketUDP + cmp dword[PacketSendSize],0 + je .nopacket + pushad + ; Send PacketSendArray with size of PacketSendSize + ; SendData(int dsize,char *dptr) + mov eax,PacketSendArray + push eax + mov eax,[PacketSendSize] + push eax + call SendDataUDP + or eax,eax + jnz .failed + add esp,8 + popad +.nopacket + ret +.failed + add esp,8 + popad + call TCPIPDisconnect + mov byte[RemoteDisconnect],1 + ret + +NEWSYM TCPIPRecvPacket + pushad + ; Store packet to PacketRecvArray, size at PacketRecvSize + ; int GetData(int dsize,char *dptr) + mov eax,PacketRecvArray + push eax + mov eax,2048 + push eax + call GetData + cmp eax,-1 + je .failed + mov [PacketRecvSize],eax + add esp,8 + popad + ret +.failed + add esp,8 + popad + call TCPIPDisconnect + mov byte[RemoteDisconnect],1 + ret + +NEWSYM TCPIPDisconnect + call DeInitTCP + cmp byte[TCPIPStatus],2 + jne .notserver + call StopServer +.notserver + cmp byte[TCPIPStatus],3 + jne .notclient + call Disconnect +.notclient + mov byte[TCPIPStatus],0 + ret + +NEWSYM TCPIPPreparePacket + mov dword[PacketSendSize],0 + ret + +NEWSYM ClearUDPStuff + pushad + call UDPClearVars + popad + ret + +NEWSYM Wait1SecWin + pushad + call UDPWait1Sec + popad + ret + +NEWSYM EnableSUDPPacket + pushad + call UDPEnableMode + popad + ret + +NEWSYM DisableSUDPPacket + pushad + call UDPDisableMode + popad + ret + +NEWSYM WinErrorA + call WinErrorA2 + ret +NEWSYM WinErrorB + call WinErrorB2 + ret +NEWSYM WinErrorC + call WinErrorC2 + ret + +NEWSYM GotoHomepage + pushad + call ZsnesPage + popad + ret + +NEWSYM GetTimeInSeconds + push dword SystemTime + call [_imp__GetLocalTime@4] + movzx eax,word [SystemTime.wHour] + mov ebx,60 + mul ebx + movzx ebx,word [SystemTime.wMinute] + add eax,ebx + mov ebx,60 + mul ebx + movzx ebx,word [SystemTime.wSecond] + add eax,ebx + ret + +SystemTime: +.wYear dw 0 +.wMonth dw 0 +.wDayOfWeek dw 0 +.wDay dw 0 +.wHour dw 0 +.wMinute dw 0 +.wSecond dw 0 +.wMilliseconds dw 0 + \ No newline at end of file diff --git a/zsnes/src/win/winlink.cpp b/zsnes/src/win/winlink.cpp new file mode 100644 index 00000000..d2538666 --- /dev/null +++ b/zsnes/src/win/winlink.cpp @@ -0,0 +1,2313 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#define DIRECTINPUT_VERSION 0x700 +#define DIRECTSOUND_VERSION 0x700 + +extern "C" { + #include + #include + #include + #include + #include +} +#include +#include +#include +#include +#include "resource.h" + +DWORD WindowWidth = 256; +DWORD WindowHeight = 224; +DWORD FullScreen = 0; + +DWORD Moving= 0; +DWORD SoundBufferSize=1024*18; +DWORD FirstSound=1; + +int AllowDefault=0; +int SoundEnabled=1; + +#define BYTE unsigned char +#define WORD unsigned short +#define DWORD unsigned long + +HWND hMainWindow; + +extern "C" +{ +HINSTANCE hInst; +} + +LPDIRECTSOUND lpDirectSound; +LPDIRECTSOUNDBUFFER SoundBuffer; +LPDIRECTSOUNDBUFFER lpPrimaryBuffer; +DSBUFFERDESC dsbd; + +LPVOID lpvPtr1; +DWORD dwBytes1; +LPVOID lpvPtr2; +DWORD dwBytes2; + +LPDIRECTDRAW BasiclpDD = NULL; + +LPDIRECTDRAW2 lpDD = NULL; +LPDIRECTDRAWSURFACE DD_Primary = NULL; +LPDIRECTDRAWSURFACE DD_CFB = NULL; +LPDIRECTDRAWCLIPPER lpDDClipper =NULL; +RECT rcWindow; + +LPDIRECTINPUT DInput; +LPDIRECTINPUTDEVICE MouseInput; +LPDIRECTINPUTDEVICE KeyboardInput; +LPDIRECTINPUTDEVICE7 JoystickInput[4]; +DIJOYSTATE js[4]; + + +DWORD X1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD X2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD Y1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD Y2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD Z1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD Z2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD RX1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD RX2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD RY1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD RY2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD RZ1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD RZ2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD S01Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD S02Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD S11Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +DWORD S12Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + +DWORD CurrentJoy=0; + +DWORD BitDepth; +DWORD GBitMask; +BYTE BackColor=0; +DEVMODE mode; + +float MouseMinX=0; +float MouseMaxX=256; +float MouseMinY=0; +float MouseMaxY=223; +float MouseX; +float MouseY; +float MouseMoveX; +float MouseMoveY; +int MouseMove2X; +int MouseMove2Y; + +DWORD SurfaceX=0; +DWORD SurfaceY=0; + +extern "C" { +DWORD MouseButton; +} + + +#define UPDATE_TICKS_GAME 1000/60 // milliseconds per world update +#define UPDATE_TICKS_GAMEPAL 1000/50 // milliseconds per world update +#define UPDATE_TICKS_GUI 1000/36 // milliseconds per world update +#define UPDATE_TICKS_UDP 1000/60 // milliseconds per world update + +_int64 start, end, freq, update_ticks_pc, start2, end2, update_ticks_pc2; + +extern "C" +{ + void drawscreenwin(void); + void Init_2xSaI(UINT32 BitFormat); + DWORD LastUsedPos=0; + DWORD CurMode=-1; +} + +void DrawScreen() +{ + if(DD_CFB==NULL) return; + if(DD_Primary->Blt(&rcWindow,DD_CFB,NULL,DDBLT_WAIT,NULL)!=DD_OK) + { + // Error!!! + } +} + +DWORD InputEn=0; + +InputAcquire(void) +{ + if(JoystickInput[0]) JoystickInput[0]->Acquire(); + if(JoystickInput[1]) JoystickInput[1]->Acquire(); + if(JoystickInput[2]) JoystickInput[2]->Acquire(); + if(JoystickInput[3]) JoystickInput[3]->Acquire(); + + if(MouseInput) MouseInput->Acquire(); + if(KeyboardInput) KeyboardInput->Acquire(); + InputEn=1; + return TRUE; +} + +BOOL InputDeAcquire(void) +{ + if(MouseInput) { MouseInput->Unacquire(); } + if(KeyboardInput) KeyboardInput->Unacquire(); + if(JoystickInput[0]) JoystickInput[0]->Unacquire(); + if(JoystickInput[1]) JoystickInput[1]->Unacquire(); + if(JoystickInput[2]) JoystickInput[2]->Unacquire(); + if(JoystickInput[3]) JoystickInput[3]->Unacquire(); + InputEn=0; + return TRUE; +} + +extern "C" { +unsigned char keyboardhit=0; +void initwinvideo(); +extern BYTE StereoSound; +extern DWORD SoundQuality; +extern int CurKeyPos; +extern int CurKeyReadPos; +extern int KeyBuffer[16]; +} + +BOOL InputRead(void) +{ + static PrevZ=0; + MouseMoveX=0; + MouseMoveY=0; + if(MouseInput&&InputEn==1) + { + DIMOUSESTATE dims; + HRESULT hr; +aquireagain:; + hr=MouseInput->GetDeviceState(sizeof(DIMOUSESTATE),&dims); + + if(hr==DIERR_INPUTLOST) + { + hr=MouseInput->Acquire(); + if(SUCCEEDED(hr)) + { + goto aquireagain; + } + } + + + if(SUCCEEDED(hr)) + { + + MouseMoveX=dims.lX; + MouseMoveY=dims.lY; + + long zDelta = dims.lZ-PrevZ; + if (!dims.lZ) zDelta=0; + while (zDelta>0){ + zDelta-=40; + if (!((CurKeyPos+1==CurKeyReadPos) || ((CurKeyPos+1==16) + && (CurKeyReadPos==0)))){ + KeyBuffer[CurKeyPos]=72+256; + CurKeyPos++; + if (CurKeyPos==16) CurKeyPos=0; + } + } + while (zDelta<0){ + zDelta+=40; + if (!((CurKeyPos+1==CurKeyReadPos) || ((CurKeyPos+1==16) + && (CurKeyReadPos==0)))){ + KeyBuffer[CurKeyPos]=80+256; + CurKeyPos++; + if (CurKeyPos==16) CurKeyPos=0; + } + } + PrevZ=dims.lZ; + + MouseButton=(dims.rgbButtons[0]>>7)|(dims.rgbButtons[1]>>6)|(dims.rgbButtons[2]>>5)|(dims.rgbButtons[3]>>4); + } + + else + { + return FALSE; + } + + } + return TRUE; +} + + +BYTE PrevStereoSound; +DWORD PrevSoundQuality; + +void ExitFunction(void) +{ + ChangeDisplaySettings(NULL,0); +} + +LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static bool shiftpr; + bool accept; + int vkeyval; + short zDelta; + + switch (uMsg) + { + case WM_KEYDOWN: // sent when user presses a key + if (!((CurKeyPos+1==CurKeyReadPos) || ((CurKeyPos+1==16) + && (CurKeyReadPos==0)))){ + accept=false; + +// char bla[256]; +// sprintf(bla,"%d",wParam); +// MessageBox(NULL,bla,"Key",MB_SYSTEMMODAL|MB_OK); + + if (wParam==16) + shiftpr=true; + if (((wParam>='A') && (wParam<='Z')) || + ((wParam>='a') && (wParam<='z')) || (wParam==27) || + (wParam==32) || (wParam==8) || (wParam==13) || (wParam==9)) { + accept=true; vkeyval=wParam; + } + if ((wParam>='0') && (wParam<='9')) { + accept=true; vkeyval=wParam; + if (shiftpr) { + switch (wParam) { + case '1': vkeyval='!'; break; + case '2': vkeyval='@'; break; + case '3': vkeyval='#'; break; + case '4': vkeyval='$'; break; + case '5': vkeyval='%'; break; + case '6': vkeyval='^'; break; + case '7': vkeyval='&'; break; + case '8': vkeyval='*'; break; + case '9': vkeyval='('; break; + case '0': vkeyval=')'; break; + } + } + } + if ((wParam>=VK_NUMPAD0) && (wParam<=VK_NUMPAD9)) { + accept=true; vkeyval=wParam-VK_NUMPAD0+'0'; + } + if (!shiftpr){ + switch (wParam) { + case 189: vkeyval='-'; accept=true; break; + case 187: vkeyval='='; accept=true; break; + case 219: vkeyval='['; accept=true; break; + case 221: vkeyval=']'; accept=true; break; + case 186: vkeyval=';'; accept=true; break; + case 222: vkeyval=39; accept=true; break; + case 188: vkeyval=','; accept=true; break; + case 190: vkeyval='.'; accept=true; break; + case 191: vkeyval='/'; accept=true; break; + case 192: vkeyval='`'; accept=true; break; + case 220: vkeyval=92; accept=true; break; + } + } else { + switch (wParam) { + case 189: vkeyval='_'; accept=true; break; + case 187: vkeyval='+'; accept=true; break; + case 219: vkeyval='{'; accept=true; break; + case 221: vkeyval='}'; accept=true; break; + case 186: vkeyval=':'; accept=true; break; + case 222: vkeyval='"'; accept=true; break; + case 188: vkeyval='<'; accept=true; break; + case 190: vkeyval='>'; accept=true; break; + case 191: vkeyval='?'; accept=true; break; + case 192: vkeyval='~'; accept=true; break; + case 220: vkeyval='|'; accept=true; break; + } + } + switch (wParam) { + case 33: vkeyval=256+73; accept=true; break; + case 38: vkeyval=256+72; accept=true; break; + case 36: vkeyval=256+71; accept=true; break; + case 39: vkeyval=256+77; accept=true; break; + case 12: vkeyval=256+76; accept=true; break; + case 37: vkeyval=256+75; accept=true; break; + case 34: vkeyval=256+81; accept=true; break; + case 40: vkeyval=256+80; accept=true; break; + case 35: vkeyval=256+79; accept=true; break; + case 107: vkeyval='+'; accept=true; break; + case 109: vkeyval='-'; accept=true; break; + case 106: vkeyval='*'; accept=true; break; + case 111: vkeyval='/'; accept=true; break; + case 110: vkeyval='.'; accept=true; break; + } + if (accept){ + KeyBuffer[CurKeyPos]=vkeyval; + CurKeyPos++; + if (CurKeyPos==16) CurKeyPos=0; + } + } + break; + case WM_KEYUP: // sent when user releases a key + if (wParam==16) + shiftpr=false; + break; + case WM_MOUSEMOVE: + if(MouseInput) MouseInput->Acquire(); + break; +/* case 0x020A: + zDelta = (short) HIWORD(wParam); + zDelta=120; + while (zDelta>0){ + zDelta-=120; + if (!((CurKeyPos+1==CurKeyReadPos) || ((CurKeyPos+1==16) + && (CurKeyReadPos==0)))){ + KeyBuffer[CurKeyPos]=72+256; + CurKeyPos++; + if (CurKeyPos==16) CurKeyPos=0; + } + } + while (zDelta<0){ + zDelta+=120; + if (!((CurKeyPos+1==CurKeyReadPos) || ((CurKeyPos+1==16) + && (CurKeyReadPos==0)))){ + KeyBuffer[CurKeyPos]=72+256; + CurKeyPos++; + if (CurKeyPos==16) CurKeyPos=0; + } + } + break;*/ + case WM_MOVE: + initwinvideo(); + break; + case WM_PAINT: + ValidateRect(hWnd,NULL); + break; + case WM_ACTIVATE: + if(LOWORD(wParam)==WA_INACTIVE) + { + ChangeDisplaySettings(NULL,0); + } + else + { + if(FullScreen==1) + { + ChangeDisplaySettings(&mode,0); + } + initwinvideo(); + } + InputAcquire(); + break; + case WM_SETFOCUS: + if(FullScreen==1) + { + ChangeDisplaySettings(&mode,0); + } + ShowWindow(hMainWindow, SW_SHOWNORMAL); + InputAcquire(); + break; + case WM_KILLFOCUS: + ChangeDisplaySettings(NULL,0); + InputDeAcquire(); + break; + case WM_DESTROY: + ChangeDisplaySettings(NULL,0); + PostQuitMessage(0); + break; + case WM_SETTEXT: + case WM_SHOWWINDOW: + case WM_SETTINGCHANGE: + case WM_SETICON: + case WM_CREATE: + case WM_SETREDRAW: + return DefWindowProc(hWnd,uMsg,wParam,lParam); + break; + default: + break; + } + return TRUE; +} + + +int RegisterWinClass ( void ) +{ + WNDCLASS wcl; + + wcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE ; + wcl.cbClsExtra = 0; + wcl.cbWndExtra = 0; + wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION); + wcl.hCursor = NULL; + wcl.hInstance = hInst; + + wcl.lpfnWndProc = (WNDPROC)Main_Proc; + wcl.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wcl.lpszMenuName = NULL; + wcl.lpszClassName = "ZSNESWIN"; + + if (RegisterClass(&wcl) == 0) return FALSE; + + return TRUE; +} + + +void ShutdownApplication() +{ + +} + +InitSound() +{ + HRESULT hr; + WAVEFORMATEX wfx; + + if (!SoundEnabled) return FALSE; + + PrevSoundQuality=SoundQuality; + PrevStereoSound=StereoSound; + + if(DS_OK == DirectSoundCreate(NULL, &lpDirectSound,NULL)) + { + hr = lpDirectSound->SetCooperativeLevel(hMainWindow, DSSCL_NORMAL ); + if (hr != DS_OK) {SoundEnabled=0; return FALSE;} + } + else + { + SoundEnabled=0; return FALSE; + } + + wfx.wFormatTag = WAVE_FORMAT_PCM; + switch(SoundQuality) + { + case 0: + wfx.nSamplesPerSec = 8000; + SoundBufferSize=1024*2; + break; + case 1: + wfx.nSamplesPerSec = 11025; + SoundBufferSize=1024*2; + break; + case 2: + wfx.nSamplesPerSec = 22050; + SoundBufferSize=1024*4; + break; + case 3: + wfx.nSamplesPerSec = 44100; + SoundBufferSize=1024*8; + break; + case 4: + wfx.nSamplesPerSec = 16000; + SoundBufferSize=1024*4; + break; + case 5: + wfx.nSamplesPerSec = 32000; + SoundBufferSize=1024*8; + break; + case 6: + wfx.nSamplesPerSec = 48000; + SoundBufferSize=1024*8; + break; + default: + wfx.nSamplesPerSec = 11025; + } + + if(StereoSound==1) + { + wfx.nChannels = 2; + wfx.nBlockAlign = 4; + SoundBufferSize*=2; + } + else + { + wfx.nChannels = 1; + wfx.nBlockAlign = 2; + } + + wfx.wBitsPerSample = 16; + wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; + wfx.cbSize=0; + + memset(&dsbd, 0, sizeof(DSBUFFERDESC)); + dsbd.dwSize = sizeof(DSBUFFERDESC); + dsbd.dwFlags = DSBCAPS_STICKYFOCUS; // | DSBCAPS_PRIMARYBUFFER; + dsbd.dwBufferBytes = SoundBufferSize; + dsbd.lpwfxFormat = &wfx; + + hr = lpDirectSound->CreateSoundBuffer(&dsbd, &SoundBuffer, NULL); + + if(DS_OK == hr) + { + if(DS_OK != SoundBuffer->Play(0,0,DSBPLAY_LOOPING )) + { + SoundEnabled=0; return FALSE; + } + FirstSound=0; + return TRUE; + } + else + { + SoundEnabled=0; return FALSE; + } + +} + +ReInitSound() +{ + HRESULT hr; + WAVEFORMATEX wfx; + + if (!SoundEnabled) return FALSE; + + SoundBuffer->Stop(); + SoundBuffer->Release(); + + PrevSoundQuality=SoundQuality; + PrevStereoSound=StereoSound; + + + wfx.wFormatTag = WAVE_FORMAT_PCM; + switch(SoundQuality) + { + case 0: + wfx.nSamplesPerSec = 8000; + SoundBufferSize=1024*2; + break; + case 1: + wfx.nSamplesPerSec = 11025; + SoundBufferSize=1024*2; + break; + case 2: + wfx.nSamplesPerSec = 22050; + SoundBufferSize=1024*4; + break; + case 3: + wfx.nSamplesPerSec = 44100; + SoundBufferSize=1024*8; + break; + case 4: + wfx.nSamplesPerSec = 16000; + SoundBufferSize=1024*4; + break; + case 5: + wfx.nSamplesPerSec = 32000; + SoundBufferSize=1024*8; + break; + case 6: + wfx.nSamplesPerSec = 48000; + SoundBufferSize=1024*8; + break; + + default: + wfx.nSamplesPerSec = 11025; + } + + if(StereoSound==1) + { + wfx.nChannels = 2; + wfx.nBlockAlign = 4; + SoundBufferSize*=2; + } + else + { + wfx.nChannels = 1; + wfx.nBlockAlign = 2; + } + + wfx.wBitsPerSample = 16; + wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; + wfx.cbSize=0; + + memset(&dsbd, 0, sizeof(DSBUFFERDESC)); + dsbd.dwSize = sizeof(DSBUFFERDESC); + dsbd.dwFlags = DSBCAPS_STICKYFOCUS; + dsbd.dwBufferBytes = SoundBufferSize; + dsbd.lpwfxFormat = &wfx; + + hr = lpDirectSound->CreateSoundBuffer(&dsbd, &SoundBuffer, NULL); + + if(DS_OK == hr) + { + if(DS_OK != SoundBuffer->Play(0,0,DSBPLAY_LOOPING )) + { + return FALSE; + } + LastUsedPos=0; + return TRUE; + } + else + { + return FALSE; + } + +} + + +BOOL FAR PASCAL InitJoystickInput(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) +{ + LPDIRECTINPUT7 pdi = (LPDIRECTINPUT7)pvRef; +// fprintf(tempf,"Cur :%d %X\n",CurrentJoy,pdinst->guidInstance); + GUID DeviceGuid = pdinst->guidInstance; + + if(CurrentJoy>3) + return DIENUM_CONTINUE; + + // Create the DirectInput joystick device. + if (pdi->CreateDeviceEx(DeviceGuid,IID_IDirectInputDevice7, + (void**)&JoystickInput[CurrentJoy], NULL) != DI_OK) + { +// fprintf(tempf,"IDirectInput7::CreateDeviceEx FAILED\n"); + return DIENUM_CONTINUE; + } + + if (JoystickInput[CurrentJoy]->SetDataFormat(&c_dfDIJoystick) != DI_OK) + { +// fprintf(tempf,"IDirectInputDevice7::SetDataFormat FAILED\n"); + JoystickInput[CurrentJoy]->Release(); + return DIENUM_CONTINUE; + } + + if(JoystickInput[CurrentJoy]->SetCooperativeLevel(hMainWindow, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) + { +// fprintf(tempf,"IDirectInputDevice7::SetCooperativeLevel FAILED\n"); + JoystickInput[CurrentJoy]->Release(); + return DIENUM_CONTINUE; + } + + + DIPROPRANGE diprg; + + diprg.diph.dwSize = sizeof(diprg); + diprg.diph.dwHeaderSize = sizeof(diprg.diph); + diprg.diph.dwObj = DIJOFS_X; + diprg.diph.dwHow = DIPH_BYOFFSET; + diprg.lMin = -1000; + diprg.lMax = +1000; + + if FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph)) + { +// fprintf(tempf,"IDirectInputDevice7::SetProperty(DIPH_RANGE) FAILED\n"); +// JoystickInput[CurrentJoy]->Release(); +// return FALSE; + X1Disable[CurrentJoy]=1; + X2Disable[CurrentJoy]=1; + } + + diprg.diph.dwObj = DIJOFS_Y; + + if FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph)) + { +// fprintf(tempf,"IDirectInputDevice7::SetProperty(DIPH_RANGE) FAILED\n"); +// JoystickInput[CurrentJoy]->Release(); +// return FALSE; + Y1Disable[CurrentJoy]=1; + Y2Disable[CurrentJoy]=1; + } + + + + diprg.diph.dwObj = DIJOFS_Z; + if(FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph))) + { + Z1Disable[CurrentJoy]=1; + Z2Disable[CurrentJoy]=1; + } + + diprg.diph.dwObj = DIJOFS_RX; + if(FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph))) + { + RX1Disable[CurrentJoy]=1; + RX2Disable[CurrentJoy]=1; + } + + diprg.diph.dwObj = DIJOFS_RY; + if(FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph))) + { + RY1Disable[CurrentJoy]=1; + RY2Disable[CurrentJoy]=1; + } + + diprg.diph.dwObj = DIJOFS_RZ; + if(FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph))) + { + RZ1Disable[CurrentJoy]=1; + RZ2Disable[CurrentJoy]=1; + } + + diprg.diph.dwObj = DIJOFS_SLIDER(0); + if(FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph))) + { + S01Disable[CurrentJoy]=1; + S02Disable[CurrentJoy]=1; + } + + diprg.diph.dwObj = DIJOFS_SLIDER(1); + if(FAILED(JoystickInput[CurrentJoy]->SetProperty(DIPROP_RANGE, &diprg.diph))) + { + S11Disable[CurrentJoy]=1; + S12Disable[CurrentJoy]=1; + } + + + + + DIPROPDWORD dipdw; + + dipdw.diph.dwSize = sizeof(DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); + dipdw.diph.dwHow = DIPH_BYOFFSET; + dipdw.dwData = 2500; + dipdw.diph.dwObj = DIJOFS_X; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_Y; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_Z; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_RX; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_RY; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_RZ; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_SLIDER(0); + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + dipdw.diph.dwObj = DIJOFS_SLIDER(1); + JoystickInput[CurrentJoy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph); + + + + dipdw.diph.dwSize = sizeof(DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = DIPROPAXISMODE_ABS; + dipdw.diph.dwObj = 0; + JoystickInput[CurrentJoy]->SetProperty(DIPROP_AXISMODE, &dipdw.diph); + + CurrentJoy+=1; +// fprintf(tempf,"joystick initialized!\n"); + + return DIENUM_CONTINUE; +} + + +void endgame() +{ + + + if(DD_CFB) + { + DD_CFB->Release(); + DD_CFB=NULL; + } + + + if(lpDD) + { + lpDD->Release(); + lpDD=NULL; + } + + + if(lpDDClipper) + { + lpDDClipper->Release(); + lpDDClipper=NULL; + } + + if(DD_Primary) + { + DD_Primary->Release(); + DD_Primary=NULL; + } + +} + +void DInputError(){ + char message1[256]; + + sprintf(message1,"Error initializing DirectInput\nYou may need to install DirectX 7.0a or higher located at www.microsoft.com/directx \0"); + MessageBox (NULL, message1, "Init Error" , MB_ICONERROR ); +} + +bool InitInput() +{ + char message1[256]; + HRESULT hr; + + if(FAILED(hr=DirectInputCreate(hInst,DIRECTINPUT_VERSION,&DInput,NULL))) + { + sprintf(message1,"Error initializing DirectInput\nYou may need to install DirectX 7.0a or higher located at www.microsoft.com/directx \0"); + MessageBox (NULL, message1, "Init Error" , MB_ICONERROR ); + + switch(hr) + { + case DIERR_BETADIRECTINPUTVERSION: + sprintf(message1,"Beta %X\n\0",hr); + MessageBox (NULL, message1, "Init", MB_ICONERROR ); + break; + case DIERR_INVALIDPARAM: + sprintf(message1,"Invalid %X\n\0",hr); + MessageBox (NULL, message1, "Init", MB_ICONERROR ); + break; + case DIERR_OLDDIRECTINPUTVERSION: + sprintf(message1,"OLDDIRECTINPUTVERSION %X\n\0",hr); + MessageBox (NULL, message1, "Init", MB_ICONERROR ); + break; + case DIERR_OUTOFMEMORY: + sprintf(message1,"OUTOFMEMORY %X\n\0",hr); + MessageBox (NULL, message1, "Init", MB_ICONERROR ); + break; + default: + sprintf(message1,"UNKNOWN %X\n\0",hr); + MessageBox (NULL, message1, "Init", MB_ICONERROR ); + break; + } + return FALSE; + } + + hr=DInput->CreateDevice(GUID_SysKeyboard, &KeyboardInput,NULL); + if(FAILED(hr)) {DInputError();return FALSE;} + + hr=KeyboardInput->SetDataFormat(&c_dfDIKeyboard); + if(FAILED(hr)) {DInputError();return FALSE;} + + + + hr=KeyboardInput->SetCooperativeLevel(hMainWindow,DISCL_NONEXCLUSIVE | DISCL_FOREGROUND ); + + hr=DInput->CreateDevice(GUID_SysMouse, &MouseInput,NULL); + if(FAILED(hr)) {DInputError();return FALSE;} + + hr=MouseInput->SetDataFormat(&c_dfDIMouse); + if(FAILED(hr)) {DInputError();return FALSE;} + + hr=MouseInput->SetCooperativeLevel(hMainWindow,DISCL_EXCLUSIVE|DISCL_FOREGROUND); + if(FAILED(hr)) {DInputError();return FALSE;} + + JoystickInput[0]=NULL;JoystickInput[1]=NULL;JoystickInput[2]=NULL;JoystickInput[3]=NULL; + + + hr=DInput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoystickInput, + DInput, DIEDFL_ATTACHEDONLY); + if(FAILED(hr)) {DInputError();return FALSE;} + + + InputAcquire(); + + return TRUE; + +} + +void TestJoy() +{ + int i; + + for(i=0;i<4;i++) + { + if(JoystickInput[i]) + { + JoystickInput[i]->Poll(); +// memset(&js[i], 0, sizeof(DIJOYSTATE)); + + if(IDirectInputDevice7_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i])==DIERR_INPUTLOST) + { + if(JoystickInput[i]) JoystickInput[i]->Acquire(); + if(FAILED(IDirectInputDevice7_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i]))) return; + } + + + if(!X1Disable[i]) + { + if(js[i].lX>0) X1Disable[i]=1; + } + + if(!X2Disable[i]) + { + if(js[i].lX<0) X2Disable[i]=1; + } + + if(!Y1Disable[i]) + { + if(js[i].lY>0) Y1Disable[i]=1; + } + + if(!Y2Disable[i]) + { + if(js[i].lY<0) Y2Disable[i]=1; + } + + if(!Z1Disable[i]) + { + if(js[i].lZ>0) Z1Disable[i]=1; + } + + if(!Z2Disable[i]) + { + if(js[i].lZ<0) Z2Disable[i]=1; + } + + if(!RY1Disable[i]) + { + if(js[i].lRy>0) RY1Disable[i]=1; + } + if(!RY2Disable[i]) + { + if(js[i].lRy<0) RY2Disable[i]=1; + } + if(!RZ1Disable[i]) + { + if(js[i].lRz>0) RZ1Disable[i]=1; + } + if(!RZ2Disable[i]) + { + if(js[i].lRz<0) RZ2Disable[i]=1; + } + if(!S01Disable[i]) + { + if(js[i].rglSlider[0]>0) S01Disable[i]=1; + } + if(!S02Disable[i]) + { + if(js[i].rglSlider[0]<0) S02Disable[i]=1; + } + + if(!S11Disable[i]) + { + if(js[i].rglSlider[1]>0) S11Disable[i]=1; + } + if(!S12Disable[i]) + { + if(js[i].rglSlider[1]<0) S12Disable[i]=1; + } + + } + } + +} + +extern "C" DWORD converta; +extern "C" unsigned int BitConv32Ptr; + +startgame() +{ + DDSURFACEDESC ddsd; + DDPIXELFORMAT format; + HRESULT hr; + char message1[256]; + unsigned int color32,ScreenPtr2; + int i; + + ScreenPtr2=BitConv32Ptr; + for(i=0;i<65536;i++) + { + color32=((i&0xF800)<<8)+ + ((i&0x07E0)<<5)+ + ((i&0x001F)<<3)+0x7F000000; + (*(unsigned int *)(ScreenPtr2))=color32; + ScreenPtr2+=4; + } + + GetClientRect(hMainWindow, &rcWindow ); + ClientToScreen(hMainWindow, ( LPPOINT )&rcWindow ); + ClientToScreen(hMainWindow, ( LPPOINT )&rcWindow + 1 ); + + if(FAILED(DirectDrawCreate(NULL,&BasiclpDD,NULL))) + { + return FALSE; + } + + + if(FAILED(BasiclpDD->SetCooperativeLevel(hMainWindow, DDSCL_NORMAL ))) + { + return FALSE; + } + + if(FAILED(BasiclpDD->QueryInterface(IID_IDirectDraw2,(LPVOID *)&lpDD))) + { + return FALSE; + } + + BasiclpDD->Release(); + + ddsd.dwSize = sizeof( ddsd ); + ddsd.dwFlags = DDSD_CAPS; + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + + if (FAILED(lpDD->CreateSurface( &ddsd, &DD_Primary, NULL ))) + { + return FALSE; + } + + + if (FAILED(lpDD->CreateClipper(0,&lpDDClipper,NULL))) + { + return FALSE; + } + + if (FAILED(lpDDClipper->SetHWnd(0,hMainWindow))) + { + return FALSE; + } + + if (FAILED( DD_Primary->SetClipper(lpDDClipper))) + { + return FALSE; + } + + format.dwSize = sizeof(DDPIXELFORMAT); + if (DD_Primary->GetPixelFormat(&format) != DD_OK) + { + return FALSE; + } + + BitDepth=format.dwRGBBitCount; + GBitMask=format.dwGBitMask; // 0x07E0 or not + + if(BitDepth==16&& GBitMask!=0x07E0) + { + converta=1; + Init_2xSaI(555); + } + else + { + converta=0; + } + + if(DD_CFB!=NULL) DD_CFB->Release(); + + DD_CFB=NULL; + + ddsd.dwSize = sizeof( ddsd ); + ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH; + ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN ; + + ddsd.dwWidth = SurfaceX; + ddsd.dwHeight = SurfaceY; + + if ( lpDD->CreateSurface( &ddsd, &DD_CFB, NULL ) != DD_OK ) + { + DD_CFB = NULL; + return FALSE; + } + + return TRUE; +} + +BYTE* SurfBuf; +DDSURFACEDESC ddsd; + +DWORD LockSurface() +{ + + if (DD_CFB == NULL) return(0); + + memset(&ddsd,0,sizeof(ddsd)); + ddsd.dwSize = sizeof( ddsd ); + ddsd.dwFlags = DDSD_LPSURFACE | DDSD_PITCH; + if (DD_CFB->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL) != DD_OK) + { + return(0); + } + + SurfBuf = (BYTE*)ddsd.lpSurface; + return(ddsd.lPitch); +} + +void UnlockSurface() +{ + DD_CFB->Unlock(ddsd.lpSurface); + DrawScreen(); +} + + + +extern "C" { + +void WinUpdateDevices(); + +DWORD NeedBuffer=1; +short Buffer[1800*2]; +int Running=0; + +unsigned char Noise[]={ 27,232,234,138,187,246,176,81,25,241,1,127,154,190,195,103,231,165,220,238, +232,189,57,201,123,75,63,143,145,159,13,236,191,142,56,164,222,80,88,13, +148,118,162,212,157,146,176,0,241,88,244,238,51,235,149,50,77,212,186,241, +88,32,23,206,1,24,48,244,248,210,253,77,19,100,83,222,108,68,11,58, +152,161,223,245,4,105,3,82,15,130,171,242,141,2,172,218,152,97,223,157, +93,75,83,238,104,238,131,70,22,252,180,82,110,123,106,133,183,209,48,230, +157,205,27,21,107,63,85,164}; + + + int X, Y; + DWORD Temp1; + MSG msg; + DWORD SurfBufD; + int count, x,count2; + HRESULT hr; + int i; + short *Sound; + DWORD CurrentPos; + DWORD WritePos; + DWORD SoundBufD; + DWORD SoundBufD2; + + + +DWORD T60HZEnabled=0; +DWORD T36HZEnabled=0; + +extern unsigned int pressed; +extern unsigned char romispal; +void Start60HZ(void) +{ + update_ticks_pc2 = UPDATE_TICKS_UDP * freq / 1000; + if(romispal==1) + { + update_ticks_pc = UPDATE_TICKS_GAMEPAL * freq / 1000; + } + else + { + update_ticks_pc = UPDATE_TICKS_GAME * freq / 1000; + } + QueryPerformanceCounter((LARGE_INTEGER*)&start); + QueryPerformanceCounter((LARGE_INTEGER*)&start2); + T36HZEnabled=0; + T60HZEnabled=1; +} + +void Stop60HZ(void) +{ + T60HZEnabled=0; +} + +void Start36HZ(void) +{ + update_ticks_pc2 = UPDATE_TICKS_UDP * freq / 1000; + update_ticks_pc = UPDATE_TICKS_GUI * freq / 1000; + QueryPerformanceCounter((LARGE_INTEGER*)&start); + QueryPerformanceCounter((LARGE_INTEGER*)&start2); + T60HZEnabled=0; + T36HZEnabled=1; +} + +void Stop36HZ(void) +{ + T36HZEnabled=0; +} + +char WinMessage[256]; +extern unsigned char cvidmode; +DWORD FirstVid=1; +DWORD FirstFull=1; +extern BYTE GUIWFVID[]; +void clearwin(); + +char WinName[]={"ZSNESW\0"}; + +void initwinvideo(void) +{ + RECT zwindowrect; + WINDOWPLACEMENT wndpl; + RECT rc1, swrect; + DWORD newmode=0; + if(CurMode!=cvidmode) + { + CurMode=cvidmode; + newmode=1; + SurfaceX=256; + SurfaceY=224; + X=0; + Y=0; + FullScreen=GUIWFVID[cvidmode]; + + switch(cvidmode) + { + case 0: + WindowWidth=64; + WindowHeight=56; + break; + case 1: + WindowWidth=128; + WindowHeight=112; + break; + case 2: + WindowWidth=256; + WindowHeight=224; + break; + case 3: + WindowWidth=640; + WindowHeight=480; + SurfaceX=320; + SurfaceY=240; + break; + case 4: + WindowWidth=512; + WindowHeight=448; + break; + case 5: + WindowWidth=512; + WindowHeight=448; + SurfaceX=512; + SurfaceY=448; + break; + case 6: + WindowWidth=640; + WindowHeight=480; + break; + case 7: + WindowWidth=640; + WindowHeight=480; + SurfaceX=640; + SurfaceY=480; + break; + case 8: + WindowWidth=640; + WindowHeight=480; + SurfaceX=512; + SurfaceY=448; + break; + case 9: + WindowWidth=640; + WindowHeight=480; + break; + case 10: + WindowWidth=800; + WindowHeight=600; + break; + case 11: + WindowWidth=800; + WindowHeight=600; + SurfaceX=512; + SurfaceY=448; + break; + case 12: + WindowWidth=800; + WindowHeight=600; + break; + case 13: + WindowWidth=800; + WindowHeight=600; + SurfaceX=512; + SurfaceY=448; + break; + case 14: + WindowWidth=1024; + WindowHeight=768; + break; + case 15: + WindowWidth=1024; + WindowHeight=768; + SurfaceX=512; + SurfaceY=448; + break; + case 16: + WindowWidth=1024; + WindowHeight=768; + break; + case 17: + WindowWidth=1024; + WindowHeight=768; + SurfaceX=512; + SurfaceY=448; + break; + default: + WindowWidth=256; + WindowHeight=224; + break; + } + } + + if(((PrevStereoSound!=StereoSound)||(PrevSoundQuality!=SoundQuality))&&FirstSound!=1) + ReInitSound(); + + if(FirstVid!=1) + { +// sprintf(WinMessage,"FirstVid!=1 start\n\0"); +// MessageBox (NULL, WinMessage, "Init", MB_ICONERROR ); + + if(X<0)X=0; + if(X>(GetSystemMetrics( SM_CXSCREEN )-WindowWidth)) X=(GetSystemMetrics( SM_CXSCREEN )-WindowWidth); + if(Y<0)Y=0; + if(Y>(GetSystemMetrics( SM_CYSCREEN )-WindowHeight)) Y=(GetSystemMetrics( SM_CYSCREEN )-WindowHeight); + if(FullScreen==1) {X=0; Y=0;} + + MoveWindow( hMainWindow, X, Y, + WindowWidth, WindowHeight, TRUE ); + + wndpl.length = sizeof(wndpl); + GetWindowPlacement( hMainWindow, &wndpl); + SetRect( &rc1, 0, 0, WindowWidth, WindowHeight ); + + AdjustWindowRectEx( &rc1,GetWindowLong( hMainWindow, GWL_STYLE ), + GetMenu( hMainWindow ) != NULL, GetWindowLong( hMainWindow, GWL_EXSTYLE ) ); +// X=(GetSystemMetrics( SM_CXSCREEN ) - WindowWidth) / 2; +// Y=(GetSystemMetrics( SM_CYSCREEN ) - WindowHeight) / 2; + + GetClientRect( hMainWindow, &rc1 ); + ClientToScreen( hMainWindow, ( LPPOINT )&rc1 ); + ClientToScreen( hMainWindow, ( LPPOINT )&rc1 + 1 ); +// return; +// sprintf(WinMessage,"FirstVid!=1 end\n\0"); +// MessageBox (NULL, WinMessage, "Init", MB_ICONERROR ); + +// MoveScreen(wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top); + } + else + { + FirstVid=0; + if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq)) return; +// hInst=GetModuleHandle(0); + if ( !RegisterWinClass() ); // { return; } + X=(GetSystemMetrics( SM_CXSCREEN ) - WindowWidth) / 2; + Y=(GetSystemMetrics( SM_CYSCREEN ) - WindowHeight) / 2; + if(FullScreen==1) {X=0; Y=0;} + if(hMainWindow) CloseWindow(hMainWindow); + + hMainWindow = CreateWindow( "ZSNESWIN", WinName, WS_VISIBLE|WS_POPUP,X,Y, //WS_OVERLAPPED "ZSNESWIN" + WindowWidth,WindowHeight,NULL,NULL,hInst,NULL); + + if(!hMainWindow) { return; } + + ShowWindow(hMainWindow, SW_SHOWNORMAL); + SetWindowText(hMainWindow,"ZSNESWIN"); + InitInput(); + InitSound(); + TestJoy(); + } + + + if(Moving==1) return; + if(FullScreen==1) + { + if(FirstFull==1) + { + atexit(ExitFunction); + } + mode.dmSize=sizeof(DEVMODE); + mode.dmBitsPerPel=16; + mode.dmPelsWidth=WindowWidth; + mode.dmPelsHeight=WindowHeight; + mode.dmDisplayFlags=0; + mode.dmDisplayFrequency=0; + mode.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; + ChangeDisplaySettings(&mode,0); + } + else + { + ChangeDisplaySettings(NULL,0); + } + //endgame(); + + if(startgame()!=TRUE) {return; } + if(newmode==1) clearwin(); +// MessageBox (NULL, "Done", "Init", MB_ICONERROR ); +} + +extern unsigned int vidbuffer; +extern void SoundProcess(); +extern int DSPBuffer; +int * DSPBuffer1; +DWORD ScreenPtr; +DWORD ScreenPtr2; +extern GUI36hzcall(void); +extern Game60hzcall(void); +extern int packettimeleft[256]; +extern int PacketCounter; +extern int CounterA; +extern int CounterB; + + +void CheckTimers(void) +{ + QueryPerformanceCounter((LARGE_INTEGER*)&end2); + while ((end2 - start2) >= update_ticks_pc2) + { + if (CounterA>0) CounterA--; + if (CounterB>0) CounterB--; + if (PacketCounter){ + for (int i=0;i<256;i++){ + if (packettimeleft[i]>0) + packettimeleft[i]--; + } + } + start2 += update_ticks_pc2; + } + + if(T60HZEnabled) + { + QueryPerformanceCounter((LARGE_INTEGER*)&end); + + while ((end - start) >= update_ticks_pc) + { + _asm{ + pushad + call Game60hzcall + popad + } + start += update_ticks_pc; + } + } + + if(T36HZEnabled) + { + QueryPerformanceCounter((LARGE_INTEGER*)&end); + + while ((end - start) >= update_ticks_pc) + { + _asm{ + pushad + call GUI36hzcall + popad + } + start += update_ticks_pc; + } + } +} + +void UpdateVFrame(void) +{ + int DataNeeded; + int SPCSize=256; + + if(StereoSound==1)SPCSize=256; + + while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + WinUpdateDevices(); + CheckTimers(); + + if (!SoundEnabled) return; + + SoundBuffer->GetCurrentPosition(&CurrentPos,&WritePos); + + if(LastUsedPos <= CurrentPos) + { + DataNeeded=CurrentPos-LastUsedPos; + } + else + { + DataNeeded=SoundBufferSize- LastUsedPos + CurrentPos; + } + + DataNeeded/=(SPCSize*2); + DataNeeded*=(SPCSize*2); + + while(DataNeeded>0) + { + _asm + { + pushad + call SoundProcess + popad + } + + DSPBuffer1=(int *)&DSPBuffer; + + for(i=0;i32767)Buffer[i]=32767; + if(DSPBuffer1[i]<-32767)Buffer[i]=-32767; + if(T36HZEnabled)Buffer[i]=0; + } + + if(DS_OK!=SoundBuffer->Lock(LastUsedPos, + SPCSize*2, &lpvPtr1, + &dwBytes1, &lpvPtr2, + &dwBytes2, 0)) + { + return; + } + + Sound=(short *)lpvPtr1; + + CopyMemory(lpvPtr1, &Buffer[0], dwBytes1); + + if(NULL != lpvPtr2) + { + CopyMemory(lpvPtr2, &Buffer[0]+dwBytes1, dwBytes2); + } + + if(DS_OK != SoundBuffer->Unlock(lpvPtr1, dwBytes1, lpvPtr2, dwBytes2)) + { + return; + } + + LastUsedPos+=SPCSize*2; + if(LastUsedPos==SoundBufferSize) LastUsedPos=0; + DataNeeded-=(SPCSize*2); + } + +} + +extern unsigned char curblank; +extern DWORD AddEndBytes; +extern DWORD NumBytesPerLine; +extern unsigned char * WinVidMemStart; +extern void copy640x480x16bwin(void); +extern unsigned char FPUCopy; +extern unsigned char NGNoTransp; +extern unsigned char newengen; + +void clearwin() +{ + DWORD i,j,color32; + DWORD *SURFDW; + + Temp1=LockSurface(); + if(Temp1==0) { return; } + + SurfBufD=(DWORD) &SurfBuf[0]; + SURFDW=(DWORD *) &SurfBuf[0]; + + switch(BitDepth) + { + case 16: + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + mov edi,SurfBufD + xor ebx,ebx + Blank2: + xor eax,eax + mov ecx,SurfaceX + rep stosw + add edi,Temp1 + sub edi,SurfaceX + sub edi,SurfaceX + add ebx,1 + cmp ebx,SurfaceY + jne Blank2 + } + break; + case 32: + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + mov edi,SurfBufD + xor ebx,ebx + Blank3: + xor eax,eax + mov ecx,SurfaceX + rep stosd + add edi,Temp1 + sub edi,SurfaceX + sub edi,SurfaceX + sub edi,SurfaceX + sub edi,SurfaceX + add ebx,1 + cmp ebx,SurfaceY + jne Blank3 + } + break; + } + UnlockSurface(); +} + +void drawscreenwin(void) +{ + DWORD i,j,color32; + DWORD *SURFDW; + + NGNoTransp = 0; // Set this value to 1 within the appropriate + // video mode if you want to add a custom + // transparency routine or hardware + // transparency. This only works if + // the value of newengen is equal to 1. + // (see ProcessTransparencies in newgfx16.asm + // for ZSNES' current transparency code) + + UpdateVFrame(); + if(curblank!=0) return; + + Temp1=LockSurface(); + if(Temp1==0) { return; } + + ScreenPtr=vidbuffer; + ScreenPtr+=16*2+32*2+256*2; + SurfBufD=(DWORD) &SurfBuf[0]; + SURFDW=(DWORD *) &SurfBuf[0]; + if(SurfaceX==256&&SurfaceY==224) + { + switch(BitDepth) + { + case 16: + if (FPUCopy){ + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + mov esi,ScreenPtr + mov edi,SurfBufD + Copying3: + mov ecx,32 + CopyLoop: + movq mm0,[esi] + movq mm1,[esi+8] + movq [edi],mm0 + movq [edi+8],mm1 + add esi,16 + add edi,16 + dec ecx + jnz CopyLoop + inc eax + add edi,Temp1 + sub edi,512 + sub esi,512 + add esi,576 + cmp eax,223 + jne Copying3 + + xor eax,eax + mov ecx,128 + rep stosd + pop es + emms + } + } else { + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + mov esi,ScreenPtr + mov edi,SurfBufD + Copying: + mov ecx,128 + rep movsd + inc eax + add edi,Temp1 + sub edi,512 + sub esi,512 + add esi,576 + cmp eax,223 + jne Copying + + xor eax,eax + mov ecx,128 + rep stosd + pop es + } + } + break; + case 32: + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + mov ebx,BitConv32Ptr + mov esi,ScreenPtr + mov edi,SurfBufD + Copying32b: + mov ecx,256 + push eax + xor eax,eax + CopyLoop32b: + mov ax,[esi] + add esi,2 + mov edx,[ebx+eax*4] + mov [edi],edx + add edi,4 + loop CopyLoop32b + pop eax + inc eax + add edi,Temp1 + sub edi,1024 + sub esi,512 + add esi,576 + cmp eax,223 + jne Copying32b + pop es + } + + +/* for(j=0;j<223;j++) + { + for(i=0;i<256;i++) + { + color32=(((*(WORD *)(ScreenPtr))&0xF800)<<8)+ + (((*(WORD *)(ScreenPtr))&0x07E0)<<5)+ + (((*(WORD *)(ScreenPtr))&0x001F)<<3)+0x7F000000; + SURFDW[i]=color32; + ScreenPtr+=2; + } + ScreenPtr=ScreenPtr+576-512; + SURFDW=(DWORD *) &SurfBuf[j*Temp1]; + } */ + + SURFDW=(DWORD *) &SurfBuf[222*Temp1]; + color32=0x7F000000; + + for(i=0;i<256;i++) + { + SURFDW[i]=color32; + } + + SURFDW=(DWORD *) &SurfBuf[223*Temp1]; + color32=0x7F000000; + + for(i=0;i<256;i++) + { + SURFDW[i]=color32; + } + break; + case 24: + MessageBox (NULL, "Sorry. ZSNESw does not work in windowed 24 bit color modes. \nClick 'OK' to switch to a full screen mode.", "DDRAW Error" , MB_ICONERROR ); + cvidmode=3; + initwinvideo(); + Sleep(1000); + drawscreenwin(); + break; + default: + UnlockSurface(); + MessageBox (NULL, "Mode only available in 16 and 32 bit color", "DDRAW Error" , MB_ICONERROR ); + cvidmode=2; + initwinvideo(); + Sleep(1000); + drawscreenwin(); +// exit(0); + break; + } + } + + if(SurfaceX==320&&SurfaceY==240) + { + switch(BitDepth) + { + case 16: + if (FPUCopy){ + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + xor ebx,ebx + mov esi,ScreenPtr + mov edi,SurfBufD + Blank1MMX: + xor eax,eax + mov ecx,160 + rep stosd + sub edi,640 + add edi,Temp1 + add ebx,1 + cmp ebx,8 + jne Blank1MMX + xor ebx,ebx + pxor mm0,mm0 + Copying2MMX: + mov ecx,4 + MMXLoopA: + movq [edi],mm0 + movq [edi+8],mm0 + add edi,16 + dec ecx + jnz MMXLoopA + mov ecx,32 + MMXLoopB: + movq mm1,[esi] + movq mm2,[esi+8] + movq [edi],mm1 + movq [edi+8],mm2 + add esi,16 + add edi,16 + dec ecx + jnz MMXLoopB + mov ecx,4 + MMXLoopC: + movq [edi],mm0 + movq [edi+8],mm0 + add edi,16 + dec ecx + jnz MMXLoopC + inc ebx + add edi,Temp1 + sub edi,640 + sub esi,512 + add esi,576 + cmp ebx,223 + jne Copying2MMX + + xor eax,eax + mov ecx,128 + rep stosd + pop es + emms + } + } else { + _asm { + push es + mov ax,ds + mov es,ax + xor eax,eax + xor ebx,ebx + mov esi,ScreenPtr + mov edi,SurfBufD + Blank1: + xor eax,eax + mov ecx,160 + rep stosd + sub edi,640 + add edi,Temp1 + add ebx,1 + cmp ebx,8 + jne Blank1 + xor ebx,ebx + Copying2: + xor eax,eax + mov ecx,16 + rep stosd + mov ecx,128 + rep movsd + xor eax,eax + mov ecx,16 + rep stosd + inc ebx + add edi,Temp1 + sub edi,640 + sub esi,512 + add esi,576 + cmp ebx,223 + jne Copying2 + + xor eax,eax + mov ecx,128 + rep stosd + pop es + } + } + break; + case 32: + for(j=0;j<8;j++) + { + SURFDW=(DWORD *) &SurfBuf[j*Temp1]; + color32=0x7F000000; + + for(i=0;i<320;i++) + { + SURFDW[i]=color32; + } + } + + for(j=8;j<223+8;j++) + { + color32=0x7F000000; + for(i=0;i<32;i++) + { + SURFDW[i]=color32; + } + + for(i=32;i<(256+32);i++) + { + color32=(((*(WORD *)(ScreenPtr))&0xF800)<<8)+ + (((*(WORD *)(ScreenPtr))&0x07E0)<<5)+ + (((*(WORD *)(ScreenPtr))&0x001F)<<3)+0x7F000000; +// SURFDW[i]=color32; + ScreenPtr+=2; + } + + color32=0x7F000000; + for(i=(256+32);i<320;i++) + { + SURFDW[i]=color32; + } + + ScreenPtr=ScreenPtr+576-512; + SURFDW=(DWORD *) &SurfBuf[(j)*Temp1]; + } + + for(j=(223+8);j<240;j++) + { + SURFDW=(DWORD *) &SurfBuf[j*Temp1]; + + color32=0x7F000000; + for(i=0;i<320;i++) + { + SURFDW[i]=color32; + } + } + break; + default: + UnlockSurface(); + MessageBox (NULL, "Mode only available in 16 and 32 bit color", "DDRAW Error" , MB_ICONERROR ); + cvidmode=2; + initwinvideo(); + Sleep(1000); + drawscreenwin(); +// exit(0); + break; + } + } + + if(SurfaceX==512&&SurfaceY==448) + { + switch(BitDepth) + { + case 16: + AddEndBytes=Temp1-1024; + NumBytesPerLine=Temp1; + WinVidMemStart=&SurfBuf[0]; + _asm + { + pushad + call copy640x480x16bwin + popad + } + break; + default: + UnlockSurface(); + MessageBox (NULL, "Mode only available in 16 bit color", "DDRAW Error" , MB_ICONERROR ); + cvidmode=2; + initwinvideo(); + Sleep(1000); + drawscreenwin(); +// exit(0); + } + } + + if(SurfaceX==640&&SurfaceY==480) + { + switch(BitDepth) + { + case 16: + AddEndBytes=Temp1-1024; + NumBytesPerLine=Temp1; + WinVidMemStart=&SurfBuf[16*640*2+64*2]; + _asm + { + pushad + call copy640x480x16bwin + popad + } + break; + default: + UnlockSurface(); + MessageBox (NULL, "Mode only available in 16 bit color", "DDRAW Error" , MB_ICONERROR ); + cvidmode=2; + initwinvideo(); + Sleep(1000); + drawscreenwin(); +// exit(0); + } + } + + + UnlockSurface(); +} + + + +extern char fulladdtab[65536*2]; +extern WORD vesa2_usbit; +extern WORD vesa2_clbit; +extern WORD vesa2_rpos; +extern WORD vesa2_rfull; +extern WORD vesa2_rtrcl; +extern WORD vesa2_rtrcla; +extern WORD vesa2_gpos; +extern WORD vesa2_gfull; +extern WORD vesa2_gtrcl; +extern WORD vesa2_gtrcla; +extern WORD vesa2_bpos; +extern WORD vesa2_bfull; +extern WORD vesa2_btrcl; +extern WORD vesa2_btrcla; +extern WORD nojoystickpoll; + +extern void SwitchFullScreen(void); + +void WinUpdateDevices() +{ + int i,j; + unsigned char * keys; + unsigned char keys2[256]; + HRESULT hRes; + + for (i=0;i<256;i++) + keys2[i]=0; + keys=(unsigned char *)&pressed; + + if(KeyboardInput&&InputEn==1) + { + KeyboardInput->GetDeviceState(256, keys2); + } + else + { + return; + } + if(keys2[0x38]!=0&&keys2[0x3E]!=0) exit(0); + if(keys2[0x38]!=0&&keys2[0x1c]!=0) + { + _asm{ + pushad + call SwitchFullScreen + popad + } + return; + } + for(i=0;i<256;i++) + { + if(keys2[i]==0) keys[i]=0; + if(keys2[i]!=0&&keys[i]==0) keys[i]=1; + } +// keys[1]=keys[16]; + keys[0]=0; + +// if (nojoystickpoll) return; + + for(i=0;i<4;i++) + { + if(JoystickInput[i]) + { + for(j=0;j<32;j++) + { + keys[0x100+i*32+j]=0; + } + +// memset(&js[i], 0, sizeof(DIJOYSTATE)); + JoystickInput[i]->Poll(); + if(IDirectInputDevice7_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i])==DIERR_INPUTLOST) + { + if(JoystickInput[i]) JoystickInput[i]->Acquire(); + if(FAILED(IDirectInputDevice7_GetDeviceState(JoystickInput[i],sizeof(DIJOYSTATE), &js[i]))) return; + } + + if(!X1Disable[i]) + { + if(js[i].lX>0) keys[0x100+i*32+0]=1; + } + + if(!X2Disable[i]) + { + if(js[i].lX<0) keys[0x100+i*32+1]=1; + } + + + if(!Y1Disable[i]) + { + if(js[i].lY>0) keys[0x100+i*32+2]=1; + } + + if(!Y2Disable[i]) + { + if(js[i].lY<0) keys[0x100+i*32+3]=1; + } + + if(!Z1Disable[i]) + { + if(js[i].lZ>0) keys[0x100+i*32+4]=1; + } + + if(!Z2Disable[i]) + { + if(js[i].lZ<0) keys[0x100+i*32+5]=1; + } + if(!RY1Disable[i]) + { + if(js[i].lRy>0) keys[0x100+i*32+6]=1; + } + if(!RY2Disable[i]) + { + if(js[i].lRy<0) keys[0x100+i*32+7]=1; + } + + if(!RZ1Disable[i]) + { + if(js[i].lRz>0) keys[0x100+i*32+8]=1; + } + if(!RZ2Disable[i]) + { + if(js[i].lRz<0) keys[0x100+i*32+9]=1; + } + if(!S01Disable[i]) + { + if(js[i].rglSlider[0]>0) keys[0x100+i*32+10]=1; + } + if(!S02Disable[i]) + { + if(js[i].rglSlider[0]<0) keys[0x100+i*32+11]=1; + } + if(!S11Disable[i]) + { + if(js[i].rglSlider[1]>0) keys[0x100+i*32+12]=1; + } + if(!S12Disable[i]) + { + if(js[i].rglSlider[1]<0) keys[0x100+i*32+13]=1; + } + if(js[i].rgbButtons[0]) keys[0x100+i*32+16]=1; + if(js[i].rgbButtons[1]) keys[0x100+i*32+17]=1; + if(js[i].rgbButtons[2]) keys[0x100+i*32+18]=1; + if(js[i].rgbButtons[3]) keys[0x100+i*32+19]=1; + if(js[i].rgbButtons[4]) keys[0x100+i*32+20]=1; + if(js[i].rgbButtons[5]) keys[0x100+i*32+21]=1; + if(js[i].rgbButtons[6]) keys[0x100+i*32+22]=1; + if(js[i].rgbButtons[7]) keys[0x100+i*32+23]=1; + if(js[i].rgbButtons[8]) keys[0x100+i*32+24]=1; + if(js[i].rgbButtons[9]) keys[0x100+i*32+25]=1; + if(js[i].rgbButtons[10]) keys[0x100+i*32+26]=1; + if(js[i].rgbButtons[11]) keys[0x100+i*32+27]=1; + if(js[i].rgbButtons[12]) keys[0x100+i*32+28]=1; + if(js[i].rgbButtons[13]) keys[0x100+i*32+29]=1; + if(js[i].rgbButtons[14]) keys[0x100+i*32+30]=1; + if(js[i].rgbButtons[15]) keys[0x100+i*32+31]=1; + } + else + { + for(j=0;j<32;j++) + { + keys[0x100+i*32+j]=0; + } + } + } + +} + + +int GetMouseX(void) +{ + char message1[256]; + InputRead(); + MouseX+=MouseMoveX; + if(MouseX>MouseMaxX) + { + if(abs(MouseMoveX)>10&&T36HZEnabled) + { + MouseInput->Unacquire(); + SetCursorPos(X+WindowWidth+32,Y+(MouseY*WindowHeight/224)); + } + MouseX=MouseMaxX; + } + + if(MouseX10&&T36HZEnabled) + { + MouseInput->Unacquire(); + SetCursorPos(X-32,Y+(MouseY*WindowHeight/224)); + } + MouseX=MouseMinX; + } + return((int)MouseX); +// return(100); +} + +int GetMouseY(void) +{ + MouseY+=MouseMoveY; + if(MouseY>MouseMaxY) + { + MouseY=MouseMaxY; + if(abs(MouseMoveY)>10&&T36HZEnabled) + { + MouseInput->Unacquire(); + SetCursorPos(X+(MouseX*WindowWidth/256), Y+WindowHeight+32); + } + } + if(MouseY10&&T36HZEnabled) + { + MouseInput->Unacquire(); + SetCursorPos(X+(MouseX*WindowWidth/256), Y-32); + } + } + return((int)MouseY); +// return(100); + +} + +int GetMouseMoveX(void) +{ +// InputRead(); + MouseMove2X=MouseMoveX; + return(MouseMove2X); +} + +int GetMouseMoveY(void) +{ + MouseMove2Y=MouseMoveY; + return(MouseMove2Y); +} + +int GetMouseButton(void) +{ + RECT rc1; + if(MouseButton&2) + { + while((MouseButton!=0)&&T36HZEnabled&&(FullScreen==0)) + { + Moving=1; + X+=MouseMoveX; + Y+=MouseMoveY; + if(X<0)X=0; + if(X>(GetSystemMetrics( SM_CXSCREEN )-WindowWidth)) X=(GetSystemMetrics( SM_CXSCREEN )-WindowWidth); + if(Y<0)Y=0; + if(Y>(GetSystemMetrics( SM_CYSCREEN )-WindowHeight)) Y=(GetSystemMetrics( SM_CYSCREEN )-WindowHeight); + InputRead(); + initwinvideo(); + } + } + if(Moving==1) + { + Moving=0; + initwinvideo(); + } + return((int)MouseButton); +} + +void SetMouseMinX(int MinX) +{ +} + +void SetMouseMaxX(int MaxX) +{ +} + +void SetMouseMinY(int MinY) +{ +} + +void SetMouseMaxY(int MaxY) +{ +} + +void SetMouseX(int X) +{ +} + +void SetMouseY(int Y) +{ +} + +void ZsnesPage() +{ + ShellExecute(NULL, NULL, "http://www.zsnes.com", NULL, NULL, 0); +} + + + + +} + + + \ No newline at end of file diff --git a/zsnes/src/win/zfilew.c b/zsnes/src/win/zfilew.c new file mode 100644 index 00000000..6c04522a --- /dev/null +++ b/zsnes/src/win/zfilew.c @@ -0,0 +1,289 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include +#include + +#define DWORD unsigned int +#define BYTE unsigned char + +FILE *FILEHANDLE[16]; +DWORD CurrentHandle=0; + + + +// ZFileSystemInit +// return 0 + +// ZOpenFile info : +BYTE * ZOpenFileName; +DWORD ZOpenMode; +// Open modes : 0 read/write in +// 1 write (create file, overwrite) +// return file handle if success, 0xFFFFFFFF if error + +// ZCloseFile info : +DWORD ZCloseFileHandle; +// return 0 + +// ZFileSeek info : +DWORD ZFileSeekHandle; +DWORD ZFileSeekPos; +DWORD ZFileSeekMode; // 0 start, 1 end +// return 0 + +// ZFileReadBlock info : +BYTE * ZFileReadBlock; +DWORD ZFileReadSize; +DWORD ZFileReadHandle; +// return 0 + +// ZFileWriteBlock info : +BYTE * ZFileWriteBlock; +DWORD ZFileWriteSize; +DWORD ZFileWriteHandle; +// return 0 + +// ZFileTell +DWORD ZFileTellHandle; + +// ZFileGetftime +BYTE * ZFFTimeFName; +DWORD ZFTimeHandle; +DWORD ZFDate; +DWORD ZFTime; + +// MKDir/CHDir +BYTE * MKPath; +BYTE * CHPath; +BYTE * RMPath; + +// GetDir +BYTE * DirName; +DWORD DriveNumber; + +// ZFileDelete +BYTE * ZFileDelFName; +// return current position + +DWORD ZFileSystemInit() +{ + CurrentHandle=0; + return(0); +} + +DWORD ZOpenFile() +{ + if(ZOpenMode==0) + { + if((FILEHANDLE[CurrentHandle]=fopen(ZOpenFileName,"rb"))!=NULL) + { + CurrentHandle+=1; + return(CurrentHandle-1); + } + return(0xFFFFFFFF); + } + if(ZOpenMode==1) + { + if((FILEHANDLE[CurrentHandle]=fopen(ZOpenFileName,"wb"))!=NULL) + { + CurrentHandle+=1; + return(CurrentHandle-1); + } + return(0xFFFFFFFF); + } + if(ZOpenMode==2) + { + if((FILEHANDLE[CurrentHandle]=fopen(ZOpenFileName,"r+b"))!=NULL) + { + CurrentHandle+=1; + return(CurrentHandle-1); + } + return(0xFFFFFFFF); + } + return(0xFFFFFFFF); +} + +DWORD ZCloseFile() +{ + fclose(FILEHANDLE[ZCloseFileHandle]); + CurrentHandle-=1; + return(0); +} + +DWORD ZFileSeek() +{ + if(ZFileSeekMode==0) + { + fseek(FILEHANDLE[ZFileSeekHandle],ZFileSeekPos,SEEK_SET); + return(0); + } + if(ZFileSeekMode==1) + { + fseek(FILEHANDLE[ZFileSeekHandle],ZFileSeekPos,SEEK_END); + return(0); + } + return(0xFFFFFFFF); +} + +DWORD ZFileRead() +{ + return(fread(ZFileReadBlock,1,ZFileReadSize,FILEHANDLE[ZFileReadHandle])); +} + + +DWORD ZFileWrite() +{ + if((fwrite(ZFileWriteBlock,1,ZFileWriteSize,FILEHANDLE[ZFileWriteHandle]))!=ZFileWriteSize) return(0xFFFFFFFF); + return(0); +} + +DWORD ZFileTell() +{ + return(ftell(FILEHANDLE[ZFileTellHandle])); +} + +DWORD ZFileDelete() +{ + return(remove(ZFileDelFName)); +} + +DWORD ZFileGetFTime() +{ + ZFDate=0; + ZFTime=0; + return(0); +} + +DWORD ZFileMKDir() +{ + return(mkdir(MKPath)); +} + +DWORD ZFileCHDir() +{ + return(chdir(CHPath)); +} + +DWORD ZFileRMDir() +{ + return(rmdir(RMPath)); +} + +DWORD ZFileGetDir() +{ + return(getcwd(DirName,128)); +} + +BYTE * ZFileFindPATH; +DWORD ZFileFindATTRIB; +DWORD DTALocPos; + +//struct _find_t { +// char reserved[21] __attribute__((packed)); +// unsigned char attrib __attribute__((packed)); +// unsigned short wr_time __attribute__((packed)); +// unsigned short wr_date __attribute__((packed)); +// unsigned long size __attribute__((packed)); +// char name[256] __attribute__((packed)); +//}; + + +int FindFirstHandle; +int TempFind; +struct _finddata_t FindDataStruct; + +DWORD ZFileFindNext() +{ + TempFind=_findnext(FindFirstHandle,&FindDataStruct); + if(TempFind==-1) return(-1); + + *(char *)(DTALocPos+0x15)=0; + + if(ZFileFindATTRIB&0x10 && (FindDataStruct.attrib&0x10)==0) return(ZFileFindNext()); + if((ZFileFindATTRIB&0x10==0) && FindDataStruct.attrib&0x10) return(ZFileFindNext()); + + if(FindDataStruct.attrib&_A_SUBDIR) *(char *)(DTALocPos+0x15)=0x10; + strcpy((char *)DTALocPos+0x1E,FindDataStruct.name); + if(TempFind==-1) return(-1); + return(0); +} + +DWORD ZFileFindFirst() +{ + FindFirstHandle=_findfirst(ZFileFindPATH,&FindDataStruct); + *(char *)(DTALocPos+0x15)=0; + TempFind=0; + if(FindFirstHandle==-1) return(-1); + if(ZFileFindATTRIB&0x10 && (FindDataStruct.attrib&0x10)==0) return(ZFileFindNext()); + if((ZFileFindATTRIB&0x10==0) && FindDataStruct.attrib&0x10) return(ZFileFindNext()); + + if(FindDataStruct.attrib&_A_SUBDIR) *(char *)(DTALocPos+0x15)=0x10; + strcpy((char *) DTALocPos+0x1E,FindDataStruct.name); + if(FindFirstHandle==-1) return(-1); + return(0); +} + + +DWORD ZFileFindEnd() // for compatibility with windows later +{ + _findclose(FindFirstHandle); + return(0); +} + + +//BYTE * DirName; +//DWORD DriveNumber; + +//unsigned int _dos_findfirst(char *_name, unsigned int _attr, struct _find_t *_result); +//unsigned int _dos_findnext(struct _find_t *_result); + + +DWORD GetTime() +{ + + DWORD value; + struct tm *newtime; + time_t long_time; + + time( &long_time ); + newtime = localtime( &long_time ); + + value = ((newtime->tm_sec) % 10)+((newtime->tm_sec)/10)*16 + +((((newtime->tm_min) % 10)+((newtime->tm_min)/10)*16) << 8) + +((((newtime->tm_hour) % 10)+((newtime->tm_hour)/10)*16) << 16); + return(value); +} + +DWORD GetDate() +{ + + DWORD value; + struct tm *newtime; + time_t long_time; + + time( &long_time ); + newtime = localtime( &long_time ); + value = ((newtime->tm_mday) % 10)+((newtime->tm_mday)/10)*16 + +(((newtime->tm_mon)+1) << 8) + +((((newtime->tm_year) % 10)+((newtime->tm_year)/10)*16) << 16); + +((newtime->tm_wday) << 28); + + return(value); +} \ No newline at end of file diff --git a/zsnes/src/win/zipxw.c b/zsnes/src/win/zipxw.c new file mode 100644 index 00000000..22806ce4 --- /dev/null +++ b/zsnes/src/win/zipxw.c @@ -0,0 +1,49 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include + +void ipx_init(){}; +void sendpacket(){}; +void checkpacket(){}; +void read_packet(){}; +void ipx_deinit(){}; + +unsigned short ipx_initcode; +unsigned int ipx_packet; +unsigned int ipx_packet_size; +unsigned char ipx_packet_ready; +unsigned int ipx_read_packet; + +/* +EXTSYM _ipx_init ; To init ipx +EXTSYM _ipx_initcode ; return 0 if everything is ok (int) + +EXTSYM _ipx_packet ; 80 bytes buffer to send +EXTSYM _ipx_packet_size ; size to send (max 80 bytes) (dword) +EXTSYM _sendpacket ; to send a packet + +EXTSYM _checkpacket ; check if a packet is ready to receive +EXTSYM _ipx_packet_ready ; return 1 if there is a packet ready (byte) + +EXTSYM _read_packet ; to read an incoming packet +EXTSYM _ipx_read_packet ; 80 bytes buffer of received packet + +EXTSYM _ipx_deinit ; to deinit the ipx +*/ + \ No newline at end of file diff --git a/zsnes/src/win/zloaderw.c b/zsnes/src/win/zloaderw.c new file mode 100644 index 00000000..4ab22d02 --- /dev/null +++ b/zsnes/src/win/zloaderw.c @@ -0,0 +1,539 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include +#include + +extern void zstart(void); +extern void DosExit(void); +extern void ConvertJoyMap1(void); +extern void ConvertJoyMap2(void); +extern void displayparams(void); +extern void makeextension(void); + +extern unsigned char Palette0, SPC700sh, OffBy1Line, DSPDisable, + FPUCopy, Force8b, ForcePal, GUIClick, MouseDis, + MusicRelVol, ScreenScale, SoundCompD, SoundQuality, + StereoSound, V8Mode, antienab, cvidmode, debugdisble, + debugger, enterpress, finterleave, frameskip, + gammalevel, guioff, per2exec, pl1contrl, pl2contrl, + romtype, scanlines, showallext, smallscreenon, soundon, + spcon, vsyncon, DisplayS, fname, filefound, SnowOn, + NetChatFirst,NetServer,NetNewNick, + NetFilename,GUINetTextk2,NetQuitAfter,UDPConfig; + +void ccmdline(void); + +char *ers[] = +{ + "Frame Skip must be a value of 0 to 9!\n", + "Gamma Correction Level must be a value of 0 to 5!\n", + "Sound Sampling Rate must be a value of 0 to 5!\n", + "Invalid Video Mode!\n", + "Percentage of instructions to execute must be a number from 50 to 150!\n", + "Player Input must be a value from 0 to 6!\n", + "Volume must be a number from 0 to 100!\n" + +}; + + + +int argc; +char **argv; + +char ucase(char ch){ + if ((ch>='a') && (ch<='z')) ch-='a'-'A'; + return(ch); +} + +extern HINSTANCE hInst; +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) +{ + int longueur; + + char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR]; + char fname2[_MAX_FNAME],ext[_MAX_EXT], File[_MAX_PATH]; + DWORD dwRead; + + char * strp; + + char ExtA[4][512]; + int charptr,strptr,strcharptr,dquotes; + int i,j,nofile; + + hInst=hInstance; + + // Commandline: /ABCDE + // nickname = user nickname + // fname = filename w/ full path (if L) or path name (if C) + // = IP Address (Client Only) + // A = U (UDP - Recommended if works), T (TCP/IP) + // B = S (Server), C (Client) + // C = C (Chat first), L (load game first) + // D = N (Stay in ZSNESw after disconnect), Q (Quit after disconnect) + // E = # of connections (Keep it 2 for now) + // eg: ZSNESW /UCCN2 nickname d:\snesroms 202.36.124.28 + + strptr=0; + charptr=0; + + while (szCmdLine[charptr]!=0){ + while (szCmdLine[charptr]==' ') charptr++; + dquotes=0; + if (szCmdLine[charptr]=='"'){ + dquotes=1; + charptr++; + } + strcharptr=0; + while (((szCmdLine[charptr]!=' ') || (dquotes)) && (szCmdLine[charptr]!=0)) { + if (szCmdLine[charptr]=='"'){ + dquotes=0; + } else { + if (strptr<4){ + ExtA[strptr][strcharptr]=szCmdLine[charptr]; + if (strcharptr<511) + strcharptr++; + } + } + charptr++; + } + ExtA[strptr][strcharptr]=0; + if (strcharptr) strptr++; + charptr++; + } + + NetServer=0; + NetChatFirst=0; + NetQuitAfter=0; + nofile=0; + if ((strptr>2) && (ExtA[0][0]=='/') && (strlen(ExtA[0])>=5)){ + nofile=1; + if (ucase(ExtA[0][1])=='T') UDPConfig=0; + if (ucase(ExtA[0][2])=='S') NetServer=1; + if (ucase(ExtA[0][2])=='C') NetServer=2; + if (ucase(ExtA[0][3])=='C') NetChatFirst=0; + if (ucase(ExtA[0][3])=='L') NetChatFirst=1; + if (ucase(ExtA[0][4])=='N') NetQuitAfter=0; + if (ucase(ExtA[0][4])=='Q') NetQuitAfter=1; + strp=&NetNewNick; + i=0; j=0; + while (ExtA[1][i]!=0){ + switch (ExtA[1][i]){ + case '_': + case '-': + case '^': + case '=': + case '+': + case '[': + case ']': + if (j<10){ + strp[j]=ExtA[1][i]; + j++; + } + break; + default: + if (((ucase(ExtA[1][i])>='A') && (ucase(ExtA[1][i])<='Z')) + || ((ExtA[1][i]>='0') && (ExtA[1][i]<='9'))){ + if (j<10){ + strp[j]=ExtA[1][i]; + j++; + } + } + break; + } + i++; + } + strp[j]=0; + strp=&NetFilename; + strncpy(strp,ExtA[2],512); + strp[511]=0; + if (NetServer==2){ + if (strptr<4) { + NetServer=0; + } else { + strp=&GUINetTextk2; + strncpy(strp,ExtA[3],28); + } + } + } + + GetModuleFileName(NULL,path_buffer,sizeof(path_buffer)); + _splitpath( path_buffer, drive, dir, fname2, ext ); + _chdrive(drive[0]-'A'+1); + chdir(dir+1); + + argc=0; + + longueur=strlen(szCmdLine); + + if((longueur!=0) && (!nofile)) + { + char *fvar; + fvar=&fname; + + fvar[0] = longueur; + if(szCmdLine[0]=='"') + { + strncpy(&fvar[1],&szCmdLine[1],127); + fvar[longueur-1]=0; + } + else + { + strncpy(&fvar[1],szCmdLine,127); + } + makeextension(); + } + + zstart(); +} + + +int my_atoi(char *nptr) +{ + int p,c; + c=0; + for(p=0;nptr[p];p++) + { + if( !isdigit(nptr[p]) ) c+=1; + } + if(c) return -1; + else return atoi(nptr); + +} + + +void ccmdline(void) +{ + int p=0; + p=pccmdline(); + if(p == 0) return; + + if(p == 9) + { + displayparams(); + } + if(p == 4) + { +// printf("Mangled command line, did you forget a parm?\n"); + printf("Invalid Commandline!\n"); + DosExit(); + } + + if((p > 9) && (p < 17)) + { + printf(ers[p-10]); + DosExit(); + } + if(p == 2) + { + DosExit(); + } + + + printf("cmdline returned %i\n",p); + DosExit(); + +} + +int pccmdline(void) +{ + int p; + int gfnm=0; + + for(p=1;p 6) return 15; + p++; + ConvertJoyMap1(); + break; + } + case '2': /* Player 2 Input */ + { + if(!hasroom) return 4; + pl2contrl=my_atoi(argv[p+1]); + if(pl2contrl > 6) return 15; + p++; + ConvertJoyMap2(); + break; + } + case 'f': + { + if(!hasroom) return 4; + frameskip=my_atoi(argv[p+1]); + if(frameskip > 9) return 10; + p++; + break; + } + case 'g': + { + if(!hasroom) return 4; + gammalevel=my_atoi(argv[p+1]); + if(gammalevel > 5) return 11; + p++; + break; + } + case 'p': + { + if(!hasroom) return 4; + per2exec=my_atoi(argv[p+1]); + if(per2exec > 150) return 14; + if(per2exec < 50) return 14; + p++; + break; + } + case 'r': + { + if(!hasroom) return 4; + SoundQuality=my_atoi(argv[p+1]); + if(SoundQuality > 5) return 12; + p++; + break; + } + case 'v': + { + if(nn == '8') + { + V8Mode=1; + pp++; + } + else + { + if(!hasroom) return 4; + cvidmode=my_atoi(argv[p+1]); + if(cvidmode > 10) return 13; + p++; + } + break; + } + case 'k': + { + if(!hasroom) return 4; + MusicRelVol=my_atoi(argv[p+1]); + if(MusicRelVol > 100) return 16; + p++; + break; + } + case '8': + { + Force8b=1; + break; + } + case '0': /* Palette 0 disable */ + { + Palette0=1; + break; + } + case '7': /* SPC700 speed hack disable */ + { + SPC700sh=1; + break; + } + case '9': /* Off by 1 line */ + { + OffBy1Line=1; + break; + } + case 'e': + { + enterpress=1; + break; + } + case 'h': + { + romtype=2; + break; + } + case 'l': + { + romtype=1; + break; + } + case 'm': + { + guioff=1; /* disables GUI */ + break; + } + case 'n': + { + scanlines=1; + break; + } + case 's': + { + if(nn == 'p') + { + DisplayS=1; + pp++; + } + else + if(nn == 'a') + { + showallext=1; + pp++; + } + else + if(nn == 'n') + { + SnowOn=1; + pp++; + } + else + { + spcon=1; + soundon=1; + } + break; + } + case 't': + { + ForcePal=1; + break; + } + case 'u': + { + ForcePal=2; + break; + } + case 'w': + { + vsyncon=1; + break; + } + case 'z': + { + StereoSound=1; + break; + } + case 'd': + { + if(nn == 'd') + { + DSPDisable=1; + pp++; + } + else + { + debugger=1; + debugdisble=0; + } + break; + } + case 'b': + { + SoundCompD=1; + break; + } + + case 'c': + { + if(nn == 'c') + { + smallscreenon=1; + pp++; + } + else + { + ScreenScale=1; + } + break; + } + + case 'y': + { + antienab=1; + break; + } + case 'o': + { + if(nn == 'm') + { + FPUCopy=2; + pp++; + } + else + { + FPUCopy=0; + } + break; + } + case 'i': + { + finterleave=1; + break; + } + case 'j': + { + GUIClick=0; + MouseDis=1; + break; + } + case '?': + { + return 9; + } + } + + } + + } + else + { + if(gfnm > 0) + { + printf("Limit yourself to one filename\n"); + return 2; + } + else + { + char *fvar; + fvar=&fname; + fvar[0] = strlen(argv[p]); + strncpy(&fvar[1],argv[p],127); + gfnm++; + } + } + } + if(gfnm == 1) + { + filefound=0; + makeextension(); + } + return 0; +} + \ No newline at end of file diff --git a/zsnes/src/win/zsnes.rc b/zsnes/src/win/zsnes.rc new file mode 100644 index 00000000..81ae29ee --- /dev/null +++ b/zsnes/src/win/zsnes.rc @@ -0,0 +1,2 @@ +IDR_MAINFRAME ICON DISCARDABLE "ZSNES.ICO" + \ No newline at end of file diff --git a/zsnes/src/win/ztcp.c b/zsnes/src/win/ztcp.c new file mode 100644 index 00000000..c436ecb2 --- /dev/null +++ b/zsnes/src/win/ztcp.c @@ -0,0 +1,1184 @@ +//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later +//version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +/**********************************************************\ +* ZSNES TCP/IP MODULE FOR NETWORK PLAY * +* * +* Coded by the ZSNES team * +* TCP/IP drivers coded by _Demo_, revised by Pharos * +* UDP drivers coded by _Demo_, revised by zsKnight * +* Gameplay netplay implementation by zsKnight * +* UDP Packet loss/out of order algorithm/implementation * +* by zsKnight, assistance on normal packets by Pharos * +\**********************************************************/ + +// UDP Algorithm: +// +// UDP Header (1 byte): 1 = Normal Packet w/ reply req, 2 = Reply Packet, +// 3 = Gameplay Packet (single byte), +// 4 = Gameplay Packet (larger packet), 5 = Re-request gameplay +// packet +// +// Normal Packets: +// Note: The actual implementation turned out to be quite different +// than the below descriptions. +// First byte contains the packet counter, followed by packet contents. +// Remote will send a Reply Packet (just contains packet counter) +// Each packet buffer will have a timer counter which decreases after +// every 1/60 seconds (value set at start is 60). If this reaches 0 +// that packet will be re-sent and reset the timer value back to 60. +// If the local side receives the reply packet, it will set the timer +// counter to -1. +// +// Gameplay Packets: +// Note: Gameplay counter is separate from normal packet counter. +// Note2: When referring to TCP/IP, it refers to the Normal Packets above. +// Each packet in TCP/IP will contain a byte counter when UDP is +// enabled. +// Each UDP packet will contain a byte counter, the number of packets, +// then each packet will contain a byte size only if there are > 1 +// packets. If the packet is just one byte long and contains a value<2, +// it will follow by a byte containing info on how many packets its has +// been like that for (it will not go beyond 32). If the packet is +// more than one byte long, it will repeat that packet as the extra +// packets for the next 3 packets, with the first byte of those packets +// as the byte counter of that packet, then the second as the size. +// Also, the send data will be stored in a 256*32 byte buffer in case +// of packet loss. +// When receiving, since no UDP packets will exceed 32bytes in length, +// there will be a 256*32 byte buffer and a 256 byte flag buffer. +// The flag clearing pointer will move at an offset of 128 from the +// actual point of the receive buffer. When it receives data from +// the UDP (or TCP), if the byte count of the data matches the +// receive pointer, it will just send the data directly and increase the +// receive pointer. Else it will fill the buffer accordingly based on +// the send data (for a maximum of 32 bytes). Then if the bit on the +// flag buffer is set for the current receive pointer, return the +// appropriate buffer and increase receive pointer. +// In case of packet loss, if no data has been received for every 500ms, the +// local side would send a re-send package request. What this would +// do is let the remote side build up a package containing all the +// data from the requested send point to the current receive point. +// A resend request will start off with 0x00,0xFF, then the counter +// number. A resent packet will start off with 0x00,0xFE, the # of +// packets, then the packet data (size of packet, data). A resend will +// only be done if the requested packet is within the past 64 packets. +// In-game chat will be moved to a separate packet in TCP/IP + +#include +#include +#include +#include + +int RecvPtr; +int RecvPtr2; +unsigned char RecvFlags[256]; +unsigned char RecvBuffer[256*32]; +int RecvBufferSize[256]; + +int SendPtr; +int SendPtr2; +unsigned char SendBuffer[256*32]; +int SendBufferSize[256]; + +int SendRepeated; + +int PrevSPacket[16]; +int PrevSData[16*32]; +int PrevSSize[16]; +int PrevSPtr[16]; + +int tcperr; +unsigned short portval; +int UDPEnable = 1; +int UDPConfig = 1; +int UDPBackTrace = 6; +int blahblahblah = 0; +int CounterA = -1; +int CounterB = -1; +int UDPMode2 = 0; + +int packetnum,packetnumhead; +int packetrecvhead; +unsigned char packetdata[2048*16]; +unsigned char packetrdata[2048*32]; +int packetconfirm[256]; +int packetreceived[256]; +int packetreceivesize[256]; +int packetsize[256]; +unsigned char cpacketdata[2048+32]; +UINT ConnectAddr; +int packettimeleft[256]; +int packetresent[256]; +int PacketCounter=0; +unsigned char CLatencyVal=0; + + +SOCKET gamesocket; /* tcp socket for the game */ +SOCKET serversocket; /* tcp socket when the server is listening */ + +SOCKET ugamesocket; /* udp socket sending */ +SOCKET userversocket; /* udp socket listening */ + +SOCKADDR_IN serveraddress; /* address of the server */ +SOCKADDR_IN ugameaddress; /* address of the server */ +SOCKADDR_IN userveraddress; /* address of the server */ + +char blah[256]; +char remotehost[256]; +char hostname[50] = "IP N/A"; + +// Function Prototypes + +int SendData(int dsize,unsigned char *dptr); +int GetData(int dsize,unsigned char *dptr); + +/**********************************************************\ +* Initialize the zsnes tcpip module * +* - no parameters * +* - return 0 on success other value on error * +* * +* - no known side effects * +\**********************************************************/ + +int InitTCP() +{ + + char blah[255]; + WORD versionneeded = MAKEWORD(2,2); + WSADATA wsadata; + + UDPEnable=0; + + /* Startup winsock */ + WSAStartup(versionneeded, &wsadata); + + /* Verify version number and exit on wrong version */ + if (wsadata.wVersion != versionneeded) + { + return(-1); + } + serversocket=INVALID_SOCKET; + return(0); +} + + +/**********************************************************\ +* Deinitialize the zsnes tcpip module * +* - no parameters * +* * +* - no known side effects * +\**********************************************************/ + +void DeInitTCP() +{ + WSACleanup(); +} + +/**********************************************************\ +* Gets UDP Status through sending data * +* - no parameters * +* * +* - no known side effects * +\**********************************************************/ + +void GetUDPStatus() { + int retval; + char NoSend = 0; + + UDPEnable=UDPConfig; + + if (!UDPEnable){ + blah[0]=0; + retval = send(gamesocket,blah,1,0); + gethostname(blah,255); + retval = send(gamesocket,blah,strlen(blah),0); + } + else { + blah[0]=1; + retval = send(gamesocket,blah,1,0); + gethostname(blah,255); + retval = send(gamesocket,blah,strlen(&blah[1])+1,0); + } + + retval = recv(gamesocket,blah,256,0); + if (blah[0]==0) UDPEnable=0; + retval = recv(gamesocket,blah,256,0); +} + +/**********************************************************\ +* Connect to game server * +* - parameters * +* - pointer server name * +* - server port * +* - return 0 on success other value on error * +* * +* - no known side effects * +\**********************************************************/ + +int isipval(char *name){ + int i; + int tcperr; + i=0; + while(name[i]!=0){ + if (!((name[i]=='.') || ((name[i]>='0') && (name[i]<='9')))) + return(0); + i++; + } + return(1); +} + +int ConnectServer(char *servername, unsigned int port) +{ + char blah[255]; + int retval,i; + LPHOSTENT host1; + unsigned long addr1; + int yesip; + WSADATA wsadata; + + packetnum = 0; + packetnumhead = 0; + packetrecvhead = 0; + RecvPtr = 0; + SendPtr = 0; + RecvPtr2 = 0; + SendPtr2 = 0; + + ConnectAddr = 0; + SendRepeated = 0; + for (i=0;i<16;i++) + PrevSPacket[i]=0; + + /* get host and verify if it is valid */ + yesip = isipval(servername); + if (!yesip){ + host1 = gethostbyname(servername); + if (host1 == NULL) + { + return(-1); + } + } + +// return(-1); + if (UDPConfig) UDPEnable = 1; + + if (UDPEnable) + { + PacketCounter=1; + for (i=0;i<256;i++) {packettimeleft[i]=-1; packetconfirm[i]=1; packetreceived[i]=0; RecvFlags[i]=0;} + + userveraddress.sin_family = AF_INET; + ugameaddress.sin_family = AF_INET; + + if (!yesip) + { + ugameaddress.sin_addr = *( (LPIN_ADDR) *host1->h_addr_list ); + } + else + { + ugameaddress.sin_addr.s_addr = inet_addr(servername); + } + + ConnectAddr = ugameaddress.sin_addr.s_addr; + + userveraddress.sin_addr.s_addr = INADDR_ANY; + +// port++; + ugameaddress.sin_port = htons((unsigned short) port); + userveraddress.sin_port = htons((unsigned short) port); +// port--; + + userversocket = socket(AF_INET, SOCK_DGRAM,0); + ugamesocket = socket(AF_INET, SOCK_DGRAM,0); + + if (ugamesocket == INVALID_SOCKET) + { + tcperr=WSAGetLastError(); + sprintf(blah,"Could not initialize UDP(2) : %d",tcperr); + MessageBox(NULL,blah,"Error",MB_SYSTEMMODAL|MB_OK); + return(-2); + } + + if (userversocket == INVALID_SOCKET) + { + tcperr=WSAGetLastError(); + sprintf(blah,"Could not initialize UDP(2.5) : %d",tcperr); + MessageBox(NULL,blah,"Error",MB_SYSTEMMODAL|MB_OK); + return(-2); + } + + if (bind(userversocket,(struct sockaddr*)&userveraddress,sizeof(userveraddress))== + SOCKET_ERROR) + { + tcperr=WSAGetLastError(); + sprintf(blah,"Could not initialize UDP(16) : %d",tcperr); + MessageBox(NULL,blah,"Error",MB_SYSTEMMODAL|MB_OK); + return(-2); + } + + +// blah[0]=1; +// retval = sendto(ugamesocket,blah,1,0,(struct sockaddr*)&ugameaddress,sizeof(struct sockaddr)); +// if (retval == SOCKET_ERROR) return(-1); + + blah[0]=1; + SendData(1,blah); + +// retval = sendto(ugamesocket,blah,5,0,(struct sockaddr*)&ugameaddress,sizeof(struct sockaddr)); +// blah[0]=0; +// i = sizeof(struct sockaddr); +// retval = recvfrom(userversocket,blah,5,0,(struct sockaddr*)&userveraddress,&i); + +// MessageBox(NULL,blah, +// "Error", +// MB_SYSTEMMODAL|MB_OK); + + return(0); + +// retval = send(gamesocket,blah,1,0); +// retval = recv(gamesocket,blah,1,0); + } + + + /* create the game socket and verify if it is valid */ + gamesocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (gamesocket == INVALID_SOCKET) + { + return(-2); + } + + + /* initialize server address */ + serveraddress.sin_family = AF_INET; + if (!yesip) + serveraddress.sin_addr = *( (LPIN_ADDR) *host1->h_addr_list ); + else + serveraddress.sin_addr.s_addr = inet_addr(servername); + + serveraddress.sin_port = htons((unsigned short)port); + + + /* try to connect to the server */ + retval = connect( gamesocket, + (LPSOCKADDR)&serveraddress, + sizeof(struct sockaddr)); + if (retval == SOCKET_ERROR) + { + + sprintf(blah,"Could not connect to other side"); + MessageBox(NULL,blah, + "Error", + MB_SYSTEMMODAL|MB_OK); + + closesocket(gamesocket); + return(-3); + } + +// GetUDPStatus(); + + return(0); +} + +int WaitForServer(){ + int i; + + if (UDPEnable){ + if (i=GetData(1,blah)){ + if ((i==1) && (blah[0]==1)) + return(1); + } + return(0); + } + return(1); +} + + +/**********************************************************\ +* Disconnect from game server * +* - no parameters * +* * +* - no known side effects * +\**********************************************************/ + +void Disconnect() +{ + if (UDPEnable) + { + closesocket(ugamesocket); + closesocket(userversocket); + return; + } + PacketCounter=0; + closesocket(gamesocket); +} + + +/**********************************************************\ +* Start the game server * +* - parameters * + - port number +* - return 0 on success other value on error * +* * +* - no known side effects * +\**********************************************************/ + +int StartServerCycle(unsigned short port) +{ + int retval,sizet,i; + + portval = port; + packetnum = 0; + packetnumhead = 0; + packetrecvhead = 0; + ConnectAddr = 0; + SendRepeated = 0; + RecvPtr = 0; + SendPtr = 0; + RecvPtr2 = 0; + SendPtr2 = 0; + + for (i=0;i<16;i++) + PrevSPacket[i]=0; + + + if (UDPConfig) UDPEnable = 1; + + if (UDPEnable) + { + /* get host and verify if it is valid */ + PacketCounter=1; + for (i=0;i<256;i++) {packettimeleft[i]=-1; packetconfirm[i]=1; packetreceived[i]=0; RecvFlags[i]=0;} + + userveraddress.sin_family = AF_INET; + ugameaddress.sin_family = AF_INET; + + userveraddress.sin_addr.s_addr = INADDR_ANY; + ugameaddress.sin_addr.s_addr = INADDR_ANY; + +// portval++; + ugameaddress.sin_port = htons((unsigned short) portval); + userveraddress.sin_port = htons((unsigned short) portval); +// portval--; + + userversocket = socket(AF_INET, SOCK_DGRAM,0); + ugamesocket = socket(AF_INET, SOCK_DGRAM,0); + + if (userversocket == INVALID_SOCKET) + { + tcperr=WSAGetLastError(); + sprintf(blah,"Could not initialize UDP(5) : %d",tcperr); + MessageBox(NULL,blah,"Error",MB_SYSTEMMODAL|MB_OK); + return(-2); + } + if (bind(userversocket,(struct sockaddr*)&userveraddress,sizeof(userveraddress))== + SOCKET_ERROR) + { + tcperr=WSAGetLastError(); + sprintf(blah,"Could not initialize UDP(6) : %d",tcperr); + MessageBox(NULL,blah,"Error",MB_SYSTEMMODAL|MB_OK); + return(-2); + } + + + blah[0]=2; + blah[1]='C'; + blah[2]='B'; + blah[3]='A'; + blah[4]=0; + + +// retval = recvfrom(userversocket,blah,5,0, +// (struct sockaddr *)&userveraddress,&socklen); + + ugameaddress.sin_addr.s_addr = userveraddress.sin_addr.s_addr; + + ugamesocket = socket(AF_INET, SOCK_DGRAM,0); + + return(0); + +// retval = send(gamesocket,blah,1,0); +// retval = recv(gamesocket,blah,1,0); + + } + + /* Create the listen socket */ + serversocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (serversocket == INVALID_SOCKET) + { + tcperr=WSAGetLastError(); + + return(-1); + } + + serveraddress.sin_family = AF_INET; + serveraddress.sin_addr.s_addr = INADDR_ANY; + serveraddress.sin_port = htons(port); + + /* bind name and socket */ + retval = bind(serversocket, + (LPSOCKADDR)&serveraddress, + sizeof(struct sockaddr)); + if (retval == SOCKET_ERROR) + { + tcperr=WSAGetLastError(); + closesocket(serversocket); + return(-2); + } + + /* setup socket to listen */ + retval = listen(serversocket, SOMAXCONN); + if (retval == SOCKET_ERROR) + { + tcperr=WSAGetLastError(); + closesocket(serversocket); + return(-3); + } + + return 0; +} + +int acceptzuser() +{ + int retval,r,i; + LPHOSTENT host1; + int yesip; + + if (UDPEnable) + { + return(0); + } + + /* wait for connection */ + + gamesocket = accept(serversocket, NULL, NULL); + if (gamesocket == INVALID_SOCKET) + { + tcperr=WSAGetLastError(); + closesocket(serversocket); + serversocket=-1; + return(-1); + } + +// GetUDPStatus(); + + return(0); +} + +int ServerCheckNewClient() +{ + FD_SET zrf; + struct timeval nto; + int r; + + if (UDPEnable) + { + r=GetData(256,blah); + if (r == -1) return(-1); + if (r > 0){ + ugameaddress.sin_addr.s_addr=userveraddress.sin_addr.s_addr; + ConnectAddr = ugameaddress.sin_addr.s_addr; + blah[0]=1; + r=SendData(1,blah); + return(1); + } + return(0); + } + + if(serversocket == INVALID_SOCKET) + { + return(-1); + } + nto.tv_sec=0; + nto.tv_usec=0; /* return immediately */ + + FD_ZERO(&zrf); + FD_SET(serversocket,&zrf); + r=select(serversocket+1,&zrf,0,0,&nto); + + if(r == -1) + { + tcperr=WSAGetLastError(); + return(-2); + } + if(r == 0) + { + return(0); + } + if(FD_ISSET(serversocket,&zrf)) + { + return 1; + } + return(0); + +} + + +/**********************************************************\ +* Stop the game server * +* - no parameters * +* * +* - no known side effects * +\**********************************************************/ + +void StopServer() +{ + if (UDPEnable) + { + closesocket(ugamesocket); + closesocket(userversocket); + return; + } + PacketCounter=0; + closesocket(gamesocket); + closesocket(serversocket); +} + + +/**********************************************************\ +* Send data * +* - parameters : * +* - size of data * +* - pointer to data * +* - return 0 on success other value on error * +* * +* - side effects : * +* - close the socket on error * +\**********************************************************/ + +int PacketReceive() +{ + int dataleft,i,i2,i3,i4,i5,i6,i7,retval; + + dataleft=GetLeftUDP(); + if (dataleft<=0) return(dataleft); + i = sizeof(userveraddress); + retval = recvfrom(userversocket,cpacketdata,2048+32,0,(struct sockaddr *)&userveraddress,&i); + if ((ConnectAddr!=0) && (ConnectAddr != userveraddress.sin_addr.s_addr)) return(0); + if (retval == SOCKET_ERROR) + { + closesocket(ugamesocket); + return(-1); + } + if ((cpacketdata[0]==1) && (retval>0)) { + i=(unsigned char)cpacketdata[1]; + blah[0]=2; + blah[1]=cpacketdata[1]; + sendto(ugamesocket,blah,2,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress)); + if (!packetreceived[i]){ + packetreceived[i]=1; + packetreceivesize[i]=retval-2; + CopyMemory(&(packetrdata[2048*(i & 0x0F)]),&(cpacketdata[2]),retval-2); + } + } + if (cpacketdata[0]==2){ + packetconfirm[cpacketdata[1]]=1; + while ((packetconfirm[packetnumhead]) && (packetnum!=packetnumhead)) + packetnumhead=(packetnumhead+1) & 0xFF; + } + + if ((cpacketdata[0]==16) && (cpacketdata[1]!=SendPtr)){ + i=cpacketdata[1]; + cpacketdata[0]=17; + cpacketdata[2]=SendPtr; + i3=3; + while (i!=SendPtr){ + cpacketdata[i3]=SendBufferSize[i]; + i3++; + for (i4=0;i4=0) && (i3<=127))) { + + + CLatencyVal=cpacketdata[1]; + i=cpacketdata[2]; + i3=0; + + if ((cpacketdata[0] & 0x07)==4){ + for (i2=0;i2512) packettimeleft[packetnum]=60*3; + packetresent[i]++; + CopyMemory(&(cpacketdata[2]),&(packetdata[2048*(i & 0x0F)]),packetsize[i]); + cpacketdata[0]=1; + cpacketdata[1]=(char)i; + sendto(ugamesocket,cpacketdata,packetsize[i]+2,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress)); + } + } +} + +extern void UpdateVFrame(void); + +int SendData(int dsize,unsigned char *dptr) +{ + int retval; + char message1[256]; + + if (UDPEnable){ +/* retval = sendto(ugamesocket,dptr,dsize,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress)); + if (retval == SOCKET_ERROR) + { + closesocket(gamesocket); + return(-1); + } + return(0); */ + + if (((packetnum-packetnumhead) & 0xFF) >= 15){ +// sprintf(message1,"Packet Overflow."); +// MessageBox (NULL, message1, "Init Error" , MB_ICONERROR ); + + // wait for receive packet, call JoyRead while waiting + while (((packetnum-packetnumhead) & 0xFF) >= 15){ + PacketResend(); + PacketReceive(); + UpdateVFrame(); + while ((packetconfirm[packetnumhead]) && (packetnum!=packetnumhead)) + packetnumhead=(packetnumhead+1) & 0xFF; + } + } + CopyMemory(&(cpacketdata[2]),dptr,dsize); + CopyMemory(&(packetdata[2048*(packetnum & 0x0F)]),dptr,dsize); + packetsize[packetnum]=dsize; + packetconfirm[packetnum]=0; + cpacketdata[0]=1; + cpacketdata[1]=(char)packetnum; + retval = sendto(ugamesocket,cpacketdata,dsize+2,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress)); + packettimeleft[packetnum]=60; + if (dsize>512) packettimeleft[packetnum]=90; + packetresent[packetnum]=1; + packetnum=(packetnum+1) & 0xFF; + if (retval == SOCKET_ERROR) + { + closesocket(ugamesocket); + return(-1); + } + return(0); + } + + /* send data with the socket */ + retval = send(gamesocket,dptr,dsize,0); + if (retval == SOCKET_ERROR) + { + closesocket(gamesocket); + return(-1); + } + return(0); +} + + +/**********************************************************\ +* Send data UDP * +* - parameters : * +* - size of data * +* - pointer to data * +* - return 0 on success other value on error * +* * +* - side effects : * +* - close the socket on error * +\**********************************************************/ + +int AttachEnd(int psb){ + int i,i2,i3,ps; +//int PrevSPacket[4]; +//int PrevSData[4*32]; +//int PrevSSize[4]; + + ps=psb; + i2=0; + for (i=0;i<(UDPBackTrace-1);i++){ + if (PrevSPacket[i]) i2++; + } +// if (PrevSPacket[0]) i2=0; + if (i2){ + cpacketdata[0]+=8; + cpacketdata[ps]=(char)i2; + ps++; + for (i=0;i<(UDPBackTrace-1);i++){ + if (PrevSPacket[i]){ + cpacketdata[ps]=PrevSPtr[i]; + cpacketdata[ps+1]=PrevSSize[i]; + ps+=2; + for (i3=0;i3h_addr)); + strcat(hostname,blah); + } +} + +void UDPWait1Sec(){ + CounterB=60; + while (CounterB>0) + UpdateVFrame(); +} + +void UDPClearVars(){ + int i; + CounterA=-1; + RecvPtr = 0; + SendPtr = 0; + for (i=0;i<16;i++) + PrevSPacket[i]=0; + for (i=0;i<256;i++) + RecvFlags[i]=0; +} + +void UDPEnableMode(){ + UDPMode2=1; +} + +void UDPDisableMode(){ + UDPMode2=0; +} + +void WinErrorA2(void){ + char message1[256]; + sprintf(message1,"Failed waiting for checksum."); + MessageBox (NULL, message1, "Init Error" , MB_ICONERROR ); +} + +void WinErrorB2(void){ + char message1[256]; + sprintf(message1,"Failed waiting for confirmation."); + MessageBox (NULL, message1, "Init Error" , MB_ICONERROR ); +} + +void WinErrorC2(void){ + char message1[256]; + sprintf(message1,"Failed waiting for confirmation(B)."); + MessageBox (NULL, message1, "Init Error" , MB_ICONERROR ); +} + + \ No newline at end of file diff --git a/zsnes/srcinfo.txt b/zsnes/srcinfo.txt new file mode 100644 index 00000000..d93508af --- /dev/null +++ b/zsnes/srcinfo.txt @@ -0,0 +1,155 @@ + +(this part was written by zsKnight) + +File List/Information +--------------------- + +; Porting Routine Files + +-DOS- +ZLOADER.C ; Start-up C routines for DOS (Commandline parser, etc.) +DOSINTRF.ASM ; DOS Interface routines (File,video,timers,etc.) + +-WINDOWS- +ZLOADERW.C ; Start-up C routines for Windows (Commandline parser, etc.) +Winintrf.asm ; Windows Interface routines (File,video,timers,etc.) +winlink.cpp ; Win32 routines (DirectX, Win32 functions) +ztcp.c ; TCP/IP & UDP driver +copyvwin.asm ; Video Blitter for D modes + +; ---------------------------------------------------------------- +; The following are generally compiled for both ports, but they +; are not necessarily used by both +; ---------------------------------------------------------------- + +; General Stuff +MACROS.MAC ; Global Macro file (NEWSYM/EXTSYM global var control macros) +UI.ASM ; Start-up/initialization routines (env variables, cfg + ; loader, memory allocation, etc.) +INIT.ASM ; Emulation initialization routines (eg. memory map, emu + ; variables, etc.) +CFGLOAD.ASM ; ZSNES.CFG/ZSNESW.CFG file loading/parsing routines +PROCVID.ASM ; In-game video initialization/text displays/mouse routines/ + ; 8-bit palette/F3 menu routines +TABLE.ASM ; Generates the SNES CPU tables (but in an inefficient way) +TABLEB.ASM +TABLEC.ASM +STABLE.ASM +VCACHE.ASM ; Performs tile caching and also vframe initialization stuff +MENU.ASM ; F1 Menu routines +ENDMEM.ASM ; Where those large arrays go +ZFILE.C ; File Access Routines + +; ZSNES GUI Stuff +GUI.ASM ; Main GUI file +GUITOOLS.INC ; Simple tools for the GUI +GUIWINDP.INC ; GUI Window Display Routines +GUINETPL INC ; GUI Netplay Routines +GUILOAD INC ; GUI File Load Routines +GUIKEYS INC ; GUI Keyboard Input Routines +GUIMOUSE INC ; GUI Mouse Input Routines +GUICHEAT INC ; GUI Cheat Code Routines (search + regular codes) +GUICOMBO INC ; GUI Key Combo Routines +GUIMISC INC ; Misc GUI Stuff (Movie, Joystick setting (display) routines, + ; SNES Reset Function + +; DOS Specific stuff +VESA2.ASM ; VESA2 DOS Routines +VESA12.ASM ; VESA1.2 DOS Routines +ZSIPX.ASM ; IPX routines (DOS) +JOY.ASM ; DOS Joystick Drivers +COPYVID.INC ; Graphics blitter routines for DOS (copys screen to display) +INITVID.ASM ; Video Initialization routines (DOS) +DEBUG.ASM ; SNES Debugger routines +SW.ASM ; Sidewinder routines +SW32.ASM ; More Sidewinder routines (not sure which file is the real + ; one) +GPPRO.ASM ; Gamepad Pro routines (non-USB) +MODEMRTN.ASM ; DOS Modem routines + +; Graphics Enhancers +2XSAIMMX.INC ; Kreed's 2xSaI routines +2xSaI.cpp ; Kreed's Super 2xSaI routines +2xsaiw.asm ; 2xSaI for windows (without selector usage) +water.c ; Water Effect + +; SNES CPU Emulation routines +execute.asm ; Main emulation execution loop routines (includes save + ; states and in-game netplay routines) +SPC700.ASM ; SNES SPC700 Sound CPU emulation routine files +SPCADDR.INC +SPCDEF.INC +DSPPROC.ASM ; SNES Digital Sound Processor main emulation routines +DSP.ASM ; SNES Digital Sound Processor register routines +DMA.ASM ; SNES PPU DMA/HDMA routines +IRQ.ASM ; SNES 65816 IRQ routines (VIRQ/NMI) +MEMORY.ASM ; SNES Memory access routines + C4 routines (Sorry that I + ; didn't have these in a separate file since a small memory + ; hack of the C4 originated on this file and just grew and + ; grew) +E65816.INC ; 65816 emulation routines (w/o SPC700) +65816D.INC +E65816B.INC ; 65816 emulation routines (Debugger I think) +65816DB.INC +E65816C.INC ; 65816 emulation routines (w/ SPC700) - Sorry about these + ; 3 files. They used to be just 1 until I removed the + ; self-modifying code routines +65816DC.INC +SE65816.INC ; 65816 emulation routines (SA-1) +S65816D.INC +ADDRNI.ASM ; 65816 Non-incrementing addressing modes +ADDRNI.INC +SADDRNI.INC +ADDRESS.INC ; 65816 Incrementing addressing modes +ADDRESS2.INC +SADDRESS.INC +REGS.INC ; SNES I/O register emulation +REGS.MAC +REGSW.INC +REGSW.MAC + +; SNES PPU Emulation Routines +MAKEVID.ASM ; 8-bit old graphics engine +MAKEV16B.ASM ; 16-bit old graphics engine +MAKEV16T.ASM ; 16-bit old graphics engine (transparencies) +MV16TMS.ASM ; 16-bit old graphics engine (transp w/ Main+Sub enabled) +MODE7.ASM ; 8-bit mode 7 routines +MODE7.MAC +MODE7EXT.ASM ; 8-bit mode 7 EXTBG routines +MODE716B.ASM ; 16-bit mode 7 routines +MODE716T.ASM ; 16-bit mode 7 routines (transparencies) +MODE716E.ASM ; 16-bit mode 7 EXTBG routines +M716TEXT.ASM ; 16-bit mode 7 EXTBG routines (transparencies) +MODE716D.ASM ; 16-bit mode 7 Direct routines +mode716.asm ; Mode 7 16-bit new graphics engine routines +mode716.mac +NEWGFX.ASM ; 8-bit new graphics engine files +NEWGFX.MAC +NEWGFX2.ASM +NEWGFX2.MAC +NEWGFXB.MAC +NEWGFXWN.MAC +newgfx16.asm ; 16-bit new graphics engine files +newgfx16.mac +NEWG162.ASM +newg162.mac +NEWG163.MAC +NEWG16WN.MAC +VIDMACRO.MAC ; Generic Video Macros File +VIDMACRB.MAC + +; Special Chip Emulation Routines +FXEMU2.ASM ; Super FX emulation files +FXEMU2.MAC +FXEMU2B.ASM +FXEMU2B.MAC +FXEMU2C.ASM +FXEMU2C.MAC +FXTABLE.ASM +SFXPROC.ASM +DSP1PROC.ASM ; DSP1 communication routines +DSP1EMU.C ; DSP1 C routines (also includes some C4 C routines) +SA1PROC.ASM ; SA-1 processing routines +SA1REGS.ASM ; SA-1 registers, also includes S-DD1 and SPC7110 routines + + \ No newline at end of file diff --git a/zsnes/thanks.txt b/zsnes/thanks.txt new file mode 100644 index 00000000..152f9ed5 --- /dev/null +++ b/zsnes/thanks.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/zsnes/todo.txt b/zsnes/todo.txt new file mode 100644 index 00000000..8d880a34 --- /dev/null +++ b/zsnes/todo.txt @@ -0,0 +1,35 @@ +Some Issues : + +Windows Port: +- For some reason DirectDraw runs very slow on 3dfx cards. + Is this possible to fix? Or maybe implementing a glide mode would fix it. + DirectDraw blit routines are probably not handled in an optimal way +- DirectSound in ZSNESw doesn't support the primary sound buffer. + Unfortunately, this causes 8-bit quality sounds on certain computers. +- DirectInput seems to cause some systems to really slow down for some + odd reason. When those systems that are affected disables their joystick + from the control panel, the framerate suddenenly goes up from choppy to + smooth. +- VSync or triple buffering not implemented +- Glide,OpenGL, or Direct3D support would be nice +- .ZIPed files seems to not work on certain Win2K configurations +- Use another (free) compiler for the windows version (cygwin?) + +General +- Maybe add in Cubic Spline Interpolation to the SNES DSP Sound processor + (DSPPROC.ASM) since some people like the clarity of it compared to + Gaussian Interpolation (even though that's the method the real snes uses) + and also make a variable to select between those interpolations (If + someone can do this, I'll add an option to switch between them in the + GUI later) +- Clean up the makefiles (get rid of this ugly link.win32) +- ZSNES doesn't compile with nasm 0.98.08 because of problems with + the way it deals with loops + +Compatibility +- Game not working - Guikuden 1 (and some more) +- Graphics Glitches - Uniracers (2p mode), Killer Instinct (couple stages, + black background), FF3 (some sprite clipping probs), Metal Combat, + Tactic Ogre (Menus?) +- Special Chips - DSP1 (60% done), DSP2 (0% done), SA-1 (95% done), + SDD-1 (decompression left), and others  \ No newline at end of file diff --git a/zsnes/win/guinotes.txt b/zsnes/win/guinotes.txt new file mode 100644 index 00000000..b16e3e3f --- /dev/null +++ b/zsnes/win/guinotes.txt @@ -0,0 +1,493 @@ +Table of Contents +ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ +I. ) The Game Menu +II. ) The Quick Menu (Arrow Menu) +III.) The Config Menu +IV. ) The Cheat Menu +V. ) The MultiPlay Menu +VI. ) The Misc Menu + +---------------------------------------------------------------------------- + +Note : If any windows exists in the GUI field, pressing ESC always closes + the top-most window +Note : Pressing ESC when no window is active is equivalent to RUN. It will + not function if no game is loaded + +Notes on the filename box where you can manually type in the filename: + - Typing text into the box would automatically seek to the closest + matching filename in the box where the file selection cursor is located + - When you press enter with text in the box without any '\' or ':' in the + filename, ZSNES will first look for a directory matching the text and + changes its directory if one is found. Otherwise, it will load the + current file or directory highlighted by the selection cursor. + - You can type in the full filename or directory including path + (eg. d:\games\mario.smc) or the drive name (eg. d:) + +---------------------------------------------------------------------------- + +--------------------- +- I.) The Game Menu - +--------------------- + +Load : + Perform : Load File and Run + Usage : + Loading a File : + You can move through the list using either the mouse or the + keyboard. The keys for the keyboard are : + Up/Down - Move Up/Down through the list + Left/Right - Switch between the File and Directory Window + PageUp/PageDown/Home/End - Move through the list in larger + increments + A .. Z, \, : - Enters filename/directory into the load box + Enter - Load File or Change Directory (depending on which + window you are in) + Show all Extensions : This will force the GUI to show + all of the file extensions instead of the default (.SMC,.SFC,...) + +Run : + Perform : Runs the game + +Reset : + Perform : Resets the game, but asks user for confirmation first + +Save State : + Perform : Saves the state (Equivalent to default F2), but asks + user for confirmation first +Load State : + Perform : Loads the state (Equivalent to default F4), but asks + user for confirmation first + +Pick State : + Perform : Allows user to select the state position to use + (Equivalent to default F3) + +Quit : + Perform : Quits ZSNES + +---------------------------------------------------------------------------- + +----------------------------------------------- +- II.) The Quick Menu (Displayed as an Arrow) - +----------------------------------------------- + +Perform : Allows the user to quickly select the last 10 games loaded off + the GUI. Also allows the user to freeze/clear the list. + +Tip : You can create a favorites list by first clearing the list then + loading up all the games (last game loaded will be at the top) and + turning freeze on. + +---------------------------------------------------------------------------- + +------------------------- +- III.) The Config Menu - +------------------------- + +Input #1-#5 : + Perform : Allows user to select the input device and control + keys for each player + Usage : + Selecting an Input Device : + Using your mouse, move through the list of input devices + until the device of your choice is highlighted. From + there, click on SET and the input device you selected + should appear after CDV: (CDV = Current Device) + Changing default keys : + Click on the key which you want to change using your + mouse and then press the key or joystick button/pad + which you want to change it to. Pressing ESC disables + the game key. + Joystick 209h usage : + Some dual joystick cards support dual joystick ports + (port 201h and 209h) which allows for 2 6-button joysticks + or 2 different types of joysticks (sidewinder and a + standard joystick). If you have one of these, check + the 'Use joystick port 209h' box. If you do not have + a dual joystick/dual port card and if you check the box, + then the joystick will not work. + +Options : + Perform : Allows the user to select some in-game options + Usage : + Auto Frame Rate - Enables Auto Frame Rate + Frame Skip - (Shown when Auto Frame Rate is disabled) + Sets the constant frame skip value used when a game plays + Max Frame Skip - (Shown when Auto Frame Rate is enabled) + Sets the maximum allowable frame skip in auto framerate mode + New Gfx Engine - Enables/Disables the New Graphics engine + in 256 color modes or 320x240x65536 mode + VSync - Enables vertical sync wait to reduce sheering of the + screen. Requires a very fast computer. + MMX Copy - Enables MMX Copying routines for a slight speed + increase (MMX processors only) + Use Pl1/2 as Pl3/4 - Allows the user to use 2 devices for 1 player + such as the keyboard and the joystick. (set keyboard as input + device 1 and joystick as input device 3). This, however, disables + multitap support + Sidewinder Fix - Click this when your sidewinder doesn't work + after disabling the sidewinder profiler and pressed the + mode button twice + FPS at Start - Checking this would make the FPS appear whenever + you start ZSNES + Use 30Hz for Turbo - When activated, Turbo will change at 30hz NTSC + or 25hz PAL. Otherwise, Turbo will change at 60hz NTSC or 50hz PAL + Enable Game Clock - Enabling this will show the system clock on-screen + Toggled Fast Fwd - Checking this will change the way how the fast forward + button functions. Having it checked will cause it to act as a switch + and having it unchecked will cause it to act as a push button. + SRam Check+Save - This will enable automatic Save Ram write detection and + save the sram (.srm) to disk approximately 10 seconds after. + Old Gfx Mode 2 - This will enable the Old Gfx Engine Mode 2 which fixes + many transparency bugs that currently plagues ZSNES in the current + engine, however, it also creates some new ones. This mode can be + slower at times so it's recommended that you only turn it on when + you need it. + Start at Latest Save - Checking this will automatically set the + save state pointer (F3 Menu) to the most recently saved location + whenever you load a rom image. + Auto State Save/Load - Enabling this will allow ZSNES to automatically + re-load the state whenever you return back to the game after a + proper exit. + Don't Save Current Path - This will prevent ZSNES from changing the + current start-up game path in the configuration. You can + access this in Config->Options. + Disable Sound CPU Emu - Selecting this would disable the SPC700 chip + that controls the sound. Using this would speed up emulation, + but the drawback is that you won't have sound and the gane + compatibility rate would be lower. +Add-ons: + Perform : Changes the current special input selected for the game + Usage : + None - Uses the regular snes controllers + SNES Mouse at Port #1 - Emulates the SNES mouse at controller port #1 + SNES Mouse at Port #2 - Emulates the SNES mouse at controller port #2 + Super Scope - Emulates the SNES Super Scope + Lethal Enforcer Gun - Simulates the mouse movements for Lethal + Enforcers 1 + +Video : + Perform : Changes the current video mode and sets some options + Usage : + Changing the video mode - Use the mouse to select the video mode + and click 'SET'. When the video mode changes and if the result + doesn't look right, wait for 10 seconds without pressing any key + or button and the display will return to the previous one. + Scanlines - Only available in 256x256x256 and VESA2 640x480 modes. + This mode adds a blank line in between every line to produce + a scanline effect similar, if not exact, to a TV. + Eagle Engine - Only available in VESA2 320x240x256. Setting + this would enable the Eagle Engine designed by Dirk Stevens + which basically locates 3 similar colored pixels together + and places a small dot in between to smooth out some graphics. + Interpolation - Only available in VESA2 640x480x65536. Setting + this enable interpolation which basically blends all the + inbetween colors to produce a blurry effect. However, this + slows down emulation. + Full Screen - Only available in VESA2 320x240 and 640x480 modes. + Setting this would scale the image to fit the screen. This, + however, slows down emulation. + Small Screen - Only available in VESA2 640x480 modes. Setting + this would display the image in a small, centered screen. This + greatly improves performance in 640x480 modes. + 50% Scanlines - Only available in 640x480x65536 video mode. This + will enable scanline mode except that each line is 50% darker than + the line above it. + 25% Scanlines - Only available in 640x480x65536 video mode. This + will enable scanline mode except that each line is 25% darker than + the line above it. + 2xSaI Engine - Setting this would enable Kreed's 2x Scale Advanced + Interpolation engine. + Super Eagle - Setting this would enable Kreed's Super Eagle engine. + Super 2xSaI Engine - Setting this would enable Kreed's Super 2x Scale + Advanced Interpolation engine. This mode would require a lot of + cpu power since it is written in C. + Triple Buffering - This will enable Triple Buffering if it is available + on your VESA drivers/Video Card. If it isn't available, then Zsnes + will use simulated Triple Buffering which is slower, but still does + the job. Note that Triple Buffering will not work with 2xSaI/Super + Eagle. + Hi-resolution Mode 7 - Enabling this would activate high resolution + mode 7 whenever standard mode 7 is used within a game. This mode + is only available in video modes that support it. + +Sound : + Perform : Allows user to change the sound configurations of ZSNES + Usage : + Enable Sound - Setting this turns on the sound + Stereo Sound - Enables Stereo Sound (Noticably slower though unless + you have a fast cpu) + Sound Rate - To change the sound rate, just click on the box + containing the value to rotate through all the + possible values. + Volume Level - To change, just slide the bar + Disable Noise Sim. (Disable Noise Simulation) - Setting this will + disable the noise filter which corrects many sound effects in + certain games, but will also ruin some others. + Surround Sound - Enables simulated 2 speaker surround sound + Sound Interpolation - Enables Sound Interpolation which smoothes out + the wave forms of lower frequency sounds + Reverse Stereo - This function swaps the L & R volume levels + in stereo mode + Low Pass Filter - The Low Pass Filter, when enabled, will produce + better bass in certain sound effects. However, the side effect + is that the sound will overall be more muffled. + +---------------------------------------------------------------------------- + +----------------------- +- IV.) The Cheat Menu - +----------------------- + +Add Code : + Perform : Enter Cheat Code Window and Set the keyboard cursor + on the cheat code entry box + Usage : Type in the code in either Game Genie, Pro Action Replay, or + Gold Finger format, press enter, then enter the description. + Note : Be sure to include the '-' when entering Game Genie codes + Note : You can also quickly modify the value of the currently selected + cheat code (in the browse window) by typing a 2 digit hex number + in the cheat code enter space + +Cheat Code Reflector - What this feature does is that it allows a value + of one cheat code to be mirrored from a value of another cheat code. To + enable this option, type an 'R' at the end of any cheat code as the + destination, then type another cheat code (Without the 'R') as the source. + For example, if you want address 7E1000 to reflect the value at address + 7F2000 (Whatever value written to 7E2000 from the game will also be + written to 7E1000), enter cheat code 7E1000FFR, then cheat code + 7F2000FF (where FF can be any value). + +Browse : + Perform : Enter Cheat Code Window and Set the keyboard cursor at the + browse box + Usage : Move through the list using either the mouse or keyboard and + select the cheat code you want to modify. Then click on the + buttons to the right or type in the key of the first letter + of the action. + Actions : + Toggle - Turns a cheat code on or off + Remove - Deletes the cheat code off the list + Save - Saves the current list into a .cht file which will + be located in the save directory + Load - Loads a previously saved list + Fix - Clicking this fixes some cheat codes that don't work, + but it will not always work + You can also toggle a cheat code on or off by double clicking on + them. + +Search : + Perform : Allows you to search for values in memory such as life, score, + etc. and allows you to change their values to your own preferred + choice. + Usage : + Select Size : You can choose what data size to search for. If you + know the numerical values of the data you're going to select, + select the smallest number range that fits the data values. + (eg. If you know the value cannot go higher than 50000, then + select 2 BYTES (0..65535) instead of 3 BYTES (0..16777215)). + Sometimes, you don't know the numerical value (in the case of + life bars) and you'd have to guess the size. + Select Format : DEC (Decimal, 0 .. 9), HEX (Hexadecimal, 0 .. F) + Most of the time, it's recommended that you'd use decimal, although + there are some cases that the values in memory are sometimes stored + as hex. + Search Type : + Exact Value Search - In this mode, you have to enter the exact + numerical value that you want to search for. Such as if you + have 3 lives left, then search for the value 3. The cheat + search engine also looks for value - 1 since even if a game + tells you that you have 3 lives left, it stores the value as + 2 in memory. + Comparitive Search - In this mode, you select whether the value + is less than, greater than, equal to, or not equal to the + previous value. Such as if you have a life bar and if the life + bar suddenly goes down, go back to the cheat search engine and + select less than to search for any value that has been decreased. + +---------------------------------------------------------------------------- + +------------------------ +- V.) The NetPlay Menu - +------------------------ + +Modem Mode : + +NOTE #1 : DOS Compatible modem is REQUIRED! + If you don't know your modem settings and you're in win95/98, go to + Control Panel -> System -> Device Manager -> Modem and select + your modem. Then click on your resources tab and the settings should + be there. + + 1.) Dial Menu - Allows you to enter the phone number to dial and then + dials and connects + 2.) Wait for Ring - Waits for ring + 3.) Config Modem - Allows you to configure your modem : + ComPort, IRQ, Baudrate - Sets your modem settings + Use Fossil Driver - Set this option if you want + ZSNES to use your a fossil driver. If you don't + know what a fossil driver is, just leave this + option unchecked and pretend it doesn't exist. + 4.) Manual - Allows you to connect manually through the terminal. + However, if both remote and local users select manual, + the player numbers will not be assigned. + +IPX : + + IPX mode currently connects at the first remote connection it detects. + This will probabily change in the future if there is a demand. + +Chat Mode : + + Latency - The lower the number, the better the control response time. + But setting it too low can cause a lot of frame skip problems. + This value should vary depending on the traffic of the connection + you are using. A value of 2 or 3 is recommended for modem. The + value for IPX varies. Latency is basically the amount of time + between a user input and that input being affected in the actual + game. The delay should be higher than the time it takes for data + to move from one end to the other. Latency value of 1 is + equivalent to 1/30th of a second on NTSC games or 1/25th of a + second on PAL games. + Player # boxes - This will allow you to select up to a 5 player multiplayer + game. Anything that is checked will be controlled locally + starting from player 1 as the lowest checked player. Anything + marked with an X will be controlled remotely. + For example, if players 2,3,5 are checked and 1,4 are X'ed : + local player 1 will control player 2 + local player 2 will control player 3 + local player 3 will control player 5 + remote player 1 will control player 1 + remote player 2 will control player 4 + +---------------------------------------------------------------------------- + +---------------------- +- VI.) The Misc Menu - +---------------------- + +Game Keys : + Perform : Allows user to change the game keys to their own preference + Usage : + Click on the key which you want to change using your + mouse and then press the key or joystick button/pad + which you want to change it to. Pressing ESC disables + the key. + +GUI Options : + Perform : Allows the user to customize some of the GUI + Usage : + Mouse Wrap - Allows the mouse pointer to wrap at the borders of the + screen + Mouse Shadow - Disables/Enables the Mouse Shadow + Keep Menu Positions - When enabled, re-entering the GUI from the + game does not automatically enter the Load Menu, but + the previous menu which you were on when you last exit + the GUI + Save Window Positions - When enabled, the GUI doesn't reset the locations + of the windows when you exit/enter the GUI + Click Enters/Exits GUI - When enabled, it allows the right mouse button + to automatically run and exit the game to the GUI. This + however, slows down emulation by a bit since it has to + check the mouse button status once in a while. In the + windows port, the right click button won't return back + to the game. + Use JoyPad1 to Control - When enabled, it allows Player 1's device + to be used to move through the GUI. This is mainly used + if you want to use your joystick in the GUI. The equivalent + SNES keys to the Keyboard keys are : + + SNES ControlPad = Move + SNES A = Enter + SNES B = ESC + SNES L = PageUp + SNES R = PageDown + Enable Water Effect - Enables the water effect in the GUI background + Enable Snow Effect - Enables the snow effect in the GUI background + +Key Comb. (Key Combination Editor) : + Perform : Allows you to specify certain keyboard combination routines + with a single keystroke/joystick button press. + Usage : + Description - Allows you type in the description of the combination key + Key - Clicking on this box will allow you to select which key/button to + use + Combination Keys - this window will display the sequence of events + selected by the user + P# - Selects which player # to use those keys as + > = Last - Enabling this would mean that the event symbol > will + mean the last left or right direction the user presses in the game and + the symbol < is the opposite of that direction. When disabled, > means + right and < means left. + Game Specfic (Game Specific) - Enabling this will tell Zsnes to use + separate Key Combination files for each individual game. + Clear - Clears the current key combination field + Add - Adds the key combination fields below as a new entry + Replace - Copies the contents of the key combination fields below + to the current highlighted key combination above + Delete - Deletes the highlighted key combination above + Events: + Press+Rel - The key will be pressed and held. It will be released + once another key is pressed after any amount of frame or second + delay. + Press Only - The key will be pressed and held + Rel Only - The key will be released if it is Pressed + by a pressed only event + Frame Delay - Delays for the specified number of frames + Second Delay - Delays for the specified number of seconds + Del - Deletes the event at the end of the Combination Keys list if + one exists + Note : A 1 frame delay exists after the combination key list has finished + processing + + Example Key Combination: (Down / Down+Right / Right / L) : + Method 1: + Press+Rel Down / 2 Frame Delay / Press+Rel Down / Press+Rel Right / + 2 Frame Delay / Press+Rel Right / 2 Frame Delay / Press+Rel L + Method 2: + Press Only Down / 2 Frame Delay / Press Only Right / 2 Frame Delay / + Rel Only Down / 2 Frame Delay / Rel Only Right / Press Only L + +Movie Options : + Perform : Allows you to record SNES Movies so that you can play them + back at a later date either to amuse your friends, torture + your friends, or whatever. Just don't play anything in + front of your enemies since they might break your computer. + Usage : + Movies are saved as .ZMV, .ZM1, .ZM2, etc. files. They should be + located in the same directory as your save files. A movie file + consists of a save state file, saveram data, and the recorded + controller data. The initial filesize of a .ZMV file is the + combination of a .zst and a .srm file (around 300kbytes) and + it averages around 7kbytes/minute (value varies) or 420kbytes/hour. + + You can record : + - Standard 1/2 player games + - 3-4 player Multitap games + - SNES Mouse games + - Network/Modem games + You cannot record : + - Super Scope Games + + GUI Usage : + Record - Begins recording the movie file + Play - Begins playing the movie file + Stop - Stops the movie process + The numbers at the right side selects which movie file to play/record. + + NOTE : Movies recorded without sound cannot be played when sound + is enabled and vice versa + NOTE : Loading another game, loading a state, or resetting the + game will halt the play/record process + NOTE : When you play a movie file, the SRAM data becomes invalid and + ZSNES won't save it until you load a game. This way, you don't have + to worry about your save ram when you load up a movie file. + +Save Cfg : + Perform : Saves the configuration files + +About : + Perform : Just displays the version # and the authors of ZSNES + + \ No newline at end of file diff --git a/zsnes/win/readme.txt b/zsnes/win/readme.txt new file mode 100644 index 00000000..23809d1a --- /dev/null +++ b/zsnes/win/readme.txt @@ -0,0 +1,492 @@ + + ZSNES + by zsKnight, _Demo_, and Pharos + http://www.zsnes.com + + +ZSNES is a Super Nintendo Entertainment System emulator written mostly +in assembler. + +We would really like to thank the snes9x team for all their help and +also for an excellent snes emulator. We also wish them the very best +of luck! + +--------------------------------------------------------------------------- +Table of Contents +--------------------------------------------------------------------------- + +1.) What's New +2.) Disclaimer +3.) System Requirements +4.) Things you should know about ZSNES (Updated v1.00) +5.) Current Progress +6.) Future Progress +7.) ZSNES Default Keys +8.) Extra Pop-Up Menu (F1 Menu) +9.) Configuration File (ZSNES.CFG) +10.) Cheat Codes +11.) Extra Features (SNES Mouse/Super Scope/SuperFX/DSP1/MultiTap/IPS) +12.) Bugs Section +13.) Contact Information +14.) The Debugger +15.) Error Codes +16.) Credits + +--------------------------------------------------------------------------- +1.) What's New +--------------------------------------------------------------------------- + +See WHATSNEW.TXT + +--------------------------------------------------------------------------- +2.) Disclaimer +--------------------------------------------------------------------------- + +zsKnight, _Demo_, and Pharos are not responsible for any damages caused +by the use of this software. This software also must not be distributed +with ROMs. + +--------------------------------------------------------------------------- +3.) System Requirements +--------------------------------------------------------------------------- + +- Fast Pentium processor strongly recommended +- 32MB of RAM +- Windows 95/98/ME/2000 or compatible +- DirectX 7.0 or higher + +Recommended System for SFX support : + +- Fast Pentium processor (P200 - P2-300 (depending on the game)) +- 32MB of RAM +- Windows 95/98/ME/2000 or compatible +- DirectX 7.0 or higher + +Recommended System for SA-1 support : (Mario RPG) + +- Fast Pentium processor (P200 or higher) +- 32MB of RAM +- Windows 95/98/ME/2000 or compatible +- DirectX 7.0 or higher + +*An FPU is required for DSP1 emulation +*You can download directx at www.microsoft.com/directx/ + +--------------------------------------------------------------------------- +4.) Things you should know about ZSNES +--------------------------------------------------------------------------- + +- You can use both keyboard and joystick for player 1 or 2 with some + configuration adjustments. Refer to zsnes.faq for details +- Several special chip emulation (SA-1) have unknown bugs to + them +- SuperFX can be slow because it is an extra 10/20mhz cpu that has to be + emulated as well as the snes emulation +- Screen Snapshot and FPS counter are available through a menu by pressing + F1 during emulation +- Screen Snapshot currently saves as Image.PCX (256 colors) and Image.BMP + (65536 colors). This may change in the future. +- FPS counter currently only works when auto frame rate is on. +- To use the cheat function, be sure to have the ROM which you want to + patch loaded already. +- If the cheat codes do not work, chances are that you are using a different + version of the rom that was originally used to create them or the codes + are converted incorrectly from other code formats. +- There are still many bugs left in ZSNES so don't expect it to run all + your favorite games. +- SNES Mouse support is still missing some features such as speed settings +- Pressing the Fast Forward key is equivalent to running ZSNES using -f 9 +- If ZSNES doesn't work for you, then don't use it. Use SNES9X, NLKE, + SNEESE, or SNEMUL instead! In fact, even if you use ZSNES, + use those emulators too! + +--------------------------------------------------------------------------- +5.) Current Progress +--------------------------------------------------------------------------- + +The following are implemented : +- complete 65816 instruction set +- SRAM support +- LoROM and HiROM support +- SlowROM and FastROM support +- Full DMA support +- HIRQ/VIRQ/NMI Interrupts +- Support for most snes file formats +- Multi file format support (.1,.2,.3,A.,B.,C.) +- Interleaved format support +- PAL/NTSC timing support + +The following are implemented in the new graphics engine 8 bit : +- Combination of line by line and tile based graphics engine +- Graphic Modes 0,1,2,3,4,5,6,7 +- 8x8, 16x16, 32x32 and 64x64 sprite support (flipped in all directions) +- 8x8 and 16x16 tiles +- 32x32,64x32,32x64,64x64 tile modes +- Full HDMA effects for wavy backgrounds, interesting mode 7 effects, etc. +- Mode 7 rotating and scaling effects +- BG priorities +- Sprite Priorities +- Add/sub of back area +- Mosaic Effects +- Offset per tile mode (mode 2/vertical only) +- High res 512 resolution and 448/478 vertical resolution +- Windowing effects +- High res Mode 7 (only in 640x480x256 video mode/disable Eagle/Scanlines) + +The following are implemented in the old graphics engine : +- Line by line based graphics engine +- Graphic Modes 0,1,2,3,4,5,6,7 +- 8x8, 16x16, 32x32 and 64x64 sprite support (flipped in all directions) +- Mosaic effects +- 8x8 and 16x16 tiles +- 32x32,64x32,32x64,64x64 tile modes +- Full HDMA effects for wavy backgrounds, interesting mode 7 effects, etc. +- Mode 7 rotating and scaling effects +- Single and Dual Windowing Routines +- BG priorities +- Sprite Priorities +- Add/sub of back area +- 16-bit graphics support +- offset per tile mode (mode 2/vertical only) +- High res 512 horizontal resolution (missing in 16x16) + +Following are present in 16-bit graphics mode : + +- Palette changing in the middle of a screen +- Screen Addition (full and half) +- Screen Subtraction (full) +- Fixed Color Addition/Subtraction +- Window clipping for Fixed Color + +The following are implemented in the new graphics engine 16 bit : +- All of old graphics engine 16bit +- Combination of line by line and tile based graphics engine +- High resolution mode 7 +- High resolution 16x16 tiles for mode 5 +- full 15bit color transparencies (instead of the previous 13bit speed + hack) for improved picture quality (MMX compatible CPUs only) + +The following are present in sound : + +- 16bit digital stereo sound +- SPC700 Sound CPU +- DSP Sound Processor + - Echo Effects + - FIR Filter + - ADSR volume effects + - GAIN volume effects + - Noise effects + - Pitch Modulation + +The following are extra features emulated : + +- Super NES Mouse Support +- Super NES Super Scope Support +- SuperFX support (Still has a bug or 2 left) +- MultiTap (Multiplayer 5) support (4 players on a single computer, 5 players + remote (ipx/modem)) +- DSP1 emulation (not complete) +- SA-1 emulation (not complete) + +The following are the features present in ZSNES : + +- Game State Save (F2=Save, F3=Select, F4=Load). + Warning : A state file takes 260 kbytes of HD space! +- Auto frame rate to give you constant Super Nintendo speed up to 9 + frame skips +- configuration file support (ZSNES.CFG) +- 2 player support w/ Joystick and Gamepad support + +The following features are missing : + +- Pseudo 512 snes horizontal resolution + (Haven't seen any game that uses them yet) +- Some modes in Offset Per Tile Mode +- Some Direct Color Modes (Haven't seen any game that uses them yet) + +What will not run (or not play properly) : + +- Some Super FX games such as Dirt Trax FX or Winter Gold (causes instability) +- DSP1 games such as Pilotwings +- Games with other special chips such Street Fighter Alpha 2, Star + Ocean (S-DD1), and Far East of Eden 2 (SPC7110) +- Games which doesn't have a valid header +- Games that hit a severe bug in the 65816/PPU/SPC700/DSP routines +- Games that require special timing + +--------------------------------------------------------------------------- +6.) Future Progress +--------------------------------------------------------------------------- + +This section is removed + +--------------------------------------------------------------------------- +7.) ZSNES Default Keys +--------------------------------------------------------------------------- + +Here are the default keys while running the emulator. They can be changed +through the GUI except for F1 and ESC : + +Disable Backgrounds 1,2,3,4 = 1,2,3,4 +Disable Sprites = 5 +Panic Key (enable all) = 6 +Enable SNES Mouse/SuperScope = 7 +Enable New Graphics Engine = 8 +Disable Windowing = 9 +Disable OffsetMode = 0 +Fast Forward Key = ~ +PopUp Extra Menu = F1 +Save State = F2 +Switch State = F3 +Load State = F4 +Disable Sound Channel = F5 - F12 +Quit = ESC + +Here are the default keys for the game play (unless modified through the GUI): + +Player 1 : + +Up,Down,Left,Right : Cursor Keys +A,B,X,Y : X,Z,S,A +L,R : D,C +Start, Select : Enter, RShift + +--------------------------------------------------------------------------- +8.) Extra Pop-Up Menu (F1 Menu) +--------------------------------------------------------------------------- + +Save Snapshot - Saves a snapshot as either .PCX (8-bit color) or .BMP + (16-bit color) + +Show/Hide FPS - Shows or hides the frame per second display which appears + on the bottom-left corner of the screen. This can only + be enabled in auto-frame rate mode. + +Save SPC Data - Selecting this will search for the beginning of the next + song and save the data into a .spc file which saves it + similarly as a .srm file. To capture a song, it is best + recommended to initiate this feature approx 2 seconds + before the next song starts. This does have potential to + fail though so don't expect it to work all the time. + Also, this feature doesn't work in the new gfx engine. + +Sound Buffer Dump - This dumps the sound buffer in zsnes and also filters + out any unoccupied space. The sound buffer contains + decompressed samples which are written to when zsnes + plays/decodes a sample from sound memory. Because of the + way zsnes buffers the sound data, this can produce + inaccurate results. + +Snapshot/Increment Frame - Same as snapshot, but it returns to the F1 menu + after a couple frames. Useful for making animations. + +--------------------------------------------------------------------------- +9.) Configuration File (ZSNESW.CFG) +--------------------------------------------------------------------------- + +Almost everything in zsnes.cfg should now be editable through the gui + +--------------------------------------------------------------------------- +10.) Cheat Codes +--------------------------------------------------------------------------- + +Currently, ZSNES supports Game Genie, Pro Action Replay and GoldFinger codes + +Here are the steps to get the codes working : + +1.) Load the ROM which you want to patch +2.) Exit to the GUI, enter the code of your choice in the cheat menu +3.) After that, you may have to RESET the game to get the cheat code to + work. Sometimes, it is not necessary. You also may have to click + on the FIX button. + +NOTE : Some cheat codes are meant to be for different versions of the game. + If a cheat code doesn't work and there is one for both Game Genie + and Pro Action Replay, try them both. + +--------------------------------------------------------------------------- +11.) Extra Features (SNES Mouse/Super Scope/SuperFX/DSP1/MultiTap) +--------------------------------------------------------------------------- + +To Enable SNES Mouse, Press 7 once for 1st player and twice for 2nd player +To Enable SNES Super Scope, Press 7 three times +To disable either one, either press 6 or press 7 until you see a disable + message onscreen. + +Here are the controls for the Super Scope : + + Fire = Left Mouse button + Cursor Mode Button = Right Mouse button + Pause = Backspace Key on keyboard + Enable/Disable Autofire = =/+ key on keyboard, should be located to the + left of the backspace key + +DSP1 is enabled automatically. Currently, it runs mario kart and some other + games, but it does not run pilotwings due to a lack of dsp1 functions + that are implemented. + +Zsnes auto-detects the SFX emulation from the header and enables it when + found. Also, take note that the SFX is an additional 10Mhz(Ver1) or + 20Mhz(Ver2) chip which also has to be emulated with the snes and will + most likely produce a very noticeable slow down in emulation if you + don't have a fast computer. + +Sometimes, the Multitap isn't compatible with some games. If that happens, + disable Multitap by setting Player3,4, and 5's input device to 'None' in + the GUI + +IPS patcher : + Rename your .IPS file to the rom filename with the .IPS extension + (eg. If your rom is SD3.SMC and your rom is SD3V05.IPS, rename SD3V05.IPS + to SD3.IPS) + and ZSNES will patch the rom realtime without modifying the rom file's + contents. + +--------------------------------------------------------------------------- +12.) Bugs Section +--------------------------------------------------------------------------- + +- 65816 lacks correct timing. Although ZSNES bases the timing on a + variable cycle/instruction, it does not deduct correct values such + as 16bit instructions should deduct 1 more cycle than 8bit instructions. + 100% cycles of zsnes isn't 100% cycles of a snes because of that. + This means that a lot of games either won't run or will produce horrible + displays. Sometimes adjusting the % of execution can fix those problems. + This is due to inaccurate documentation used when the 65816 was written. + There is no plans on re-writing the 65816 timing yet. +- Games sometimes tend to not display things properly because of graphic + features that aren't implemented yet +- The Sound DSP chip still has its bugs (not many though) + +--------------------------------------------------------------------------- +13.) Contact Information +--------------------------------------------------------------------------- + +The ZSNES homepage is located at : http://www.zsnes.com + +If you have any questions about zsnes and you have read ZSNES.FAQ, +README.TXT, and GUINOTES.TXT to make sure the answer isn't there. +And your question is NOT a ROM Request or asking about a newer +version, you can post your question at the zsnes www board located at : + +http://www.zsnes.com/board/ + +Remember : This board should be mainly used for zsnes related questions. +ROM requests (or asking for games, a link to a rom site, or where to +find them) are forbidden!!! Be sure to also read the RULES! +The rules are located at the top of the page. + +If you wish to contact the authors, you may contact them through : +(Remember - No ROM requests please! and don't send any files without + permission!) + +zsknight@zsnes.com +_demo_@zsnes.com +pharos@zsnes.com + +Try not to send a copy of your e-mail to all of us since that will just + waste our time. Also, don't expect to get a reply since we are often + busy. + +--------------------------------------------------------------------------- +14.) The Debugger +--------------------------------------------------------------------------- + +Note : The debugger is disabled when you don't enter zsnes with a -d + +Here are the keys: + +1 : Enable/Disable spc700 display +2 : Enable/Disable 65816 display +T : Trace (in 65816 opcodes) +B : 65816 break point +S : SPC break point +C : Clear Counter +M : 65816 modify +A : SPC modify +D : Debug Dump (SPC/DSPRam Dump Only) +W : Break at signal (Used only by the programmers) +F1 : Exit debugger and return to Game +F2 : Save State +F4 : Load State +ESC : Exit entire program + +--------------------------------------------------------------------------- +15.) Error Codes +--------------------------------------------------------------------------- + +-blank- + +--------------------------------------------------------------------------- +16.) Credits +--------------------------------------------------------------------------- + +ZSNES uses NASM, DJGPP, WDOSX, and CWSDPMI (source codes & binary updates + located at http://www.dbit.com/pub/cwsdpmi ) as the compilers and dos + extenders. Thanks to those who produced these fine programs! + +Special thanks to wnelson! Without him, ZSNES would have never existed! +Also to Y0SHi for his excellent snes docs, his help, and his excellent + support! + +Also Thanks to : + The_Teach of snes9x for some great info and the nice chats! + Trepalium of snes9x for some great info and help! + Gary of Snes9x and Steve Snake of KGen for being the source of info for + sound decompression! + Gary of Snes9x for being the source of info for TCall/PCall and also + for lots of help! + MrGrim for his great support! + Crono for info on Sound Blaster Programming, Surround Sound, Sound + Interpolation, and other sound stuff! + Aquis for the zsnes logo! + Alucard for helping us with an issue in the 65816! + Vertigo for making a compatibility list! + EFX for being a great supporter and also giving a lot of help and stuff! + Zophar for being a great supporter and also maintaining the mirror site! + Chris Hickman for redesigning the ZSNES web page! + CSoft for hosting our web page! (www.csoft.net) + Marius Fodor for the code for VSync, Sidewinder, Gamepad Pro, and some + optimisation info! + Sardu for some great info and help! + Lord Esnes for some great help! + Robert Grubbs for the sidewinder info! + Nerlaska for some useful info on optimising and also for some help! + Diskdude for writing sneskart which we used for the info on cheat codes! + DarkForce for some great help! + Pharos for some keyboard coding help! + Ivar and Gary of the snes9x team for all the great help which includes + their superfx info and code, DSP1 info, info on interleave formats + (hirom & superfx), offset per tile mode, FIR filter, some spc700 + and hdma bugs! + WolfWings ShadowFlight for help on several issues of nasm! + Wildfire for some help! + A CoolMan for the algorithm for EAGLE! + X-Sykodad and darklore for maintaining the ZSNES www board! + Neill Corlett for some info on the .IPS format and also helping out + a lot on improving the sound engine! + Kreed (derek-liauw@usa.net) for the 2xSaI and Super Eagle Source Codes! + 2xSaI homepage: http://members.xoom.com/derek_liauw/index.html + Markus Oberhumer & Laszlo Molnar for the UPX compression utility + UPX homepage: http://cdata.tvnet.hu/~ml/upx.html + Jean-loup Gailly, Mark Adler, and Gilles Vollant for the unzip routines! + Kode54 for the low pass filter routines! + Andy Goth for some help on the design of the key combination engine! + Yamaha of XYZZ (Scott Scriven) for his water effect code + Yamaha's homepage: http://www.VIS.colostate.edu/~scriven/) + All those people who helped us by either sending us docs, + helping us, supporting us, and reporting bugs! + Special Thanks to : Ashley, Barubary, CyberWarriorX, DCX, DooMStalK, + Fanwen, GreenImp, Hucard, Kaiden, Stalphos Knight, Star Creator, + TeleKawaru, the people in #zsnes efnet, and the regulars of the + ZSNES message board! + And also to all those whom we forgot! + +Special Thanks to all our beta testers for being a great help! +Info on 256x256x256 scanlines mode is from the MAME source. Thanks to + those behind MAME! + +Also, good luck to all those who are writing emulators, especially those + who are writing snes emulators, including Snes9x, Nlke, SNEeSe, and + SNEMul! And also good luck to the makers of TheSE! + \ No newline at end of file diff --git a/zsnes/win/zsnesfaq.txt b/zsnes/win/zsnesfaq.txt new file mode 100644 index 00000000..67ceda76 --- /dev/null +++ b/zsnes/win/zsnesfaq.txt @@ -0,0 +1,374 @@ +_[ ZSNES Windows Frequently Asked Questions ]______________________________ + +[GENERAL ISSUES:] + +Q: Why does ZSNESw crash and give me an error with dinput.dll? +Q: Why do I get a black (or corrupted) box when I start up ZSNESw? +Q: Why in the GUI under Config/Options are some of the choices gone? +Q: How do I use CD-ROMs with ZSNESw? +Q: Why is netplay choppy/slow? + + +[SOUND COMPATIBILITY ISSUES:] + +Q: Will ZSNES Windows be able to use my sound card now? It wouldn't work + for me in the DOS version. +Q: How come I don't get any sound? +Q: ZSNES Windows tends to have some static when playing games is there any + way to remove it? +Q: How come stereo is reversed? + + +[VIDEO ISSUES:] + +Q: Why do I get a dark line every quarter inch roughly on my screen when I +Q: In the Video section where I set my resolution what do those letters + stand for to the right of the resolution? +Q: Will ZSNES Windows support a 3DFX graphics mode? +Q: Are there transparencies in ZSNES? +Q: How come the graphics are really screwed up? + + +[GAME COMPATIBILITY ISSUES:] + +Q: Why doesn't *name of game* work on ZSNES? +Q: Can you get *name of game* working by the next release? +Q: Why is *name of game* not working in v.*version #* of ZSNES? It was + working before. +Q: When do you think you will emulate the *DSP/SFX chip? My favorite game + *name of game with chip* won't run without it. +Q: This game tells me that it is not compatible with the MultiTap (or an + external device attached). What should I do? +Q: How do I improve the compatibility of ZSNES? +Q: Why am I experiencing problems with Chrono Trigger? +Q: Why doesn't Pilotwings/Star Ocean/Street Fighter Alpha 2 work? +Q: Can you guys get Pilotwings/Star Ocean/Street Fighter Alpha 2 to work? + + +[SPEED ISSUES:] + +Q: Why is ZSNES slow? +Q: Can you please make ZSNES faster? +Q: Can you implement dynamic recompilation into ZSNES? +Q: Why does the game slow down even though I'm using auto frame rate and + the FPS is pretty high? + + +[[KEYBOARD/JOYSTICK ISSUES:] + +Q: Will ZSNES Windows now be able to use my Windows Joystick/Gamepad? +Q: Why can't I press more than 2 keys at a time? +Q: How come my joystick keeps holding in one direction? +Q: How do I use both my Keyboard and Joystick for the 1st player? + + +[CHEAT ISSUES:] + +Q: How come the game genie codes don't work? +Q: How do I use .CHT files? + + +[FREEZING/CRASHING ISSUES:] + +Q: When I load a ROM, how come ZSNES crashes? + + +[MISC:] + +Q: How does the auto .IPS patching feature work? +Q: Where do I get the games? + + +_[ GENERAL ISSUES ]________________________________________________________ + +Q: Why does ZSNESw crash and give me an error with dinput.dll? + +A: If you get this error, download and install the latest version of DirectX + which is located at www.microsoft.com/directx + If you already have the newest version of directx installed for + a while, try re-installing it (and make sure that you're installing + DirectX v7.0a or higher). + +Q: Why do I get a black (or corrupted) box when I start up ZSNESw? + +A: First of all, make sure that you have the latest version of DirectX + installed (see above question). If that didn't help, then check + your desktop color settings and make sure that the number of colors + is set to either 16bit or 32bit (since ZSNESw will only work with those + modes). + +Q: Why in the GUI under Config/Options are some of the choices gone? + +A: Basically they have become obsolete due to the abilities of Windows. + One such removed option is "vsync" because Direct Draw renders the + screen in synch without a speed loss as with the DOS version so it was + not needed anymore. + +Q: How do I use CD-ROMs with ZSNESw? + +A: You need to define a save directory that points to your hard drive. + In order to do this, use a text editing program such as wordpad and + open up zsnesw.cfg, which should be located in the directory where you + installed ZSNESw in (this will only appear after you run ZSNESw at + least once). Then look for the line SaveDirectory= and enter + the directory where you want all the writeable files to be stored. + +Q: Why is netplay choppy/slow? + +A: Please read netplay.txt that is included in the original ZSNESw archive. + +_[ SOUND COMPATIBILITY ISSUES ]____________________________________________ + +Q: Will ZSNES Windows be able to use my sound card now? It wouldn't work + for me in the DOS version. + +A: It is very likely that your sound card will in fact work given that your + card is supported by Windows and Direct Sound from Microsoft's Direct X. + + +Q: How come I don't get any sound? + +A: There could be several situations : + +A: Either you accidently disabled sound (You can enable it through the GUI) + or you don't have a sound card or the sound drivers aren't properly + installed in your system. + +Q: ZSNES Windows tends to have some static when playing games is there any + way to remove it? + +A: First of all, make sure that you have the latest sound drivers installed. + Also, the problem could be in relation to many different variables. The + emulator uses Direct Sound for audio so it is likely not an issue with + Windows but most likely a setting in the emulator. The problem could be + in relation to using a lower khz value than the SNES uses which is + 32000khz. Another more likely reason is that you have one of the + special sound filters engaged. For higher end cards (better than SB16) + it appears that the Low Pass Filter can cause static. + +Q: How come stereo is reversed? + +A: Turn on 'Reverse Stereo' in the Sound configuration in the GUI. + + +_[ VIDEO ISSUES ]__________________________________________________________ + +Q: Why do I get a dark line every quarter inch roughly on my screen when I + use 25/50% scanlines in a full screen stretched video mode? + +A: This is a video card based issue in which your card does not scale the + video image properly and that is the result. + +Q: In the Video section where I set my resolution what do those letters + stand for to the right of the resolution? + +A: There are four different sets of letters which are R, S, DR, and DS. R + stands for ratio as these modes will retain the screen size ratio to the + output of a real SNES. S stands for stretched, any of these modes will + stretch the image to the exact size of the resolution you have chosen. + The D in DR/DS meants high resolution which allows for the use of + interpolation, 25/50% scanlines, 2xSai, and Super Eagle modes. + +Q: Will ZSNES Windows support a 3DFX graphics mode? + +A: Probably not as the author has little interest in adding support for it. + + +Q: Are there transparencies in ZSNES? + +A: Yes. Transparencies are in ZSNES. + + +Q: How come the graphics are really screwed up? + +A: It's probably a problem with the emulation. You can try running the + game 80% or 120% execution which can be set in the ZSNESW.CFG through + the DOS prompt or another editor. It might fix your problem, but then + again maybe it won't be the solution. + + +_[ COMPATIBILITY ISSUES ]__________________________________________________ + +Q: Why doesn't *name of game* work on ZSNES? + +A: Getting the compatibility higher is a very hard task to do. We're + always trying to get more games working. + + +Q: Can you get *name of game* working by the next release? + +A: We're always trying, but we can never guarantee a specific game will be + working because of the difficulties involved in bug fixing. + + +Q: Why is *name of game* not working in v.*version #* of ZSNES? It was + working before. + +A: Whenever we change something in the emulation, whether it's optimisation + or bug fixes, it has a good potential to have caused a problem elsewhere. + Usually, these problems aren't discovered until after a release. + + +Q: When do you think you will emulate the *DSP/SFX chip? My favorite game + *name of game with chip* won't run without it. + +A: We will consider emulating extra chips only if decent information on + those chips are found. However, even if we find info on them, we + cannot guarantee to be able to implement them. + + +Q: This game tells me that it is not compatible with the MultiTap. What + should I do? + +A: Set both Player 3, Player 4, and Player 5's input device to 'None'. + + +Q: How do I improve the compatibility of ZSNES? + +A: Turning on sound helps a lot here. Also, try in the ZSNES configuration + file to keep the % of execution at 100%. If a game still doesn't work, + try tweaking the percentage of execution to both 120% or 80%. If that + still doesn't work, then it's either a corrupt rom, a game that requires + a special chip, or a bug in ZSNES. + + +Q: Why am I experiencing problems with Chrono Trigger? + +A: If you cannot press the L+R+A seqence, then you would need to assign + both the L and R key as the same key such as set L and R to PageUp and + set A to Home, then pressing PageUp+Home will be the same as pressing + L,R, and A together. This is a hardware limitation of the keyboard, + not a bug in ZSNES. + + +Q: Why doesn't Pilotwings/Star Ocean/Street Fighter Alpha 2 work? + +A: Pilotwings uses the DSP1 chip which as of yet is not completely figured + out. So far the only DSP1 game which will run is Super Mario Kart. + Star Ocean and Street Fighter Alpha 2 both use the SDD-1 chip, which + uses an unknown compression routine that has to be figured out before + it can be emulated. + + +Q: Can you guys get Pilotwings/Star Ocean/Street Fighter Alpha 2 to work? + +A: We have already worked on them to an extent, however, we cannot go much + further until we gain knowledge on how to get them to work. + Unfortunately, we are not magicians. + + +_[ SPEED ISSUES ]__________________________________________________________ + +Q: Why is ZSNES slow? + +A: For the Windows version, you might want to change your video mode in + ZSNESWin to different settings until you find the mode that's optimal + in performance. + + Emulating a SNES is slow because it is a complex system. Also, ZSNES + by default uses a tile/line engine which is newly completed in v1.0. + This engine is faster than the old so if the speed isn't up to par you + may try a solution below, or your computer just may be too slow. + + +Q: Can you please make ZSNES faster? + +A: We're always trying and there are still a lot of room left for + optimisation, but a lack of time keeps us from implementing them. + + +Q: Can you implement dynamic recompilation into ZSNES? + +A: There is no plans to implement it since it doesn't seem necessary. The + SuperNES only uses a 3mhz cpu compared to say the 93mhz cpu inside the + Nintendo 64. Implementing a dynamic recompilation engine will be hard + work and won't improve performance by much. + + +Q: Why does the game slow down even though I'm using auto frame rate and + the FPS is pretty high? + +A: A game slows down like that when it executes its code beyond the speed + of cpu emulation that ZSNES currently handles. To reduce slowdowns, + increase the percentage of execution by using editing the ZSNESW.CFG. + + +_[ KEYBOARD/JOYSTICK ISSUES ]______________________________________________ + +Q: Will ZSNES Windows now be able to use my Windows Joystick/Gamepad? + +A: Yes, the controls are now handed via Direct Input so all Windows based + control devices should work within ZSNES Windows. + +Q: Why can't I press more than 2 keys at a time? + +A: It's mainly the limitation of the PC Keyboard. If you want to press + more than 2 keys at a time, either use a joystick or change the keyboard + keys around until you find a combination where you can press more than + 2 keys at a time. Another technique that works is to set multiple + buttons to a single key. That way, pressing that key presses multiple + buttons at the same time. + + +Q: How come my joystick keeps holding in one direction? + +A: That happens when you hold a direction when ZSNES Windows starts up. + If that happens, then exit ZSNES and reload to recalibrate. Clicking on + SET in the input device window also calibrates the joystick, but it also + resets the controls to the default joystick settings. + + +Q: How do I use both my Keyboard and Joystick for the 1st player? + +A: In the GUI, enter the CONFIG -> OPTIONS menu. Then check 'USE Pl1/2 AS + Pl3/4'. Once you've done that, Player 3 controls will control Player 1 + so if you have joystick set on Player 1, set Player 3 as keyboard. + This disables multitap emulation however. + + +_[ CHEAT ISSUES ]__________________________________________________________ + +Q: How come the game genie codes don't work? + +A: You probably didn't insert the '-'. Otherwise, try clicking on the FIX + button once while the highlight is over the code. + + +Q: How do I use .CHT files? + +A: Copy the .CHT file to the ROM Directory or if you have a save directory + defined, copy it to the Save Directory. Then rename the .CHT file if + necessary so that the filename before the . matches the ROM file. + + +_[ FREEZING/CRASHING ISSUES ]______________________________________________ + + +Q: When I load a ROM, how come ZSNES crashes? + +A: For ZSNESWin, you first might want to see if you have any other major + program running in the background (eg. WinAMP). If it still crashes + after you close those programs, you might want to download and install + the newest version of DirectX which is located at + www.microsoft.com/directx + + Odds are, if the emulator crashes as you load a ROM then it is probably + not compatable with ZSNES Windows due to it being incomplete, a bad + header, or for some other reason making it broken. + + +-[ MISC ]__________________________________________________________________ + +Q: How does the auto .IPS patching feature work? + +A: The auto .IPS feature works by copying the .IPS file to the directory of + your ROM file or if you have a save directory defined, then the .IPS + file goes into the save directory. Next, rename the .IPS file so that + it matches filename (eg. If your ROM filename is THISGAME.SMC, then + your .IPS filename is THISGAME.IPS.) + + +Q: Where do I get the games? + +A: The ZSNES Team will *NOT* provide any games or any links to games. + \ No newline at end of file