2019-07-30 01:05:21 -07:00
|
|
|
//
|
|
|
|
// 6502.h
|
|
|
|
// 6502
|
|
|
|
//
|
|
|
|
// Created by Tamas Rudnai on 7/22/19.
|
|
|
|
// Copyright © 2019 GameAlloy. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef __6502_H__
|
|
|
|
#define __6502_H__
|
|
|
|
|
2020-02-16 20:38:38 -08:00
|
|
|
#include <stdint.h>
|
2020-05-27 19:12:28 -07:00
|
|
|
#include "common.h"
|
2020-06-02 10:10:18 -07:00
|
|
|
#include "woz.h"
|
2020-02-16 20:38:38 -08:00
|
|
|
|
2019-07-30 01:05:21 -07:00
|
|
|
|
2020-05-17 19:32:45 -07:00
|
|
|
extern const unsigned long long default_MHz_6502;
|
2020-01-27 22:54:03 -08:00
|
|
|
extern unsigned long long MHz_6502;
|
|
|
|
extern unsigned long long clk_6502_per_frm;
|
2020-02-16 23:09:29 -08:00
|
|
|
extern unsigned long long clk_6502_per_frm_set;
|
2020-04-29 15:35:54 -07:00
|
|
|
extern unsigned long long clk_6502_per_frm_max;
|
2020-05-27 17:16:49 -07:00
|
|
|
extern unsigned long long clk_6502_per_frm_max_sound;
|
2020-04-29 15:35:54 -07:00
|
|
|
extern unsigned int clkfrm;
|
2020-01-27 22:54:03 -08:00
|
|
|
|
|
|
|
|
2019-09-09 00:27:31 -07:00
|
|
|
typedef enum {
|
2019-09-17 02:12:05 -07:00
|
|
|
NO_INT,
|
2020-06-06 20:19:44 -07:00
|
|
|
HALT,
|
2019-11-27 20:27:32 -08:00
|
|
|
IRQ,
|
2019-09-09 00:27:31 -07:00
|
|
|
NMI,
|
|
|
|
HARDRESET,
|
|
|
|
SOFTRESET,
|
|
|
|
} interrupt_t;
|
2019-07-30 01:05:21 -07:00
|
|
|
|
2020-02-16 20:38:38 -08:00
|
|
|
|
2019-11-27 20:27:32 -08:00
|
|
|
typedef struct debugLevel_s {
|
|
|
|
uint8_t trace : 1;
|
|
|
|
uint8_t step : 1;
|
|
|
|
uint8_t brk : 1;
|
|
|
|
uint8_t rts : 1;
|
|
|
|
uint8_t bra : 1;
|
|
|
|
uint8_t bra_true : 1;
|
|
|
|
uint8_t bra_false : 1;
|
|
|
|
uint8_t compile : 1;
|
2019-09-22 01:31:09 -07:00
|
|
|
} debugLevel_t;
|
|
|
|
|
2020-02-16 20:38:38 -08:00
|
|
|
|
2020-05-01 21:52:51 -07:00
|
|
|
typedef union flags_u {
|
|
|
|
struct {
|
|
|
|
uint8_t C:1; // Carry Flag
|
|
|
|
uint8_t Z:1; // Zero Flag
|
|
|
|
uint8_t I:1; // Interrupt Flag
|
|
|
|
uint8_t D:1; // Decimal Flag
|
|
|
|
uint8_t B:1; // B Flag
|
|
|
|
uint8_t res:1; // reserved -- should be always 1
|
|
|
|
uint8_t V:1; // Overflow Flag ???
|
|
|
|
uint8_t N:1; // Negative Flag
|
|
|
|
};
|
|
|
|
|
|
|
|
uint8_t SR;
|
|
|
|
} flags_t;
|
|
|
|
|
|
|
|
|
2019-07-30 01:05:21 -07:00
|
|
|
typedef struct m6502_s {
|
|
|
|
uint8_t A; // Accumulator
|
|
|
|
uint8_t X; // X index register
|
|
|
|
uint8_t Y; // Y index register
|
2019-09-15 04:02:22 -07:00
|
|
|
// union {
|
|
|
|
// uint8_t instr; // Instruction
|
|
|
|
// struct {
|
|
|
|
// uint8_t cc:2;
|
|
|
|
// uint8_t bbb:3;
|
|
|
|
// uint8_t aaa:3;
|
|
|
|
// };
|
|
|
|
// };
|
2020-05-01 21:52:51 -07:00
|
|
|
struct { // no bitfield faster processing
|
|
|
|
uint8_t C; // Carry Flag
|
|
|
|
uint8_t Z; // Zero Flag
|
|
|
|
uint8_t I; // Interrupt Flag
|
|
|
|
uint8_t D; // Decimal Flag
|
|
|
|
uint8_t B; // B Flag
|
|
|
|
uint8_t res; // reserved -- should be always 1
|
|
|
|
uint8_t V; // Overflow Flag ???
|
|
|
|
uint8_t N; // Negative Flag
|
2019-07-30 01:05:21 -07:00
|
|
|
};
|
2020-05-01 21:52:51 -07:00
|
|
|
|
2019-09-15 04:02:22 -07:00
|
|
|
uint16_t PC; // Program Counter
|
|
|
|
uint8_t SP; // Stack Pointer ( stack addr = 0x01 + sp )
|
2020-02-07 00:40:31 -08:00
|
|
|
|
|
|
|
// unsigned clk; // Clock Counter
|
|
|
|
uint64_t clktime;
|
2020-02-16 20:38:38 -08:00
|
|
|
uint64_t clklast;
|
2020-02-07 00:40:31 -08:00
|
|
|
|
2019-09-22 01:31:09 -07:00
|
|
|
debugLevel_t dbgLevel; // 0: No Debug, 1: Disassembly Only, 2: Run till BRK, 3: StepByStep
|
2019-09-09 00:27:31 -07:00
|
|
|
|
|
|
|
union {
|
2019-09-17 02:12:05 -07:00
|
|
|
unsigned int IF; // interrut flag
|
2019-09-09 00:27:31 -07:00
|
|
|
interrupt_t interrupt;
|
|
|
|
};
|
2020-02-07 00:40:31 -08:00
|
|
|
|
2019-09-09 00:27:31 -07:00
|
|
|
} m6502_t;
|
2019-07-30 01:05:21 -07:00
|
|
|
|
|
|
|
|
2019-09-22 01:31:09 -07:00
|
|
|
typedef struct disassembly_s {
|
2019-11-27 20:27:32 -08:00
|
|
|
char addr[5]; // 4 digits + \0
|
|
|
|
char opcode[4 * 3 + 1]; // max 4 bytes * (2 digits + 1 space) + \0
|
|
|
|
char * pOpcode; // pointer for opcode string builder
|
|
|
|
char inst[6 + 1]; // 3 char (unknown instr? -- give it 6 chars) + \0
|
2020-04-27 11:58:38 -07:00
|
|
|
char oper[14 + 2 + 1 + 1 + 1]; // 4 digits + 2 brackets + 1 comma + 1 index + \0
|
2019-11-27 20:27:32 -08:00
|
|
|
char comment[256]; // to be able to add some comments
|
2019-09-22 01:31:09 -07:00
|
|
|
} disassembly_t;
|
|
|
|
|
|
|
|
|
2020-04-27 11:58:38 -07:00
|
|
|
// Memory Config
|
|
|
|
typedef struct MEMcfg_s {
|
|
|
|
unsigned RAM_16K : 1;
|
|
|
|
unsigned RAM_128K : 1;
|
|
|
|
unsigned RD_RAM : 1;
|
|
|
|
unsigned WR_RAM : 1;
|
|
|
|
unsigned RAM_BANK_2 : 1;
|
|
|
|
unsigned AUX_BANK : 1;
|
2020-04-27 20:32:58 -07:00
|
|
|
unsigned txt_page_2 : 1; // 0: page 1 1: page 2 (aux video memory)
|
|
|
|
unsigned int_Cx_ROM : 1; // 0: Slot Cx ROM 1: Internal Cx ROM
|
|
|
|
unsigned slot_C3_ROM : 1; // 0: Internal ROM 1: Slot 3 ROM
|
|
|
|
unsigned is_80STORE : 1;
|
|
|
|
unsigned RD_AUX_MEM : 1;
|
|
|
|
unsigned WR_AUX_MEM : 1;
|
|
|
|
unsigned ALT_ZP : 1;
|
2020-04-27 11:58:38 -07:00
|
|
|
} MEMcfg_t;
|
|
|
|
|
|
|
|
|
2020-02-22 16:37:54 -08:00
|
|
|
typedef union videoMode_u {
|
|
|
|
struct {
|
2020-04-27 11:58:38 -07:00
|
|
|
uint8_t text : 1; // 0: graphics 1: text
|
|
|
|
uint8_t col80 : 1; // 0: 40 col 1: 80 col
|
|
|
|
uint8_t altChr : 1; // 0: normal 1: alternate character set
|
|
|
|
uint8_t mixed : 1; // 0: no mix 1: mixed graphics and text when in graphics mode
|
|
|
|
uint8_t hires : 1; // 0: loRes 1: hiRes
|
2020-02-22 16:37:54 -08:00
|
|
|
};
|
|
|
|
uint8_t mode;
|
|
|
|
} videoMode_t;
|
|
|
|
|
|
|
|
extern videoMode_t videoMode;
|
2020-04-27 11:58:38 -07:00
|
|
|
extern MEMcfg_t MEMcfg;
|
2020-02-22 16:37:54 -08:00
|
|
|
|
2019-09-09 00:27:31 -07:00
|
|
|
extern m6502_t m6502;
|
2020-04-27 11:58:38 -07:00
|
|
|
extern uint8_t * const AUX; // Pointer to the auxiliary memory so we can use this from Swift
|
2020-04-27 08:15:36 -07:00
|
|
|
extern uint8_t * const RAM;
|
2020-05-01 14:43:41 -07:00
|
|
|
extern uint8_t * const MEM; // Pointer to the Shadow Memory Map so we can use this from Swift//extern uint8_t * AUX_VID_RAM;
|
2019-11-27 20:27:32 -08:00
|
|
|
extern uint32_t * videoMemPtr;
|
|
|
|
|
2020-05-20 22:22:44 -07:00
|
|
|
extern double * pdl_valarr;
|
2020-05-21 22:09:57 -07:00
|
|
|
extern double * pdl_prevarr;
|
|
|
|
extern double * pdl_diffarr;
|
2020-05-20 22:22:44 -07:00
|
|
|
|
2020-05-02 21:26:24 -07:00
|
|
|
//extern void hires_Update(void);
|
2019-07-30 01:05:21 -07:00
|
|
|
|
2019-09-17 02:12:05 -07:00
|
|
|
extern double mips;
|
|
|
|
extern double mhz;
|
2020-02-16 23:09:29 -08:00
|
|
|
|
2020-05-24 12:14:09 -07:00
|
|
|
#define fps 30U
|
2019-07-30 01:05:21 -07:00
|
|
|
|
2020-04-26 00:23:05 -07:00
|
|
|
extern void rom_loadFile( const char * bundlePath, const char * filename );
|
2019-11-27 20:27:32 -08:00
|
|
|
extern void tst6502(void);
|
2020-04-26 00:23:05 -07:00
|
|
|
extern void m6502_ColdReset( const char * bundlePath, const char * romFilePath );
|
2019-11-27 20:27:32 -08:00
|
|
|
extern void m6502_Run(void);
|
2019-09-22 01:31:09 -07:00
|
|
|
extern void kbdInput ( uint8_t code );
|
2020-05-20 22:22:44 -07:00
|
|
|
extern void kbdUp (void);
|
2020-02-22 16:37:54 -08:00
|
|
|
extern void setIO ( uint16_t ioaddr, uint8_t val );
|
2019-07-30 01:05:21 -07:00
|
|
|
|
2020-05-02 22:35:59 -07:00
|
|
|
extern void interrupt_IRQ(void);
|
|
|
|
extern void interrupt_NMI(void);
|
|
|
|
extern void hardReset(void);
|
|
|
|
extern void softReset(void);
|
|
|
|
|
2020-02-16 20:38:38 -08:00
|
|
|
|
2019-07-30 01:05:21 -07:00
|
|
|
#endif /* __6502_H__ */
|