u/FinancialShow7176

Issue with the Arithmetic Shift Left instruction on a W65C816S processor

Issue with the Arithmetic Shift Left instruction on a W65C816S processor

I am currently developing an LCD library using the I2C functions I have already developed.

As far as sending data via I2C is concerned, everything is working; I have already tested it on other components and can already write to the screen using this programme

    ; ==================================================
    ; Write data to CGRAM/DDRAM
    ; ==================================================
    LDA #%01001001 ;  DB7/DB4 -> 0100  Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

    LDA #%01001101 ;  DB7/DB4 -> 0100  Backlight = 1, E = 1, RW = 0, RS = 1
    JSR I2C_SEND

    LDA #%01001001 ;  DB7/DB4 -> 0100  Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND
    
    LDA #%01011001 ;  DB7/DB4 -> 1000  Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

    LDA #%01011101 ;  DB7/DB4 -> 1000  Backlight = 1, E = 1, RW = 0, RS = 1
    JSR I2C_SEND

    LDA #%01011001 ;  DB7/DB4 -> 1000  Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

This piece of code allows the character ‘E’ to be sent to the LCD screen.

I tried to create a function to simply load the desired character into the accumulator and then send it to the screen.

Here is that function:

LCD_WRITE_CHARACTER:


    STA $0010
    ; ======================================
    ; Envoie des 4 bits de poids fort
    ; ======================================
    AND #%11110000
    ORA #%00001001 ;  DB7/DB4 -> poids fort  Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

    ORA #%00000100 ;  DB7/DB4 -> poids fort  Backlight = 1, E = 1, RW = 0, RS = 1
    JSR I2C_SEND

    AND #%11111011 ;  DB7/DB4 -> poids fort  Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND


    ; ======================================
    ; Envoie des 4 bits de poids faible
    ; ======================================
    
    LDA $0010

    ;décalage des 4 bits de poids faible vers poids fort
    ASL
    ASL
    ASL
    ASL

    AND #%11110000
    ORA #%00001001 ;  DB7/DB4 -> poids faible Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

    ORA #%00000100 ;  DB7/DB4 -> poids faible Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

    AND #%11111011 ;  DB7/DB4 -> poids faible Backlight = 1, E = 0, RW = 0, RS = 1
    JSR I2C_SEND

    RTS

The address $0010 is used to store the character to be sent so that it can be retrieved after the most significant bit has been sent.

The problem here is that the screen LEDs go out just as the character is sent. I therefore assume that the byte created to match the screen’s 4-bit operation is incorrect. But I can’t see what the problem is here.

According to what I’ve read in the CPU documentation, the Arithmetic Shift Left sets the least significant bit to 0, so this shouldn’t be a carry issue.

https://preview.redd.it/idpsvmngkl2h1.png?width=598&format=png&auto=webp&s=403db4794dfbed131496d5da7f4ac35fa77286ff

On initialisation, the CPU is in Emulation mode (8-bit) and at no point in my programme do I switch to 16-bit mode.

I’m just starting to use the assembler and I might not understand everything, so thank you for taking the time to read this.

reddit.com
u/FinancialShow7176 — 1 day ago

Bonjour tout le monde, je commence à utiliser un processeur W65C816S et je voudrais essayer de faire des petits programme pour commencer à comprendre la programmation en langage machine / assembleur.

Voici le programme que j'ai actuellement :

rom[0] = 0xD8 # CLD

rom[1] = 0x18 # CLC

rom[2] = 0xAD # LDA $83E8

rom[3] = 0xE8

rom[4] = 0x83

rom[5] = 0x69 # ADC #05

rom[6] = 0x05

rom[7] = 0x8D # STA $8400

rom[8] = 0x00

rom[9] = 0x84

rom[1000] = 0x2D

rom[0x7FFC] = 0x00

rom[0x7FFD] = 0x80

Le problème ici est que sur la partie STA, la CPU écris 0x22 vers la mémoire alors que le résultat devrait être 0x32.

Si je retire la partie avec ADC, la valeure écrite est bien 0x2D (valeur lue à l'adresse 83E8).

Je suppose qu'il ne manque pas grand chose mais je n'arrive pas a trouver ou est mon erreur

Voici ce que je lis sur les deux bus avec une clock à 1Hz à partir de l'initialisation avec en premier l'adresse du bus, en second Lecture ou écriture et en troisème position la valeur du bus de data :

fffc R 00

fffd R 80

8000 R d8

8001 R 18

8001 R 18

8002 R ad

8002 R ad

8003 R e8

8004 R 83

83e8 R 2d

8005 R 69

8006 R 05

8007 R 8d

8008 R 00

8009 R 84

8400 W 22

Je vous remercie d'avance pour le temps passé à lire ceci

reddit.com
u/FinancialShow7176 — 15 days ago

Problem using the ADC with a W65C816S CPU

Hello everyone, I’m just starting to use a W65C816S processor and I’d like to try writing some simple programs to begin understanding programming in machine language/assembly.

Here is the program I currently have:

rom[0] = 0xD8 # CLD

rom[1] = 0x18 # CLC

rom[2] = 0xAD # LDA $83E8

rom[3] = 0xE8

rom[4] = 0x83

rom[5] = 0x69 # ADC #05

rom[6] = 0x05

rom[7] = 0x8D # STA $8400

rom[8] = 0x00

rom[9] = 0x84

rom[1000] = 0x2D

rom[0x7FFC] = 0x00

rom[0x7FFD] = 0x80

The problem here is that in the STA section, the CPU writes 0x22 to memory when the result should be 0x32.

If I remove the section with the ADC, the value written is indeed 0x2D (value read at address 83E8).

I suppose I’m not far off, but I can’t seem to find where my mistake is.

Here is what I read on the two buses at a 1Hz clock rate from initialisation, with the bus address first, read or write second, and the data bus value third:

fffc R 00

fffd R 80

8000 R d8

8001 R 18

8001 R 18

8002 R ad

8002 R ad

8003 R e8

8004 R 83

83e8 R 2d

8005 R 69

8006 R 05

8007 R 8d

8008 R 00

8009 R 84

8400 W 22

Thank you in advance for taking the time to read this

reddit.com
u/FinancialShow7176 — 15 days ago