Section courante

A propos

Section administrative du site

 Langage  Installation  Elément  Tutoriel  Programmation  Bibliothèque  Cadre d'application  GUI  Projet  Jeux  Outils  Emulateur  Annexe  Aide 
ABAP/4
Ada
Assembleur
Assembly & bytecode
ASP (Active Server Pages)
Basic
C
C++
C# (C Sharp)
Cobol
ColdFusion
Fortran
HTML
Java
JavaScript
LISP
Logo
LotusScript
Oberon
Pascal
Perl
PHP
PL/1
Prolog
Python
Rebol
REXX
Ruby
SAS
NoSQL
SQL
Swift
X++ (Axapta)
GNAT
SMALLAda
VHDL
Assembleur 370
Assembleur 1802
Assembleur 4004
Assembleur 6502
Assembleur 6800
Assembleur 68000
Assembleur 8080 et 8085
Assembleur 8089
Assembleur 80x86
Assembleur AGC4
Assembleur ARM
Assembleur DPS 8000
Assembleur i860
Assembleur Itanium
Assembleur MIPS
Assembleur PDP-11
Assembleur PowerPC
Assembleur RISC-V
Assembleur SPARC
Assembleur SuperH
Assembleur UNIVAC I
Assembleur VAX
Assembleur Z80
Assembleur Z8000
Assembleur z/Architecture
ASSEMBLER/MONITOR 64
Micol Assembler
GFA Assembler
A86
MASM (Macro Assembler)
TASM (Turbo Assembler)
CIL
Jasmin
LLVM
MSIL
Parrot
P-Code (PCode)
SWEET16
G-Pascal
ASP 1.0
ASP 2.0
ASP 3.0
ASP.NET
ASP.NET Core
ABasiC (Amiga)
Adam SmartBASIC
Altair BASIC
AmigaBASIC (Amiga)
AMOS Basic (Amiga)
Atari Basic (Atari 400, 600 XL, 800, 800XL)
Basic Apple II (Integer BASIC/APPLESOFT)
Basic Commodore 64 (CBM-BASIC)
Basic Commodore 128 (BASIC 7.0)
Basic Commodore VIC-20 (CBM-BASIC 2.0)
Basic Coco 1 (Color Basic)
Basic Coco 2 (Extended Color Basic)
Basic Coco 3 (Extended Color Basic 2.0)
BASICA (PC DOS)
Basic Pro
BBC BASIC
Blitz BASIC (Amiga)
DarkBASIC
Dartmouth BASIC
GFA-Basic (Atari ST/Amiga)
GWBASIC (MS-DOS)
Liberty BASIC
Locomotive BASIC (Amstrad CPC)
MSX-Basic
Omikron Basic (Atari ST)
Oric Extended Basic
Power Basic
Quick Basic/QBasic (MS-DOS)
Sinclair BASIC (ZX80, ZX81, ZX Spectrum)
ST BASIC (Atari ST)
Turbo Basic
Vintage BASIC
VBScript
Visual Basic (VB)
Visual Basic .NET (VB .NET)
Visual Basic pour DOS
Yabasic
BeckerBASIC
SIMONS' BASIC
Basic09 d'OS-9
Disk Extended Color Basic
Basic09 d'OS-9
Disk Extended Color Basic
Access
Excel
Visual Basic pour Windows
Visual Basic .NET pour Windows
C Shell Unix (csh)
C pour Amiga
C pour Atari ST
C pour DOS
C pour Falcon030
C pour GEMDOS (Atari ST)
C pour Linux
C pour PowerTV OS
C pour OS/2
C pour Unix
C pour Windows
Aztec C
CoCo-C
GNU C
HiSoft C
IBM C/2
Introl-C
Lattice C
Microsoft C
MinGW C
MSX-C
Open Watcom C
OS-9 C Compiler
Pure C
Quick C
Turbo C
HiSoft C for Atari ST
HiSoft C for CP/M (Amstrad CPC)
C++ pour OS/2
C++ pour Windows
Borland C++
C++Builder
IBM VisualAge C++
Intel C++
MinGW C++
Open Watcom C++
Symantec C++
Turbo C++
Visual C++
Visual C++ .NET
Watcom C++
Zortech C++
C# (C Sharp) pour Windows
Apple III Cobol
Microsoft Cobol
BlueDragon
Lucee
OpenBD
Railo
Smith Project
Microsoft Fortran
WATFOR-77
CSS
FBML
Open Graph
SVG
XML
XSL/XSLT
LESS
SASS
GCJ (GNU)
JSP
Jython
Visual J++
Node.js
TypeScript
AutoLISP
ACSLogo
LotusScript pour Windows
Amiga Oberon
Oberon .NET
Apple Pascal
Delphi/Kylix/Lazarus
Free Pascal
GNU Pascal
HighSpeed Pascal
IBM Personal Computer Pascal
Lisa Pascal
Maxon Pascal
MPW Pascal
OS-9 Pascal
OSS Personal Pascal
Pascal-86
Pascal du Cray Research
Pascal/VS
Pascal-XT
PURE Pascal
QuickPascal
RemObjets Chrome
Sun Pascal
THINK Pascal
Tiny Pascal (TRS-80)
Turbo Pascal
UCSD Pascal
VAX Pascal
Virtual Pascal
Turbo Pascal for CP/M-80
Turbo Pascal for DOS
Turbo Pascal for Macintosh
Turbo Pascal for Windows
CodeIgniter (Cadre d'application)
Drupal (Projet)
Joomla! (Projet)
Phalanger (PHP .NET)
phpBB (Projet)
Smarty (balise)
Twig (balise)
Symfony (Cadre d'application)
WordPress (Projet)
Zend (Cadre d'application)
PL360
PL/M-80
PL/M-86
Turbo Prolog
CPython
IronPython
Jython
PyPy
AREXX
Regina REXX
JMP
Btrieve
Cassandra
Clipper
CouchDB
dBASE
Hbase
Hypertable
MongoDB
Redis
Access
BigQuery
DB2
H2
Interbase
MySQL
Oracle
PostgreSQL
SAP HANA
SQL Server
Sybase
U-SQL
Turbo Pascal 5
Turbo Pascal 5.5
Turbo Pascal 6
Turbo Pascal 7
Introduction
Les remarques
Les opérateurs
Les instructions conditionnelles
Les instructions de boucles
Type de données
Référence des unités
Références de mots réservés (mots clefs)
Définition de procédure et fonction
Référence de procédures et fonctions
Référence des directives de compilation
CRT
DOS
GRAPH
OBJECTS
OVERLAY
PRINTER
STRINGS
SYSTEM
TURBO3
WINDOS
Catégorie
Prototype
ASCIZ
Date
Ensemble
Fichier
Mémoire
Temps
Trigonométrie
Les premiers pas
Les jetons
Les constantes
Les types
Variables et constantes typées
Les expressions
Les instructions
Blocs, localité et étendue
Procédures et fonctions
Programmes et unités
Vue d'ensemble de la bibliothèque d'exécution
Procédures et fonctions standard
Entrée et sortie
Utilisation du 80x87
Interfaçage avec DOS
Utilisation de chaînes de caractères terminées par NULL
Utilisation de l'interface graphique Borland
Utilisation de recouvrement
Problèmes de mémoire
Problèmes de contrôle
Optimiser votre code
L'assembleur intégré
Liaison de code assembleur
Programmation orientée objet (POO)
Les fichiers
Les périphériques logiques
Files d'attente, piles, listes liées et arborescences
Bonjour
Affichage
Astronomie
Biochimie
Chimie
Conversion
Électrotechnique
Emulateur
Fichiers
Finance
Géographie
Géophysique
Géométrie
Histoire
Jeux & stratégies
Mathématique
Matrice
Médicale
Météorologie
Océanographie
Onirologie
Sport
Temps
Tri
Trigonométrie
Validation
«DRAW» du BASIC
Phase lunaire
Calcul du calcium corrigé
Calcul le taux d'alcoolémie
Bin,Hex,Base62,...
Emulateur de microprocesseur 6502
Texte séquentiel
IPaymt/Interet
NPer
PPaymt/Principal
Distance en Km entre deux longitudes et latitudes
Aire d'un cercle
Aire d'une surface de prisme rectangulaire
Aire d'un triangle
Distance entre deux points
Treillis
Chiffre romain
Méthode du chiffre César (code César)
Asteroids
Bowling
Breakout
Lode Runner
Missile Command
Pac-Man
Patience
Peg Leap
Soko-Ban
Space Invaders
Space Jockey
Tetris
Tic-Tac-Toe
Tours d'Hanois
Ackermann
Exp
Factoriel
Fibonacci
Log
Nombre premier
Odd
Random
Sqrt
Triangle Pascal
Sommation
Hauteur utérine
Calcul de votre poids santé (IMC)
Unité de mesure
Fréquence des vagues
Hockey
Année bissextile
Calendrier
Date de la Pâque
FirstDayOfMonth
Horloge à aiguille
Tri à bulle (Bubble Sort)
Tri Shell Sort
ArcCos
ArcSin
Atn/ATan/ArcTan/ArcTangente
Cos
Sin
Courriel
AMDEKSYSTEM88LIB-TP
APMLIB-TP
BASICSTRLIB-TP
BIOSLIB-TP
COLORIMETRYLIB-TP
CSVLIB-TP
CYRIXLIB-TP
DRDOSLIB-TP
ELECTRICLIB-TP
ERLOGLIB-TP
FINANCIALLIB-TP
GEOLIB-TP
GRAPHICSSOLUTIONLIB-TP
HDLLIB-TP
HISTORICLIB-TP
HTMLLIB-TP
IALIB-TP
INTLLIB-TP
JSONLIB-TP
K8042LIB-TP
LETTRESLIB-TP
LOTUSSCRIPTSTRLIB-TP
METEOLIB-TP
OCEANOGRAPHICLIB-TP
OS2LIB-TP
OSSPASCALLIB-TP
POSIX-TP
PYTHONLIB-TP
SANE-TP
SNOBOLLIB-TP
SVGLIB-TP
TPW4TPLIB-TP
TSENGLABSET4000LIB-TP
VGALIB-TP
WINDOWS9XLIB-TP
XMLLIB-TP
Turbo Vision
UNITEST
MOS
AlimBase
AMIGADOS-0
AXTRO
Colorix
Corail
COREUTILS-0
DEV-COOLS
EDUX
FLEX-0
GEO-COMMANDER
HISTORIK
lettrex
LINUX-0
MATHIX
METEOPOLIS
Micro Calc
MYSTIX
Monsterbook
MSDOS-0
MSXDOS-0
OS9-0
Renegade BBS
Système Information
TRSDOS-0
Turbo Calc
UNIX-0
VIE
7iles
Arkanoid
Digger
Mario and Luigi
Turbo Assembler
Turbo Debugger
DOSBox
PCE - PC Emulator
PCem
Base de connaissances
Table ASCII
Table de codes ANSI et page de codes
RAM de l'IBM PC
Code d'erreur
Génération du code en interne du Turbo Pascal 3
Code source du Turbo Pascal 6
TPU
OBJ
Archives de paquet
Alternative
Bibliographie
Turbo Pascal à FreeDOS/FreePascal
Turbo Pascal à Linux/FreePascal
Turbo Pascal à FreeBSD/FreePascal
Turbo Pascal à eComStation/FreePascal
Préface
Notes légal
Dictionnaire
Recherche

Émulateur de microprocesseur 6502

Un émulateur de microprocesseur 6502 permet d'exécuter le code qu'exécuterait le microprocesseur 6502 utilisé par exemple dans les Apple II et la NES de Nintendo. L'émulateur 6502 en soi ne fait qu'imiter le comportement d'une puce et il ne rend pas automatiquement exécutable tout logiciel écrit pour les micro-ordinateurs et les consoles de jeux. Ainsi, pour que l'émulateur puisse exécuter des logiciels dédiés à des plateformes particulières, il doit également imiter le comportement des puces électroniques dédié à l'affichage, au son et aux périphériques y étant connecté. La puce 6502 n'a pas de port d'entrée/sortie à gérer, donc, tous signal envoyé à l'électronique passe directement par l'affectation d'une cellule mémoire de la RAM. Aussi, la pile gérable est d'un maximum de 256 octets et est toujours situé à l'adresse 0100h.

Le rôle d'un émulateur 6502 n'est pas si compliqué en soi, il s'agit de passer un par un chaque octet de mémoire (opcode) et d'effectuer les actions en mémoire en fonction de l'opération demandée. Une opération peut être, une addition, une soustraction, des tests, des opérateurs binaires, des déplacements du compteur de programme en mémoire, l'affectation de la pile,... Voici un schéma d'un émulateur 6502 :

Il est à noter également que le code suivant n'est pas optimisé pour le compilateur Turbo Pascal. Ainsi, il n'utilise pas les procédures INC et DEC afin d'incrémenter ou décrémenter des valeurs, mais plutôt une affectation manuelle. Le but de l'exemple suivant est de monter le fonctionnement et de rendre facilement portable le code sous différentes marques de compilateurs Pascal. Dans cet exemple, étant donné que l'émulateur ne contient rien dans la mémoire de la RAM de l'émulateur (variable «memory»), il arrêtera immédiatement à l'instruction d'opcode BRK. Ce sera à vous de charger des données afin pouvoir tester le comportement de routines Assembleur 6502.

L'émulateur à la fonctionnalité du débogueur d'instruction activé par défaut, lequel affiche la valeur des registres et sa position d'exécution entre chaque instruction exécutée. Il va de soit, que cette option n'est pas indispensables à l'émulateur mais permet aux développeurs de suivre facilement, pas à pas, ce qui se passe dans le programme tentant d'être exécuté.

  1. Program emul6502;
  2.  
  3. Const
  4.  DebugOn:Boolean=True;
  5.  
  6. Var
  7.  codeRunning:Boolean;
  8.  A:Byte;     { Registre accumulateur }
  9.  X:Byte;     { Registre d'index X }
  10.  Y:Byte;     { Registre d'index Y }
  11.  P:Byte;     { Registre d'etat de processeur }
  12.  PC:Word; { Registre de compteur der programmes }
  13.  SP:Word; { Registre de pointeur de pile }
  14.  memory:Array[0..16384] of Byte;
  15.  
  16. Procedure InitEmul;Begin
  17.  codeRunning:=True;
  18.  A:=0;
  19.  X:=0;
  20.  Y:=0;
  21.  P:=0;
  22.  PC:=$600;
  23.  SP:=$100;
  24. End;
  25.  
  26. Function num2hex(nr:Byte):String;
  27. Const
  28.  HexStr:Array[0..15]of Char=('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
  29. Begin
  30.  num2hex := HexStr[(nr and $f0) shr 4] + HexStr[nr and $F];
  31. End;
  32.  
  33. Function addr2hex(address:Word):String;Begin
  34.   addr2hex := num2hex((address shr 8) and $ff)+num2hex(address and $ff);
  35. End;
  36.  
  37. Function popByte:Byte;Begin
  38.  popByte := memory[PC] and $ff;
  39.  PC := PC + 1;
  40. End;
  41.  
  42. Function popWord:Word;Begin
  43.  popWord := popByte + (popByte shl 8);
  44. End;
  45.  
  46. Procedure stackPush(value:Byte);Begin
  47.   If SP >= 0 Then Begin
  48.    SP := SP - 1;
  49.    memory[(SP and $ff)+$100] := value and $ff;
  50.   End
  51.    else
  52.   Begin
  53.    WriteLn('Pile pleine: ',SP);
  54.    codeRunning := false;
  55.   End;
  56. End;
  57.  
  58. Function stackPop:Byte;Begin
  59.   If SP < $100 Then Begin
  60.    stackPop := memory[SP+$100];
  61.    SP := SP + 1;
  62.   End
  63.    else
  64.   Begin
  65.    WriteLn('Pile vide');
  66.    codeRunning := false;
  67.    stackPop:=0;
  68.   End;
  69. End;
  70.  
  71. Procedure jumpBranch(offset:Word);Begin
  72.   If offset > $7f Then PC := PC - ($100 - offset) Else PC := PC + offset;
  73. End;
  74.  
  75. Procedure memStoreByte(address:Word; value:Byte);Begin
  76.  memory[address] := (value and $ff);
  77. End;
  78.  
  79. Function memReadByte(address:Word):Byte;Begin
  80.  memReadByte := memory[address];
  81. End;
  82.  
  83. Procedure testADC(value:Byte);
  84. Var
  85.  tmp:Word;
  86. Begin
  87.   If (A xor value) and $80 = $80 Then P := P and $bf else P := P or $40;
  88.   If P and 8 = 8 Then Begin
  89.     tmp := (A and $0f) + (value and $0f) + (P and 1);
  90.     If tmp >= 10 Then tmp := $10 or ((tmp+6) and $0f);
  91.     tmp := tmp + (A and $f0) + (value and $f0);
  92.     If tmp >= 160 Then Begin
  93.       P := P or 1;
  94.       If (P and $bf <> 0) and (tmp >= $180 ) Then P := P and $bf;
  95.       tmp := tmp + $60;
  96.     End
  97.      else
  98.     Begin
  99.       P := P and $fe;
  100.       If (P and $bf <> 0) and ( tmp < $80 ) Then P := P and $bf;
  101.     End;
  102.   End
  103.    else
  104.   Begin
  105.     tmp := A + value + (P and 1);
  106.     If tmp >= $100 Then Begin
  107.       P := P or 1;
  108.       If (P and $bf <> 0) and (tmp >= $180) Then P := P and $bf;
  109.     End
  110.      else
  111.     Begin
  112.       P := P and $fe;
  113.       If (P and $bf <> 0) and (tmp < $80) Then P := P and $bf;
  114.     End;
  115.   End;
  116.   A := tmp and $ff;
  117.   If A <> 0 Then P := P and $fd else P := P or $02;
  118.   If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  119. End;
  120.  
  121. Procedure testSBC(value:Byte);
  122. Var
  123.  tmp,w:Word;
  124. Begin
  125.   If P and 8 = 8 Then Begin
  126.    tmp := $0f + (A and $0f) - (value and $0f) + (P and 1);
  127.    If tmp < $10 Then Begin
  128.     w := 0;
  129.     tmp := tmp - 6;
  130.    End
  131.     else
  132.    Begin
  133.     w := $10;
  134.     tmp := tmp - $10;
  135.    End;
  136.    w := w +$f0 + (A and $f0) - (value and $f0);
  137.    If w < $100 Then Begin
  138.     P := P and $fe;
  139.     If (P and $bf <> 0) and (w < $80) Then P := P and $bf;
  140.     w := w - $60;
  141.    End
  142.     Else
  143.    Begin
  144.     P := P or 1;
  145.     If (P and $bf <> 0) and (w >= $180) Then P := P and $bf;
  146.    End;
  147.    w := w + tmp;
  148.   End
  149.    else
  150.   Begin
  151.    w := $ff + A - value + (P and 1);
  152.    If w < $100 Then Begin
  153.     P := P and $fe;
  154.     If (P and $bf <> 0) and (w < $80) Then P := P and $bf;
  155.    End
  156.     else
  157.    Begin
  158.     P := P or 1;
  159.     If(P and $bf<>0) and (w >= $180) Then P := P and $bf;
  160.    End;
  161.   End;
  162.   A := w and $ff;
  163.   If A <> 0 Then P := P and $fd else P := P or $02;
  164.   If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  165. End;
  166.  
  167. Procedure doCompare(reg,val:Word);Begin
  168.   if (reg+val) > $ff Then P := P or 1 else P := P and $fe;
  169.   val := (reg-val);
  170.   If val <> 0 Then P := P and $fd else P := P or $02;
  171.   If val and $80 = $80 Then P := P or $80 else P := P and $7f;
  172. End;
  173.  
  174. Procedure ExecEmul;
  175. Var
  176.  opcode,zp,offset:Byte;
  177.  currAddr,address,value,sf:Word;
  178. Begin
  179.   If Not(codeRunning)Then Exit;
  180.   opcode := popByte;
  181.   If(DebugOn)Then WriteLn('PC=', addr2hex(PC-1), ' opcode=', opcode, ' X=', X, ' Y=', Y, ' A=', A, ' P=', P);
  182.   Case opcode of
  183.     $00:                            { BRK implicite }
  184.       codeRunning := false;
  185.     $01:Begin                       { ORA INDX }
  186.       address := popByte + X;
  187.       value := memReadByte(address) + (memReadByte( address+1) shl 8);
  188.       A := A or Lo(value);
  189.       If A <> 0 Then P := P and $fd else P := P or $02;
  190.       If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  191.      End;
  192.     $05:Begin                       { ORA ZP }
  193.       zp := popByte;
  194.       A := A or memReadByte(zp);
  195.       If A <> 0 Then P := P and $fd else P := P or $02;
  196.       If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  197.      End;
  198.     $06:Begin                       { ASL ZP }
  199.       zp := popByte;
  200.       value := memReadByte( zp );
  201.       P := (P and $fe) or ((value shr 7) and 1);
  202.       value := value shl 1;
  203.       memStoreByte( zp, value );
  204.       If value <> 0 Then P := P and $fd else P := P or $02;
  205.       If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  206.      End;
  207.     $08:                            { PHP }
  208.       stackPush(P);
  209.     $09:Begin                       { ORA IMM }
  210.       A := A or popByte;
  211.       If A <> 0 Then P := P and $fd else P := P or $02;
  212.       If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  213.      End;
  214.     $0a:Begin                       { ASL IMPL }
  215.        P := (P and $fe) or ((A shr 7) and 1);
  216.        A := A shl 1;
  217.        If A <> 0 Then P := P and $fd else P := P or $02;
  218.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  219.       End;
  220.     $0d:                            { ORA ABS }
  221.       Begin
  222.        A := A or memReadByte( popWord );
  223.        If A <> 0 Then P := P and $fd else P := P or $02;
  224.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  225.       End;
  226.     $0e:Begin                       { ASL ABS }
  227.        address := popWord;
  228.        value := memReadByte(address);
  229.        P := (P and $fe) or ((value shr 7) and 1);
  230.        value := value shl 1;
  231.        memStoreByte(address, value);
  232.        If value <> 0 Then P := P and $fd else P := P or 2;
  233.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  234.       End;
  235.     $10:Begin                      { BPL }
  236.        offset := popByte;
  237.        If P and $80 = 0 Then jumpBranch( offset );
  238.       End;
  239.     $11:Begin                      { ORA INDY }
  240.        zp := popByte;
  241.        value := memReadByte(zp) + (memReadByte(zp+1) shl 8) + Y;
  242.        A := A or memReadByte(value);
  243.        If A <> 0 Then P := P and $fd  Else P := P or $02;
  244.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  245.       End;
  246.     $15:Begin                      { ORA ZPX }
  247.        address := (popByte + X) and $ff;
  248.        A := A or memReadByte(address);
  249.        If A <> 0 Then P := P and $fd else P := P or $02;
  250.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  251.       End;
  252.     $16:Begin                      { ASL ZPX }
  253.        address := (popByte + X) and $ff;
  254.        value := memReadByte(address);
  255.        P := (P and $fe) or ((value shr 7) and 1);
  256.        value := value shl 1;
  257.        memStoreByte(address, value);
  258.        If value <> 0 Then P := P and $fd else P := P or $02;
  259.        If value and $80 <> $80 Then P := P or $80 else P := P and $7f;
  260.       End;
  261.     $18:                            { CLC }
  262.       P := P and $fe;
  263.     $19:Begin                       { ORA ABSY }
  264.        address := popWord + Y;
  265.        A := A or memReadByte(address);
  266.        If A <> 0 Then P := P and $fd else P := P or $02;
  267.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  268.       End;
  269.     $1d:Begin                       { ORA ABSX }
  270.        address := popWord + X;
  271.        A := A or memReadByte(address);
  272.        If A <> 0 Then P := P and $fd else P := P or $02;
  273.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  274.       End;
  275.     $1e:Begin                       { ASL ABSX }
  276.        address := popWord + X;
  277.        value := memReadByte(address);
  278.        P := (P and $fe) or ((value shr 7) and 1);
  279.        value := value shl 1;
  280.        memStoreByte( address, value );
  281.        If value <> 0 Then P := P and $fd else P := P or $02;
  282.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  283.       End;
  284.     $20:Begin                      { JSR ABS }
  285.        address := popWord;
  286.        currAddr := PC - 1;
  287.        stackPush((currAddr shr 8) and $ff);
  288.        stackPush(currAddr and $ff);
  289.        PC := address;
  290.       End;
  291.     $21:Begin                      { AND INDX }
  292.        address := (popByte + X) and $ff;
  293.        value := memReadByte(address) + (memReadByte(address + 1) shl 8);
  294.        A := A and value;
  295.        If A <> 0 Then P := P and $fd else P := P or $02;
  296.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  297.       End;
  298.     $24:Begin                      { BIT ZP }
  299.        zp := popByte;
  300.        value := memReadByte( zp );
  301.        If value and A <> 0 Then P := P and $fd else P := P or $02;
  302.        P := (P and $3f) or (value and $c0);
  303.       End;
  304.     $25:Begin                      { AND ZP }
  305.        zp := popByte;
  306.        A := A and memReadByte( zp );
  307.        If A <> 0 Then P := P and $fd else P := P or 2;
  308.        If A and $80 = $80 Then P := P and $80 else P := P and $7f;
  309.       End;
  310.     $26:Begin                      { ROL ZP }
  311.        sf := (P and 1);
  312.        address := popByte;
  313.        value := memReadByte( address );
  314.        P := (P and $fe) or ((value shr 7) and 1);
  315.        value := value shl 1;
  316.        value := value or sf;
  317.        memStoreByte( address, value );
  318.        If value <> 0 Then P := P and $fd else P := P or $02;
  319.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  320.       End;
  321.     $28:                            { PLP }
  322.       P := stackPop or $20;
  323.     $29:Begin                       { AND IMM }
  324.        A := A and popByte;
  325.        If A <> 0 Then P := P and $fd else P := P or $02;
  326.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  327.      End;
  328.     $2a:Begin                       { ROL A }
  329.        sf := (P and 1);
  330.        P := (P and $fe) or ((A shr 7) and 1);
  331.        A := A shl 1;
  332.        A := A or sf;
  333.        If A <> 0 Then P := P and $fd else P := P or $02;
  334.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  335.       End;
  336.     $2c:Begin                      { BIT ABS }
  337.        value := memReadByte(popWord);
  338.        If value and A <> 0 Then P := P and $fd else P := P or $02;
  339.        P := (P and $3f) or (value and $c0);
  340.       End;
  341.     $2d:Begin                      { AND ABS }
  342.        value := memReadByte(popWord);
  343.        A := A and value;
  344.        If A <> 0 Then P := P and $fd else P := P or $02;
  345.        If A and $80=$80 Then P := P or $80 else P := P and $7f;
  346.       End;
  347.     $2e:Begin                      { ROL ABS }
  348.        sf := P and 1;
  349.        address := popWord;
  350.        value := memReadByte( address );
  351.        P := (P and $fe) or ((value shr 7) and 1);
  352.        value := value shl 1;
  353.        value := value or sf;
  354.        memStoreByte( address, value );
  355.        If value <> 0 Then P := P and $fd else P := P or $02;
  356.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  357.       End;
  358.     $30:Begin                       { BMI }
  359.        offset := popByte;
  360.        If P and $80 <> $80 Then jumpBranch( offset );
  361.       End;
  362.     $31:Begin                       { AND INDY }
  363.        zp := popByte;
  364.        value := memReadByte(zp) + (memReadByte(zp+1) shl 8) + Y;
  365.        A := A and memReadByte(value);
  366.        If A <> 0 Then P := P and $fd else P := P or $02;
  367.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  368.       End;
  369.     $35:Begin                       { AND INDX }
  370.        zp := popByte;
  371.        value := memReadByte(zp) + (memReadByte(zp+1) shl 8) + X;
  372.        A := A and memReadByte(value);
  373.        If A <> 0 Then P := P and $fd else P := P or $02;
  374.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  375.       End;
  376.     $36:Begin                       { ROL ZPX }
  377.        sf := P and 1;
  378.        address := (popByte + X) and $ff;
  379.        value := memReadByte(address);
  380.        P := (P and $fe) or ((value shr 7) and 1);
  381.        value := value shl 1;
  382.        value := value or sf;
  383.        memStoreByte( address, value );
  384.        If value <> 0 Then P := P and $fd else P := P or $02;
  385.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  386.       End;
  387.     $38:                            { SEC }
  388.       P := P or 1;
  389.     $39:Begin                       { AND ABSY }
  390.        address := popWord + Y;
  391.        value := memReadByte( address );
  392.        A := A and value;
  393.        If A <> 0 Then P := P and $fd else P := P or $02;
  394.        If A and $80 = $80 Then P := P or $80 else P := P and  $7f;
  395.       End;
  396.     $3d:Begin                       { AND ABSX }
  397.        address := popWord + X;
  398.        value := memReadByte(address);
  399.        A := A and value;
  400.        If A <> 0 Then P := P and $fd else P := P or $02;
  401.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  402.       End;
  403.     $3e:Begin                       { ROL ABSX }
  404.        sf := P and 1;
  405.        address := popWord + X;
  406.        value := memReadByte(address);
  407.        P := (P and $fe) or ((value shr 7) and 1);
  408.        value := value shl 1;
  409.        value := value or sf;
  410.        memStoreByte(address, value);
  411.        If value <> 0 Then P := P and $fd else P := P or $02;
  412.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  413.       End;
  414.     $40:;                           { RTI (non-supporté, =NOP) }
  415.     $41:Begin                       { EOR INDX }
  416.        zp := (popByte + X) and $ff;
  417.        value := memReadByte(zp) + (memReadByte(zp+1) shl 8);
  418.        A := A xor memReadByte(value);
  419.        If A <> 0 Then P := P and $fd else P := P or $02;
  420.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  421.       End;
  422.     $45:Begin                       { EOR ZPX }
  423.        address := (popByte + X) and $ff;
  424.        value := memReadByte(address);
  425.        A := A xor value;
  426.        If A <> 0 Then P := P and $fd else P := P or $02;
  427.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  428.       End;
  429.     $46:Begin                       { LSR ZP }
  430.        address := popByte and $ff;
  431.        value := memReadByte(address);
  432.        P := (P and $fe) or (value and 1);
  433.        value := value shr 1;
  434.        memStoreByte(address, value);
  435.        If value <> 0 Then P := P and $fd else P := P or 2;
  436.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  437.       End;
  438.     $48:                            { PHA }
  439.       stackPush(A);
  440.     $49:Begin                       { EOR IMM }
  441.        A := A xor popByte;
  442.        If A <> 0 Then P := P and $fd else P := P or $02;
  443.        If A and $80 = $80 Then P := P + $80 else P := P and $7f;
  444.       End;
  445.     $4a:Begin                        { LSR }
  446.        P := (P and $fe) or (A and 1);
  447.        A := A shr 1;
  448.        If A <> 0 Then P := P and $fd else P := P or $02;
  449.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  450.       End;
  451.     $4c:                            { JMP abs }
  452.       PC := popWord;
  453.     $4d:Begin                       { EOR abs }
  454.        address := popWord;
  455.        value := memReadByte(address);
  456.        A := A xor value;
  457.        If A <> 0 Then P := P and $fd else P := P or $02;
  458.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  459.       End;
  460.     $4e:Begin                       { LSR abs }
  461.        address := popWord;
  462.        value := memReadByte(address);
  463.        P := (P and $fe) or (value and 1);
  464.        value := value shr 1;
  465.        memStoreByte(address, value);
  466.        If value <> 0 Then P := P and $fd else P := P or $02;
  467.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  468.       End;
  469.     $50:Begin                      { BVC (efface le debordement) }
  470.        offset := popByte;
  471.        If P and $40 = 0 Then jumpBranch(offset);
  472.       End;
  473.     $51:Begin                      { EOR INDY }
  474.        zp := popByte;
  475.        value := memReadByte(zp) + (memReadByte(zp+1) shl 8) + Y;
  476.        A := A xor memReadByte(value);
  477.        If A <> 0 Then P := P and $fd else P := P or $02;
  478.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  479.       End;
  480.     $55:Begin                      { EOR ZPX }
  481.        address := (popByte + X) and $ff;
  482.        A := A xor memReadByte(address);
  483.        If A <> 0 Then P := P and $fd else P := P or $02;
  484.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  485.       End;
  486.     $56:Begin                      { LSR ZPX }
  487.        address := (popByte + X) and $ff;
  488.        value := memReadByte(address);
  489.        P := (P and $fe) or (value and 1);
  490.        value := value shr 1;
  491.        memStoreByte(address, value);
  492.        If value <> 0 Then P := P and $fd else P := P or $02;
  493.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  494.       End;
  495.     $58:;                          { CLI (ne fait rien) }
  496.     $59:Begin                      { EOR ABSY }
  497.        address := popWord + Y;
  498.        value := memReadByte(address);
  499.        A := A xor value;
  500.        If A <> 0 Then P := P and $fd else P := P or $02;
  501.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  502.       End;
  503.     $5d:Begin                      { EOR ABSX }
  504.        address := popWord + X;
  505.        value := memReadByte(address);
  506.        A := A xor value;
  507.        If A <> 0 Then P := P and $fd else P := P or $02;
  508.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  509.       End;
  510.     $5e:Begin                      { LSR ABSX }
  511.        address := popWord + X;
  512.        value := memReadByte(address);
  513.        P := (P and $fe) or (value and 1);
  514.        value := value shr 1;
  515.        memStoreByte(address, value);
  516.        If value <> 0 Then P := P and $fd else P := P or $02;
  517.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  518.       End;
  519.     $60:                           { RTS }
  520.       PC := (stackPop + 1) or (stackPop shl 8);
  521.     $61:Begin                      { ADC INDX }
  522.        zp := (popByte + X) and $ff;
  523.        address := memReadByte(zp) + (memReadByte(zp+1) shl 8);
  524.        value := memReadByte(address);
  525.        testADC( value );
  526.       End;
  527.     $65:Begin                      { ADC ZP }
  528.        address := popByte;
  529.        value := memReadByte(address);
  530.        testADC(value);
  531.       End;
  532.     $66:Begin                      { ROR ZP }
  533.        sf := P and 1;
  534.        address := popByte;
  535.        value := memReadByte( address );
  536.        P := (P and $fe) or (value and 1);
  537.        value := value shr 1;
  538.        If sf <> 0 Then value := value or $80;
  539.        memStoreByte( address, value );
  540.        If value <> 0 Then P := P and $fd else P := P or $02;
  541.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  542.       End;
  543.     $68:Begin                      { PLA }
  544.        A := stackPop;
  545.        If A <> 0 Then P := P and $fd else P := P or $02;
  546.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  547.       End;
  548.     $69:Begin                      { ADC IMM }
  549.        value := popByte;
  550.        testADC(value);
  551.       End;
  552.     $6a:Begin                      { ROR A }
  553.       sf := P and 1;
  554.       P := (P and $fe) or (A and 1);
  555.       A := A shr 1;
  556.       If sf <> 0 Then A := A or $80;
  557.       If A <> 0 Then P := P and $fd else P := P or $02;
  558.       If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  559.       End;
  560.     $6c:                           { JMP INDIR }
  561.       PC := memReadByte(popByte) + (memReadByte(popByte) shl 8);
  562.     $6d:Begin                      { ADC ABS }
  563.        address := popWord;
  564.        value := memReadByte(address);
  565.        testADC(value);
  566.       End;
  567.     $6e:Begin                      { ROR ABS }
  568.        sf := P and 1;
  569.        address := popWord;
  570.        value := memReadByte(address);
  571.        P := (P and $fe) or (value and 1);
  572.        value := value shr 1;
  573.        If sf <> 0 Then value := value or $80;
  574.        memStoreByte(address, value);
  575.        If value <> 0 Then P := P and $fd else P := P or $02;
  576.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  577.       End;
  578.     $70:Begin                     { BVS (branch on overflow set) }
  579.        offset := popByte;
  580.        If P and $40 = $40 Then jumpBranch(offset);
  581.       End;
  582.     $71:Begin                     { ADC INY }
  583.        zp := popByte;
  584.        address := memReadByte(zp) + (memReadByte(zp + 1) shl 8);
  585.        value := memReadByte(address + Y);
  586.        testADC(value);
  587.       End;
  588.     $75:Begin                     { ADC ZPX }
  589.        address := (popByte + X) and $ff;
  590.        value := memReadByte(address);
  591.        P := (P and $fe) or (value and 1);
  592.        testADC(value);
  593.       End;
  594.     $76:Begin                     { ROR ZPX }
  595.        sf := (P and 1);
  596.        address := (popByte + X) and $ff;
  597.        value := memReadByte(address);
  598.        P := (P and $fe) or (value and 1);
  599.        value := value shr 1;
  600.        If sf <> 0 Then value := value or $80;
  601.        memStoreByte(address, value);
  602.        If value <> 0 Then P := P and $fd else P := P or $02;
  603.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  604.       End;
  605.     $78:;                          { SEI (ne fait rien) }
  606.     $79:Begin                      { ADC ABSY }
  607.        address := popWord;
  608.        value := memReadByte(address + Y);
  609.        testADC(value);
  610.       End;
  611.     $7d:Begin                      { ADC ABSX }
  612.        address := popWord;
  613.        value := memReadByte(address + X);
  614.        testADC(value);
  615.       End;
  616.     $7e:Begin                      { ROR ABSX }
  617.        sf := P and 1;
  618.        address := popWord + X;
  619.        value := memReadByte(address);
  620.        P := (P and $fe) or (value and 1);
  621.        value := value shr 1;
  622.        If value <> 0 Then value := value or $80;
  623.        memStoreByte( address, value );
  624.        If value <> 0 Then P := P and $fd else P := P or $02;
  625.        If value and $80 = $80 Then P := P and $80 else P := P and $7f;
  626.       End;
  627.     $81:Begin                     { STA INDX }
  628.        zp := (popByte + X) and $ff;
  629.        address := memReadByte(zp) + (memReadByte(zp+1) shl 8);
  630.        memStoreByte(address, A);
  631.       End;
  632.     $84:                           { STY ZP }
  633.       memStoreByte( popByte, Y);
  634.     $85:                           { STA ZP }
  635.       memStoreByte( popByte, A);
  636.     $86:                           { STX ZP }
  637.       memStoreByte( popByte, X);
  638.     $88:Begin                      { DEY (1 octet) }
  639.        Y := (Y-1) and $ff;
  640.        If Y <> 0 Then P := P and $fd else P := P or $02;
  641.        If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  642.       End;
  643.     $8a:Begin                      { TXA (1 octet); }
  644.       A := X and $ff;
  645.        If A <> 0 Then P := P and $fd else P := P or $02;
  646.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  647.       End;
  648.     $8c:                           { STY abs }
  649.       memStoreByte( popWord, Y );
  650.     $8d:                           { STA ABS (3 octets) }
  651.       memStoreByte( popWord, A );
  652.     $8e:                           { STX abs }
  653.       memStoreByte( popWord, X );
  654.     $90:Begin                      { BCC (branchement dans l'effacement de retenue) }
  655.        offset := popByte;
  656.        If P and 1 = 0 Then jumpBranch( offset );
  657.       End;
  658.     $91:Begin                      { STA INDY }
  659.        zp := popByte;
  660.        address := memReadByte(zp) + (memReadByte(zp + 1) shl 8) + Y;
  661.        memStoreByte(address, A);
  662.       End;
  663.     $94:                           { STY ZPX }
  664.       memStoreByte( popByte + X, Y );
  665.     $95:                           { STA ZPX }
  666.       memStoreByte( popByte + X, A );
  667.     $96:                           { STX ZPY }
  668.       memStoreByte( popByte + Y, X );
  669.     $98:Begin                      { TYA }
  670.        A := Y and $ff;
  671.        If A <> 0 Then P := P and $fd else P := P or $02;
  672.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  673.       End;
  674.     $99:                           { STA ABSY }
  675.       memStoreByte( popWord + Y, A );
  676.     $9a:                           { TXS }
  677.       SP := X and $ff;
  678.     $9d:Begin                      { STA ABSX }
  679.        address := popWord;
  680.        memStoreByte(address + X, A);
  681.       End;
  682.     $a0:Begin                      { LDY IMM }
  683.        Y := popByte;
  684.        If Y <> 0 Then P := P and $fd else P := P or $02;
  685.        If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  686.       End;
  687.     $a1:Begin                      { LDA INDX }
  688.        zp := (popByte + X) and $ff;
  689.        address := memReadByte(zp) + (memReadByte(zp + 1) shl 8);
  690.        A := memReadByte(address);
  691.        If A <> 0 Then P := P and $fd else P := P or $02;
  692.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  693.       End;
  694.     $a2:Begin                      { LDX IMM }
  695.        X := popByte;
  696.        If X <> 0 Then P := P and $fd else P := P or $02;
  697.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  698.       End;
  699.     $a4:Begin                      { LDY ZP }
  700.       Y := memReadByte(popByte);
  701.       If Y <> 0 Then P := P and $fd else P := P or $02;
  702.       If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  703.       End;
  704.     $a5:Begin                      { LDA ZP }
  705.        A := memReadByte(popByte);
  706.        If A <> 0 Then P := P and $fd else P := P or $02;
  707.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  708.       End;
  709.     $a6:Begin                      { LDX ZP }
  710.        X := memReadByte(popByte);
  711.        If X <> 0 Then P := P and $fd else P := P or $02;
  712.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  713.       End;
  714.     $a8:Begin                      { TAY }
  715.        Y := A and $ff;
  716.        If Y <> 0 Then P := P and $fd else P := P or $02;
  717.        If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  718.       End;
  719.     $a9:Begin                      { LDA IMM }
  720.        A := popByte;
  721.        If A <> 0 Then P := P and $fd else P := P or $02;
  722.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  723.       End;
  724.     $aa:Begin                      { TAX }
  725.        X := A and $ff;
  726.        If X <> 0 Then P := P and $fd else P := P or $02;
  727.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  728.       End;
  729.     $ac:Begin                      { LDY ABS }
  730.        Y := memReadByte(popWord);
  731.        If Y <> 0 Then P := P and $fd else P := P or $02;
  732.        If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  733.       End;
  734.     $ad:Begin                      { LDA ABS }
  735.        A := memReadByte(popWord);
  736.        If A <> 0 Then P := P and $fd else P := P or $02;
  737.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  738.       End;
  739.     $ae:Begin                      { LDX ABS }
  740.        X := memReadByte(popWord);
  741.        If X <> 0 Then P := P and $fd else P := P or $02;
  742.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  743.       End;
  744.     $b0:Begin                      { BCS }
  745.        offset := popByte;
  746.        If P and 1 = 1 Then jumpBranch(offset);
  747.       End;
  748.     $b1:Begin                      { LDA INDY }
  749.        zp := popByte;
  750.        address := memReadByte(zp) + (memReadByte(zp+1) shl 8) + Y;
  751.        A := memReadByte(address);
  752.        If A <> 0 Then P := P and $fd else P := P or $02;
  753.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  754.       End;
  755.     $b4:Begin                      { LDY ZPX }
  756.        Y := memReadByte(popByte + X);
  757.        If Y <> 0 Then P := P and $fd else P := P or $02;
  758.        If Y = Y and $80 Then P := P or $80 else P := P and $7f;
  759.       End;
  760.     $b5:Begin                      { LDA ZPX }
  761.        A := memReadByte((popByte + X) and $ff);
  762.        If A <> 0 Then P := P and $fd else P := P or $02;
  763.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  764.       End;
  765.     $b6:Begin                      { LDX ZPY }
  766.        X := memReadByte(popByte + Y);
  767.        If X <> 0 Then P := P and $fd else P := P or $02;
  768.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  769.       End;
  770.     $b8:                          { CLV }
  771.       P := P and $bf;
  772.     $b9:Begin                     { LDA ABSY }
  773.        address := popWord + Y;
  774.        A := memReadByte(address);
  775.        If A <> 0 Then P := P and $fd else P := P or $02;
  776.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  777.       End;
  778.     $ba:                          { TSX }
  779.       X := SP and $ff;
  780.     $bc:Begin                     { LDY ABSX }
  781.        address := popWord + X;
  782.        Y := memReadByte(address);
  783.        If Y <> 0 Then P := P and $fd else P := P or $02;
  784.        If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  785.       End;
  786.     $bd:Begin                     { LDA ABSX }
  787.        address := popWord + X;
  788.        A := memReadByte(address);
  789.        If A <> 0 Then P := P and $fd else P := P or $02;
  790.        If A and $80 = $80 Then P := P or $80 else P := P and $7f;
  791.       End;
  792.     $be:Begin                     { LDX ABSY }
  793.        address := popWord + Y;
  794.        X := memReadByte(address);
  795.        If X <> 0 Then P := P and $fd else P := P or $02;
  796.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  797.       End;
  798.     $c0:Begin                     { CPY IMM }
  799.        value := popByte;
  800.        If Y + value > $ff Then P := P or 1 else P := P and $fe;
  801.        value := Y-value;
  802.        If value <> 0 Then P := P and $fd else P := P or $02;
  803.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  804.       End;
  805.     $c1:Begin                     { CMP INDY }
  806.        zp := popByte;
  807.        address := memReadByte(zp) + (memReadByte(zp + 1) shl 8) + Y;
  808.        value := memReadByte(address);
  809.        doCompare(A, value);
  810.       End;
  811.     $c4:Begin                     { CPY ZP }
  812.        value := memReadByte(popByte);
  813.        doCompare(Y, value);
  814.       End;
  815.     $c5:Begin                     { CMP ZP }
  816.        value := memReadByte(popByte);
  817.        doCompare(A, value);
  818.       End;
  819.     $c6:Begin                     { DEC ZP }
  820.        zp := popByte;
  821.        value := memReadByte(zp);
  822.        value := value - 1;
  823.        memStoreByte( zp, value and $ff );
  824.        If value <> 0 Then P := P and $fd else P := P or $02;
  825.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  826.       End;
  827.     $c8:Begin                     { INY }
  828.        Y := (Y + 1) and $ff;
  829.        If Y <> 0 Then P := P and $fd else P := P or $02;
  830.        If Y and $80 = $80 Then P := P or $80 else P := P and $7f;
  831.       End;
  832.     $c9:Begin                     { CMP IMM }
  833.       value := popByte;
  834.       doCompare( A, value );
  835.       End;
  836.     $ca:Begin                     { DEX }
  837.        X := (X - 1) and $ff;
  838.        If X <> 0 Then P := P and $fd else P := P or $02;
  839.        If X and $80 = $80 Then P := P or $80 else P := P and $7f;
  840.       End;
  841.     $cc:Begin                     { CPY ABS }
  842.        value := memReadByte(popWord);
  843.        doCompare(Y, value);
  844.       End;
  845.     $cd:Begin                     { CMP ABS }
  846.        value := memReadByte(popWord);
  847.        doCompare(A, value);
  848.       End;
  849.     $ce:Begin                     { DEC ABS }
  850.        address := popWord;
  851.        value := memReadByte( address );
  852.        value := value - 1;
  853.        value := value and $ff;
  854.        memStoreByte( address, value );
  855.        If value <> 0 Then P := P and $fd else P := P  or $02;
  856.        If value and $80 = $80 Then P := P or $80 Else P := P and $7f;
  857.       End;
  858.     $d0:Begin                     { BNE }
  859.        offset := popByte;
  860.        If P and 2 = 0 Then jumpBranch( offset );
  861.       End;
  862.     $d1:Begin                     { CMP INDY }
  863.        zp := popByte;
  864.        address := memReadByte(zp) + (memReadByte(zp + 1) shl 8) + Y;
  865.        value := memReadByte(address);
  866.        doCompare(A, value );
  867.       End;
  868.     $d5:Begin                     { CMP ZPX }
  869.        value := memReadByte( popByte + X );
  870.        doCompare(A, value);
  871.       End;
  872.     $d6:Begin                     { DEC ZPX }
  873.        address := popByte + X;
  874.        value := memReadByte(address);
  875.        value := value - 1;
  876.        value := value and $ff;
  877.        memStoreByte( address, value );
  878.        If value <> 0 Then P := P and $fd else P := P or $02;
  879.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  880.       End;
  881.     $d8:                          { CLD (CLear Decimal) }
  882.       P := P and $f7;
  883.     $d9:Begin                     { CMP ABSY }
  884.        address := popWord + Y;
  885.        value := memReadByte(address);
  886.        doCompare(A, value);
  887.       End;
  888.     $dd:Begin                     { CMP ABSX }
  889.        address := popWord + X;
  890.        value := memReadByte(address);
  891.        doCompare(A,value);
  892.       End;
  893.     $de:Begin                     { DEC ABSX }
  894.        address := popWord + X;
  895.        value := memReadByte(address);
  896.        value := value - 1;
  897.        value := value and $ff;
  898.        memStoreByte( address, value );
  899.        If value <> 0 Then P := P and $fd else P := P or $02;
  900.        If value = value and $80 Then P := P or $80 else P := P and $7f;
  901.       End;
  902.     $e0:Begin                     { CPX IMM }
  903.        value := popByte;
  904.        doCompare( X, value );
  905.       End;
  906.     $e1:Begin                     { SBC INDX }
  907.        zp := (popByte+X) and $ff;
  908.        address := memReadByte(zp) + (memReadByte(zp+1) shl 8);
  909.        value := memReadByte(address);
  910.        testSBC(value);
  911.       End;
  912.     $e4:Begin                     { CPX ZP }
  913.        value := memReadByte(popByte);
  914.        doCompare( X, value );
  915.       End;
  916.     $e5:Begin                     { SBC ZP }
  917.        address := popByte;
  918.        value := memReadByte(address);
  919.        testSBC(value);
  920.       End;
  921.     $e6:Begin                     { INC ZP }
  922.        zp := popByte;
  923.        value := memReadByte(zp);
  924.        value := value + 1;
  925.        value := value and $ff;
  926.        memStoreByte(zp, value);
  927.        If value <> 0 Then P := P and $fd else P := P or $02;
  928.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  929.       End;
  930.     $e8:Begin                     { INX }
  931.        X := (X + 1) and $ff;
  932.        if X <> 0 Then P := P and $fd else P := P or $02;
  933.        if X and $80 = $80 Then P := P or $80 else P := P and $7f;
  934.       End;
  935.     $e9:Begin                     { SBC IMM }
  936.        value := popByte;
  937.        testSBC(value);
  938.       End;
  939.     $ea:;                        { NOP }
  940.     $ec:Begin                    { CPX ABS }
  941.        value := memReadByte(popWord);
  942.        doCompare(X, value);
  943.       End;
  944.     $ed:Begin                    { SBC ABS }
  945.        address := popWord;
  946.        value := memReadByte( address );
  947.        testSBC(value);
  948.       End;
  949.     $ee:Begin                    { INC ABS }
  950.        address := popWord;
  951.        value := memReadByte(address);
  952.        value := value + 1;
  953.        value := value and $ff;
  954.        memStoreByte(address, value);
  955.        If value <> 0 Then P := P and $fd else P := P or $02;
  956.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  957.       End;
  958.     $f0:Begin                     { BEQ }
  959.        offset := popByte;
  960.        If P and 2 = 2 Then jumpBranch(offset);
  961.       End;
  962.     $f1:Begin                     { SBC INDY }
  963.        zp := popByte;
  964.        address := memReadByte(zp) + (memReadByte(zp+1) shl 8);
  965.        value := memReadByte( address + Y );
  966.        testSBC( value );
  967.       End;
  968.     $f5:Begin                     { SBC ZPX }
  969.        address := (popByte + X) and $ff;
  970.        value := memReadByte( address );
  971.        P := (P and $fe) or (value and 1);
  972.        testSBC(value);
  973.       End;
  974.     $f6:Begin                     { INC ZPX }
  975.        address := popByte + X;
  976.        value := memReadByte(address);
  977.        value := value + 1;
  978.        value := value and $ff;
  979.        memStoreByte(address, value);
  980.        If value <> 0 Then P := P and $fd else P := P or $02;
  981.        If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  982.       End;
  983.     $f8:                         { SED }
  984.       P := P or 8;
  985.     $f9:Begin                    { SBC ABSY }
  986.        address := popWord;
  987.        value := memReadByte(address + Y);
  988.        testSBC(value);
  989.       End;
  990.     $fd:Begin                    { SBC ABSX }
  991.        address := popWord;
  992.        value := memReadByte(address + X);
  993.        testSBC(value);
  994.       End;
  995.     $fe:Begin                    { INC ABSX }
  996.       address := popWord + X;
  997.       value := memReadByte(address);
  998.       value := value + 1;
  999.       value := value and $ff;
  1000.       memStoreByte(address, value);
  1001.       If value <> 0 Then P := P and $fd else P := P or $02;
  1002.       If value and $80 = $80 Then P := P or $80 else P := P and $7f;
  1003.      End;
  1004.      Else Begin
  1005.       WriteLn('Adresse $', addr2hex(PC), ' - code inconnu ', opcode);
  1006.       codeRunning := False;
  1007.      End;
  1008.   End;
  1009.  
  1010.   If (PC = 0) or (Not codeRunning) Then Begin
  1011.     WriteLn('Programme terminé à PC=$', addr2hex(PC-1));
  1012.     codeRunning := False;
  1013.   End;
  1014. End;
  1015.  
  1016.  
  1017. BEGIN
  1018.  InitEmul;
  1019.  Repeat
  1020.   ExecEmul;
  1021.  Until Not codeRunning;
  1022. END.

Remarques



PARTAGER CETTE PAGE SUR
Dernière mise à jour : Jeudi, le 30 juillet 2020