A commodore 64 conversion

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

A commodore 64 conversion

Post by GreyGhost »

Hello everyone. I have been working briefly on converting a game from the commodore 64 to the vic 20. I ran across this little code snippet:

Code: Select all

            lda CIA_A              ; AD 0E DC
            and #$FE               ; 29 FE
            sta CIA_A              ; 8D 0E DC
;
;
;
            lda CIA_A              ; AD 0E DC
            ora #$01               ; 09 01
            sta CIA_A              ; 8D 0E DC
Can anyone explain what this does and if their is an equivalent for the vic or not? It only occurs these two times. I thought it may be for setting up the joystick but when they are removed the game seems to freeze up.

Code: Select all

DC0E  56334                CIA Control Register A
                           7       Time-of-Day Clock Frequency: 1 = 50 Hz, 0 = 60 Hz
                           6       Serial Port I/O Mode Output, 0 = Input
                           5       Timer A Counts: 1 = CNT Signals, 0 = System 02 Clock
                           4       Force Load Timer A: 1 = Yes
                           3       Timer A Run Mode: 1 = One-Shot, 0 = Continuous
                           2       Timer A Output Mode to PB6: 1 = Toggle, 0 = Pulse
                           1       Timer A Output on PB6: 1 = Yes, 0 = No
                           0       Start/Stop Timer A: 1 = Start, 0 = Stop
I found this and it's basically saying it stops and then starts timer A. What is this be for? The only thing in the code in between these two snippets that I do not understand is changing the contents of memory location 1. I don't have a reference to this memory location for the commodore 64. The rest of the code in between is pretty straight forward.

Edit: Okay I found out that part memory location 1 on the c64 controls the memory that the cpu can "see" for character and the screen. Is this correct? Do you have to reset the timer when this is done? Also, why does CBM Prg Studio's memory map reference for the commodore 64 start with location 5?
Rob
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: A commodore 64 conversion

Post by tlr »

Like you say it just stops timer A and then later reenables it.

Without knowing which game we are talking about here I'd say it's just a kludgy way to avoid having IRQ interrupts during a specific section of the code. (Timer A is used for the regular Jiffy IRQ on the c64)
groepaz
Vic 20 Scientist
Posts: 1180
Joined: Wed Aug 25, 2010 5:30 pm

Re: A commodore 64 conversion

Post by groepaz »

$01 is the cpu port and indeed it is responsible for the memory layout, look here

as for the timer start/stop - this is probably to disable/enable the system interrupt (which is driven by CIA1/Timer1)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
FD22
Vic 20 Hobbyist
Posts: 148
Joined: Mon Feb 15, 2010 12:31 pm

Re: A commodore 64 conversion

Post by FD22 »

To echo and possibly extend what others have already said: this is a quick way of stopping and starting the CIA timer whilst switching memory banks. You wouldn't want an IRQ triggering just as you're switching the ROM out, for example, as random code might get executed and almost certainly crash the system.

For the VIC-20, which features the 6502 rather than the 6510 found in the C64 - and therefore has no bank-switching capability - this code is entirely redundant and can be eliminated.
Post Reply