CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Commodore 64 ROM emulator using an 18F PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RetroBytes



Joined: 19 Jun 2016
Posts: 1

View user's profile Send private message

Commodore 64 ROM emulator using an 18F PIC
PostPosted: Sun Jun 19, 2016 12:00 pm     Reply with quote

Hi,

I have a dead ROM chip in my Commodore 64 (checked with working chip), I was hoping to emulate the ROM chip (2364) using a PIC18F66K80. I’m not sure if it’s possible...

CE is connected to RB0
Data bus to Port C
Address bus to Port D & F

I am using an 8 port logic analyser to look at VCC, CE, D0-2 & A0-2, it’s hard to see what is going on. I set the analyser going from power up, the working chip and PIC look a little different, which is obviously why it’s not working.

I’m new to CCS and C so I thought I would post my code here for suggestions and any errors I might have made.

My thoughts are... try to use an interrupt on the CE pin, or maybe some delays... I’m not sure on the spec of the 2364 ROM.

Hopefully I have attached three files…

main.c, main.h and RomArray.h

Any suggestions welcome...

main.c
Code:

#include <main.h>
#include <RomArray.h>

unsigned int16 AB16;
unsigned int8 x;

void main()
{
set_tris_c(0xFF);

setup_wdt( WDT_OFF );
setup_oscillator ( OSC_PLL_ON | 2);         // 64MHz
setup_adc_ports( NO_ANALOGS );              // Turn all ADC's off
setup_adc( ADC_OFF );
setup_ccp1( CCP_OFF);
setup_ccp2( CCP_OFF);
setup_ccp3( CCP_OFF);
setup_ccp4( CCP_OFF);
setup_ccp5( CCP_OFF);
setup_psp( 0 );
setup_spi( SPI_DISABLED );
setup_comparator ( NC_NC_NC_NC );

port_b_pullups(0b00000001);
//port_c_pullups(0b11111111);

//port_d_pullups(0b11111111);
//port_f_pullups(0b11111111);

delay_us(100);

   while(TRUE)
   {
        //set_tris_c(0xFF);

        if ( input(PIN_B0) == 0 )  // Chip selected
        {
            set_tris_c(0x00);
            output_high(LED);
            //AB16 = 0;                     // For testing
            AB16 = input_f();               // Address bus high - Port F
            //AB16 = 0x0;
            AB16 <<= 8;
            AB16 += input_d();              // Address bus low - Port D
            //AB16 += 0x0;                  // For testing
           
            //delay_us(1);
           
            //set_tris_c(0x00);
           
            x = (RomArray[AB16]);
           
            //output_c(RomArray[AB16]);       // Data bus - Port C
            output_c(x);

            //delay_us(1);
            output_low(LED);
        }
       
        else  // Chip NOT selected
        {
            set_tris_c(0xFF);
            //delay_us(1);
        }
   }
}


main.h
Code:

#include <18F66K80.h>
#use delay(internal=64000000)
#use fast_io(c)
#fuses NOWRT

#define LED     PIN_G1
#define DELAY   1000


RomArray.h (first 46 lines):-
Code:

// C64 - Kernel - 8KB - 901227-03
rom unsigned char RomArray[] = {
0x85,0x56,0x20,0x0F,0xBC,0xA5,0x61,0xC9,0x88,0x90,0x3,0x20,0xD4,0xBA,0x20,0xCC,
0xBC,0xA5,0x7,0x18,0x69,0x81,0xF0,0xF3,0x38,0xE9,0x1,0x48,0xA2,0x5,0xB5,0x69,
0xB4,0x61,0x95,0x61,0x94,0x69,0xCA,0x10,0xF5,0xA5,0x56,0x85,0x70,0x20,0x53,0xB8,
0x20,0xB4,0xBF,0xA9,0xC4,0xA0,0xBF,0x20,0x59,0xE0,0xA9,0x0,0x85,0x6F,0x68,0x20,
0xB9,0xBA,0x60,0x85,0x71,0x84,0x72,0x20,0xCA,0xBB,0xA9,0x57,0x20,0x28,0xBA,0x20,
0x5D,0xE0,0xA9,0x57,0xA0,0x0,0x4C,0x28,0xBA,0x85,0x71,0x84,0x72,0x20,0xC7,0xBB,
0xB1,0x71,0x85,0x67,0xA4,0x71,0xC8,0x98,0xD0,0x2,0xE6,0x72,0x85,0x71,0xA4,0x72,
0x20,0x28,0xBA,0xA5,0x71,0xA4,0x72,0x18,0x69,0x5,0x90,0x1,0xC8,0x85,0x71,0x84,
0x72,0x20,0x67,0x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20,
0xBA,0xFF,0x20,0x6,0xE2,0x20,0x0,0xE2,0x8A,0xA8,0xA6,0x4A,0xA5,0x49,0x20,0xBA,
0xFF,0x20,0x6,0xE2,0x20,0x0E,0xE2,0x20,0x9E,0xAD,0x20,0xA3,0xB6,0xA6,0x22,0xA4,
0x23,0x4C,0xBD,0xFF,0xA9,0xE0,0xA0,0xE2,0x20,0x67,0xB8,0x20,0x0C,0xBC,0xA9,0xE5,
0xA0,0xE2,0xA6,0x6E,0x20,0x7,0xBB,0x20,0x0C,0xBC,0x20,0xCC,0xBC,0xA9,0x0,0x85,
0x6F,0x20,0x53,0xB8,0xA9,0xEA,0xA0,0xE2,0x20,0x50,0xB8,0xA5,0x66,0x48,0x10,0x0D,
0x20,0x49,0xB8,0xA5,0x66,0x30,0x9,0xA5,0x12,0x49,0xFF,0x85,0x12,0x20,0xB4,0xBF,
0xA9,0xEA,0xA0,0xE2,0x20,0x67,0xB8,0x68,0x10,0x3,0x20,0xB4,0xBF,0xA9,0xEF,0xA0,
0xE2,0x4C,0x43,0xE0,0x20,0xCA,0xBB,0xA9,0x0,0x85,0x12,0x20,0x6B,0xE2,0xA2,0x4E,
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Sun Jun 19, 2016 1:44 pm     Reply with quote

Probably just speed. Odds are you are taking too long.
However you can speed things up quite a bit:

1) Use fast_io on the ports. This means each I/O operation just involves reading or writing the data register, whereas with standard I/O the TRIS is accessed as well.

2) Use make16:

AB16 = make16(input_f(),input_d());

With fast_io, this will just involve two byte moves. Probably several times faster.

3) You then should wait for the input to go high before exiting the loop. Currently so long as B0 is low, it'll keep looping and outputting the same value.

So:
Code:

   set_tris_c(0xFF);
   while(TRUE)
   {
        if ( input(PIN_B0) == 0 )  // Chip selected
        {         
            output_c(RomArray[make16(input_f(),input_d())]);
            //get the byte as fast as possible
            set_tris_c(0):
            //then set the TRIS
            output_high(LED); //Only waste time for this after the data is sent.
            while (input(PIN_B0)==0)
                ; //wait for the de-select
            set_tris_c(0xFF);
            //turn off the TRIS and the LED
            output_low(LED);
        }
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group