X16Community / x16-emulator

Emulator for the Commander X16 8-bit computer
BSD 2-Clause "Simplified" License
205 stars 43 forks source link

Opcodes that both read and write to IO areas that have 'side effects' do not work as hardware. #277

Open Yazwh0 opened 5 months ago

Yazwh0 commented 5 months ago

For opcodes like ror and inc, the CPU actually reads the memory location twice, while the emulator only does this once.

So if the location has a side effect from being read, such as DATA0, the outcome will be incorrect.

Yazwh0 commented 5 months ago

rol version attached

FXLINE.zip

import BM="bm.bmasm";

.machine CommanderX16R42
    BM.X16Header();

    sei

    stz CTRL
    lda DC_VIDEO
    and #$0f
    ora #$10    ; just layer 0
    sta DC_VIDEO

    lda #$07
    sta L0_CONFIG   ; bitmap + 256mode
    stz L0_TILEBASE ; x320
    stz L0_MAPBASE

    lda #64
    sta DC_HSCALE
    sta DC_VSCALE

    lda #%00010000           ; ADDR1 increment: +1 byte
    sta ADDRx_H
    lda #0                   ; Setting start to $00000
    sta ADDRx_M
    lda #0                   ; Setting start to $00000
    sta ADDRx_L

    ldx #$ff
    ldy #$80
    lda #02

.loop:
    lda #$13
    stz DATA0
    lda #$2
    sta DATA0
    dex
    bne -loop
    dey
    bne -loop

    ; skip fx setup to test data port access
    jmp no_fx

    lda #%00000100           ; DCSEL=2, ADDRSEL=0
    sta CTRL

    lda #%11100000           ; ADDR0 increment: +320 bytes
    sta ADDRx_H

    lda #%00000001           ; Entering *line draw mode*
    sta $9F29

    lda #%00000101           ; DCSEL=2, ADDRSEL=1
    sta CTRL

    lda #%00010000           ; ADDR1 increment: +1 byte
    sta ADDRx_H
    lda #0                   ; Setting start to $00000
    sta ADDRx_M
    lda #0                   ; Setting start to $00000
    sta ADDRx_L

    lda #%00000110           ; DCSEL=3, ADDRSEL=0
    sta CTRL

    ; Note: 73<<1 is just a nice looking slope ;)
    ; 73<<1 (=146) means: for each x pixel-step there is 146/512th y pixel-step

    lda #<(73<<1)            ; X increment low
    sta $9F29
    lda #%01111100            ; X increment high
    lda #0
    sta $9F2A

.draw_line:

    ldx #150 ; Drawing 150 pixels to the right
    lda #1   ; White color

.draw_line_next_pixel:
    sec
    rol DATA1
    dex
    bne draw_line_next_pixel

.loop:
    jmp -loop

.no_fx:

    lda #%00000001           ; DCSEL=0, ADDRSEL=1
    sta CTRL

    lda #%00010000           ; ADDR1 increment: +1 byte
    sta ADDRx_H
    lda #0                   ; Setting start to $00000
    sta ADDRx_M
    lda #0                   ; Setting start to $00000
    sta ADDRx_L

    jmp draw_line
Yazwh0 commented 2 months ago

There many other instances where reading the dataport on hardware has a different result to the emulator.

Attached is an application which demonstrates these. Use F1 - F5 to switch between different opcodes. Source is in the archive.

On the left are the values from my 65c02 based X16. On the right are the actual values from the machine its running on. Red values are different. Eg:

image

MAIN.zip

Yazwh0 commented 2 months ago

Full list:

image