Sunday, September 24, 2017

Writing to both the Third Millenium Arcade Board and the Super Sprite.


I wanted to write to the Third Millenium Arcade Board and the Super Sprite, but there's just one problem: The Super Sprite has its addresses at $C0F0 and $C0F1.

You can write to those addresses just fine in machine language with STA $C0F1 but an AppleSoft POKE doesn't work the same.

Applesoft POKE actually executes a STA ($50),Y to address $C0F1, but that actually reads $C0F1 before it writes $C0F1. It's kind of counter intuitive that you would have a read when you're trying to write something, but that's the wacky design of the 6502.

That read has the side effect of resetting the TMS9918A address pointer so when it writes, the TMS9918 thinks you want to specify the low byte of the address pointer. Each time you write $C0F1 it resets that pointer so you never actually finish setting the high byte of address pointer.

So you have to resort to assembly language, and I poke a little routine into memory and then call it. STA absolute doesn't have the same problem as the STA ($50),Y register indirect mode and it will write to $C0F1 properly without reading it first.

This applesoft program is horribly unoptimized, I just wanted something that would work.

It you let it run for a few minutes it will display the following:

(hint: display the frameskip with F11, set the frameskip to 6 with F8/F9 and unthrottle with F10 to speed things up)

./mame64 apple2e -sl4 arcbd -sl7 ssprite










The simple routines I poke into memory and call:

4000: 2 writes to C0F1 to set an address, reading C0F1 first to make sure we reset the address register
     It's a register write if the second byte has the hi byte set.
4014: same routine as 4000
     It's an address write if the second byte has bit 6 set, bit 6 clear if just to read.
4028: write to C0F0, write DATA register
403C: read from C0F0, read DATA register

]CALL -151

*4000L

4000-   AD F1 C0    LDA   $C0F1
4003-   A9 0F       LDA   #$0F
4005-   8D F1 C0    STA   $C0F1
4008-   A9 87       LDA   #$87
400A-   8D F1 C0    STA   $C0F1
400D-   60          RTS   
400E-   00          BRK   
400F-   00          BRK   
4010-   00          BRK   
4011-   00          BRK   
4012-   00          BRK   
4013-   00          BRK   
4014-   AD F1 C0    LDA   $C0F1
4017-   A9 00       LDA   #$00
4019-   8D F1 C0    STA   $C0F1
401C-   A9 78       LDA   #$78
401E-   8D F1 C0    STA   $C0F1
4021-   60          RTS   
4022-   00          BRK   
4023-   00          BRK   
*L

4024-   00          BRK   
4025-   00          BRK   
4026-   00          BRK   
4027-   00          BRK   
4028-   A9 78       LDA   #$78
402A-   8D F0 C0    STA   $C0F0
402D-   60          RTS   
402E-   00          BRK   
402F-   00          BRK   
4030-   00          BRK   
4031-   00          BRK   
4032-   00          BRK   
4033-   00          BRK   
4034-   00          BRK   
4035-   00          BRK   
4036-   00          BRK   
4037-   00          BRK   
4038-   00          BRK   
4039-   00          BRK   
403A-   00          BRK   
*L

403B-   00          BRK   
403C-   AD C0 C0    LDA   $C0C0
403F-   8D 4E 40    STA   $404E
4042-   60          RTS   
4043-   00          BRK   
4044-   00          BRK   
4045-   00          BRK   
4046-   00          BRK   
4047-   00          BRK   
4048-   00          BRK   
4049-   00          BRK   
404A-   00          BRK   
404B-   00          BRK   
404C-   00          BRK   
404D-   00          BRK   
404E-   00          BRK   
404F-   00          BRK   
4050-   00          BRK   
4051-   00          BRK   
4052-   00          BRK   

No comments:

Post a Comment