# Yape User Manual

YAPE (Yet Another Plus/4 Emulator) is copyright Attila Grósz, 2000-2012
Homepage: http://yape.plus4.net

## Legal

YAPE is FREEWARE and as such comes 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 or harmful, you assume the cost of all necessary servicing, repair or correction. You may freely redistribute verbatim unaltered binary copies of YAPE as long as the original copyright and no warranty notices are also present. You may not however commercially exploit YAPE in any way without prior authorization.

## What is YAPE?

YAPE is a Commodore 264 family emulator. It's an 8-bit microcomputer family from the once-great-now-defunc Commodore Business Machines Ltd. They were released as a successor to the immensely popular Commodore 64 supposedly to either compete with the ZX Spectrum or other micros but eventually failed to gain market success and the whole line was dumped within a couple of years. However they were hugely popular in a few countries such as Hungary, Germany or Italy (to a certain extent also in the UK).

The program features an accurate cycle-exact approach and a high level of emulation. The user interface aims to exploit the potentials of the Windows operating environment. The emulator is written in C++ and is compiled with MS Visual C++. There's an older port to other platforms than Windows (using the SDL library). In the future there'll probably be other ports made.

YAPE was born out of a disassembler project during the summer of 2000 and had been for some time the only actively updated Commodore 264 family emulator. See the Changes.txt for development and release milestones.

## Minimum system requirements

Since YAPE is a cycle-based emulator (much like the Commodore 64 emulators Hoxs or Frodo), its system requirements are higher than that of other line-, instruction- or event-based emulators. In return however, it makes development easier for me while providing maximum possible accuracy. For attaining 100% relative speed to the original hardware, you need:

PII 333 MHz or higher without sound and true drive emulation.
PII 500 MHz or higher for both sound and true drive emulation.
8 MB VGA card capable of DirectX 3.0
Sound card (DirectSound compatible)
Windows 9x (separate build), 2000/XP/Vista/Win7

## Features

All the known 264 family members are emulated:

- Commodore 16/116 (optionally with 64 KB memory extension)
- Commodore 232 (prototype unit with 32 KB RAM, never sold)
- Commodore plus/4
- Commodore V364 (prototype unit, 64KB + Speech hardware)

You can select the desired machine configuration from the 'Machine' submenu's Configuration option. The Commodore 364 prototype unit is also emulated even though the interfacing (MOS 8706R0 custom ASIC) between the machine and the speech hardware (Toshiba 6721A speech synthesizer LSI) is to some extent unknown. Note that it is real emulation, not 'simulation', no speech samples are used, but all the utterances are generated realtime, on the fly.

The following hardware components are emulated:

- cycle exact CPU (MOS 7501/8501) and TED (MOS 7360/8360) emulation
- cycle exact 1541 drive emulation (6502 CPU, VIA 6522 i/o chip and FDC emulation)
- cycle exact 1551 drive emulation (6510T CPU, TIA 6523 i/o chip and FDC emulation)
- 100% of regular and illegal CPU opcodes are implemented
- 16K, 32K, 64 and 256 KB RAM configurations are all supported
- all TED character and graphic modes
- rasterline exact hardware cursor
- timer and raster interrupts
- PAL and NTSC video modes with most known artifacts
- full ROM banking and external cartridge support (in raw format only)
- PRG/P00/D64/G64/T64 image format support, also ZIP-ped
- TAP image support, both MTAP and digital samples (aka WAVs)
- keyboard+joystick emulation via the PC keys and/or joystick
- full TED sound (sampled noise, generated 2 channel square wave), decent SID-card emulation (both 6581 and 8580 selectable) with custom chip address
- simple high- and low-pass sound filter
- functional T6721A Toshiba speech chip and custom MOS 8706R0 glue chip emulation
- user port (RS-232) lightpen
- partial PAL emulation (dynamic YUV palette: brightness, contrast, gamma correction, saturation; the emulator expects 'valid' vblank signals otherwise the emulator screen may start flickering like the real TV)
- emulator and multimedia snapshot (video, audio), screenshot support

Note, that the SID card and the 256 KB RAM are hobbyist extensions to the original hardware and not to be found in stock machines.
The following are not emulated at the moment:

- all low level TV signals
- 157x series of floppy drives

There are three emulation accuracy levels. These are:

- low level: the emulation is line based, the timers are also updated every line only. Provides very good performace on older computers while at the same time adequate accuracy for playing most of the well-known classic games, though true drive emulation is not available. Also do not try running demos in this mode.
- high level (default): the emulation is very accurate, the only missing features are the video shift register emulation and a few weird quirks of the clocking. Runs 99.9 percent of the programs perfectly, only a handful of demos will fail, that are deliberately overwriting the horizontal counter (and not even all of them fail per se)
- very high accuracy: all known TED effects are emulated, should run all programs ~100% accurately; if not, report it immediately :)

In case you're coding a demo, the last option is the best choice, otherwise just go for the default option. If your computer is made prior to 1999, then you probably have to use the low level mode.
YAPE can interact with the Windows operating environment in the following ways:

- You can copy the contents of the screen memory to the Windows clipboard by pressing ALT+C
- You can copy the contents of the Windows clipboard to the emulator. In this case the clipboard is interpreted as text and will be feeded to the emulated machines's keyboard buffer
- You can associate YAPE with the most common CBM emulator images (PRG, D64, G64, TAP). Select 'File associations'from the File menu and tick the file extensions you want to get associated. Untick causes the association to be deleted from the Windows Registry.
- Drag'n' drop support: by dragging a supported emulator image over the window of the emulator, it'll get autostarted as if you had selected 'Autostart image' from the menu. If you drag an image file with the Ctrl key pressed it won't autostart though.
- Always on top: you can force YAPE to be the topmost window on your desktop even when it's not the active window. Select 'Always on top' from the Screen menu
- You can make screenshots ofthe emulator's screen in BMP or GIF format by pressing F6. The file gets placed in the current folder (not necessarily where the emulator resides, but where you the last time have programs loaded from). If you have loaded a PRG or P00 file previously, the name of the screenshot will be PROGRAMNAME0000.BMP otherwise it'll get a name of YAPE0000.BMP where 0000 is a serial number so you can place more screenshots of the same program (up to 10,000) in the actual folder without overwriting the older ones.
- You can make multimedia snapshots, either in video or audio format. When recording to video, first you will be presented with the default codec-selector dialog window where all the system-wide installed video encoders are present. Choose one that supports both audio and compressed video otherwise the resulting video file may become enormous (or wihout sound). Sound snapshots are presently only available into 16 bit mono, 44,1 kHz uncompressed PCM (WAV) format.
- You can switch to full screen mode and back to windowed by pressing ALT+ENTER or selecting 'Full screen' from the Machine menu. Full screen mode is meant to be the quickest as it uses DirectX and direct primary surface access. Select it of you experience speed problems on your PC. The best performance in windowed mode can be achieved with the 'Use GDI' option from the Screen menu and by turning 'Double screen'off. Also this is the most compatible screen mode. Unfortunatley, the user interface is limited in full screen mode, so you may have to switch back and forth if you need a certain UI functionality.

## Installing and running the emulator

Installation is simple: just copy all the files from the ZIP file into a separate folder on your hard disk. You start the emulator by simply double clicking on YAPE.EXE. If you have associated some emulator image formats with YAPE, you can also start it up by doubleclicking on the image. To set/amend the associations, simply select 'File associtioans' from the 'File' menu. Alternatively, you can also use Yape with the always on top option and drag'n'drop.

Once running the emulator, you can PAUSE it any time by pressing the Pause/Break key or selecting this option from the Machine menu. Once paused the emulator will not use up your PC's CPU resources. Pressing the Page Down button will advance the emulation by one single frame.

The following command line options are supported at the moment:

- '/DISK#:image' for attaching an image to drive {8,9,10,11} at startup
- '/LOAD:textfile' for typing text from 'textfile' on startup
- '/TAPE:image' for attaching a TAP/WAV image on startup
- '/TYPE:text' for typing 'text' on startup
- '/NOSTART' will suppress autostart
- '/BREAK:address' will set a breakpoint to the given address that can be both decimal and hexadecimal (0x0000 format)

While using the emulator, you can monitor some internals by pressing SHIFT+F9 or selecting the 'Quickdebugger' option from the Screen menu. The following information is displayed then:

- internal registers of the machine CPU (on the left side)
- a simple tape counter (simply the offset in the TAP or WAV file)
- when a disk drive is emulated on the CPU level, you can also see:

- the PC of the drive CPU
- the drive LED (black when no activity, green when the drive motor is on and red during error or other activity)
- the current track and sector number

You can toggle on/off the speedometer by pressing ALT+S or selecting the 'Display speed' option from the Screen menu. The default speed is 100% which means that the emulator is running 100% of the original machine's speed, and 50 FPS (frames per second) which is the PAL standard, or 60 FPS (NTSC). You can select a lower or higher speed the top speed is limited only by your hardware (the processor and the graphics card both have an effect as well as your emulator settings). If you have a slow graphic card, you can select a lower framerate from the Screen menu but that may cause the screen to flicker. The fastest display mode is full-screen, but the graphical user interface is then mostly becomes unavailable from there. You can still use most keyboard shortcuts though.
If for some reason during tape loading for example) you want to boost the speed to the very limit you can select the 'Full throttle' option from the Machine menu (or alternatively press ALT+W). This will turn off sound, set the frame rate to a certain number of frames per second giving the emulated machine more CPU power.

Just like the real machine, you can reset the emulator, too. The switches are accessible from the 'Machine' submenu. The following reset variances are supported:

- RUN/STOP + reset (TAB+F11): equivalent to the one on the real machine; jumps to the machine language monitor without losing memory conents and BASIC programs and variables.
- Soft reset (F11): equivalent to pushing the white RESET button of a 264 computer. You will not lose the memory contents only BASIC programs and variables. If a program masks the RST vector,you may not be able to restart the emulated machine this way.
- Hard reset (SHIFT+F11): equivalent to turning the power on and off in a real machine in that it clears all the RAM contents
- Forced reset (CTRL+F11): will always jump to the ROM reset vector, even when it's disabled. Great for debugging.
- Drive reset: eventually drives may crash, too, so they can be reset here, all at once or individually. This is the equivalent of turning the drive off and then on.

You can quit the emulator in several ways: ESC key quits with a confirmation dialog window, F12 and ALT+F4 quits immediately.

## Loading and starting programs

Most Commodore plus/4 programs are distributed in either PRG (raw) or D64 (disk format). There are some other formats as it was noted above but they are much scarcer. The most convenient way of loading programs to YAPE is to choose 'Autostart image' from the File menu (or by pressing F7). You'll be presented a file dialog window where all supported images in the actual folder can be seen. If you select any of them, YAPE loads and tries to RUN it. If the program is in PRG/P00 format and has a SYS startup code, it'll fail. In that case you have to find out the start address yourself (probably from the file name or the documentation). Note, that the autostart feature will reset the emulated machine hence all previous RAM contents will be lost.

There are other ways of loading programs to the emulator, but these are dependent on the format, and won't be started automatically. Also the memory contents will not be lost:

- for PRG and P00 files you can press F8 or select 'Load PRG' from the File menu
- for TAP images you can select the 'Attach TAP' option from the Tape menu then type LOAD and press ENTER. You are faced with a text that says 'PRESS PLAY ON TAPE'. To press the Play button the virtual tape device, press F5 or select 'Play' from the 'Tape" menu
- for D64 images you can press ALT+D or select 'Attach D64' option from the File menu: in the file dialog you can see some other options. If you're emulating a 1551 drive in YAPE, you can select under which drive number you wish to attach it. You can also create an empty D64 by ticking the 'Creaty empty D64' option.
- T64 images you can currently only attach within the 'Autostart image' option

For games, demos and programs, visit:
http://plus4.emucamp.com or
ftp://c64.rulez.org/pub/plus4 or
http://www.c16.de or
ftp://ftp.funet.fi/pub/cbm/plus4
On how to make TAP or WAV images from your original tapes that can then be loaded into the emulator, visit:
http://markus.brenner.de
http://minus4.plus4.net

## Keyboard and joystick control

The emulated C= 264 keyboard is mapped to its original place wherever it was possible. If that does not suit you, select symbolic keymapping from the input setup dialog window. It will map the symbols (also shift-ed ones) found on the real plus/4 keyboard to their equivalents of your PC keyboard locale. Note that the 2 Shift keys on the PC keyboard act differently: left shift only applies to the PC keyboard while right shift also to the emulated machine if you are accessing a key that is shifted on the PC's keyboard.
DirectInput and MessageQueue input methods both are applying positional keymapping. DirectInput is recommended and you should only use the MessageQueue if DirectInput fails for some reason. Positional mapping may be annoying at first if you're not used to the plus/4 keyboard, but it comes handy for keyboard control in games that rely on the physical positions of the keys. Here are the positional mappings of a couple of special keys (these are mostly valid in symbolic keymapping mode, too!):
plus/4 PC
ESCAPE: ` (tilde)
COMMODORE: left Ctrl
CTRL: right Ctrl or Insert (for laptops)
SHIFT LOCK: Caps Lock
RUN/STOP: Tab
HOME: Home
POUND: End
INS/DEL: BackSpace
CURSOR PAD: cursor keys
RESET: F11
These are the key mappings when the josytick is emulated through the PC keyboard.
JOYSTICK MOVE: cursor keys or numpad 2, 4, 6, 8 (selectable via the Input dialog window)
JOYSTICK FIRE: numeric 0
Select 'Joystick emulation' from the 'Settings' submenu to plug the virtual joystick to the numeric keypad and the numeric 0 key. If you do not succeed try 'Swap joystick' (or press ALT+J), this will switch between joystick port 1 and 2. Tick the 'Use PC joystick' option in the dialog window, if you own a PC jopystick and want to use that for joystick emulation. The recommended input setup is DirectInput, as it allows more accurate input handling while at the same time uses less system resources.

## Disk drive support

Currently three kinds of drives are supported: the 1541, 1551 and the 1581. In the future there might be more exotic drives supported, but the available software for them is very limited, so the priority is low.

### 1541 drive emulation (CPU)

The 1541 is a well-known device also compatible with other Commodore products, like the popular C64. This mode sports a full-blown 1541 emulation together with a 1 MHz 6502 CPU, the 2 VIA-6522 chips and the floppy disk controller, disk rotation etc. Custom loaders are therefore also supported. The D64 files are first converted to GCR format and buffered by the emulator internally for reading. Writing is also implemented. If you encounter turbo loaders that fail, you may attempt enabling a built-in hack by pressing Ctrl+Alt+X that will circumvent a necessary half-cycle accuracy for now.

One can also select parallelized 1541 drive emulation, although the available software for it is rather limited.

You can debug the drive from the external monitor (see chapter 'The external monitor' later).

### 1551 drive emulation (IEC and CPU)

The 1551 is a high-speed parallel drive specifically made for the 264-series. It has a proprietary interface called TCBM that has not been used in any other Commodore products. The 1551 emulation has two modes: IEC and CPU. The first one is not real disk drive emulation. Disk commands are caught on the parallel bus and intepreted by the emulator itself, so actually the behaviour of the DOS is simulated. Advantage is that it has virtually no overhead compared to a true drive emulation, disadvantage is that custom disk loaders will not work with it. The 1551/CPU mode aims to emulate a full 1551 drive together with the 2 TIA chips, 2 MHz 6510T processor, 555 astable multivibrator for IRQ and the disk drive mechanics (that is actually the same as that of the 1541). As a consequence, it's the slowest drive emulation mode, while in turn all possible custom loaders should work fine (in due time).

1551/IEC has support for only two device numbers 8 and 9. This limitation is caused by the architecture of the TCBM bus and not a shortcoming of the emulator. In this mode also high speed write operations and T64 images are supported. Almost the full DOS is supported, except for:

- REL files
- B-E (block-execute) and M-E (memory-execute)
- overwrite command (@)

Note: the option 'Set drive folder' only affects the 1551/IEC emulation when no D64 files are attached (on startup or after a 'Detach D64' is selected from the File menu). It sets the current folder for the 1551 and it will be used for disk save and write operations. The possibilities are limited when using a folder as a drive, as it may not have blocks for example.

### 1581 drive emulation (CPU)

The Commodore 1581 is a 3½ inch double sided double density floppy disk drive made by Commodore primarily for the C64 and C128, although it is compatible with the 264 series as well since it is using the CBM serial bus. The drive stores 800 kilobytes using an MFM format different from both DOS (720 KB), and the Amiga (880 KB) formats. The 1581 provides a total of 3160 blocks free when formatted (a block being equal to 256 bytes) and also implements subdirectories. Its native image format on emulators is the D81. The D81 image files pertaining to this drive are read/writable in the emulator. This mode sports a full-blown 1581 emulation together with a 2 MHz 6502 CPU, the CIA chip and the WD1772 floppy disk controller, but no disk rotation atm. Custom loaders are not known to exist but are in theory also supported to a certain degree.

## Printer support

The Commodore serial printers are supported through the serial IEC interface, both as device 4 and 5. This includes printing to raw and CR/LF corrected ASCII dumps as well as bitmap with the MPS-803 printer on an IEC protocol level and a CPU level emulation of the MPS-802, though the latter has a few known issues and only works with bitmap file as target. The path of the target output file can be specified through the printer setup dialog window. Also, custom character ROMs can be specified for these printers.

## Tape device support

There's read/write support for low level raw tape images commonly known as the MTAP format. Loading a TAP image's content is simple: you can do it via the 'Autostart image' option or thru the Tape menu by selecting 'Attach TAP'. If you choose for the latter, you have to make sure that you type the appropriate BASIC commands for tape loading: LOAD"",1,1 . Then press F5 to start the tape. If you have the Quickdebugger selected from the Screen menu you can see as the the emulator advances in the file.

Creating TAPs is a bit more complicated. Firstly: you can only create new TAP files, can not append to existing ones or overwrite them. To create an empty TAP image, select 'Create TAP' from the Tape menu. You can select between wholewave and halfwave format by ticking/unticking this option in the file dialog window. The wholewave format is about half the size of the halfwave one, but is less compatible with all the turbos. As the 264 family's tape interface is edge-triggered, rather than level-triggered, there are more possible waveforms than on the Commodore 64 for example. You must not attach the newly created TAP again! When you typed SAVE from the emulated machine you can press the RECORD button by selecting it from the Tape menu or pressing SHIFT+F6. When finished saveing make sure you detach the TAP you've just written and reattach it before trying to load as the 'Detach' option puts some very important information into the TAP header which you miss you may be unable to use your TAP elsewhere.

Alternatively you can load 8-bit digitised WAV or RAW samples to the emulator. It is however not encouraged as is having a lower sample frequency than the MTAP while taking up to about 8 times more disk space. The advantage is that you can create working WAV/RAW samples without any special hardware if you're lucky enough.

## The external monitor

YAPE has a simple external monitor which you can use to track the internals of the emulated machine. You can enter the monitor by pressing ALT+M or selecting 'Monitor' from the Machine menu. The monitor is console-like that is you have to type in commands and press ENTER. Limited editing functioanlity within the command line is also supported (cursor left/right, BACKSPACE, command history etc.). You can also enter the monitor explicitely either by reaching a breakpoint (set from the monitor) or a crash instruction (in the latter case you are prompted with a confirmation dialog window first).
The monitor features:

- almost all functionality that can be found in the TEDMON (the 264 famliy's built-in machine code monitor)

- display memory contents (M)
- change memory conents (>)

- transfer memory contents (T)
- hunt memory for a certain byte (H)
- fill memory with a certain byte (F)
- compare memory areas (C)
- disassembly (D) : this can be redirected to an external file if you give the 3rd parameter as a file name
- display CPU registers (R)
- go command (G) : sets the PC of the CPU to the selected address

- debug the CPU (Z) : depending on the actual context, it'll show and execute the next opcode of the selected CPU
- debug step over command (Y): same as above, but JSR commands will not be followed
- advance 1 or more system bus cycle (S) : without a parameter it will advance one system bus cycle (there are 114x312 cycles per frame in the 264 family) If a parameter is given, it'll advance the number of cycles given
- breakpoint support (B) : by providing an address as an argument, the machine (or drive) CPU will be set to jump into the monitor when the PC reaches the address given. In case a 3rd parameter is provided, this will be a memory watchpoint for a combination of R for READ, X for EXECUTE and W for WRITE. Note that watchpoints halt the CPU *after* the instruction. This feature is also supported for the emulated drive's CPU. Once set, you can turn it on/off by typing B followed by the address as parameter. By simply typing 'B', Yape will list all breakpoints/watchpoints along with their corresponding types (read, write, execute).
- context switching between the drive and the machine if true drive emulation is selected (W). If it's followed by a device number, Yape will switch to that device's (drive's) context.
- '@' will toggle between the machine's RAM and current ROM banking scheme's

You can get a simple help on these commands from the monitor itself by typing '?'. To exit the monitor type 'X' or simply click the upper left corner of the monitor window.

## Development using YAPE

If you don't own the original hardware or it is not functional anymore, you may consider developing under the emulator with an approppriate cross-development tool. Programming information on the 264-family hardware can be found:

- http://www.funet.fi/pub/cbm/plus4/programming/

- http://www.plus4.org/program.htm

Cross development tools that can be used with YAPE directly:

- PLUS4IDE by Csaba Pankaczy: open source integrated development environment using the AS65 or the TASM compilers

- AP4 by Zoltán Péter: assembler and IDE in one, discontinued

## Credits

A number of people helped me during development either by providing hardware information, testing or user hints. Thanks to:

- Csaba Pankaczy and Mike Legg for pointing out bugs, tips and some code in the monitor, and all their work on 'plus/4 world'
- Levente Hársfalvi for reverse engineering the sound hardware, sampling the noise output, writing the HP/LP filters, some TED and oscilloscope measurements
- Zsolt Prievara, Mike Dailly, Tibor Biczó in helping me getting familiar with emulator programming and the plus/4 hardware during the early days of development
- Markus Brenner for his help implementing the MTAP support
- Marko Mäkelä for his advices with the CPU and tape emulation
- Ingo Jache, Valentino Zenari, Luca Caraffiello, Balázs Kiss, Vladimir Lidovski and many other people for bug reports, testing and tips
- JoseQ, Navvie, Jim and Joco for hosting

The following information sources were used:

- The plus/4 mail list archive
- 64doc by Marko Mäkelä
- 'A Commodore plus/4 belső felépítése', 1988, Novotrade Rt.
- TED preliminary data sheets (7360R0)
- TIA 6523 data sheets
- VIA 6522 data sheets
- CIA 8520 data sheets
- Christian Bauer's VIC-II article
- Inside the C= DOS
- Circuit diagram of the 1541
- Circuit diagram of the 1551
- Circuit diagram of the 1581
- Toshiba 6721A speech LSI data sheet

And of course special thanks to all the users and the plus/4 sceners who helped and encouraged me during all the years! Kudos for all those nasty demos that failed or still fail to run properly! Keep up the good work, and keep the scene alive! Cheers!

## Miscellaneous

If you like YAPE you may wish to check out my other emulator projects:

- 'tedplay': is a Commodore format music player supporting SID, C8M and PRG files. Link: http://tedplay.codeplex.com.
- 'HoLa!': it emulates a Hungarian 8-bit micro called HomeLab, the "Hungarian Apple ][". Find it at: http://homelab.8bit.hu (in Hungarian only).
- 'HT1080Z': a System-80 emulator. It is a very similar machine to the TRS-80 Model I Level 2. Homepage (in Hungarian): http://ht.homeserver.hu
- 'Ultimo': it emulates a Hungarian 8-bit microcomputer called Primo, manufactured between 1984 and 1986. Find it at: http://primo.homeserver.hu (in Hungarian only).
- 'WinTVC': it emulates another Hungarian 8-bit micro called TV Computer, very similar to the ill-faited Enterprise 128, manufactured between 1986 and 1989. Find it at: http://tvc.homeserver.hu (in Hungarian only).
- My own homepage that hosts all the above emulators at one place.