home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Emulatoren / FS_FRO23.LZX / Frodo / src / 6510.asm < prev    next >
Encoding:
Assembly Source File  |  1996-06-13  |  59.4 KB  |  3,397 lines

  1. *
  2. * 6510.asm - 6510-Emulation (eigener Task)
  3. *
  4. * Copyright (C) 1994-1996 by Christian Bauer
  5. *
  6.  
  7. *
  8. * Anmerkungen:
  9. * ------------
  10. *
  11. * Register d0/d1/a4 - WICHTIG:
  12. *  - Der Emulator geht davon aus, daß die MSWs von d0 und d1 immer Null
  13. *    sind. Denn dadurch kann das C64-RAM mittels (RAMPTR,d0.l) ohne
  14. *    Vorzeichen indiziert angesprochen werden.
  15. *  - Die Makros Read#?Zero#? und Read#?Ind#? gehen zusätlich davon aus,
  16. *    daß nur das untere Byte von d0 Null ist, da diese Makros immer nur
  17. *    am Anfang eines Befehls stehen und d0 vom Next-Makro noch gelöscht
  18. *    ist
  19. *  - Register a4 wird zur Near-Adressierung verwendet
  20. *
  21. * Speicherkonfigurationen:
  22. *
  23. * $01  $a000-$bfff  $d000-$dfff  $e000-$ffff
  24. * -----------------------------------------------
  25. *  0       RAM          RAM          RAM
  26. *  1       RAM       Char-ROM        RAM
  27. *  2       RAM       Char-ROM    Kernal-ROM
  28. *  3    Basic-ROM    Char-ROM    Kernal-ROM
  29. *  4       RAM          RAM          RAM
  30. *  5       RAM          I/O          RAM
  31. *  6       RAM          I/O      Kernal-ROM
  32. *  7    Basic-ROM       I/O      Kernal-ROM
  33. *
  34. * Zugriff auf den C64-Speicher:
  35. *  - Fast alle Speicherzugriffe laufen über die ReadByte/WriteByte-Makros,
  36. *    die die eingestellte Speicherkonfiguration dadurch berücksichtigen,
  37. *    daß die oberen 8 Adreßbits als Index in eine Sprungtabelle
  38. *    (ReadWriteTab) dienen, die Zeiger auf die ReadByte*/WriteByte*-
  39. *    Routinen enthalten, über die der tatsächliche Zugriff erfolgt.
  40. *    Für jede der 8 Speicherkonfigurationen existiert jeweils eine solche
  41. *    Tabelle Bei einer Änderung der Speicherkonfiguration (NewConfig)
  42. *    wird der Zeiger auf die Tabelle (RWTAB) geändert.
  43. *  - Das LESEN aus der Zero-Page geschieht immer direkt,
  44. *    da dort keine Register liegen ($00/$01 werden auch im RAM abgelegt)
  45. *  - Beim Schreiben in die Zero-Page wird nur auf $00/$01 getestet,
  46. *    ansonsten direkt zugegriffen
  47. *  - Der Stack wird immer direkt angesprochen
  48. *  - Die ReadByte-/WriteByte-Routinen dürfen nur d0-d1/a0-a1 verändern
  49. *
  50. * Programmzähler:
  51. *  - Aus Geschwindigkeitsgründen wird der PC durch einen 32-Bit-
  52. *    Amiga-Zeiger repräsentiert und über diesen direkt auf den
  53. *    Speicher zugegriffen (und nicht über ReadByte). Bei einem
  54. *    Sprungbefehl wird aus dem 16-Bit Sprungziel und der aktuellen
  55. *    Speicherkonfiguration die neue 32-Bit-Adresse berechnet,
  56. *    indem ähnlich zur ReadWriteTab die oberen 8 Bit des Sprungziels
  57. *    als Index in die JumpTab verwendet werden. Die darüber aufgerufenen
  58. *    Routinen führen die Umrechnung durch.
  59. *  - Durch die Art, wie das Hauptprogramm den Speicher anfordert,
  60. *    entsprechen die unteren 16 Bit des 32-Bit-PCs immer der
  61. *    16-Bit-C64-Adresse. Das erleichtert erheblich das Ablegen des
  62. *    PC auf dem Stack, da dazu einfach nur die unteren 16 Bit
  63. *    genommen werden müssen (ansonsten müßte man je nach RAM/ROM-
  64. *    Bereich erst die jeweilige Basisadresse subtrahieren).
  65. *  - Im RAM-Bereich $10000-$100ff wird der Opcode $d2 installiert,
  66. *    der den PC auf $0000-$00ff umrechnet, falls ein Programm den
  67. *    Wraparound macht
  68. *  - Durch diese Art der PC-Verwaltung bestehen folgende Inkompatibilitäten:
  69. *     - Ein Branch oder ein Hineinlaufen in einen anderen Speicherbereich
  70. *       (z.B. RAM->ROM) funktioniert nicht. Das sollte allerdings kein
  71. *       Problem darstellen.
  72. *     - Ein Sprung in den I/O-Bereich ist z.Z. nicht möglich
  73. *
  74. * Condition-Codes:
  75. *  - Die Emulation verwendet zwei Register, um die Prozessorflags zu
  76. *    speichern: RCCR und RP.
  77. *  - RCCR ist ein Abbild des 680x0-CCR und wird nach den entsprechenden
  78. *    Operationen mit "move ccr,RCCR" gelesen. Von RCCR werden nur das N-
  79. *    und das Z-Flag verwendet.
  80. *  - Die einzigen Opcodes, die V ändern, sind ADC, SBC, CLV, PLP und RTI.
  81. *    Darum wird das V-Flag nicht aus dem 680x0-V-Flag erzeugt, sondern
  82. *    gegebenenfalls von Hand gesetzt.
  83. *  - Im oberen Byte (Bit 8-15) von RP sind die 6510-Flags V,B,D und I
  84. *    in der selben Anordnung wie beim 6510 gespeichert. Das untere Byte
  85. *    enthält in Bit 0 das Carry-Flag in 6510-Interpretation (bei SBC und
  86. *    CMP/CPX/CPY inverse Bedeutung zum 680x0), das bei den entsprechenden
  87. *    Opcodes aus dem CCR gelesen (und ggf. invertiert) wird. Der Einfachheit
  88. *    halber wird immer das ganze untere Byte von CCR gelesen, da nur Bit 0
  89. *    interessant ist.
  90. *
  91. * Opcode-Ausführung:
  92. *  - Es gibt keine Fetch-Decode-Schleife, sondern jede Opcode-Routine
  93. *    enthält am Schluß den Code, der den nächsten Befehl ausführt
  94. *    ("Next"-Makro).
  95. *  - Die Verzweigung in die einzelnen Opcode-Routinen geschieht über
  96. *    eine Sprungtabelle, die OpcodeTable.
  97. *
  98. * Zyklenzähler/Periodic/Interrupts:
  99. *  - Die Variable CyclesLeft enthält die Anzahl Zyklen, die dem 6510 in
  100. *    der augenblicklichen Rasterzeile noch zur Verfügung stehen.
  101. *  - Ein Zeiger auf CyclesLeft steht in (CYCPTR) (wg. schnellerer
  102. *    Adressierung).
  103. *  - Nach jeder Opcode-Ausführung wird dieser Zähler um die Zyklenzahl
  104. *    des gerade ausgeführten Befehls erniedrigt. Dazu wird dem Next-Makro
  105. *    die Anzahl Zyklen übergeben. Unterschreitet der Zähler Null, wird
  106. *    die Routine "Periodic" aufgerufen.
  107. *  - In dieser Routine werden die Unterroutinen von VIC und CIA
  108. *    ausgeführt, die die Aktionen für eine Rasterzeile durchführen
  109. *    (VIC (Periodic6569): Eine Bildschirmzeile aufbauen, CIA
  110. *    (Periodic6526): Timer zählen)
  111. *  - In Periodic6569 wird der Zyklenzähler neu gesetzt (der Wert hängt
  112. *    davon ab, ob eine Bad Line stattfand oder nicht)
  113. *
  114. * Interrupts:
  115. *  - Die Haupt-Interruptquellen sind VIC und CIA, daher prüft der
  116. *    Emulator das Auftreten eines Interrupts im Rahmen der Periodic-
  117. *    Routine
  118. *  - Es gibt folgende Interrupt-Möglichkeiten (Prioritäten):
  119. *     - RESET, Sprung nach ($FFFC) oder 6510-Task beenden (RESETIsEXIT-Flag)
  120. *     - NMI, Sprung nach ($FFFA)
  121. *     - VIC-IRQ, I-Flag wird geprüft, Sprung nach ($FFFE)
  122. *     - CIA-IRQ, I-Flag wird geprüft, Sprung nach ($FFFE)
  123. *  - Die Aufteilung in VIC- und CIA-IRQ erleichtert die Handhabung, wenn
  124. *    beide IRQs gleichzeitig auftreten
  125. *  - Die einzige Möglichkeit, außerhalb des Periodic einen Interrupt
  126. *    auszulösen, ist das Löschen des I-Flags, wenn ein IRQ ansteht.
  127. *    Die Opcode-Routinen für PLP, RTI und CLI enthalten deswegen besondere
  128. *    Abfragen, die ggf. in den Interrupt-Handler verzweigen.
  129. *
  130. * Erweiterungen:
  131. *  - Über den Opcode $f2 sind die IEC-Routinen implementiert. Dem Opcode
  132. *    folgt ein Byte, das die Nummer der auzurufenden Routine angibt.
  133. *
  134. * Inkompatibilitäten:
  135. *  - ($ff),Y-Adressierung liest das zweite Byte der indirekten Adresse
  136. *    aus $0100 statt $0000. Dies geschieht aus Geschwindigkeitsgründen,
  137. *    der korrekte Code ist im Makro ReadAdrIndY auskommentiert.
  138. *  - In der Verwaltung des PCs bestehen einige Ungenauigkeiten (siehe
  139. *    Abschnitt "Programmzähler")
  140. *  - RMW-Befehle sollten erst die Originaldaten und dann die geänderten
  141. *    schreiben, aber das spielt nur eine Rolle für Register wie das
  142. *    VIC-IRQFLAG-Register, das in 6569.asm deswegen speziell behandelt wird
  143. *  - Zyklen werden nur für ganze Befehle gezählt, Extra-Zyklen für
  144. *    Seitenüberschreitungen werden nicht berechnet (dies betrifft die
  145. *    Adressierungsarten xxxx,X xxxx,Y (xx),Y und die Branch-Befehle)
  146. *  - Der Kassettenschalter ist immer geschlossen
  147. *  - RRA und ISB kennen keinen Dezimalmodus
  148. *
  149.  
  150.         MACHINE    68020
  151.  
  152.         INCLUDE    "exec/types.i"
  153.         INCLUDE    "exec/macros.i"
  154.         INCLUDE    "exec/execbase.i"
  155.         INCLUDE    "exec/nodes.i"
  156.         INCLUDE    "dos/dos.i"
  157.         INCLUDE    "dos/dostags.i"
  158.         INCLUDE    "Frodo_rev.i"
  159. CATCOMP_NUMBERS    = 1
  160.         INCLUDE    "LocStrings.i"
  161.  
  162.         XREF    _SysBase
  163.         XREF    _DOSBase
  164.         XREF    _IntuitionBase
  165.  
  166.         XREF    GetString    ;Strings.o
  167.         XREF    TheLocale
  168.  
  169.         XDEF    TheRAM        ;Main.asm
  170.         XDEF    TheBasic
  171.         XDEF    TheKernal
  172.         XDEF    TheChar
  173.         XDEF    TheColor
  174.         XREF    MainTask
  175.         XREF    Random
  176.         XREF    ResetC64
  177.  
  178.         XREF    _InitDisplayFrom6510    ;Display.c
  179.         XREF    _ExitDisplayFrom6510
  180.         XREF    _EmulToBack
  181.         XREF    _EmulToFront
  182.  
  183.         XREF    ReadFrom6526A    ;6526.asm
  184.         XREF    ReadFrom6526B
  185.         XREF    WriteTo6526A
  186.         XREF    WriteTo6526B
  187.  
  188.         XREF    ReadFrom6569    ;6569.asm
  189.         XREF    WriteTo6569
  190.         XREF    Periodic6569
  191.  
  192.         XREF    ReadFrom6581    ;6581.asm
  193.         XREF    WriteTo6581
  194.  
  195.         XREF    IECOut        ;IEC.asm
  196.         XREF    IECOutATN
  197.         XREF    IECOutSec
  198.         XREF    IECIn
  199.         XREF    IECSetATN
  200.         XREF    IECRelATN
  201.         XREF    IECTurnaround
  202.         XREF    IECRelease
  203.  
  204.         XDEF    Init6510
  205.         XDEF    Reset6510
  206.         XDEF    Start6510
  207.         XDEF    Stop6510
  208.         XDEF    _Pause6510
  209.         XDEF    _Resume6510
  210.         XDEF    _SAMReadByte
  211.         XDEF    _SAMWriteByte
  212.         XDEF    Localize6510
  213.         XDEF    IntIsRESET
  214.         XDEF    IntIsNMI
  215.         XDEF    IntIsVICIRQ
  216.         XDEF    IntIsCIAIRQ
  217.         XDEF    NMIState
  218.         XDEF    CyclesLeft
  219.         XDEF    CPUTask
  220.         XDEF    Peri6569Cont
  221.         XDEF    Peri6526Cont
  222.         XDEF    IsFrodoSC
  223.         XDEF    _IsFrodoSC
  224.         XDEF    _InvokeSAMSet
  225.  
  226.         NEAR    a4,-2
  227.         XREF    _DATA_BAS_
  228.  
  229.         SECTION    "text",CODE
  230.  
  231.         FAR
  232.  
  233.  
  234. **
  235. ** Definitionen
  236. **
  237.  
  238. ; Bitdefinitionen für RP (6510-Statusregister)
  239. InterruptBit    = 10    ;Interrupts abgeschaltet
  240. InterruptMask    = $0400
  241. DecimalBit    = 11    ;Dezimalmodus
  242. DecimalMask    = $0800
  243. OverflowBit    = 14    ;Arith. Überlauf
  244. OverflowMask    = $4000
  245.  
  246. ; Registerbelegung
  247. RA        EQUR    d2    ;A
  248. RX        EQUR    d3    ;X
  249. RY        EQUR    d4    ;Y
  250. RS        EQUR    d5    ;S (16-Bit, $01xx)
  251. RCCR        EQUR    d6    ;CCR, nur N und Z
  252. RP        EQUR    d7    ;Oberes Byte: 6510-Status ohne N,Z und C
  253.                 ;Unteres Byte: Carry in 6510-Interpretation
  254. RWTAB        EQUR    a2    ;Zeiger auf ReadByte/WriteByte-Sprungtabelle
  255.                 ;256*8*8+RWTAB zeigt auf JumpTab
  256. CYCPTR        EQUR    a3    ;Zeiger auf CyclesLeft
  257. RAMPTR        EQUR    a5    ;Zeiger auf C64-RAM
  258. RPC        EQUR    a6    ;PC (32-Bit Amiga-Adresse, untere 16 Bit
  259.                 ;    stimmen mit C64-PC überein)
  260.  
  261.  
  262. **
  263. ** Emulation vorbereiten (Sprungtabellen aufbauen)
  264. **
  265.  
  266. ; ReadWriteTabs aufbauen
  267. Init6510    lea    ReadWriteTab0,a0    ;Alle mit RAM vorbelegen
  268.         move.w    #256*8-1,d0
  269. 1$        move.l    #ReadByteRAM,(a0)+
  270.         move.l    #WriteByteRAM,(a0)+
  271.         dbra    d0,1$
  272.  
  273.         move.l    #WriteBytePage0,ReadWriteTab0+4 ;Zeropage immer speziell
  274.         move.l    #WriteBytePage0,ReadWriteTab1+4
  275.         move.l    #WriteBytePage0,ReadWriteTab2+4
  276.         move.l    #WriteBytePage0,ReadWriteTab3+4
  277.         move.l    #WriteBytePage0,ReadWriteTab4+4
  278.         move.l    #WriteBytePage0,ReadWriteTab5+4
  279.         move.l    #WriteBytePage0,ReadWriteTab6+4
  280.         move.l    #WriteBytePage0,ReadWriteTab7+4
  281.  
  282.         lea    ReadWriteTab3+160*8,a0    ;Basic-ROM
  283.         moveq    #31,d0
  284. 21$        move.l    #ReadByteBasic,(a0)+
  285.         addq.l    #4,a0
  286.         dbra    d0,21$
  287.  
  288.         lea    ReadWriteTab7+160*8,a0
  289.         moveq    #31,d0
  290. 22$        move.l    #ReadByteBasic,(a0)+
  291.         addq.l    #4,a0
  292.         dbra    d0,22$
  293.  
  294.         lea    ReadWriteTab2+224*8,a0    ;Kernal-ROM
  295.         moveq    #31,d0
  296. 31$        move.l    #ReadByteKernal,(a0)+
  297.         addq.l    #4,a0
  298.         dbra    d0,31$
  299.  
  300.         lea    ReadWriteTab3+224*8,a0
  301.         moveq    #31,d0
  302. 32$        move.l    #ReadByteKernal,(a0)+
  303.         addq.l    #4,a0
  304.         dbra    d0,32$
  305.  
  306.         lea    ReadWriteTab6+224*8,a0
  307.         moveq    #31,d0
  308. 33$        move.l    #ReadByteKernal,(a0)+
  309.         addq.l    #4,a0
  310.         dbra    d0,33$
  311.  
  312.         lea    ReadWriteTab7+224*8,a0
  313.         moveq    #31,d0
  314. 34$        move.l    #ReadByteKernal,(a0)+
  315.         addq.l    #4,a0
  316.         dbra    d0,34$
  317.  
  318.         lea    ReadWriteTab5+208*8,a0    ;I/O-Bereich
  319.         bsr    InitIOPages
  320.  
  321.         lea    ReadWriteTab6+208*8,a0
  322.         bsr    InitIOPages
  323.  
  324.         lea    ReadWriteTab7+208*8,a0
  325.         bsr    InitIOPages
  326.  
  327.         lea    ReadWriteTab1+208*8,a0    ;Char-ROM
  328.         moveq    #15,d0
  329. 41$        move.l    #ReadByteChar,(a0)+
  330.         addq.l    #4,a0
  331.         dbra    d0,41$
  332.  
  333.         lea    ReadWriteTab2+208*8,a0
  334.         moveq    #15,d0
  335. 42$        move.l    #ReadByteChar,(a0)+
  336.         addq.l    #4,a0
  337.         dbra    d0,42$
  338.  
  339.         lea    ReadWriteTab3+208*8,a0
  340.         moveq    #15,d0
  341. 43$        move.l    #ReadByteChar,(a0)+
  342.         addq.l    #4,a0
  343.         dbra    d0,43$
  344.  
  345. ; JumpTabs aufbauen
  346.         lea    JumpTab0,a0        ;Alle mit RAM vorbelegen
  347.         move.w    #256*8-1,d0
  348. 6$        move.l    #JumpToRAM,(a0)+
  349.         addq.l    #4,a0
  350.         dbra    d0,6$
  351.  
  352.         lea    JumpTab3+160*8,a0    ;Basic-ROM
  353.         moveq    #31,d0
  354. 71$        move.l    #JumpToBasic,(a0)+
  355.         addq.l    #4,a0
  356.         dbra    d0,71$
  357.  
  358.         lea    JumpTab7+160*8,a0
  359.         moveq    #31,d0
  360. 72$        move.l    #JumpToBasic,(a0)+
  361.         addq.l    #4,a0
  362.         dbra    d0,72$
  363.  
  364.         lea    JumpTab2+224*8,a0    ;Kernal-ROM
  365.         moveq    #31,d0
  366. 81$        move.l    #JumpToKernal,(a0)+
  367.         addq.l    #4,a0
  368.         dbra    d0,81$
  369.  
  370.         lea    JumpTab3+224*8,a0
  371.         moveq    #31,d0
  372. 82$        move.l    #JumpToKernal,(a0)+
  373.         addq.l    #4,a0
  374.         dbra    d0,82$
  375.  
  376.         lea    JumpTab6+224*8,a0
  377.         moveq    #31,d0
  378. 83$        move.l    #JumpToKernal,(a0)+
  379.         addq.l    #4,a0
  380.         dbra    d0,83$
  381.  
  382.         lea    JumpTab7+224*8,a0
  383.         moveq    #31,d0
  384. 84$        move.l    #JumpToKernal,(a0)+
  385.         addq.l    #4,a0
  386.         dbra    d0,84$
  387.  
  388.         lea    JumpTab1+208*8,a0    ;Char-ROM
  389.         moveq    #15,d0
  390. 85$        move.l    #JumpToChar,(a0)+
  391.         addq.l    #4,a0
  392.         dbra    d0,85$
  393.  
  394.         lea    JumpTab2+208*8,a0
  395.         moveq    #15,d0
  396. 86$        move.l    #JumpToChar,(a0)+
  397.         addq.l    #4,a0
  398.         dbra    d0,86$
  399.  
  400.         lea    JumpTab3+208*8,a0
  401.         moveq    #15,d0
  402. 87$        move.l    #JumpToChar,(a0)+
  403.         addq.l    #4,a0
  404.         dbra    d0,87$
  405.  
  406.         lea    JumpTab5+208*8,a0    ;I/O-Bereich
  407.         moveq    #15,d0
  408. 88$        move.l    #JumpToIO,(a0)+
  409.         addq.l    #4,a0
  410.         dbra    d0,88$
  411.  
  412.         lea    JumpTab6+208*8,a0
  413.         moveq    #15,d0
  414. 89$        move.l    #JumpToIO,(a0)+
  415.         addq.l    #4,a0
  416.         dbra    d0,89$
  417.  
  418.         lea    JumpTab7+208*8,a0
  419.         moveq    #15,d0
  420. 810$        move.l    #JumpToIO,(a0)+
  421.         addq.l    #4,a0
  422.         dbra    d0,810$
  423.         rts
  424.  
  425. InitIOPages    move.l    #ReadByteVIC,(a0)+
  426.         move.l    #WriteByteVIC,(a0)+
  427.         move.l    #ReadByteVIC,(a0)+
  428.         move.l    #WriteByteVIC,(a0)+
  429.         move.l    #ReadByteVIC,(a0)+
  430.         move.l    #WriteByteVIC,(a0)+
  431.         move.l    #ReadByteVIC,(a0)+
  432.         move.l    #WriteByteVIC,(a0)+
  433.         move.l    #ReadByteSID,(a0)+
  434.         move.l    #WriteByteSID,(a0)+
  435.         move.l    #ReadByteSID,(a0)+
  436.         move.l    #WriteByteSID,(a0)+
  437.         move.l    #ReadByteSID,(a0)+
  438.         move.l    #WriteByteSID,(a0)+
  439.         move.l    #ReadByteSID,(a0)+
  440.         move.l    #WriteByteSID,(a0)+
  441.         move.l    #ReadByteColor,(a0)+
  442.         move.l    #WriteByteColor,(a0)+
  443.         move.l    #ReadByteColor,(a0)+
  444.         move.l    #WriteByteColor,(a0)+
  445.         move.l    #ReadByteColor,(a0)+
  446.         move.l    #WriteByteColor,(a0)+
  447.         move.l    #ReadByteColor,(a0)+
  448.         move.l    #WriteByteColor,(a0)+
  449.         move.l    #ReadByteCIA1,(a0)+
  450.         move.l    #WriteByteCIA1,(a0)+
  451.         move.l    #ReadByteCIA2,(a0)+
  452.         move.l    #WriteByteCIA2,(a0)+
  453.         move.l    #ReadByteUndef,(a0)+
  454.         move.l    #WriteByteUndef,(a0)+
  455.         move.l    #ReadByteUndef,(a0)+
  456.         move.l    #WriteByteUndef,(a0)
  457.         rts
  458.  
  459.  
  460. **
  461. ** 6510 zurücksetzen
  462. **
  463.  
  464. Reset6510    st.b    IntIsRESET
  465.         rts
  466.  
  467.  
  468. **
  469. ** 6510-Task starten
  470. ** Rückgabe: d0#0 = Fehler
  471. **
  472.  
  473. ; Signale einrichten
  474. Start6510    move.l    _SysBase,a6
  475.         moveq    #-1,d0
  476.         JSRLIB    AllocSignal
  477.         move.b    d0,ReadySig
  478.         moveq    #0,d1
  479.         bset    d0,d1
  480.         move.l    d1,ReadySet
  481.  
  482.         moveq    #-1,d0
  483.         JSRLIB    AllocSignal
  484.         move.b    d0,InvokeSAMSig
  485.         moveq    #0,d1
  486.         bset    d0,d1
  487.         move.l    d1,InvokeSAMSet
  488.  
  489. ; Task starten
  490.         move.l    _DOSBase,a6
  491.         move.l    #ProcTags,d1
  492.         JSRLIB    CreateNewProc
  493.         move.l    d0,CPUProc
  494.         beq    1$
  495.  
  496. ; Auf Signal warten
  497.         move.l    _SysBase,a6
  498.         move.l    ReadySet,d0
  499.         JSRLIB    Wait
  500.         moveq    #0,d0        ;Alles OK
  501.         rts
  502.  
  503. ; Fehler aufgetreten
  504. 1$        moveq    #-1,d0
  505.         rts
  506.  
  507.  
  508. **
  509. ** 6510-Task stoppen
  510. **
  511.  
  512. ; Task stoppen
  513. Stop6510    move.l    _SysBase,a6
  514.         tst.l    CPUProc
  515.         beq    1$
  516.         st.b    RESETIsEXIT    ;EXIT-Reset auslösen
  517.         st.b    IntIsRESET
  518.         move.l    ReadySet,d0
  519.         JSRLIB    Wait
  520.  
  521. ; Signale freigeben
  522. 1$        move.b    InvokeSAMSig,d0
  523.         JSRLIB    FreeSignal
  524.  
  525.         move.b    ReadySig,d0
  526.         JMPLIB    FreeSignal
  527.  
  528.  
  529. **
  530. ** 6510-Task anhalten, Zustand sichern
  531. **
  532.  
  533. _Pause6510    move.l    a6,-(sp)
  534.         move.l    _SysBase,a6
  535.         st.b    RESETIsPause    ;Pause-Reset auslösen
  536.         st.b    IntIsRESET
  537.         move.l    ReadySet,d0
  538.         JSRLIB    Wait
  539.         move.l    (sp)+,a6
  540.         rts
  541.  
  542.  
  543. **
  544. ** 6510-Task fortsetzen, Zustand übernehmen
  545. **
  546.  
  547. _Resume6510    move.l    a6,-(sp)
  548.         move.l    _SysBase,a6
  549.         move.l    CPUTask,a1    ;Continue-Signal schicken
  550.         move.l    ContinueSet,d0
  551.         JSRLIB    Signal
  552.         move.l    (sp)+,a6
  553.         rts
  554.  
  555.  
  556. **
  557. ** Byte lesen (für SAM)
  558. **
  559.  
  560. _SAMReadByte    moveq    #0,d0
  561.         move.w    6(sp),d0
  562.         movem.l    d2/a4/RAMPTR,-(sp)
  563.         lea    _DATA_BAS_,a4
  564.         lea    32766(a4),a4
  565.         move.l    TheRAM,RAMPTR
  566.         move.l    d0,d1
  567.         lsr.w    #8,d1
  568.         move.b    _SAMMemConfig,d2
  569.         and.w    #7,d2
  570.         move.l    (ConfigTab,d2.w*4),a0
  571.         move.l    (a0,d1.w*8),a0
  572.         jsr    (a0)
  573.         movem.l    (sp)+,d2/a4/RAMPTR
  574.         rts
  575.  
  576.  
  577. **
  578. ** Byte schreiben (für SAM)
  579. **
  580.  
  581. _SAMWriteByte    moveq    #0,d0
  582.         move.w    6(sp),d0
  583.         move.l    8(sp),d1
  584.         cmp.w    #$d000,d0
  585.         blo    1$
  586.         movem.l    d2/a4/RAMPTR/RPC,-(sp)
  587.         lea    _DATA_BAS_,a4
  588.         lea    32766(a4),a4
  589.         move.l    TheRAM,RAMPTR
  590.         lea    RequestStream+16,RPC    ;Dummy für WriteTo6526, das bei Zugriff auf das ICR den Opcode prüft
  591.         move.l    d0,a1
  592.         lsr.w    #8,d0
  593.         move.b    _SAMMemConfig,d2
  594.         and.w    #7,d2
  595.         move.l    (ConfigTab,d2.w*4),a0
  596.         move.l    (4,a0,d0.w*8),a0
  597.         jsr    (a0)
  598.         movem.l    (sp)+,d2/a4/RAMPTR/RPC
  599.         rts
  600. 1$        move.l    TheRAM,a0
  601.         move.b    d1,(a0,d0.l)
  602.         rts
  603.  
  604.  
  605. **
  606. ** Strings in Datenstrukturen lokalisieren
  607. **
  608.  
  609. GetStr        MACRO    ;Label
  610.         lea    TheLocale,a0
  611.         move.l    #\1,d0
  612.         jsr    GetString
  613.         ENDM
  614.  
  615. Localize6510    GetStr    MSG_REQTITLE
  616.         move.l    d0,IllegalOpReq+8
  617.         move.l    d0,JumpToIOReq+8
  618.  
  619.         GetStr    MSG_REQGADS6
  620.         move.l    d0,IllegalOpReq+16
  621.  
  622.         GetStr    MSG_REQGADS4
  623.         move.l    d0,JumpToIOReq+16
  624.  
  625.         GetStr    MSG_ILLEGALOP
  626.         move.l    d0,IllegalOpReq+12
  627.  
  628.         GetStr    MSG_JUMPTOIO
  629.         move.l    d0,JumpToIOReq+12
  630.         rts
  631.  
  632.  
  633. **
  634. ** 6510-Emulator
  635. **
  636. ** Register:
  637. **  d0: Scratch (Oberes Wort muß IMMER Null sein!)
  638. **  d1: Scratch (Oberes Wort muß IMMER Null sein!)
  639. **  a4: Zeiger auf Variablen
  640. **
  641.  
  642.         NEAR
  643.  
  644. *
  645. * Makros für Speicherzugriffe und Adreßberechnungen
  646. *
  647.  
  648. ; Ein C64-Byte lesen
  649. ; -> d0.w: Adresse
  650. ; <- d0.b: Byte
  651. ReadByte    MACRO    ;[Ziel] (wird ein Ziel angegeben, ist das CCR gültig)
  652.         cmp.w    #$a000,d0    ;Unterhalb von $a000 ist nur Speicher
  653.         blo    \@1$
  654.         move.w    d0,d1
  655.         lsr.w    #8,d1
  656.         move.l    (RWTAB,d1.l*8),a0
  657.         jsr    (a0)
  658.     IFGE    NARG-1
  659.         move.b    d0,\1
  660.     ENDC
  661.         bra    \@2$
  662. \@1$
  663.     IFGE    NARG-1
  664.         move.b    (RAMPTR,d0.l),\1
  665.     ELSE
  666.         move.b    (RAMPTR,d0.l),d0
  667.     ENDC
  668. \@2$
  669.         ENDM
  670.  
  671. ; Ein C64-Wort lesen (Als Makro schneller)
  672. ; -> d0.w: Adresse
  673. ; <- d0.w: Wort (Bytefolge korrigiert)
  674. ReadWord    MACRO
  675.         move.l    d2,RegStore
  676.         move.l    d0,d2        ;Adresse merken
  677.         ReadByte d1
  678.         move.l    d2,d0        ;Adresse zurückholen
  679.         addq.w    #1,d0        ;Nächstes Byte
  680.         move.b    d1,d2        ;Lo-Byte merken
  681.         ReadByte
  682.         lsl.w    #8,d0        ;Hi-Byte richtig schieben
  683.         move.b    d2,d0        ;Lo-Byte dazunehmen
  684.         move.l    RegStore,d2
  685.         ENDM
  686.  
  687. ; Ein C64-Byte schreiben
  688. ; -> d0.w: Adresse (16 bit)
  689. ; -> d1.b: Byte
  690. ; Adresse steht dann in a1
  691. WriteByte    MACRO
  692.         cmp.w    #$d000,d0    ;Unterhalb von $d000 ist nur Speicher
  693.         blo    \@1$
  694.         move.l    d0,a1
  695.         lsr.w    #8,d0
  696.         move.l    (4,RWTAB,d0.l*8),a0
  697.         jsr    (a0)
  698.         bra    \@2$
  699. \@1$        move.b    d1,(RAMPTR,d0.l)
  700.         cmp.b    #2,d0
  701.         bhs    \@2$
  702.         NewConfig
  703. \@2$
  704.         ENDM
  705.  
  706. ; Ein C64-Wort am PC lesen und PC erhöhen
  707. ReadPCWord    MACRO
  708.         move.w    (RPC)+,d0
  709.         rol.w    #8,d0
  710.         ENDM
  711.  
  712. ; Relative Adressierung
  713. ReadByteRel    MACRO
  714.         move.b    (RPC)+,d0
  715.         ext.w    d0
  716.         ENDM
  717.  
  718. ; Absolute Adressierung
  719. ReadAdrAbs    MACRO
  720.         ReadPCWord
  721.         ENDM
  722.  
  723. ReadByteAbs    MACRO    ;[Ziel] (wird ein Ziel angegeben, ist das CCR gültig)
  724.         ReadAdrAbs
  725.         ReadByte \1
  726.         ENDM
  727.  
  728. ; Indirekte Adressierung
  729. ReadAdrInd    MACRO
  730.         ReadPCWord
  731.         move.l    d2,RegStore
  732.         move.l    d0,d2        ;Adresse merken
  733.         ReadByte d1
  734.         move.l    d2,d0        ;Adresse zurückholen
  735.         addq.b    #1,d0        ;Nächstes Byte OHNE Page-Crossing
  736.         move.b    d1,d2        ;Lo-Byte merken
  737.         ReadByte
  738.         lsl.w    #8,d0        ;Hi-Byte richtig schieben
  739.         move.b    d2,d0        ;Lo-Byte dazunehmen
  740.         move.l    RegStore,d2
  741.         ENDM
  742.  
  743. ; Zero-Page Adressierung
  744. ReadAdrZero    MACRO
  745.         move.b    (RPC)+,d0
  746.         ENDM
  747.  
  748. ReadByteZero    MACRO    ;Ziel (CCR ist gültig)
  749.         ReadAdrZero
  750.         move.b    (RAMPTR,d0.l),\1
  751.         ENDM
  752.  
  753. ; Absolut,X
  754. ReadAdrAbsX    MACRO
  755.         ReadPCWord
  756.         add.w    RX,d0
  757.         ENDM
  758.  
  759. ReadByteAbsX    MACRO    ;[Ziel] (wird ein Ziel angegeben, ist das CCR gültig)
  760.         ReadAdrAbsX
  761.         ReadByte \1
  762.         ENDM
  763.  
  764. ; Absolut,Y
  765. ReadAdrAbsY    MACRO
  766.         ReadPCWord
  767.         add.w    RY,d0
  768.         ENDM
  769.  
  770. ReadByteAbsY    MACRO    ;[Ziel] (wird ein Ziel angegeben, ist das CCR gültig)
  771.         ReadAdrAbsY
  772.         ReadByte \1
  773.         ENDM
  774.  
  775. ; Zero-Page,X
  776. ReadAdrZeroX    MACRO
  777.         move.b    (RPC)+,d0
  778.         add.b    RX,d0
  779.         ENDM
  780.  
  781. ReadByteZeroX    MACRO    ;Ziel (CCR ist gültig)
  782.         ReadAdrZeroX
  783.         move.b    (RAMPTR,d0.l),\1
  784.         ENDM
  785.  
  786. ; Zero-Page,Y
  787. ReadAdrZeroY    MACRO
  788.         move.b    (RPC)+,d0
  789.         add.b    RY,d0
  790.         ENDM
  791.  
  792. ReadByteZeroY    MACRO    ;Ziel (CCR ist gültig)
  793.         ReadAdrZeroY
  794.         move.b    (RAMPTR,d0.l),\1
  795.         ENDM
  796.  
  797. ; (Ind,X)
  798. ReadAdrIndX    MACRO
  799.         move.b    (RPC)+,d0
  800.         add.b    RX,d0
  801.         move.b    (RAMPTR,d0.l),d1    ;LSB lesen
  802.         addq.b    #1,d0
  803.         move.b    (RAMPTR,d0.l),d0    ;MSB lesen
  804.         lsl.w    #8,d0
  805.         move.b    d1,d0            ;LSB einfügen
  806.         ENDM
  807.  
  808. ReadByteIndX    MACRO    ;[Ziel] (wird ein Ziel angegeben, ist das CCR gültig)
  809.         ReadAdrIndX
  810.         ReadByte \1
  811.         ENDM
  812.  
  813. ; (Ind),Y
  814. ReadAdrIndY    MACRO
  815.         move.b    (RPC)+,d0
  816.  
  817. ;(Korrekt)    move.b    (RAMPTR,d0.l),d1    ;LSB lesen
  818. ;        addq.b    #1,d0
  819. ;        move.b    (RAMPTR,d0.l),d0    ;MSB lesen
  820. ;        lsl.w    #8,d0
  821. ;        move.b    d1,d0            ;LSB einfügen
  822.  
  823.         move.w    (RAMPTR,d0.l),d0    ;(Abgekürzt)
  824.         rol.w    #8,d0            ;Geht bei ($ff),y schief
  825.  
  826.         add.w    RY,d0
  827.         ENDM
  828.  
  829. ReadByteIndY    MACRO    ;[Ziel] (wird ein Ziel angegeben, ist das CCR gültig)
  830.         ReadAdrIndY
  831.         ReadByte \1
  832.         ENDM
  833.  
  834. ; Ein Byte auf den Stapel schieben
  835. PushByte    MACRO    ;Quelle
  836.         move.b    \1,(RAMPTR,RS.l)
  837.         subq.b    #1,RS
  838.         ENDM
  839.  
  840. ; PC auf Stack schieben
  841. PushPC        MACRO
  842.         move.w    RPC,d0
  843.         move.w    d0,d1
  844.         lsr.w    #8,d0
  845.         PushByte d0
  846.         PushByte d1
  847.         ENDM
  848.  
  849. ; PC+1 auf den Stack schieben
  850. PushPCPlus1    MACRO
  851.         move.w    RPC,d0
  852.         addq.w    #1,d0
  853.         move.w    d0,d1
  854.         lsr.w    #8,d0
  855.         PushByte    d0
  856.         PushByte    d1
  857.         ENDM
  858.  
  859. ; Status auf Stack schieben
  860. PushP        MACRO    ;Break-Bit
  861.         move.w    RP,d0        ;6510-Status holen
  862.         lsr.w    #8,d0
  863.         and.b    #$4c,d0        ;V,D,I behalten
  864.     IFEQ    \1
  865.         or.b    #$20,d0        ;1-Bit setzen
  866.     ELSE
  867.         or.b    #$30,d0        ;B und 1-Bit setzen
  868.     ENDC
  869.         tst.b    RP        ;C dazunehmen
  870.         beq    \@1$
  871.         or.b    #$01,d0
  872. \@1$        btst    #3,RCCR        ;N dazunehmen
  873.         beq    \@2$
  874.         or.b    #$80,d0
  875. \@2$        btst    #2,RCCR        ;Z dazunehmen
  876.         beq    \@3$
  877.         or.b    #$02,d0
  878. \@3$        PushByte d0
  879.         ENDM
  880.  
  881. ; Ein Byte vom Stapel lesen
  882. PopByte        MACRO    ;Ziel (CCR ist gültig)
  883.         addq.b    #1,RS
  884.         move.b    (RAMPTR,RS.l),\1
  885.         ENDM
  886.  
  887. ; Status vom Stack holen
  888. PopP        MACRO
  889.         PopByte    d0
  890.         move    ccr,RCCR
  891.         and.b    #$08,RCCR    ;N holen
  892.         move.b    d0,RP
  893.         and.b    #$4c,RP        ;V,D,I behalten
  894.         lsl.w    #8,RP
  895.         btst    #1,d0        ;Z holen
  896.         beq    \@1$
  897.         or.b    #$04,RCCR
  898. \@1$        btst    #0,d0        ;C holen
  899.         sne    RP
  900.         ENDM
  901.  
  902. ; PC setzen
  903. ; -> d0.w: 16-Bit-Adresse
  904. ; <- RPC.l: Amiga-Adresse
  905. Jump        MACRO
  906.         move.w    d0,d1
  907.         lsr.w    #8,d1
  908.         move.l    (256*8*8,RWTAB,d1.l*8),a0 ;JumpTab
  909.         jsr    (a0)
  910.         ENDM
  911.  
  912. ; Nächsten Befehl ausführen
  913. Next        MACRO    ;Zyklenzahl
  914.     IFNE    \1
  915.         subq.w    #\1,(CYCPTR)    ;Anzahl Zyklen abziehen
  916.         bmi    Periodic    ;Alle verbraucht: Periodic
  917.     ENDC
  918.  
  919.         moveq    #0,d0
  920.         move.b    (RPC)+,d0    ;Opcode lesen
  921.         move.l    (OpcodeTable,d0.l*4),a0 ;Zeiger auf die Opcode-Routine holen
  922.         jmp    (a0)        ;Routine aufrufen
  923.         ENDM
  924.  
  925. ; Speicherkonfiguration anpassen
  926. NewConfig    MACRO
  927.     ;!!    move.b    (RAMPTR),d0    ;Gelesenes PR richtig berechnen
  928.     ;    move.b    d0,d1
  929.     ;    not.b    d1
  930.     ;    and.b    1(RAMPTR),d0
  931.     ;    and.b    #%00010111,d1    ;Eingabepins
  932.     ;    or.b    d1,d0
  933.     ;    move.b    d0,1(RAMPTR)
  934.  
  935.         move.b    (RAMPTR),d0    ;Zustand der Ausgabepins lesen
  936.         not.b    d0        ;Eingabepins sind 1
  937.         or.b    1(RAMPTR),d0
  938.         and.w    #7,d0        ;Relevante Bits maskieren
  939.         move.l    (ConfigTab,d0.l*4),RWTAB
  940.         ENDM
  941.  
  942. ; Ein C64-Byte in die Zero-Page schreiben und nächsten Befehl ausführen.
  943. ; Prüfen, ob sich die Speicherkonfiguration geändert hat.
  944. ; -> d0.w: Adresse (16 bit)
  945. ; -> Arg1: Byte
  946. WriteZeroNext    MACRO    ;Register, Zyklenzahl
  947.         move.b    \1,(RAMPTR,d0.l)
  948.         cmp.b    #2,d0
  949.         bhs    \@1$
  950.         NewConfig
  951. \@1$        Next    \2
  952.         ENDM
  953.  
  954.  
  955. *
  956. * Initialisierung
  957. *
  958.  
  959. ; Near-Adressierung initialisieren
  960. CPUTaskProc    lea    _DATA_BAS_,a4
  961.         lea    32766(a4),a4
  962.  
  963. ; Task ermitteln
  964.         move.l    _SysBase,a6
  965.         sub.l    a1,a1
  966.         JSRLIB    FindTask
  967.         move.l    d0,CPUTask
  968.  
  969. ; Continue-Signal holen
  970.         moveq    #-1,d0
  971.         JSRLIB    AllocSignal
  972.         move.b    d0,ContinueSig
  973.         moveq    #0,d1
  974.         bset    d0,d1
  975.         move.l    d1,ContinueSet
  976.  
  977. ; Grafik initialisieren
  978.         jsr    _InitDisplayFrom6510
  979.  
  980. ; Signal an den Emulator schicken
  981.         move.l    _SysBase,a6
  982.         move.l    MainTask,a1
  983.         move.l    ReadySet,d0
  984.         JSRLIB    Signal
  985.  
  986. ; Variablen initilisieren
  987.         clr.l    Interrupt
  988.         clr.b    RESETIsEXIT
  989.         clr.b    RESETIsPause
  990.         clr.b    NMIState
  991.         move.w    #63,CyclesLeft
  992.  
  993. ; RAM mit Einschaltmuster initialisieren
  994.         move.l    TheRAM,a0
  995.         move.w    #511,d1
  996. 3$        moveq    #63,d0
  997. 1$        clr.b    (a0)+        ;Abwechselnd 64 Bytes $00
  998.         dbra    d0,1$
  999.         moveq    #63,d0
  1000. 2$        st    (a0)+        ;Und 64 Bytes $ff
  1001.         dbra    d0,2$
  1002.         dbra    d1,3$
  1003.  
  1004. ; Farb-RAM mit Zufallswerten initialisieren
  1005.         move.l    TheColor,a2
  1006.         move.w    #$03ff,d2
  1007. 4$        jsr    Random
  1008.         move.b    d0,(a2)+
  1009.         dbra    d2,4$
  1010.  
  1011. ; Speicherkonfiguration initialisieren
  1012.         move.l    TheRAM,RAMPTR
  1013.         move.b    #$00,(RAMPTR)    ;Port auf Eingabe
  1014.         NewConfig
  1015.  
  1016. ; Register setzen
  1017.         moveq    #0,d0
  1018.         moveq    #0,d1
  1019.         moveq    #0,RA
  1020.         moveq    #0,RX
  1021.         moveq    #0,RY
  1022.         move.l    #$01ff,RS
  1023.         moveq    #0,RCCR
  1024.         move.l    #InterruptMask,RP
  1025.         lea    CyclesLeft,CYCPTR
  1026.  
  1027. ; Reset-Vektor lesen, PC setzen und ersten Befehl ausführen
  1028.         move.w    #$fffc,d0
  1029.         ReadWord
  1030.         Jump
  1031.         Next    0
  1032.  
  1033. ; Unbekannten Opcode entdeckt: Requester darstellen
  1034. IllegalOp    subq.w    #1,RPC            ;PC korrigieren
  1035.         movem.l    a2-a6,-(sp)
  1036.  
  1037.         and.w    #$00ff,d0        ;Opcode
  1038.         move.w    d0,RequestStream
  1039.         move.l    RPC,d0            ;und PC anzeigen
  1040.         move.w    d0,RequestStream+2
  1041.  
  1042.         jsr    _EmulToBack
  1043.  
  1044.         move.l    _IntuitionBase,a6
  1045.         sub.l    a0,a0
  1046.         lea    IllegalOpReq,a1
  1047.         move.l    a0,a2
  1048.         lea    RequestStream,a3
  1049.         JSRLIB    EasyRequestArgs
  1050.  
  1051.         move.l    d0,-(sp)
  1052.         jsr    _EmulToFront
  1053.         move.l    (sp)+,d0
  1054.  
  1055.         movem.l    (sp)+,a2-a6
  1056.  
  1057.         tst.l    d0            ;Resetten?
  1058.         beq    1$
  1059.  
  1060.         jsr    ResetC64        ;Ja
  1061.         moveq    #0,d0
  1062.         moveq    #0,d1
  1063.         bra    HandleRESET
  1064.  
  1065. 1$        move.l    a6,-(sp)        ;Nein, SAM aufrufen
  1066.         move.l    _SysBase,a6
  1067.         move.l    MainTask,a1        ;Den Haupttask benachrichtigen
  1068.         move.l    InvokeSAMSet,d0
  1069.         JSRLIB    Signal
  1070.         move.l    (sp)+,a6
  1071.         bsr    Pause            ;In Pause-Zustand gehen
  1072.         clr.b    IntIsRESET
  1073.         clr.b    RESETIsPause
  1074.         moveq    #0,d0
  1075.         moveq    #0,d1
  1076.         NewConfig
  1077.         move.w    _RPC,d0
  1078.         Jump
  1079.         Next    0
  1080.  
  1081.  
  1082. *
  1083. * Speicherzugriff Lesen
  1084. *
  1085.  
  1086. ; Lesen aus dem RAM
  1087. ReadByteRAM    move.b    (RAMPTR,d0.l),d0
  1088.         rts
  1089.  
  1090. ; Lesen aus dem Basic-ROM
  1091. ReadByteBasic    and.w    #$1fff,d0
  1092.         move.l    TheBasic,a0
  1093.         move.b    (a0,d0.l),d0
  1094.         rts
  1095.  
  1096. ; Lesen aus einem VIC-Register
  1097. ReadByteVIC    and.w    #$3f,d0
  1098.         bra    ReadFrom6569
  1099.  
  1100. ; Lesen aus einem SID-Register
  1101. ReadByteSID    and.w    #$1f,d0
  1102.         bra    ReadFrom6581
  1103.  
  1104. ; Lesen aus dem Farb-RAM
  1105. ReadByteColor    and.w    #$03ff,d0
  1106.         move.l    TheColor,a0
  1107.         move.b    (a0,d0.l),d1
  1108.         and.b    #$0f,d1
  1109.  
  1110.         move.l    d1,-(sp)
  1111.         jsr    Random        ;Oberes Nibble ist Zufallswert
  1112.         and.b    #$f0,d0
  1113.         move.l    (sp)+,d1
  1114.  
  1115.         or.b    d1,d0
  1116.         rts
  1117.  
  1118. ; Lesen aus einem CIA 1-Register
  1119. ReadByteCIA1    and.w    #$0f,d0
  1120.         bra    ReadFrom6526A
  1121.  
  1122. ; Lesen aus einem CIA 2-Register
  1123. ReadByteCIA2    and.w    #$0f,d0
  1124.         bra    ReadFrom6526B
  1125.  
  1126. ; Lesen einer offenen Adresse
  1127. ReadByteUndef    cmp.l    #$dfa0,d0
  1128.         bhs    1$
  1129.         jsr    Random        ;Zufallswert
  1130.         moveq    #0,d1        ;MSW löschen
  1131.         rts
  1132.  
  1133. ; $dfa0-$dfff: Emulator-Identifikation
  1134. 1$        cmp.w    #$dfff,d0    ;$dfff liest abwechselnd $55/$aa
  1135.         bne    2$
  1136.         move.b    DFFFByte,d0
  1137.         not.b    DFFFByte
  1138.         rts
  1139.  
  1140. 2$        cmp.w    #$dffe,d0    ;$dffe liest "F" (Frodo-Kennung)
  1141.         bne    3$
  1142.         moveq    #'F',d0
  1143.         rts
  1144.  
  1145. 3$        cmp.w    #$dffd,d0    ;$dffd: Version
  1146.         bne    4$
  1147.         move.b    #VERSION,d0
  1148.         rts
  1149.  
  1150. 4$        cmp.w    #$dffc,d0    ;$dffc: Revision
  1151.         bne    5$
  1152.         move.b    #REVISION<<4,d0
  1153.         rts
  1154.  
  1155. 5$        sub.w    #$dfa0,d0    ;$dfa0-$dffb: ID-String
  1156.         move.b    IDString(pc,d0.w),d0
  1157.         rts
  1158.  
  1159. ; Lesen aus dem Kernal-ROM
  1160. ReadByteKernal    and.w    #$1fff,d0
  1161.         move.l    TheKernal,a0
  1162.         move.b    (a0,d0.l),d0
  1163.         rts
  1164.  
  1165. ; Lesen aus dem Char-ROM
  1166. ReadByteChar    and.w    #$0fff,d0
  1167.         move.l    TheChar,a0
  1168.         move.b    (a0,d0.l),d0
  1169.         rts
  1170.  
  1171.  
  1172. *
  1173. * Speicherzugriff Schreiben
  1174. * In a1 steht die 16-Bit-Adresse
  1175. *
  1176.  
  1177. ; Schreiben in Seite 0
  1178. WriteBytePage0    move.l    a1,d0
  1179.         move.b    d1,(RAMPTR,d0.l)
  1180.         cmp.b    #2,d0
  1181.         bhs    1$
  1182.         NewConfig
  1183. 1$        rts
  1184.  
  1185. ; Schreiben ins RAM
  1186. WriteByteRAM    move.b    d1,(RAMPTR,a1.l)
  1187.         rts
  1188.  
  1189. ; Schreiben in ein VIC-Register
  1190. WriteByteVIC    move.l    a1,d0
  1191.         and.w    #$3f,d0
  1192.         bra    WriteTo6569
  1193.  
  1194. ; Schreiben in ein SID-Register
  1195. WriteByteSID    move.l    a1,d0
  1196.         and.w    #$1f,d0
  1197.         bra    WriteTo6581
  1198.  
  1199. ; Schreiben ins Farb-RAM
  1200. WriteByteColor    move.l    a1,d0
  1201.         and.w    #$03ff,d0
  1202.         move.l    TheColor,a0
  1203.         move.b    d1,(a0,d0.l)
  1204.         rts
  1205.  
  1206. ; Schreiben in ein CIA 1-Register
  1207. WriteByteCIA1    move.l    a1,d0
  1208.         and.w    #$0f,d0
  1209.         bra    WriteTo6526A
  1210.  
  1211. ; Schreiben in ein CIA 2-Register
  1212. WriteByteCIA2    move.l    a1,d0
  1213.         and.w    #$0f,d0
  1214.         bra    WriteTo6526B
  1215.  
  1216. ; Schreiben an einer offenen Adresse
  1217. WriteByteUndef    rts
  1218.  
  1219.  
  1220. *
  1221. * Sprungbefehle
  1222. *
  1223.  
  1224. ; Sprung ins RAM
  1225. JumpToRAM    lea    (RAMPTR,d0.l),RPC
  1226.         rts
  1227.  
  1228. ; Sprung ins Basic-ROM
  1229. JumpToBasic    move.l    TheBasic,RPC
  1230.         and.w    #$1fff,d0
  1231.         add.l    d0,RPC
  1232.         rts
  1233.  
  1234. ; Sprung ins Kernal-ROM
  1235. JumpToKernal    move.l    TheKernal,RPC
  1236.         and.w    #$1fff,d0
  1237.         add.l    d0,RPC
  1238.         rts
  1239.  
  1240. ; Sprung ins Char-ROM (warum sollte jemand sowas tun? Aber egal.)
  1241. JumpToChar    move.l    TheChar,RPC
  1242.         and.w    #$0fff,d0
  1243.         add.l    d0,RPC
  1244.         rts
  1245.  
  1246. ; Sprung in den I/O-Bereich (in VIC-Register wird ab und zu gerne gesprungen,
  1247. ;  $de00 und das Farb-RAM sind auch sehr beliebt :-)
  1248. JumpToIO    movem.l    a2-a6,-(sp)
  1249.  
  1250.         move.w    d0,RequestStream    ;PC anzeigen
  1251.  
  1252.         jsr    _EmulToBack
  1253.  
  1254.         move.l    _IntuitionBase,a6
  1255.         sub.l    a0,a0
  1256.         lea    JumpToIOReq,a1
  1257.         move.l    a0,a2
  1258.         lea    RequestStream,a3
  1259.         JSRLIB    EasyRequestArgs
  1260.  
  1261.         jsr    _EmulToFront
  1262.  
  1263.         movem.l    (sp)+,a2-a6
  1264.  
  1265.         jsr    ResetC64
  1266.         moveq    #0,d0            ;MSWs von d0 und d1
  1267.         moveq    #0,d1            ; müssen Null sein
  1268.  
  1269.         addq.l    #4,sp            ;Rücksprungadresse löschen
  1270.         bra    HandleRESET
  1271.  
  1272.  
  1273. **
  1274. ** Opcode-Routinen
  1275. **
  1276.  
  1277. *
  1278. * Interrupts handhaben
  1279. *
  1280.  
  1281. ; Art des Interrupt feststellen (Priorität)
  1282. HandleInt    tst.b    IntIsRESET
  1283.         bne    HandleRESET
  1284.         tst.b    IntIsNMI
  1285.         bne    HandleNMI
  1286.         tst.w    IntIsIRQ
  1287.         bne    HandleIRQ
  1288.  
  1289. ; Kein Interrupt, nächsten Befehl ausführen
  1290. HandleIntDone    Next    0
  1291.  
  1292. ; IRQ: Interrupt-Bit testen, nach ($fffe) springen
  1293. HandleIRQ    btst    #InterruptBit,RP
  1294.         beq    IRQDoIt
  1295.         Next    0
  1296.  
  1297. IRQDoIt        PushPC
  1298.         PushP    0
  1299.  
  1300.         or.w    #InterruptMask,RP
  1301.         move.w    #$fffe,d0    ;IRQ-Vektor
  1302.         ReadWord
  1303.         Jump
  1304.         Next    7
  1305.  
  1306. ; NMI: Nach ($fffa) springen
  1307. HandleNMI    clr.b    IntIsNMI    ;Simuliert einen flankengetriggerten Eingang
  1308.  
  1309.         PushPC
  1310.         PushP    0
  1311.  
  1312.         or.w    #InterruptMask,RP
  1313.         move.w    #$fffa,d0    ;NMI-Vektor
  1314.         ReadWord
  1315.         Jump
  1316.         Next    7
  1317.  
  1318. ; RESET: Emulator beenden, anhalten oder nach ($fffc) springen
  1319. HandleRESET    tst.b    RESETIsEXIT    ;Beenden?
  1320.         bne    HandleEXIT
  1321.         tst.b    RESETIsPause    ;Pause?
  1322.         bne    HandlePause
  1323.  
  1324.         clr.l    Interrupt    ;Nein, RESET
  1325.         clr.b    NMIState
  1326.  
  1327.         cmp.l    #$c3c2cd38,$8004(RAMPTR)
  1328.         bne    1$
  1329.         cmp.b    #$30,$8008(RAMPTR)
  1330.         bne    1$
  1331.         clr.b    $8004(RAMPTR)    ;CBM80 löschen, wenn vorhanden
  1332.  
  1333. 1$        move.b    #$00,(RAMPTR)    ;Speicherkonfiguration initialisieren (Port auf Eingabe)
  1334.         NewConfig
  1335.  
  1336.         move.w    #$fffc,d0    ;RESET-Vektor
  1337.         ReadWord
  1338.         Jump
  1339.         Next    0
  1340.  
  1341. ; EXIT: Signal an den Emulator schicken
  1342. HandleEXIT    jsr    _ExitDisplayFrom6510    ;Grafik aufräumen
  1343.  
  1344.         move.l    _SysBase,a6
  1345.  
  1346.         moveq    #0,d0
  1347.         move.b    ContinueSig,d0
  1348.         JSRLIB    FreeSignal
  1349.  
  1350.         JSRLIB    Forbid
  1351.         move.l    MainTask,a1
  1352.         move.l    ReadySet,d0
  1353.         JSRLIB    Signal
  1354.         moveq    #0,d0
  1355.         rts
  1356.  
  1357. ; Pause: Signal an den Emulator schicken und dann selbst auf
  1358. ;  ein Signal warten, Zustand retten und wiederherstellen
  1359. HandlePause    bsr    Pause
  1360.         moveq    #0,d0
  1361.         moveq    #0,d1
  1362.         NewConfig
  1363.         move.w    _RPC,d0
  1364.         Jump
  1365.         Next    0
  1366.  
  1367. Pause        clr.b    IntIsRESET
  1368.         clr.b    RESETIsPause
  1369.  
  1370.         move.b    RA,_RA        ;Register für SAM bereitstellen
  1371.         move.b    RX,_RX
  1372.         move.b    RY,_RY
  1373.         move.w    RP,d0
  1374.         lsr.w    #8,d0
  1375.         and.b    #$5c,d0        ;V, B, D, I
  1376.         or.b    #$20,d0        ;1-Bit setzen
  1377.         tst.b    RP        ;C dazunehmen
  1378.         beq    1$
  1379.         or.b    #$01,d0
  1380. 1$        btst    #3,RCCR        ;N dazunehmen
  1381.         beq    2$
  1382.         or.b    #$80,d0
  1383. 2$        btst    #2,RCCR        ;Z dazunehmen
  1384.         beq    3$
  1385.         or.b    #$02,d0
  1386. 3$        move.b    d0,_RP
  1387.  
  1388.         move.b    (RAMPTR),_RDDR
  1389.         move.b    1(RAMPTR),d0
  1390.         and.b    #$3f,d0
  1391.         move.b    d0,_RPR
  1392.  
  1393.         move.b    (RAMPTR),d0
  1394.         not.b    d0
  1395.         or.b    1(RAMPTR),d0
  1396.         and.b    #$07,d0
  1397.         move.b    d0,_SAMMemConfig
  1398.  
  1399.         move.w    RPC,_RPC
  1400.         move.w    RS,_RS
  1401.  
  1402.         move.l    _SysBase,a6
  1403.         move.l    MainTask,a1
  1404.         move.l    ReadySet,d0
  1405.         JSRLIB    Signal
  1406.         move.l    ContinueSet,d0
  1407.         JSRLIB    Wait
  1408.  
  1409.         move.l    TheRAM,RAMPTR
  1410.         lea    CyclesLeft,CYCPTR
  1411.         moveq    #0,RA        ;Register von SAM lesen
  1412.         move.b    _RA,RA
  1413.         moveq    #0,RX
  1414.         move.b    _RX,RX
  1415.         moveq    #0,RY
  1416.         move.b    _RY,RY
  1417.  
  1418.         moveq    #0,RCCR
  1419.         btst    #7,_RP        ;N holen
  1420.         beq    4$
  1421.         or.b    #$08,RCCR
  1422. 4$        btst    #1,_RP        ;Z holen
  1423.         beq    5$
  1424.         or.b    #$04,RCCR
  1425. 5$
  1426.         moveq    #0,RP
  1427.         move.b    _RP,RP
  1428.         and.b    #$4c,RP        ;V,D,I behalten
  1429.         lsl.w    #8,RP
  1430.         btst    #0,_RP        ;C holen
  1431.         sne    RP
  1432.  
  1433.         move.l    #$0100,RS
  1434.         move.b    _RS+1,RS
  1435.         move.b    _RDDR,(RAMPTR)
  1436.         move.b    _RPR,1(RAMPTR)
  1437.         rts
  1438.  
  1439.  
  1440. *
  1441. * Opcodes
  1442. *
  1443.  
  1444. ; Laden
  1445. LoadA        MACRO    ;Quelle, Zyklenzahl
  1446.         move.b    \1,RA
  1447.         move    ccr,RCCR
  1448.         Next    \2
  1449.         ENDM
  1450.  
  1451. LoadX        MACRO    ;Quelle, Zyklenzahl
  1452.         move.b    \1,RX
  1453.         move    ccr,RCCR
  1454.         Next    \2
  1455.         ENDM
  1456.  
  1457. LoadY        MACRO    ;Quelle, Zyklenzahl
  1458.         move.b    \1,RY
  1459.         move    ccr,RCCR
  1460.         Next    \2
  1461.         ENDM
  1462.  
  1463. LoadAX        MACRO    ;Quelle, Zyklenzahl
  1464.         move.b    \1,RA
  1465.         move.b    RA,RX
  1466.         move    ccr,RCCR
  1467.         Next    \2
  1468.         ENDM
  1469.  
  1470. LDAImm        LoadA    (RPC)+,2
  1471.  
  1472. LDAZero        ReadAdrZero
  1473.         LoadA    (RAMPTR,d0.l),3
  1474.  
  1475. LDAZeroX    ReadAdrZeroX
  1476.         LoadA    (RAMPTR,d0.l),4
  1477.  
  1478. LDAAbs        ReadByteAbs RA
  1479.         move    ccr,RCCR
  1480.         Next    4
  1481.  
  1482. LDAAbsX        ReadByteAbsX RA
  1483.         move    ccr,RCCR
  1484.         Next    4
  1485.  
  1486. LDAAbsY        ReadByteAbsY RA
  1487.         move    ccr,RCCR
  1488.         Next    4
  1489.  
  1490. LDAIndX        ReadByteIndX RA
  1491.         move    ccr,RCCR
  1492.         Next    6
  1493.  
  1494. LDAIndY        ReadByteIndY RA
  1495.         move    ccr,RCCR
  1496.         Next    5
  1497.  
  1498. LDXImm        LoadX    (RPC)+,2
  1499.  
  1500. LDXZero        ReadAdrZero
  1501.         LoadX    (RAMPTR,d0.l),3
  1502.  
  1503. LDXZeroY    ReadAdrZeroY
  1504.         LoadX    (RAMPTR,d0.l),4
  1505.  
  1506. LDXAbs        ReadByteAbs RX
  1507.         move    ccr,RCCR
  1508.         Next    4
  1509.  
  1510. LDXAbsY        ReadByteAbsY RX
  1511.         move    ccr,RCCR
  1512.         Next    4
  1513.  
  1514. LDYImm        LoadY    (RPC)+,2
  1515.  
  1516. LDYZero        ReadAdrZero
  1517.         LoadY    (RAMPTR,d0.l),3
  1518.  
  1519. LDYZeroX    ReadAdrZeroX
  1520.         LoadY    (RAMPTR,d0.l),4
  1521.  
  1522. LDYAbs        ReadByteAbs RY
  1523.         move    ccr,RCCR
  1524.         Next    4
  1525.  
  1526. LDYAbsX        ReadByteAbsX RY
  1527.         move    ccr,RCCR
  1528.         Next    4
  1529.  
  1530. LAXZero        ReadAdrZero
  1531.         LoadAX    (RAMPTR,d0.l),3
  1532.  
  1533. LAXZeroY    ReadAdrZeroY
  1534.         LoadAX    (RAMPTR,d0.l),4
  1535.  
  1536. LAXAbs        ReadByteAbs RA
  1537.         move.b    RA,RX
  1538.         move    ccr,RCCR
  1539.         Next    4
  1540.  
  1541. LAXAbsY        ReadByteAbsY RA
  1542.         move.b    RA,RX
  1543.         move    ccr,RCCR
  1544.         Next    4
  1545.  
  1546. LAXIndX        ReadByteIndX RA
  1547.         move.b    RA,RX
  1548.         move    ccr,RCCR
  1549.         Next    6
  1550.  
  1551. LAXIndY        ReadByteIndY RA
  1552.         move.b    RA,RX
  1553.         move    ccr,RCCR
  1554.         Next    5
  1555.  
  1556. ; Speichern
  1557. StoreA        MACRO    ;Zyklenzahl
  1558.         move.b    RA,d1
  1559.         WriteByte
  1560.         Next    \1
  1561.         ENDM
  1562.  
  1563. StoreAX        MACRO    ;Zyklenzahl
  1564.         move.b    RA,d1
  1565.         and.b    RX,d1
  1566.         WriteByte
  1567.         Next    \1
  1568.         ENDM
  1569.  
  1570. STAZero        ReadAdrZero
  1571.         WriteZeroNext    RA,3
  1572.  
  1573. STAZeroX    ReadAdrZeroX
  1574.         WriteZeroNext    RA,4
  1575.  
  1576. STAAbs        ReadAdrAbs
  1577.         StoreA    4
  1578.  
  1579. STAAbsX        ReadAdrAbsX
  1580.         StoreA    5
  1581.  
  1582. STAAbsY        ReadAdrAbsY
  1583.         StoreA    5
  1584.  
  1585. STAIndX        ReadAdrIndX
  1586.         StoreA    6
  1587.  
  1588. STAIndY        ReadAdrIndY
  1589.         StoreA    6
  1590.  
  1591. STXZero        ReadAdrZero
  1592.         WriteZeroNext    RX,3
  1593.  
  1594. STXZeroY    ReadAdrZeroY
  1595.         WriteZeroNext    RX,4
  1596.  
  1597. STXAbs        ReadAdrAbs
  1598.         move.b    RX,d1
  1599.         WriteByte
  1600.         Next    4
  1601.  
  1602. STYZero        ReadAdrZero
  1603.         WriteZeroNext    RY,3
  1604.  
  1605. STYZeroX    ReadAdrZeroX
  1606.         WriteZeroNext    RY,4
  1607.  
  1608. STYAbs        ReadAdrAbs
  1609.         move.b    RY,d1
  1610.         WriteByte
  1611.         Next    4
  1612.  
  1613. SAXZero        ReadAdrZero
  1614.         StoreAX    3
  1615.  
  1616. SAXZeroY    ReadAdrZeroY
  1617.         StoreAX    4
  1618.  
  1619. SAXAbs        ReadAdrAbs
  1620.         StoreAX    4
  1621.  
  1622. SAXIndX        ReadAdrIndX
  1623.         StoreAX    6
  1624.  
  1625. ; Datentransport zwischen Registern
  1626. TAX        move.b    RA,RX
  1627.         move    ccr,RCCR
  1628.         Next    2
  1629.  
  1630. TAY        move.b    RA,RY
  1631.         move    ccr,RCCR
  1632.         Next    2
  1633.  
  1634. TXA        move.b    RX,RA
  1635.         move    ccr,RCCR
  1636.         Next    2
  1637.  
  1638. TYA        move.b    RY,RA
  1639.         move    ccr,RCCR
  1640.         Next    2
  1641.  
  1642. TXS        move.b    RX,RS
  1643.         Next    2
  1644.  
  1645. TSX        move.b    RS,RX
  1646.         move    ccr,RCCR
  1647.         Next    2
  1648.  
  1649. ; Stack
  1650. PHA        PushByte RA
  1651.         Next    3
  1652.  
  1653. PLA        PopByte    RA
  1654.         move    ccr,RCCR
  1655.         Next    4
  1656.  
  1657. PHP        PushP    1        ;Break-Flag setzen
  1658.         Next    3
  1659.  
  1660. PLP        PopP
  1661.         tst.w    IntIsIRQ    ;Steht ein IRQ an?
  1662.         beq    1$
  1663.         btst    #InterruptBit,RP ;Ja, I-Flag gelöscht?
  1664.         beq    HandleIRQ    ;Ja, Interrupt auslösen
  1665. 1$        Next    4
  1666.  
  1667. ; Vergleiche
  1668. CompareA    MACRO    ;Quelle, Zyklenzahl
  1669.         cmp.b    \1,RA
  1670.         move    ccr,RCCR
  1671.         scc    RP        ;Inverses Carry holen
  1672.         Next    \2
  1673.         ENDM
  1674.  
  1675. CMPImm        CompareA    (RPC)+,2
  1676.  
  1677. CMPZero        ReadAdrZero
  1678.         CompareA    (RAMPTR,d0.l),3
  1679.  
  1680. CMPZeroX    ReadAdrZeroX
  1681.         CompareA    (RAMPTR,d0.l),4
  1682.  
  1683. CMPAbs        ReadByteAbs
  1684.         CompareA    d0,4
  1685.  
  1686. CMPAbsX        ReadByteAbsX
  1687.         CompareA    d0,4
  1688.  
  1689. CMPAbsY        ReadByteAbsY
  1690.         CompareA    d0,4
  1691.  
  1692. CMPIndX        ReadByteIndX
  1693.         CompareA    d0,6
  1694.  
  1695. CMPIndY        ReadByteIndY
  1696.         CompareA    d0,5
  1697.  
  1698. CPXImm        cmp.b    (RPC)+,RX
  1699.         move    ccr,RCCR
  1700.         scc    RP        ;Inverses Carry holen
  1701.         Next    2
  1702.  
  1703. CPXZero        ReadAdrZero
  1704.         cmp.b    (RAMPTR,d0.l),RX
  1705.         move    ccr,RCCR
  1706.         scc    RP        ;Inverses Carry holen
  1707.         Next    3
  1708.  
  1709. CPXAbs        ReadByteAbs
  1710.         cmp.b    d0,RX
  1711.         move    ccr,RCCR
  1712.         scc    RP        ;Inverses Carry holen
  1713.         Next    4
  1714.  
  1715. CPYImm        cmp.b    (RPC)+,RY
  1716.         move    ccr,RCCR
  1717.         scc    RP        ;Inverses Carry holen
  1718.         Next    2
  1719.  
  1720. CPYZero        ReadAdrZero
  1721.         cmp.b    (RAMPTR,d0.l),RY
  1722.         move    ccr,RCCR
  1723.         scc    RP        ;Inverses Carry holen
  1724.         Next    3
  1725.  
  1726. CPYAbs        ReadByteAbs
  1727.         cmp.b    d0,RY
  1728.         move    ccr,RCCR
  1729.         scc    RP        ;Inverses Carry holen
  1730.         Next    4
  1731.  
  1732. ; Arithmetische Operationen
  1733. AdcA        MACRO    ;Zyklenzahl
  1734.         and.w    #~OverflowMask,RP
  1735.         btst    #DecimalBit,RP
  1736.         bne    \@2$
  1737.  
  1738.         add.b    RP,RP        ;Carry -> X
  1739.         addx.b    d0,RA
  1740.         scs    RP        ;Carry holen
  1741.         bvc    \@1$        ;Overflow holen
  1742.         or.w    #OverflowMask,RP
  1743. \@1$        tst.b    RA        ;N und Z holen (wegen addx)
  1744.         move    ccr,RCCR
  1745.         Next    \1
  1746.  
  1747. \@2$        bsr    AdcDec
  1748.         Next    \1
  1749.         ENDM
  1750.  
  1751. AdcDec        move.b    d0,TMPS        ;Dezimalmodus
  1752.         move.b    RA,TMPA
  1753.  
  1754.         clr.b    RCCR
  1755.  
  1756.         move.b    RA,d1        ;Unteres Nybble berechnen
  1757.         and.b    #$0f,d0
  1758.         and.b    #$0f,d1
  1759.         add.b    RP,RP        ;Carry -> X
  1760.         addx.b    d0,d1        ; -> d1
  1761.  
  1762.         cmp.b    #10,d1        ;BCD-Fixup für das untere Nybble
  1763.         blo    2$
  1764.         addq.b    #6,d1
  1765. 2$        move.b    d1,TMPAL
  1766.  
  1767.         move.b    TMPS,d0        ;Oberes Nybble berechnen
  1768.         lsr.b    #4,d0
  1769.         lsr.b    #4,RA
  1770.         add.b    d0,RA
  1771.         cmp.b    #$10,d1
  1772.         blo    1$
  1773.         addq.b    #1,RA        ; -> d2
  1774. 1$
  1775.         move.b    TMPS,d0        ;Z holen (wie im Binärmodus)
  1776.         move.b    TMPA,d1
  1777.         add.b    RP,RP        ;Carry -> X
  1778.         addx.b    d0,d1
  1779.         tst.b    d1        ;Wegen addx
  1780.         bne    6$
  1781.         or.b    #$04,RCCR
  1782. 6$
  1783.         btst    #3,RA        ;N berechnen
  1784.         beq    4$
  1785.         or.b    #$08,RCCR
  1786. 4$
  1787.         move.b    RA,d0        ;V berechnen
  1788.         lsl.b    #4,d0
  1789.         move.b    TMPA,d1
  1790.         eor.b    d1,d0
  1791.         bpl    5$
  1792.         move.b    TMPS,d0
  1793.         eor.b    d1,d0
  1794.         bmi    5$
  1795.         or.w    #OverflowMask,RP
  1796. 5$
  1797.         cmp.b    #10,RA        ;BCD-Fixup für das obere Nybble
  1798.         blo    3$
  1799.         addq.b    #6,RA
  1800. 3$
  1801.         cmp.b    #$10,RA        ;Carry holen
  1802.         shs    RP
  1803.  
  1804.         move.b    TMPAL,d0    ;Ergebnis zusammensetzen
  1805.         and.b    #$0f,d0
  1806.         lsl.b    #4,RA
  1807.         or.b    d0,RA
  1808.         rts
  1809.  
  1810. ADCImm        move.b    (RPC)+,d0
  1811.         AdcA    2
  1812.  
  1813. ADCZero        ReadByteZero    d0
  1814.         AdcA    3
  1815.  
  1816. ADCZeroX    ReadByteZeroX    d0
  1817.         AdcA    4
  1818.  
  1819. ADCAbs        ReadByteAbs
  1820.         AdcA    4
  1821.  
  1822. ADCAbsX        ReadByteAbsX
  1823.         AdcA    4
  1824.  
  1825. ADCAbsY        ReadByteAbsY
  1826.         AdcA    4
  1827.  
  1828. ADCIndX        ReadByteIndX
  1829.         AdcA    6
  1830.  
  1831. ADCIndY        ReadByteIndY
  1832.         AdcA    5
  1833.  
  1834. SbcA        MACRO    ;Zyklenzahl
  1835.         not.b    RP
  1836.         and.w    #~OverflowMask,RP
  1837.         btst    #DecimalBit,RP
  1838.         bne    \@2$
  1839.  
  1840.         add.b    RP,RP        ;Inverses Carry -> X
  1841.         subx.b    d0,RA
  1842.         scc    RP        ;Inverses Carry holen
  1843.         bvc    \@1$        ;Overflow holen
  1844.         or.w    #OverflowMask,RP
  1845. \@1$        tst.b    RA
  1846.         move    ccr,RCCR    ;N und Z holen (wegen subx)
  1847.         Next    \1
  1848.  
  1849. \@2$        bsr    SbcDec
  1850.         Next    \1
  1851.         ENDM
  1852.  
  1853. SbcDec        move.b    d0,TMPS        ;Dezimalmodus
  1854.         move.b    RA,TMPA
  1855.  
  1856.         and.b    #$0f,d0        ;Unteres Nybble berechnen
  1857.         and.b    #$0f,RA
  1858.         add.b    RP,RP        ;Inverses Carry -> X
  1859.         subx.b    d0,RA
  1860.         move    ccr,d1
  1861.         bcc    1$        ;BCD-Fixup
  1862.         subq.b    #6,RA
  1863.         st    d1
  1864. 1$        and.b    #$0f,RA
  1865.         move.b    RA,TMPAL
  1866.  
  1867.         move.b    TMPS,d0        ;Oberes Nybble berechnen
  1868.         move.b    TMPA,RA
  1869.         and.b    #$f0,d0
  1870.         and.b    #$f0,RA
  1871.         sub.b    d0,RA
  1872.         bcc    2$        ;BCD-Fixup
  1873.         and.b    #$f0,RA
  1874.         sub.b    #$60,RA
  1875.         btst    #0,d1
  1876.         beq    3$
  1877.         sub.b    #$10,RA
  1878.         bra    3$
  1879. 2$        and.b    #$f0,RA
  1880.         btst    #0,d1
  1881.         beq    3$
  1882.         sub.b    #$10,RA
  1883.         bcc    3$
  1884.         sub.b    #$60,RA
  1885. 3$        or.b    TMPAL,RA    ;Ergebnis zusammenbauen
  1886.  
  1887.         add.b    RP,RP        ;Inverses Carry -> X
  1888.         move.b    TMPS,d0        ;Flags berechnen (wie im Binärmodus)
  1889.         move.b    TMPA,d1
  1890.         subx.b    d0,d1        ;Flags berechnen
  1891.         scc    RP        ;Inverses Carry holen
  1892.         bvc    4$        ;Overflow holen
  1893.         or.w    #OverflowMask,RP
  1894. 4$        tst.b    d1        ;N und Z holen (wegen subx)
  1895.         move    ccr,RCCR
  1896.         rts
  1897.  
  1898. SBCImm        move.b    (RPC)+,d0
  1899.         SbcA    2
  1900.  
  1901. SBCZero        ReadByteZero    d0
  1902.         SbcA    3
  1903.  
  1904. SBCZeroX    ReadByteZeroX    d0
  1905.         SbcA    4
  1906.  
  1907. SBCAbs        ReadByteAbs
  1908.         SbcA    4
  1909.  
  1910. SBCAbsX        ReadByteAbsX
  1911.         SbcA    4
  1912.  
  1913. SBCAbsY        ReadByteAbsY
  1914.         SbcA    4
  1915.  
  1916. SBCIndX        ReadByteIndX
  1917.         SbcA    6
  1918.  
  1919. SBCIndY        ReadByteIndY
  1920.         SbcA    5
  1921.  
  1922. Increment    MACRO    ;Zyklenzahl
  1923.         move.l    d0,-(sp)
  1924.         ReadByte d1
  1925.         addq.b    #1,d1
  1926.         move    ccr,RCCR
  1927.         move.l    (sp)+,d0
  1928.         WriteByte
  1929.         Next    \1
  1930.         ENDM
  1931.  
  1932. IncrementZero    MACRO    ;Zyklenzahl
  1933.         addq.b    #1,(RAMPTR,d0.l)
  1934.         move    ccr,RCCR
  1935.         cmp.b    #2,d0
  1936.         bhs    \@1$
  1937.         NewConfig
  1938. \@1$        Next    \1
  1939.         ENDM
  1940.  
  1941. INCZero        ReadAdrZero
  1942.         IncrementZero    5
  1943.  
  1944. INCZeroX    ReadAdrZeroX
  1945.         IncrementZero    6
  1946.  
  1947. INCAbs        ReadAdrAbs
  1948.         Increment    6
  1949.  
  1950. INCAbsX        ReadAdrAbsX
  1951.         Increment    7
  1952.  
  1953. Decrement    MACRO    ;Zyklenzahl
  1954.         move.l    d0,-(sp)
  1955.         ReadByte d1
  1956.         subq.b    #1,d1
  1957.         move    ccr,RCCR
  1958.         move.l    (sp)+,d0
  1959.         WriteByte
  1960.         Next    \1
  1961.         ENDM
  1962.  
  1963. DecrementZero    MACRO    ;Zyklenzahl
  1964.         subq.b    #1,(RAMPTR,d0.l)
  1965.         move    ccr,RCCR
  1966.         cmp.b    #2,d0
  1967.         bhs    \@1$
  1968.         NewConfig
  1969. \@1$        Next    \1
  1970.         ENDM
  1971.  
  1972. DECZero        ReadAdrZero
  1973.         DecrementZero    5
  1974.         
  1975. DECZeroX    ReadAdrZeroX
  1976.         DecrementZero    6
  1977.  
  1978. DECAbs        ReadAdrAbs
  1979.         Decrement    6
  1980.  
  1981. DECAbsX        ReadAdrAbsX
  1982.         Decrement    7
  1983.  
  1984. INX        addq.b    #1,RX
  1985.         move    ccr,RCCR
  1986.         Next    2
  1987.  
  1988. DEX        subq.b    #1,RX
  1989.         move    ccr,RCCR
  1990.         Next    2
  1991.  
  1992. INY        addq.b    #1,RY
  1993.         move    ccr,RCCR
  1994.         Next    2
  1995.  
  1996. DEY        subq.b    #1,RY
  1997.         move    ccr,RCCR
  1998.         Next    2
  1999.  
  2000. ; Logische Operationen
  2001. AndA        MACRO    ;Quelle, Zyklenzahl
  2002.         and.b    \1,RA
  2003.         move    ccr,RCCR
  2004.         Next    \2
  2005.         ENDM
  2006.  
  2007. ANDImm        AndA    (RPC)+,2
  2008.  
  2009. ANDZero        ReadAdrZero
  2010.         AndA    (RAMPTR,d0.l),3
  2011.  
  2012. ANDZeroX    ReadAdrZeroX
  2013.         AndA    (RAMPTR,d0.l),4
  2014.  
  2015. ANDAbs        ReadByteAbs
  2016.         AndA    d0,4
  2017.  
  2018. ANDAbsX        ReadByteAbsX
  2019.         AndA    d0,4
  2020.  
  2021. ANDAbsY        ReadByteAbsY
  2022.         AndA    d0,4
  2023.  
  2024. ANDIndX        ReadByteIndX
  2025.         AndA    d0,6
  2026.  
  2027. ANDIndY        ReadByteIndY
  2028.         AndA    d0,5
  2029.  
  2030. OrA        MACRO    ;Quelle, Zyklenzahl
  2031.         or.b    \1,RA
  2032.         move    ccr,RCCR
  2033.         Next    \2
  2034.         ENDM
  2035.  
  2036. ORAImm        OrA    (RPC)+,2
  2037.  
  2038. ORAZero        ReadAdrZero
  2039.         OrA    (RAMPTR,d0.l),3
  2040.  
  2041. ORAZeroX    ReadAdrZeroX
  2042.         OrA    (RAMPTR,d0.l),4
  2043.  
  2044. ORAAbs        ReadByteAbs
  2045.         OrA    d0,4
  2046.  
  2047. ORAAbsX        ReadByteAbsX
  2048.         OrA    d0,4
  2049.  
  2050. ORAAbsY        ReadByteAbsY
  2051.         OrA    d0,4
  2052.  
  2053. ORAIndX        ReadByteIndX
  2054.         OrA    d0,6
  2055.  
  2056. ORAIndY        ReadByteIndY
  2057.         OrA    d0,5
  2058.  
  2059. EorA        MACRO    ;Zyklenzahl
  2060.         eor.b    d0,RA        ;eor.b (ea),RA geht nicht
  2061.         move    ccr,RCCR    ;(Warum nicht, Motorola ?) :-(
  2062.         Next    \1
  2063.         ENDM
  2064.  
  2065. EORImm        move.b    (RPC)+,d0
  2066.         EorA    2
  2067.  
  2068. EORZero        ReadByteZero d0
  2069.         EorA    3
  2070.  
  2071. EORZeroX    ReadByteZeroX d0
  2072.         EorA    4
  2073.  
  2074. EORAbs        ReadByteAbs
  2075.         EorA    4
  2076.  
  2077. EORAbsX        ReadByteAbsX
  2078.         EorA    4
  2079.  
  2080. EORAbsY        ReadByteAbsY
  2081.         EorA    4
  2082.  
  2083. EORIndX        ReadByteIndX
  2084.         EorA    6
  2085.  
  2086. EORIndY        ReadByteIndY
  2087.         EorA    5
  2088.  
  2089. BitTest        MACRO    ;Zyklenzahl
  2090.         clr.b    RCCR
  2091.         and.w    #~OverflowMask,RP
  2092.  
  2093.         tst.b    d0        ;Bit 7 -> N
  2094.         bpl    \@1$
  2095.         or.b    #$08,RCCR
  2096. \@1$
  2097.         btst    #6,d0        ;Bit 6 -> V
  2098.         beq    \@2$
  2099.         or.w    #OverflowMask,RP
  2100. \@2$
  2101.         and.b    RA,d0        ;A AND M -> Z
  2102.         bne    \@3$
  2103.         or.b    #$04,RCCR
  2104. \@3$        Next    \1
  2105.         ENDM
  2106.  
  2107. BITZero        ReadByteZero    d0
  2108.         BitTest    3
  2109.  
  2110. BITAbs        ReadByteAbs
  2111.         BitTest    4
  2112.  
  2113. ; Verschiebungen
  2114. ShiftLeft    MACRO    ;Zyklenzahl
  2115.         move.l    d0,-(sp)
  2116.         ReadByte d1
  2117.         add.b    d1,d1
  2118.         scs    RP        ;Carry holen
  2119.         move    ccr,RCCR
  2120.         move.l    (sp)+,d0
  2121.         WriteByte
  2122.         Next    \1
  2123.         ENDM
  2124.  
  2125. ShiftLeftZero    MACRO    ;Zyklenzahl
  2126.         lea    (RAMPTR,d0.l),a0
  2127.         move.b    (a0),d1
  2128.         add.b    d1,d1
  2129.         scs    RP        ;Carry holen
  2130.         move.b    d1,(a0)
  2131.         move    ccr,RCCR
  2132.         cmp.b    #2,d0
  2133.         bhs    \@1$
  2134.         NewConfig
  2135. \@1$        Next    \1
  2136.         ENDM
  2137.  
  2138. ASLA        add.b    RA,RA
  2139.         move    ccr,RCCR
  2140.         scs    RP        ;Carry holen
  2141.         Next    2
  2142.  
  2143. ASLZero        ReadAdrZero
  2144.         ShiftLeftZero    5
  2145.  
  2146. ASLZeroX    ReadAdrZeroX
  2147.         ShiftLeftZero    6
  2148.  
  2149. ASLAbs        ReadAdrAbs
  2150.         ShiftLeft    6
  2151.  
  2152. ASLAbsX        ReadAdrAbsX
  2153.         ShiftLeft    7
  2154.  
  2155. ShiftRight    MACRO    ;Zyklenzahl
  2156.         move.l    d0,-(sp)
  2157.         ReadByte d1
  2158.         lsr.b    #1,d1
  2159.         scs    RP        ;Carry holen
  2160.         move    ccr,RCCR
  2161.         move.l    (sp)+,d0
  2162.         WriteByte
  2163.         Next    \1
  2164.         ENDM
  2165.  
  2166. ShiftRightZero    MACRO    ;Zyklenzahl
  2167.         lea    (RAMPTR,d0.l),a0
  2168.         move.b    (a0),d1
  2169.         lsr.b    #1,d1
  2170.         scs    RP        ;Carry holen
  2171.         move.b    d1,(a0)
  2172.         move    ccr,RCCR
  2173.         cmp.b    #2,d0
  2174.         bhs    \@1$
  2175.         NewConfig
  2176. \@1$        Next    \1
  2177.         ENDM
  2178.  
  2179. LSRA        lsr.b    #1,RA
  2180.         move    ccr,RCCR
  2181.         scs    RP        ;Carry holen
  2182.         Next    2
  2183.  
  2184. LSRZero        ReadAdrZero
  2185.         ShiftRightZero    5
  2186.  
  2187. LSRZeroX    ReadAdrZeroX
  2188.         ShiftRightZero    6
  2189.  
  2190. LSRAbs        ReadAdrAbs
  2191.         ShiftRight    6
  2192.  
  2193. LSRAbsX        ReadAdrAbsX
  2194.         ShiftRight    7
  2195.  
  2196. RotateLeft    MACRO    ;Zyklenzahl
  2197.         move.l    d0,-(sp)
  2198.         ReadByte d1
  2199.         add.b    RP,RP        ;Carry -> X
  2200.         roxl.b    #1,d1
  2201.         scs    RP        ;Carry holen
  2202.         move    ccr,RCCR
  2203.         move.l    (sp)+,d0
  2204.         WriteByte
  2205.         Next    \1
  2206.         ENDM
  2207.  
  2208. RotateLeftZero    MACRO    ;Zyklenzahl
  2209.         lea    (RAMPTR,d0.l),a0
  2210.         move.b    (a0),d1
  2211.         add.b    RP,RP        ;Carry -> X
  2212.         roxl.b    #1,d1
  2213.         scs    RP        ;Carry holen
  2214.         move.b    d1,(a0)
  2215.         move    ccr,RCCR
  2216.         cmp.b    #2,d0
  2217.         bhs    \@1$
  2218.         NewConfig
  2219. \@1$        Next    \1
  2220.         ENDM
  2221.  
  2222. ROLA        add.b    RP,RP        ;Carry -> X
  2223.         roxl.b    #1,RA
  2224.         move    ccr,RCCR
  2225.         scs    RP        ;Carry holen
  2226.         Next    2
  2227.  
  2228. ROLZero        ReadAdrZero
  2229.         RotateLeftZero    5
  2230.  
  2231. ROLZeroX    ReadAdrZeroX
  2232.         RotateLeftZero    6
  2233.  
  2234. ROLAbs        ReadAdrAbs
  2235.         RotateLeft    6
  2236.  
  2237. ROLAbsX        ReadAdrAbsX
  2238.         RotateLeft    7
  2239.  
  2240. RotateRight    MACRO    ;Zyklenzahl
  2241.         move.l    d0,-(sp)
  2242.         ReadByte d1
  2243.         add.b    RP,RP        ;Carry -> X
  2244.         roxr.b    #1,d1
  2245.         scs    RP        ;Carry holen
  2246.         move    ccr,RCCR
  2247.         move.l    (sp)+,d0
  2248.         WriteByte
  2249.         Next    \1
  2250.         ENDM
  2251.  
  2252. RotateRightZero    MACRO    ;Zyklenzahl
  2253.         lea    (RAMPTR,d0.l),a0
  2254.         move.b    (a0),d1
  2255.         add.b    RP,RP        ;Carry -> X
  2256.         roxr.b    #1,d1
  2257.         scs    RP        ;Carry holen
  2258.         move.b    d1,(a0)
  2259.         move    ccr,RCCR
  2260.         cmp.b    #2,d0
  2261.         bhs    \@1$
  2262.         NewConfig
  2263. \@1$        Next    \1
  2264.         ENDM
  2265.  
  2266. RORA        add.b    RP,RP        ;Carry -> X
  2267.         roxr.b    #1,RA
  2268.         move    ccr,RCCR
  2269.         scs    RP        ;Carry holen
  2270.         Next    2
  2271.  
  2272. RORZero        ReadAdrZero
  2273.         RotateRightZero    5
  2274.  
  2275. RORZeroX    ReadAdrZeroX
  2276.         RotateRightZero    6
  2277.  
  2278. RORAbs        ReadAdrAbs
  2279.         RotateRight    6
  2280.  
  2281. RORAbsX        ReadAdrAbsX
  2282.         RotateRight    7
  2283.  
  2284. ; Sprünge/Verzweigungen
  2285. JMPAbs        ReadAdrAbs
  2286.         Jump
  2287.         Next    3
  2288.  
  2289. JMPInd        ReadAdrInd
  2290.         Jump
  2291.         Next    5
  2292.  
  2293. JSRAbs        PushPCPlus1
  2294.         ReadAdrAbs
  2295.         Jump
  2296.         Next    6
  2297.  
  2298. RTSImpl        PopByte    d1        ;LSB
  2299.         PopByte    d0        ;MSB
  2300.         lsl.w    #8,d0        ;schieben
  2301.         move.b    d1,d0        ;LSB dazunehmen
  2302.         addq.w    #1,d0        ;Adresse um eins erhöhen
  2303.         Jump
  2304.         Next    6
  2305.  
  2306. RTIImpl        PopP
  2307.         PopByte    d1        ;LSB
  2308.         PopByte    d0        ;MSB
  2309.         lsl.w    #8,d0        ;schieben
  2310.         move.b    d1,d0        ;LSB dazunehmen
  2311.         Jump
  2312.         tst.w    IntIsIRQ    ;Steht ein IRQ an?
  2313.         beq    1$
  2314.         btst    #InterruptBit,RP ;Ja, I-Flag gelöscht?
  2315.         beq    HandleIRQ    ;Ja, Interrupt auslösen
  2316. 1$        Next    6
  2317.  
  2318. BRK        PushPC
  2319.         PushP    1
  2320.         or.w    #InterruptMask,RP
  2321.         move.w    #$fffe,d0    ;IRQ-Vektor
  2322.         ReadWord
  2323.         Jump
  2324.         Next    7
  2325.  
  2326. Branch        MACRO
  2327.         ReadByteRel
  2328.         move.l    RPC,d1
  2329.         add.w    d0,d1
  2330.         move.l    d1,RPC
  2331.         moveq    #0,d1
  2332.         Next    3
  2333.         ENDM
  2334.  
  2335. BVCRel        btst    #OverflowBit,RP
  2336.         bne    BVCNot
  2337.         Branch
  2338. BVCNot        addq.l    #1,RPC
  2339.         Next    2
  2340.  
  2341. BVSRel        btst    #OverflowBit,RP
  2342.         beq    BVSNot
  2343.         Branch
  2344. BVSNot        addq.l    #1,RPC
  2345.         Next    2
  2346.  
  2347. BEQRel        btst    #2,RCCR
  2348.         beq    BEQNot
  2349.         Branch
  2350. BEQNot        addq.l    #1,RPC
  2351.         Next    2
  2352.  
  2353. BNERel        btst    #2,RCCR
  2354.         bne    BNENot
  2355.         Branch
  2356. BNENot        addq.l    #1,RPC
  2357.         Next    2
  2358.  
  2359. BPLRel        btst    #3,RCCR
  2360.         bne    BPLNot
  2361.         Branch
  2362. BPLNot        addq.l    #1,RPC
  2363.         Next    2
  2364.  
  2365. BMIRel        btst    #3,RCCR
  2366.         beq    BMINot
  2367.         Branch
  2368. BMINot        addq.l    #1,RPC
  2369.         Next    2
  2370.  
  2371. BCCRel        tst.b    RP
  2372.         bne    BCCNot
  2373.         Branch
  2374. BCCNot        addq.l    #1,RPC
  2375.         Next    2
  2376.  
  2377. BCSRel        tst.b    RP
  2378.         beq    BCSNot
  2379.         Branch
  2380. BCSNot        addq.l    #1,RPC
  2381.         Next    2
  2382.  
  2383. ; Statusregister
  2384. SEI        or.w    #InterruptMask,RP
  2385.         Next    2
  2386.  
  2387. CLI        and.w    #~InterruptMask,RP
  2388.         tst.w    IntIsIRQ    ;Steht ein IRQ an?
  2389.         bne    HandleIRQ    ;Ja, auslösen
  2390.         Next    2
  2391.  
  2392. CLC        clr.b    RP
  2393.         Next    2
  2394.  
  2395. SEC        st.b    RP
  2396.         Next    2
  2397.  
  2398. SED        or.w    #DecimalMask,RP
  2399.         Next    2
  2400.  
  2401. CLD        and.w    #~DecimalMask,RP
  2402.         Next    2
  2403.  
  2404. CLV        and.w    #~OverflowMask,RP
  2405.         Next    2
  2406.  
  2407. *
  2408. * Periodic: Wird über den Opcode-Fetch aufgerufen,
  2409. *  wenn der Zyklenzähler unterläuft
  2410. * Sitzt hier in der Mitte, um kurze Branches ausnutzen zu können
  2411. *
  2412.  
  2413. ; VIC und CIA aufrufen
  2414. Periodic    lea    RegStore+20,a0
  2415.         movem.w    d2-d7,-(a0)    ;Gerade Anzahl von Registern
  2416.         movem.l    RWTAB/RPC,-(a0)
  2417.         bra    Periodic6569    ;Springt nach Periodic6526 und hierher zurück
  2418. Peri6526Cont    lea    _DATA_BAS_,a4
  2419.         lea    32766(a4),a4
  2420.         movem.l    RegStore,RWTAB/RPC
  2421.         movem.w    RegStore+8,d2-d7
  2422.         move.l    TheRAM,RAMPTR
  2423.         lea    CyclesLeft,CYCPTR
  2424.         moveq    #0,d0
  2425.         moveq    #0,d1
  2426.  
  2427. ; Interrupt aufgetreten?
  2428.         tst.l    Interrupt
  2429.         bne    HandleInt
  2430.  
  2431. ; Nein, Nächsten Befehl ausführen
  2432.         Next    0
  2433.  
  2434.  
  2435. ; Leerbefehle
  2436. NOPImpl        Next    2
  2437.  
  2438. NOPZero        addq.w    #1,RPC
  2439.         Next    3
  2440.  
  2441. NOPZeroX    addq.w    #1,RPC
  2442.         Next    4
  2443.  
  2444. NOPAbsX
  2445. NOPAbs        addq.w    #2,RPC
  2446.         Next    4
  2447.  
  2448. ; ASL/ORA-Gruppe
  2449. ShLeftOr    MACRO    ;Zyklenzahl
  2450.         move.l    d0,-(sp)
  2451.         ReadByte d1
  2452.         add.b    d1,d1
  2453.         scs    RP        ;Carry holen
  2454.         or.b    d1,RA
  2455.         move    ccr,RCCR
  2456.         move.l    (sp)+,d0
  2457.         WriteByte
  2458.         Next    \1
  2459.         ENDM
  2460.  
  2461. ShLeftOrZero    MACRO    ;Zyklenzahl
  2462.         lea    (RAMPTR,d0.l),a0
  2463.         move.b    (a0),d1
  2464.         add.b    d1,d1
  2465.         scs    RP        ;Carry holen
  2466.         or.b    d1,RA
  2467.         move    ccr,RCCR
  2468.         move.b    d1,(a0)
  2469.         cmp.b    #2,d0
  2470.         bhs    \@1$
  2471.         NewConfig
  2472. \@1$        Next    \1
  2473.         ENDM
  2474.  
  2475. SLOZero        ReadAdrZero
  2476.         ShLeftOrZero    5
  2477.  
  2478. SLOZeroX    ReadAdrZeroX
  2479.         ShLeftOrZero    6
  2480.  
  2481. SLOAbs        ReadAdrAbs
  2482.         ShLeftOr    6
  2483.  
  2484. SLOAbsX        ReadAdrAbsX
  2485.         ShLeftOr    7
  2486.  
  2487. SLOAbsY        ReadAdrAbsY
  2488.         ShLeftOr    7
  2489.  
  2490. SLOIndX        ReadAdrIndX
  2491.         ShLeftOr    8
  2492.  
  2493. SLOIndY        ReadAdrIndY
  2494.         ShLeftOr    8
  2495.  
  2496. ; ROL/AND-Gruppe
  2497. RoLeftAnd    MACRO    ;Zyklenzahl
  2498.         move.l    d0,-(sp)
  2499.         ReadByte d1
  2500.         add.b    RP,RP        ;Carry -> X
  2501.         roxl.b    #1,d1
  2502.         scs    RP        ;Carry holen
  2503.         and.b    d1,RA
  2504.         move    ccr,RCCR    ;N und Z holen
  2505.         move.l    (sp)+,d0
  2506.         WriteByte
  2507.         Next    \1
  2508.         ENDM
  2509.  
  2510. RoLeftAndZero    MACRO    ;Zyklenzahl
  2511.         lea    (RAMPTR,d0.l),a0
  2512.         move.b    (a0),d1
  2513.         add.b    RP,RP        ;Carry -> X
  2514.         roxl.b    #1,d1
  2515.         scs    RP        ;Carry holen
  2516.         and.b    d1,RA
  2517.         move    ccr,RCCR    ;N und Z holen
  2518.         move.b    d1,(a0)
  2519.         cmp.b    #2,d0
  2520.         bhs    \@1$
  2521.         NewConfig
  2522. \@1$        Next    \1
  2523.         ENDM
  2524.  
  2525. RLAZero        ReadAdrZero
  2526.         RoLeftAndZero    5
  2527.  
  2528. RLAZeroX    ReadAdrZeroX
  2529.         RoLeftAndZero    6
  2530.  
  2531. RLAAbs        ReadAdrAbs
  2532.         RoLeftAnd    6
  2533.  
  2534. RLAAbsX        ReadAdrAbsX
  2535.         RoLeftAnd    7
  2536.  
  2537. RLAAbsY        ReadAdrAbsY
  2538.         RoLeftAnd    7
  2539.  
  2540. RLAIndX        ReadAdrIndX
  2541.         RoLeftAnd    8
  2542.  
  2543. RLAIndY        ReadAdrIndY
  2544.         RoLeftAnd    8
  2545.  
  2546. ; LSR/EOR-Gruppe
  2547. ShRightEor    MACRO    ;Zyklenzahl
  2548.         move.l    d0,-(sp)
  2549.         ReadByte d1
  2550.         lsr.b    #1,d1
  2551.         scs    RP        ;Carry holen
  2552.         eor.b    d1,RA
  2553.         move    ccr,RCCR
  2554.         move.l    (sp)+,d0
  2555.         WriteByte
  2556.         Next    \1
  2557.         ENDM
  2558.  
  2559. ShRightEorZero    MACRO    ;Zyklenzahl
  2560.         lea    (RAMPTR,d0.l),a0
  2561.         move.b    (a0),d1
  2562.         lsr.b    #1,d1
  2563.         scs    RP        ;Carry holen
  2564.         eor.b    d1,RA
  2565.         move    ccr,RCCR
  2566.         move.b    d1,(a0)
  2567.         cmp.b    #2,d0
  2568.         bhs    \@1$
  2569.         NewConfig
  2570. \@1$        Next    \1
  2571.         ENDM
  2572.  
  2573. SREZero        ReadAdrZero
  2574.         ShRightEorZero    5
  2575.  
  2576. SREZeroX    ReadAdrZeroX
  2577.         ShRightEorZero    6
  2578.  
  2579. SREAbs        ReadAdrAbs
  2580.         ShRightEor    6
  2581.  
  2582. SREAbsX        ReadAdrAbsX
  2583.         ShRightEor    7
  2584.  
  2585. SREAbsY        ReadAdrAbsY
  2586.         ShRightEor    7
  2587.  
  2588. SREIndX        ReadAdrIndX
  2589.         ShRightEor    8
  2590.  
  2591. SREIndY        ReadAdrIndY
  2592.         ShRightEor    8
  2593.  
  2594. ; ROR/ADC-Gruppe
  2595. RoRightAdc    MACRO    ;Zyklenzahl
  2596.         move.l    d0,-(sp)
  2597.         ReadByte d1
  2598.         add.b    RP,RP        ;Carry -> X
  2599.         roxr.b    #1,d1
  2600.         scs    RP        ;Carry holen
  2601.         addx.b    d1,RA
  2602.         bvc    \@2$        ;Overflow holen
  2603.         or.w    #OverflowMask,RP
  2604.         bra    \@3$
  2605. \@2$        and.w    #~OverflowMask,RP
  2606. \@3$        tst.b    RA
  2607.         move    ccr,RCCR    ;N und Z holen
  2608.         move.l    (sp)+,d0
  2609.         WriteByte
  2610.         Next    \1
  2611.         ENDM
  2612.  
  2613. RoRightAdcZero    MACRO    ;Zyklenzahl
  2614.         lea    (RAMPTR,d0.l),a0
  2615.         move.b    (a0),d1
  2616.         add.b    RP,RP        ;Carry -> X
  2617.         roxr.b    #1,d1
  2618.         addx.b    d1,RA
  2619.         scs    RP        ;Carry holen
  2620.         bvc    \@2$        ;Overflow holen
  2621.         or.w    #OverflowMask,RP
  2622.         bra    \@3$
  2623. \@2$        and.w    #~OverflowMask,RP
  2624. \@3$        tst.b    RA
  2625.         move    ccr,RCCR    ;N und Z holen
  2626.         move.b    d1,(a0)
  2627.         cmp.b    #2,d0
  2628.         bhs    \@1$
  2629.         NewConfig
  2630. \@1$        Next    \1
  2631.         ENDM
  2632.  
  2633. RRAZero        ReadAdrZero
  2634.         RoRightAdcZero    5
  2635.  
  2636. RRAZeroX    ReadAdrZeroX
  2637.         RoRightAdcZero    6
  2638.  
  2639. RRAAbs        ReadAdrAbs
  2640.         RoRightAdc    6
  2641.  
  2642. RRAAbsX        ReadAdrAbsX
  2643.         RoRightAdc    7
  2644.  
  2645. RRAAbsY        ReadAdrAbsY
  2646.         RoRightAdc    7
  2647.  
  2648. RRAIndX        ReadAdrIndX
  2649.         RoRightAdc    8
  2650.  
  2651. RRAIndY        ReadAdrIndY
  2652.         RoRightAdc    8
  2653.  
  2654. ; DEC/CMP-Gruppe
  2655. DecCompare    MACRO    ;Zyklenzahl
  2656.         move.l    d0,-(sp)
  2657.         ReadByte d1
  2658.         subq.b    #1,d1
  2659.         cmp.b    d1,RA
  2660.         move    ccr,RCCR
  2661.         scc    RP        ;Inverses Carry holen
  2662.         move.l    (sp)+,d0
  2663.         WriteByte
  2664.         Next    \1
  2665.         ENDM
  2666.  
  2667. DecCompareZero    MACRO    ;Zyklenzahl
  2668.         lea    (RAMPTR,d0.l),a0
  2669.         move.b    (a0),d1
  2670.         subq.b    #1,d1
  2671.         cmp.b    d1,RA
  2672.         move    ccr,RCCR
  2673.         scc    RP        ;Inverses Carry holen
  2674.         move.b    d1,(a0)
  2675.         cmp.b    #2,d0
  2676.         bhs    \@1$
  2677.         NewConfig
  2678. \@1$        Next    \1
  2679.         ENDM
  2680.  
  2681. DCPZero        ReadAdrZero
  2682.         DecCompareZero    5
  2683.  
  2684. DCPZeroX    ReadAdrZeroX
  2685.         DecCompareZero    6
  2686.  
  2687. DCPAbs        ReadAdrAbs
  2688.         DecCompare    6
  2689.  
  2690. DCPAbsX        ReadAdrAbsX
  2691.         DecCompare    7
  2692.  
  2693. DCPAbsY        ReadAdrAbsY
  2694.         DecCompare    7
  2695.  
  2696. DCPIndX        ReadAdrIndX
  2697.         DecCompare    8
  2698.  
  2699. DCPIndY        ReadAdrIndY
  2700.         DecCompare    8
  2701.  
  2702. ; INC/SBC-Gruppe
  2703. IncSbc        MACRO    ;Zyklenzahl
  2704.         move.l    d0,-(sp)
  2705.         ReadByte d1
  2706.         addq.b    #1,d1
  2707.         not.b    RP
  2708.         add.b    RP,RP        ;Inverses Carry -> X
  2709.         subx.b    d1,RA
  2710.         scc    RP        ;Inverses Carry holen
  2711.         bvc    \@2$        ;Overflow holen
  2712.         or.w    #OverflowMask,RP
  2713.         bra    \@3$
  2714. \@2$        and.w    #~OverflowMask,RP
  2715. \@3$        tst.b    RA        ;N und Z holen
  2716.         move    ccr,RCCR
  2717.         move.l    (sp)+,d0
  2718.         WriteByte
  2719.         Next    \1
  2720.         ENDM
  2721.  
  2722. IncSbcZero    MACRO    ;Zyklenzahl
  2723.         lea    (RAMPTR,d0.l),a0
  2724.         move.b    (a0),d1
  2725.         addq.b    #1,d1
  2726.         not.b    RP
  2727.         add.b    RP,RP        ;Inverses Carry -> X
  2728.         subx.b    d1,RA
  2729.         scc    RP        ;Inverses Carry holen
  2730.         bvc    \@2$        ;Overflow holen
  2731.         or.w    #OverflowMask,RP
  2732.         bra    \@3$
  2733. \@2$        and.w    #~OverflowMask,RP
  2734. \@3$        tst.b    RA        ;N und Z holen
  2735.         move    ccr,RCCR
  2736.         move.b    d1,(a0)
  2737.         cmp.b    #2,d0
  2738.         bhs    \@1$
  2739.         NewConfig
  2740. \@1$        Next    \1
  2741.         ENDM
  2742.  
  2743. ISBZero        ReadAdrZero
  2744.         IncSbcZero    5
  2745.  
  2746. ISBZeroX    ReadAdrZeroX
  2747.         IncSbcZero    6
  2748.  
  2749. ISBAbs        ReadAdrAbs
  2750.         IncSbc    6
  2751.  
  2752. ISBAbsX        ReadAdrAbsX
  2753.         IncSbc    7
  2754.  
  2755. ISBAbsY        ReadAdrAbsY
  2756.         IncSbc    7
  2757.  
  2758. ISBIndX        ReadAdrIndX
  2759.         IncSbc    8
  2760.  
  2761. ISBIndY        ReadAdrIndY
  2762.         IncSbc    8
  2763.  
  2764. ; Komplexe (undokumentierte) Funktionen
  2765. ANCImm        and.b    (RPC)+,RA    ;??? ($0b, $2b)
  2766.         move    ccr,RCCR
  2767.         smi.b    RP        ;N -> C (??)
  2768.         Next    2
  2769.  
  2770. ASRImm        and.b    (RPC)+,RA
  2771.         lsr.b    #1,RA
  2772.         move    ccr,RCCR
  2773.         scs    RP        ;Carry holen
  2774.         Next    2
  2775.  
  2776. ARRImm        and.b    (RPC)+,RA
  2777.         add.b    RP,RP        ;Carry -> X
  2778.         roxr.b    #1,RA
  2779.         move    ccr,RCCR
  2780.         scs    RP        ;Carry holen
  2781.         Next    2
  2782.  
  2783. ANEImm        or.b    #$ee,RA
  2784.         and.b    (RPC)+,RA
  2785.         and.b    RX,RA
  2786.         move    ccr,RCCR
  2787.         Next    2
  2788.  
  2789. LXAImm        and.b    (RPC)+,RA
  2790.         move.b    RA,RX
  2791.         move    ccr,RCCR
  2792.         Next    2
  2793.  
  2794. LASAbsY        ReadByteAbsY        ;??? ($bb)
  2795.         and.b    RS,d0
  2796.         move.b    d0,RX
  2797.         move.b    d0,RA
  2798.         move    ccr,RCCR
  2799.         Next    4
  2800.  
  2801. SHAAbsY        ReadPCWord
  2802.         move.w    d0,d1
  2803.         lsr.w    #8,d1
  2804.         addq.b    #1,d1
  2805.         and.b    RX,d1
  2806.         and.b    RA,d1
  2807.         add.w    RY,d0
  2808.         WriteByte
  2809.         Next    5
  2810.  
  2811. SHAIndY        moveq    #0,d0
  2812.         move.b    (RPC)+,d0
  2813.         move.w    (RAMPTR,d0.l),d0    ;(Abgekürzt)
  2814.         rol.w    #8,d0            ;Geht bei ($ff),y schief
  2815.         move.w    d0,d1
  2816.         lsr.w    #8,d1
  2817.         addq.b    #1,d1
  2818.         and.b    RX,d1
  2819.         and.b    RA,d1
  2820.         add.w    RY,d0
  2821.         WriteByte
  2822.         Next    6
  2823.  
  2824. SHXAbsY        ReadPCWord
  2825.         move.w    d0,d1
  2826.         lsr.w    #8,d1
  2827.         addq.b    #1,d1
  2828.         and.b    RY,d1
  2829.         add.w    RY,d0
  2830.         WriteByte
  2831.         Next    5
  2832.  
  2833. SHYAbsX        ReadPCWord
  2834.         move.w    d0,d1
  2835.         lsr.w    #8,d1
  2836.         addq.b    #1,d1
  2837.         and.b    RX,d1
  2838.         add.w    RX,d0
  2839.         WriteByte
  2840.         Next    5
  2841.  
  2842. SHSAbsY        move.b    RA,RS
  2843.         and.b    RX,RS
  2844.         ReadPCWord
  2845.         move.w    d0,d1
  2846.         lsr.w    #8,d1
  2847.         addq.b    #1,d1
  2848.         and.b    RS,d1
  2849.         WriteByte
  2850.         Next    5
  2851.  
  2852. SBXImm        and.b    RA,RX
  2853.         sub.b    (RPC)+,RX
  2854.         move    ccr,RCCR
  2855.         scc    RP        ;Inverses Carry holen
  2856.         Next    2
  2857.  
  2858. *
  2859. * Erweiterte Opcodes
  2860. *
  2861.  
  2862. ; $d2
  2863. OpWrap        move.l    RPC,d1        ;Wraparound nach $100xx?
  2864.         sub.l    RAMPTR,d1
  2865.         swap    d1
  2866.         cmp.w    #1,d1
  2867.         bne    IllegalOp
  2868.         sub.l    #$10001,RPC    ;Ja, zu $00xx umleiten
  2869.         moveq    #0,d1
  2870.         Next    0
  2871.  
  2872. ; $f2 $xx
  2873. OpIEC        move.b    (RPC)+,d0    ;Selektor holen
  2874.         beq    OpIECOut
  2875.         cmp.b    #1,d0
  2876.         beq    OpIECOutATN
  2877.         cmp.b    #2,d0
  2878.         beq    OpIECOutSec
  2879.         cmp.b    #3,d0
  2880.         beq    OpIECIn
  2881.         cmp.b    #4,d0
  2882.         beq    OpIECSetATN
  2883.         cmp.b    #5,d0
  2884.         beq    OpIECRelATN
  2885.         cmp.b    #6,d0
  2886.         beq    OpIECTurnaround
  2887.         cmp.b    #7,d0
  2888.         beq    OpIECRelease
  2889.         bra    IllegalOp
  2890.  
  2891. OpIECOut    move.b    $95(RAMPTR),d0    ;Auszugebendes Byte holen
  2892.         move.b    $a3(RAMPTR),d1    ;EOI-Flag holen
  2893.         bsr    IECOut
  2894.         bra    IECSetST
  2895.  
  2896. OpIECOutATN    move.b    $95(RAMPTR),d0    ;Auszugebendes Byte holen
  2897.         bsr    IECOutATN
  2898.         bra    IECSetST
  2899.  
  2900. OpIECOutSec    move.b    $95(RAMPTR),d0    ;Auszugebendes Byte holen
  2901.         bsr    IECOutSec
  2902.         bra    IECSetST
  2903.  
  2904. OpIECIn        bsr    IECIn
  2905.         move.b    d1,RA        ;Byte in den Akku
  2906.         move    ccr,RCCR    ;Flags entsprechend setzen
  2907.         bra    IECSetST
  2908.  
  2909. OpIECSetATN    bsr    IECSetATN
  2910.         moveq    #0,d0        ;MSWs von d0 und d1 löschen
  2911.         moveq    #0,d1
  2912.         move.w    #$edfb,d0    ;Nach $edfb springen
  2913.         Jump
  2914.         Next    0
  2915.  
  2916. OpIECRelATN    bsr    IECRelATN
  2917.         bra    IECReturn
  2918.  
  2919. OpIECTurnaround    bsr    IECTurnaround
  2920.         bra    IECReturn
  2921.  
  2922. OpIECRelease    bsr    IECRelease
  2923.         bra    IECReturn
  2924.  
  2925. IECSetST    or.b    d0,$90(RAMPTR)    ;Status setzen
  2926.         clr.b    RP        ;Carry löschen
  2927. IECReturn    moveq    #0,d0        ;MSWs von d0 und d1 löschen
  2928.         moveq    #0,d1
  2929.         bra    RTSImpl        ;RTS ausführen
  2930.  
  2931.  
  2932. **
  2933. ** Konstanten
  2934. **
  2935.  
  2936. *
  2937. * Opcode Dispatch Table
  2938. * "*" bezeichnet einen undokumentierten Opcode
  2939. *
  2940.  
  2941.         CNOP    0,4
  2942. OpcodeTable    dc.l    BRK        ;$00
  2943.         dc.l    ORAIndX
  2944.         dc.l    IllegalOp
  2945.         dc.l    SLOIndX        ;*
  2946.         dc.l    NOPZero        ;*
  2947.         dc.l    ORAZero
  2948.         dc.l    ASLZero
  2949.         dc.l    SLOZero        ;*
  2950.  
  2951.         dc.l    PHP        ;$08
  2952.         dc.l    ORAImm
  2953.         dc.l    ASLA
  2954.         dc.l    ANCImm        ;*
  2955.         dc.l    NOPAbs        ;*
  2956.         dc.l    ORAAbs
  2957.         dc.l    ASLAbs
  2958.         dc.l    SLOAbs        ;*
  2959.  
  2960.         dc.l    BPLRel        ;$10
  2961.         dc.l    ORAIndY
  2962.         dc.l    IllegalOp
  2963.         dc.l    SLOIndY        ;*
  2964.         dc.l    NOPZeroX    ;*
  2965.         dc.l    ORAZeroX
  2966.         dc.l    ASLZeroX
  2967.         dc.l    SLOZeroX    ;*
  2968.  
  2969.         dc.l    CLC        ;$18
  2970.         dc.l    ORAAbsY
  2971.         dc.l    NOPImpl        ;*
  2972.         dc.l    SLOAbsY        ;*
  2973.         dc.l    NOPAbsX        ;*
  2974.         dc.l    ORAAbsX
  2975.         dc.l    ASLAbsX
  2976.         dc.l    SLOAbsX
  2977.  
  2978.         dc.l    JSRAbs        ;$20
  2979.         dc.l    ANDIndX
  2980.         dc.l    IllegalOp
  2981.         dc.l    RLAIndX        ;*
  2982.         dc.l    BITZero
  2983.         dc.l    ANDZero
  2984.         dc.l    ROLZero
  2985.         dc.l    RLAZero        ;*
  2986.  
  2987.         dc.l    PLP        ;$28
  2988.         dc.l    ANDImm
  2989.         dc.l    ROLA
  2990.         dc.l    ANCImm        ;*
  2991.         dc.l    BITAbs
  2992.         dc.l    ANDAbs
  2993.         dc.l    ROLAbs
  2994.         dc.l    RLAAbs        ;*
  2995.  
  2996.         dc.l    BMIRel        ;$30
  2997.         dc.l    ANDIndY
  2998.         dc.l    IllegalOp
  2999.         dc.l    RLAIndY        ;*
  3000.         dc.l    NOPZeroX    ;*
  3001.         dc.l    ANDZeroX
  3002.         dc.l    ROLZeroX
  3003.         dc.l    RLAZeroX    ;*
  3004.  
  3005.         dc.l    SEC        ;$38
  3006.         dc.l    ANDAbsY
  3007.         dc.l    NOPImpl        ;*
  3008.         dc.l    RLAAbsY        ;*
  3009.         dc.l    NOPAbsX        ;*
  3010.         dc.l    ANDAbsX
  3011.         dc.l    ROLAbsX
  3012.         dc.l    RLAAbsX        ;*
  3013.  
  3014.         dc.l    RTIImpl        ;$40
  3015.         dc.l    EORIndX
  3016.         dc.l    IllegalOp
  3017.         dc.l    SREIndX        ;*
  3018.         dc.l    NOPZero        ;*
  3019.         dc.l    EORZero
  3020.         dc.l    LSRZero
  3021.         dc.l    SREZero        ;*
  3022.  
  3023.         dc.l    PHA        ;$48
  3024.         dc.l    EORImm
  3025.         dc.l    LSRA
  3026.         dc.l    ASRImm        ;*
  3027.         dc.l    JMPAbs
  3028.         dc.l    EORAbs
  3029.         dc.l    LSRAbs
  3030.         dc.l    SREAbs        ;*
  3031.  
  3032.         dc.l    BVCRel        ;$50
  3033.         dc.l    EORIndY
  3034.         dc.l    IllegalOp
  3035.         dc.l    SREIndY        ;*
  3036.         dc.l    NOPZeroX    ;*
  3037.         dc.l    EORZeroX
  3038.         dc.l    LSRZeroX
  3039.         dc.l    SREZeroX    ;*
  3040.  
  3041.         dc.l    CLI        ;$58
  3042.         dc.l    EORAbsY
  3043.         dc.l    NOPImpl        ;*
  3044.         dc.l    SREAbsY        ;*
  3045.         dc.l    NOPAbsX        ;*
  3046.         dc.l    EORAbsX
  3047.         dc.l    LSRAbsX
  3048.         dc.l    SREAbsX        ;*
  3049.  
  3050.         dc.l    RTSImpl        ;$60
  3051.         dc.l    ADCIndX
  3052.         dc.l    IllegalOp
  3053.         dc.l    RRAIndX        ;*
  3054.         dc.l    NOPZero        ;*
  3055.         dc.l    ADCZero
  3056.         dc.l    RORZero
  3057.         dc.l    RRAZero        ;*
  3058.  
  3059.         dc.l    PLA        ;$68
  3060.         dc.l    ADCImm
  3061.         dc.l    RORA
  3062.         dc.l    ARRImm        ;*
  3063.         dc.l    JMPInd
  3064.         dc.l    ADCAbs
  3065.         dc.l    RORAbs
  3066.         dc.l    RRAAbs        ;*
  3067.  
  3068.         dc.l    BVSRel        ;$70
  3069.         dc.l    ADCIndY
  3070.         dc.l    IllegalOp
  3071.         dc.l    RRAIndY        ;*
  3072.         dc.l    NOPZeroX    ;*
  3073.         dc.l    ADCZeroX
  3074.         dc.l    RORZeroX
  3075.         dc.l    RRAZeroX    ;*
  3076.  
  3077.         dc.l    SEI        ;$78
  3078.         dc.l    ADCAbsY
  3079.         dc.l    NOPImpl        ;*
  3080.         dc.l    RRAAbsY        ;*
  3081.         dc.l    NOPAbsX        ;*
  3082.         dc.l    ADCAbsX
  3083.         dc.l    RORAbsX
  3084.         dc.l    RRAAbsX        ;*
  3085.  
  3086.         dc.l    NOPZero        ;* $80
  3087.         dc.l    STAIndX
  3088.         dc.l    NOPZero        ;*
  3089.         dc.l    SAXIndX        ;*
  3090.         dc.l    STYZero
  3091.         dc.l    STAZero
  3092.         dc.l    STXZero
  3093.         dc.l    SAXZero        ;*
  3094.  
  3095.         dc.l    DEY        ;$88
  3096.         dc.l    NOPZero        ;*
  3097.         dc.l    TXA
  3098.         dc.l    ANEImm        ;*
  3099.         dc.l    STYAbs
  3100.         dc.l    STAAbs
  3101.         dc.l    STXAbs
  3102.         dc.l    SAXAbs        ;*
  3103.  
  3104.         dc.l    BCCRel        ;$90
  3105.         dc.l    STAIndY
  3106.         dc.l    IllegalOp
  3107.         dc.l    SHAIndY        ;*
  3108.         dc.l    STYZeroX
  3109.         dc.l    STAZeroX
  3110.         dc.l    STXZeroY
  3111.         dc.l    SAXZeroY    ;*
  3112.  
  3113.         dc.l    TYA        ;$98
  3114.         dc.l    STAAbsY
  3115.         dc.l    TXS
  3116.         dc.l    SHSAbsY        ;*
  3117.         dc.l    SHYAbsX        ;*
  3118.         dc.l    STAAbsX
  3119.         dc.l    SHXAbsY        ;*
  3120.         dc.l    SHAAbsY        ;*
  3121.  
  3122.         dc.l    LDYImm        ;$a0
  3123.         dc.l    LDAIndX
  3124.         dc.l    LDXImm
  3125.         dc.l    LAXIndX        ;*
  3126.         dc.l    LDYZero
  3127.         dc.l    LDAZero
  3128.         dc.l    LDXZero
  3129.         dc.l    LAXZero        ;*
  3130.  
  3131.         dc.l    TAY        ;$a8
  3132.         dc.l    LDAImm
  3133.         dc.l    TAX
  3134.         dc.l    LXAImm        ;*
  3135.         dc.l    LDYAbs
  3136.         dc.l    LDAAbs
  3137.         dc.l    LDXAbs
  3138.         dc.l    LAXAbs        ;*
  3139.  
  3140.         dc.l    BCSRel        ;$b0
  3141.         dc.l    LDAIndY
  3142.         dc.l    IllegalOp
  3143.         dc.l    LAXIndY        ;*
  3144.         dc.l    LDYZeroX
  3145.         dc.l    LDAZeroX
  3146.         dc.l    LDXZeroY
  3147.         dc.l    LAXZeroY    ;*
  3148.  
  3149.         dc.l    CLV        ;$b8
  3150.         dc.l    LDAAbsY
  3151.         dc.l    TSX
  3152.         dc.l    LASAbsY        ;*
  3153.         dc.l    LDYAbsX
  3154.         dc.l    LDAAbsX
  3155.         dc.l    LDXAbsY
  3156.         dc.l    LAXAbsY        ;*
  3157.  
  3158.         dc.l    CPYImm        ;$c0
  3159.         dc.l    CMPIndX
  3160.         dc.l    NOPZero        ;*
  3161.         dc.l    DCPIndX        ;*
  3162.         dc.l    CPYZero
  3163.         dc.l    CMPZero
  3164.         dc.l    DECZero
  3165.         dc.l    DCPZero        ;*
  3166.  
  3167.         dc.l    INY        ;$c8
  3168.         dc.l    CMPImm
  3169.         dc.l    DEX
  3170.         dc.l    SBXImm        ;*
  3171.         dc.l    CPYAbs
  3172.         dc.l    CMPAbs
  3173.         dc.l    DECAbs
  3174.         dc.l    DCPAbs        ;*
  3175.  
  3176.         dc.l    BNERel        ;$d0
  3177.         dc.l    CMPIndY
  3178.         dc.l    OpWrap
  3179.         dc.l    DCPIndY        ;*
  3180.         dc.l    NOPZeroX    ;*
  3181.         dc.l    CMPZeroX
  3182.         dc.l    DECZeroX
  3183.         dc.l    DCPZeroX    ;*
  3184.  
  3185.         dc.l    CLD        ;$d8
  3186.         dc.l    CMPAbsY
  3187.         dc.l    NOPImpl        ;*
  3188.         dc.l    DCPAbsY        ;*
  3189.         dc.l    NOPAbsX        ;*
  3190.         dc.l    CMPAbsX
  3191.         dc.l    DECAbsX
  3192.         dc.l    DCPAbsX        ;*
  3193.  
  3194.         dc.l    CPXImm        ;$e0
  3195.         dc.l    SBCIndX
  3196.         dc.l    NOPZero        ;*
  3197.         dc.l    ISBIndX        ;*
  3198.         dc.l    CPXZero
  3199.         dc.l    SBCZero
  3200.         dc.l    INCZero
  3201.         dc.l    ISBZero        ;*
  3202.  
  3203.         dc.l    INX        ;$e8
  3204.         dc.l    SBCImm
  3205.         dc.l    NOPImpl
  3206.         dc.l    SBCImm        ;*
  3207.         dc.l    CPXAbs
  3208.         dc.l    SBCAbs
  3209.         dc.l    INCAbs
  3210.         dc.l    ISBAbs        ;*
  3211.  
  3212.         dc.l    BEQRel        ;$f0
  3213.         dc.l    SBCIndY
  3214.         dc.l    OpIEC        ;Patch
  3215.         dc.l    ISBIndY        ;*
  3216.         dc.l    NOPZeroX    ;*
  3217.         dc.l    SBCZeroX
  3218.         dc.l    INCZeroX
  3219.         dc.l    ISBZeroX    ;*
  3220.  
  3221.         dc.l    SED        ;$f8
  3222.         dc.l    SBCAbsY
  3223.         dc.l    NOPImpl        ;*
  3224.         dc.l    ISBAbsY        ;*
  3225.         dc.l    NOPAbsX        ;*
  3226.         dc.l    SBCAbsX
  3227.         dc.l    INCAbsX
  3228.         dc.l    ISBAbsX        ;*
  3229.  
  3230.  
  3231. *
  3232. * Speicherkonfigurationstabelle
  3233. *
  3234.  
  3235. ; Diese Tabelle enthält für alle 8 Speicherkonfigurationen
  3236. ; die Zeiger auf die zugehörigen Read- und WriteTabs
  3237.         CNOP    0,4
  3238. ConfigTab    dc.l    ReadWriteTab0
  3239.         dc.l    ReadWriteTab1
  3240.         dc.l    ReadWriteTab2
  3241.         dc.l    ReadWriteTab3
  3242.         dc.l    ReadWriteTab4
  3243.         dc.l    ReadWriteTab5
  3244.         dc.l    ReadWriteTab6
  3245.         dc.l    ReadWriteTab7
  3246.  
  3247.  
  3248. *
  3249. * Sonstige Konstanten
  3250. *
  3251.  
  3252. ; Taglist für CreateNewProc
  3253. ProcTags    dc.l    NP_Entry,CPUTaskProc
  3254.         dc.l    NP_Name,CPUTaskName
  3255.         dc.l    NP_Priority,-1
  3256.         dc.l    0
  3257.  
  3258. ; Strings
  3259. CPUTaskName    dc.b    "6510",0
  3260.  
  3261. IDString    dc.b    "FRODO V2.3",13
  3262.         dc.b    "(C)1994-1996 CHRISTIAN BAUER",0
  3263.         ds.b    64    ;Muß mind. 92 Zeichen lang sein
  3264.  
  3265. ; Flag: Dies ist nicht Frodo SC
  3266.         CNOP    0,4
  3267. _IsFrodoSC
  3268. IsFrodoSC    dc.w    0
  3269.  
  3270.  
  3271. **
  3272. ** Initialisierte Daten
  3273. **
  3274.  
  3275.         SECTION    "DATA",DATA
  3276.  
  3277. ; Requester
  3278. IllegalOpReq    dc.l    20,0,0,0,0
  3279. JumpToIOReq    dc.l    20,0,0,0,0
  3280.  
  3281. ; Emulator-Kennung
  3282. DFFFByte    dc.b    $55    ;Wechselt bei jedem Lesen zwischen $55 und $aa
  3283.  
  3284.  
  3285. **
  3286. ** Nicht initialisierte Daten
  3287. **
  3288.  
  3289.         SECTION    "BSS",BSS
  3290.  
  3291. ; Sprungtabellen für Speicherzugriff: Zwei Einträge pro Seite (Lesen/Schreiben)
  3292. ; Eine Tabelle für jede der 8 Speicherkonfigurationen
  3293. ReadWriteTab0    ds.l    512
  3294. ReadWriteTab1    ds.l    512
  3295. ReadWriteTab2    ds.l    512
  3296. ReadWriteTab3    ds.l    512
  3297. ReadWriteTab4    ds.l    512
  3298. ReadWriteTab5    ds.l    512
  3299. ReadWriteTab6    ds.l    512
  3300. ReadWriteTab7    ds.l    512
  3301.  
  3302. ; Sprungtabellen für Sprungbefehle: Einen Eintrag pro Seite (8 Bytes, nur
  3303. ;   die ersten 4 Bytes benutzt)
  3304. JumpTab0    ds.l    512
  3305. JumpTab1    ds.l    512
  3306. JumpTab2    ds.l    512
  3307. JumpTab3    ds.l    512
  3308. JumpTab4    ds.l    512
  3309. JumpTab5    ds.l    512
  3310. JumpTab6    ds.l    512
  3311. JumpTab7    ds.l    512
  3312.  
  3313.  
  3314.         SECTION    "__MERGED",BSS
  3315.  
  3316. ; 6510-Task
  3317.         CNOP    0,4
  3318. CPUProc        ds.l    1    ;Prozess-Handle
  3319.         XDEF    _CPUTask
  3320. _CPUTask
  3321. CPUTask        ds.l    1    ;Task des Prozesses
  3322. ReadySet    ds.l    1    ;Signal des Hauptprogramms
  3323. _InvokeSAMSet
  3324. InvokeSAMSet    ds.l    1    ;Signal -> Hauptprogramm: SAM aufrufen
  3325. ContinueSet    ds.l    1    ;Signal des CPU-Tasks
  3326. ReadySig    ds.b    1
  3327. InvokeSAMSig    ds.b    1
  3328. ContinueSig    ds.b    1
  3329.  
  3330. ; Interrupt-Flags. Bei einem Interrupt wird eins dieser Flags gesetzt.
  3331. ; Das bewirkt, daß nach dem nächsten Periodic der 6510-Task in die
  3332. ; Routine "HandleInt" springt. Dort werden diese Flags ausgewertet und
  3333. ; entsprechend verzweigt.
  3334.         CNOP    0,4
  3335. Interrupt            ;Zusammenfassung als Langwort
  3336. IntIsRESET    ds.b    1    ;RESET aufgetreten, 6510 beenden oder Pause
  3337. IntIsNMI    ds.b    1    ;NMI aufgetreten
  3338. IntIsIRQ            ;Zusammenfassung als Wort
  3339. IntIsVICIRQ    ds.b    1    ;IRQ durch VIC aufgetreten
  3340. IntIsCIAIRQ    ds.b    1    ;IRQ durch CIA-A aufgetreten
  3341.  
  3342. RESETIsEXIT    ds.b    1    ;Zur Unterscheidung von RESET und EXIT
  3343. RESETIsPause    ds.b    1    ;Zur Unterscheidung von RESET und Pause
  3344.  
  3345. NMIState    ds.b    1    ;Aktueller Zustand der NMI-Leitung (für Flankentriggerung)
  3346.  
  3347. ; Zwischenspeicher für Adc/Sbc im Dezimalmodus
  3348. TMPS        ds.b    1
  3349. TMPA        ds.b    1
  3350. TMPAL        ds.b    1
  3351.  
  3352. ; Anzahl zur Verfügung stehender CPU-Zyklen bis zum nächsten Periodic
  3353.         CNOP    0,2
  3354. CyclesLeft    ds.w    1
  3355.  
  3356. ; Speicherzeiger (außer bei TheChar stimmt bei allen das untere Wort
  3357. ; mit der tatsächlichen C64-Adresse überein, also
  3358. ;  TheRAM   : xxxx0000
  3359. ;  TheBasic : xxxxa000
  3360. ;  TheKernal: xxxxe000
  3361. ;  TheColor : xxxxd800
  3362.         CNOP    0,4
  3363. TheRAM        ds.l    1    ;Zeiger auf C64-RAM (64K)
  3364. TheBasic    ds.l    1    ;Zeiger auf Basic-ROM
  3365. TheKernal    ds.l    1    ;Zeiger auf Kernal-ROM
  3366. TheChar        ds.l    1    ;Zeiger auf Char-ROM
  3367. TheColor    ds.l    1    ;Zeiger auf Farb-RAM
  3368.  
  3369. ; Zwischenspeicher für Register bei Periodic/ReadWord/ReadAdrInd
  3370. RegStore    ds.l    5
  3371.  
  3372. ; Argumente für Requester
  3373. RequestStream    ds.l    16
  3374.  
  3375. ; Registerinhalte für SAM, nur gültig innerhalb von Pause6510/Resume6510
  3376.         XDEF    _RA
  3377. _RA        ds.b    1
  3378.         XDEF    _RX
  3379. _RX        ds.b    1
  3380.         XDEF    _RY
  3381. _RY        ds.b    1
  3382.         XDEF    _RP
  3383. _RP        ds.b    1
  3384.         XDEF    _RPR
  3385. _RPR        ds.b    1
  3386.         XDEF    _RDDR
  3387. _RDDR        ds.b    1
  3388.         XDEF    _RPC
  3389. _RPC        ds.w    1
  3390.         XDEF    _RS
  3391. _RS        ds.w    1
  3392.  
  3393.         XDEF    _SAMMemConfig
  3394. _SAMMemConfig    ds.b    1    ;CHAREN, LORAM, HIRAM
  3395.  
  3396.         END
  3397.