home *** CD-ROM | disk | FTP | other *** search
/ Syzygy Magazine 7 / Syzygy_Magazine_7_1999___pl_Disk_2_of_2_Side_B.atr / xasm22.zip / doc / cpubugs.asx < prev    next >
Text File  |  1999-09-10  |  2KB  |  100 lines

  1. * This program detects 6502 bugs.
  2. * Please read text after program first.
  3.  
  4. icmd    equ    $342
  5. ibuf    equ    $344
  6. ilen    equ    $348
  7. ciomain    equ    $e456
  8.  
  9.     org    $8000
  10.     dta    h(*)        Buggy jump fetches this byte...
  11.     lda    #$ff        ... and jumps to this location
  12.     jmp    cont
  13.  
  14. start    lda    #11        Clear screen
  15.     ldx    <clstxt
  16.     ldy    #1
  17.     jsr    callio
  18.  
  19. * Check ADC bug
  20.     sed
  21.     lda    #$99        BCD 99+01=00
  22.     add    #1
  23.     cld
  24.     seq            Z flag set: no bug
  25.     lda    #$ff
  26.     ldx    <adctxt
  27.     jsr    print
  28.  
  29. * Check BRK bug
  30.     sei            Disable IRQs
  31.     inc    ^4e        Disable NMIs
  32.     mva    #$fe    ^31    Disable ROM
  33.     mwa    #nmi    $fffa    Set my NMI vector
  34.     mwa    #irq    $fffe    Set my IRQ vector
  35.     lsr    ^4e        Enable VBLKI
  36. irq    brk            BRK interrupt - infinite loop, so...
  37. nmi    inc    ^31        NMI always occurs on BRK
  38.     cli
  39.     pla:pla
  40.     sub    <irq
  41.     seq            Return adr points BRK: no bug
  42.     lda    #$ff
  43.     ldx    <brktxt
  44.     jsr    print
  45.  
  46. * Check JMP bug
  47.     jmp    (jmpptr)    You'll receive a warning from X-Asm here!
  48. cont    ldx    <jmptxt
  49.     jsr    print
  50.     jmp    *        Halt CPU
  51.  
  52. * Print results (A=$ff:bug or 0:no_bug,  X=<cmdtxt)
  53. print    pha            Save A
  54.     lda    #11        CIO write command
  55.     ldy    #3        Print 3 letters
  56.     jsr    callio
  57.     ldx    <nobtxt
  58.     pla            Restore A
  59.     seq            A=0:  X=<nobtxt
  60.     ldx    <bugtxt        A<>0: X=<bugtxt
  61.     lda    #9        CIO write_to_eol command
  62.     ldy    #$ff        Limit of printed characters
  63.  
  64. callio    sta    icmd        Call "E:" CIO: A-cmd X-<buf Y-len
  65.     stx    ibuf
  66.     mva    >*    ibuf+1
  67.     sty    ilen
  68.     mvx    #0    ilen+1    Channel 0, length<256
  69.     jmp    ciomain
  70.  
  71. clstxt    dta    b(125)        Clear screen control code
  72. adctxt    dta    c'ADC'
  73. brktxt    dta    c'BRK'
  74. jmptxt    dta    c'JMP'
  75. bugtxt    dta    c' bug detected!',b($9b)
  76. nobtxt    dta    c' bug NOT detected.',b($9b)
  77.  
  78.     ert    *>start|$ff    Program should fit on one page
  79.     org    *|$ff
  80. jmpptr    dta    a(jmp1)
  81.  
  82. jmp1    lda    #0        JMP bug not detected
  83.     jmp    cont
  84.  
  85.     run    start
  86.     end
  87.  
  88. The program above detects 3 bugs:
  89. - 'ADC bug'
  90. Flags N,V,Z are not properly set after ADC or SBC in decimal mode.
  91. You can't rely on these flags after BCD operation.
  92. - 'BRK bug'
  93. If an interrupt occurs on a BRK, it is executed with BRK-like values on stack.
  94. This means a BRK is simply passed-by if a NMI occurs.
  95. Beware of using BRK with other interrupts.
  96. - 'JMP bug' - JMP ($xxff) fetches address from $xxff and $xx00.
  97. X-Asm warns you of using such a jump.
  98.  
  99. All these bugs are supposedly fixed in CMOS chips.
  100.