Fix run on linux
This commit is contained in:
Vendored
+39
-3
@@ -1,11 +1,47 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "(lldb) Anfügen",
|
"name": "(gdb) Launch",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "attach",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/6502PC",
|
"program": "${workspaceFolder}/build/6502PC",
|
||||||
"MIMode": "lldb"
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}/build",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Set Disassembly Flavor to Intel",
|
||||||
|
"text": "-gdb-set disassembly-flavor intel",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "(lldb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/build/6502PC",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}/build",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "lldb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Set Disassembly Flavor to Intel",
|
||||||
|
"text": "settings set target.x86-disassembly-flavor intel",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -66,6 +66,8 @@ N2H ds 2
|
|||||||
|
|
||||||
code
|
code
|
||||||
org $200
|
org $200
|
||||||
|
lda #1
|
||||||
|
sta $dc02
|
||||||
TEST ldy #1 ; initialize Y (used to loop through carry flag values)
|
TEST ldy #1 ; initialize Y (used to loop through carry flag values)
|
||||||
sty ERROR ; store 1 in ERROR until the test passes
|
sty ERROR ; store 1 in ERROR until the test passes
|
||||||
lda #0 ; initialize N1 and N2
|
lda #0 ; initialize N1 and N2
|
||||||
@@ -111,24 +113,33 @@ LOOP2 lda N1 ; N1L = N1 & $0F
|
|||||||
bne DONE
|
bne DONE
|
||||||
NEXT1 inc N1 ; [5] see text
|
NEXT1 inc N1 ; [5] see text
|
||||||
bne LOOP2 ; loop through all 256 values of N1
|
bne LOOP2 ; loop through all 256 values of N1
|
||||||
NEXT2 inc N2 ; [6] see text
|
NEXT2 lda #'*'
|
||||||
|
sta $dc00
|
||||||
|
inc N2 ; [6] see text
|
||||||
bne LOOP1 ; loop through all 256 values of N2
|
bne LOOP1 ; loop through all 256 values of N2
|
||||||
dey
|
dey
|
||||||
bpl LOOP1 ; loop through both values of the carry flag
|
bpl LOOP1 ; loop through both values of the carry flag
|
||||||
lda #0 ; test passed, so store 0 in ERROR
|
lda #0 ; test passed, so store 0 in ERROR
|
||||||
sta ERROR
|
sta ERROR
|
||||||
DONE
|
DONE
|
||||||
|
lda #0
|
||||||
|
jsr RCHAR
|
||||||
lda #1
|
lda #1
|
||||||
cmp ERROR
|
cmp ERROR
|
||||||
beq _E
|
beq _E
|
||||||
lda #'P'
|
lda #'P'
|
||||||
sta $dc00
|
|
||||||
jmp _E2
|
jmp _E2
|
||||||
_E lda #'F'
|
_E lda #'F'
|
||||||
sta $dc00
|
_E2 jsr RCHAR
|
||||||
_E2
|
|
||||||
end_of_test
|
end_of_test
|
||||||
|
|
||||||
|
RCHAR sta $dc00
|
||||||
|
lda #'\r'
|
||||||
|
sta $dc00
|
||||||
|
lda #'\n'
|
||||||
|
sta $dc00
|
||||||
|
rts
|
||||||
|
|
||||||
; Calculate the actual decimal mode accumulator and flags, the accumulator
|
; Calculate the actual decimal mode accumulator and flags, the accumulator
|
||||||
; and flag results when N1 is added to N2 using binary arithmetic, the
|
; and flag results when N1 is added to N2 using binary arithmetic, the
|
||||||
; predicted accumulator result, the predicted carry flag, and the predicted
|
; predicted accumulator result, the predicted carry flag, and the predicted
|
||||||
|
|||||||
@@ -735,7 +735,9 @@ data_bss_end
|
|||||||
|
|
||||||
code
|
code
|
||||||
org code_segment
|
org code_segment
|
||||||
start cld
|
start lda #1
|
||||||
|
sta $dc02
|
||||||
|
cld
|
||||||
ldx #$ff
|
ldx #$ff
|
||||||
txs
|
txs
|
||||||
lda #0 ;*** test 0 = initialize
|
lda #0 ;*** test 0 = initialize
|
||||||
|
|||||||
+5
-1
@@ -10,7 +10,11 @@ enable_language(C)
|
|||||||
|
|
||||||
add_executable(${CMAKE_PROJECT_NAME})
|
add_executable(${CMAKE_PROJECT_NAME})
|
||||||
|
|
||||||
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic)
|
if(MSVC)
|
||||||
|
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE /W4)
|
||||||
|
else()
|
||||||
|
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
"src/main.c"
|
"src/main.c"
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
#ifndef IO_H
|
#ifndef IO_H
|
||||||
#define IO_H
|
#define IO_H
|
||||||
|
|
||||||
#include "ram.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define IO_SIZE (1 * 1024) // 1KiB
|
#define IO_SIZE (1 * 1024) // 1KiB
|
||||||
|
#define IO_BASE (55 * 1024) // 55KiB RAM, hard coded
|
||||||
#define IO_BASE (RAM_SIZE) // 55KiB RAM
|
|
||||||
|
|
||||||
#define SCREEN_ADDRESS 0
|
#define SCREEN_ADDRESS 0
|
||||||
#define KEYBOARD_ADDRESS 1
|
#define KEYBOARD_ADDRESS 1
|
||||||
|
#define ROM_BANKED_OUT 2
|
||||||
|
|
||||||
int putChar(uint8_t c);
|
int putChar(uint8_t c);
|
||||||
int getChar(void);
|
int getChar(void);
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint8_t readMemory(uint16_t address, uint8_t *ram, uint8_t *rom);
|
uint8_t readMemory(uint16_t address, uint8_t *ram, uint8_t *rom);
|
||||||
void writeMemory(uint16_t address, uint8_t value, uint8_t *ram, uint8_t *rom);
|
void writeMemory(uint16_t address, uint8_t value, uint8_t *ram);
|
||||||
|
|
||||||
uint8_t readStack(uint8_t address, uint8_t *ram);
|
uint8_t readStack(uint8_t address, uint8_t *ram);
|
||||||
void writeStack(uint8_t address, uint8_t value, uint8_t *ram);
|
void writeStack(uint8_t address, uint8_t value, uint8_t *ram);
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
|
||||||
#define RAM_SIZE (55 * 1024) // 55KiB
|
#define RAM_SIZE (64 * 1024) // 55KiB
|
||||||
//#define RAM_SIZE (64 * 1024) // Full range, DEBUG mode
|
|
||||||
|
|
||||||
#define RAM_BASE (0x00) // 0
|
#define RAM_BASE (0x00) // 0
|
||||||
|
|
||||||
int createRAM(uint8_t **ram);
|
int createRAM(uint8_t **ram);
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
#ifndef ROM_H
|
#ifndef ROM_H
|
||||||
#define ROM_H
|
#define ROM_H
|
||||||
|
|
||||||
#include "io.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define ROM_SIZE (8 * 1024) // 8KiB
|
#define ROM_SIZE (8 * 1024) // 8KiB
|
||||||
#define ROM_BASE (IO_BASE + IO_SIZE) // 55KiB RAM + 1KiB IO
|
#define ROM_BASE (56 * 1024) // 55KiB RAM + 1KiB IO, hard coded
|
||||||
|
|
||||||
uint8_t rom[ROM_SIZE];
|
extern uint8_t rom[ROM_SIZE];
|
||||||
|
|
||||||
void initRom(uint8_t *rom);
|
void initRom(uint8_t *rom);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
||||||
#include "memoryMap.h"
|
#include "memoryMap.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
|
|
||||||
@@ -74,7 +75,6 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t opcode = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t opcode = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
|
|
||||||
// Decode opcode, fetch operands, execute
|
// Decode opcode, fetch operands, execute
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case BRK: {
|
case BRK: {
|
||||||
// Store return address on stack
|
// Store return address on stack
|
||||||
@@ -132,7 +132,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
writeMemory(offset, value, ram, rom);
|
writeMemory(offset, value, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
writeMemory(COMBINE(high, low), value, ram, rom);
|
writeMemory(COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
writeMemory((uint8_t)(cpu->X + offset), value, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
writeMemory(cpu->X + COMBINE(high, low), value, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory(offset, value, ram, rom);
|
writeMemory(offset, value, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -442,7 +442,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory(COMBINE(high, low), value, ram, rom);
|
writeMemory(COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -508,7 +508,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory((uint8_t)(cpu->X + offset), value, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -558,7 +558,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory(cpu->X + COMBINE(high, low), value, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
@@ -614,7 +614,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = 0;
|
cpu->Flags.NegativeFlag = 0;
|
||||||
writeMemory(offset, value, ram, rom);
|
writeMemory(offset, value, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -677,7 +677,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = 0;
|
cpu->Flags.NegativeFlag = 0;
|
||||||
writeMemory(COMBINE(high, low), value, ram, rom);
|
writeMemory(COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -740,7 +740,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = 0;
|
cpu->Flags.NegativeFlag = 0;
|
||||||
writeMemory((uint8_t)(cpu->X + offset), value, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -787,7 +787,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Set flags and write to memory
|
// Set flags and write to memory
|
||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = 0;
|
cpu->Flags.NegativeFlag = 0;
|
||||||
writeMemory(cpu->X + COMBINE(high, low), value, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
@@ -840,7 +840,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory(offset, value, ram, rom);
|
writeMemory(offset, value, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -911,7 +911,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory(COMBINE(high, low), value, ram, rom);
|
writeMemory(COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -973,7 +973,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory((uint8_t)(cpu->X + offset), value, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1019,7 +1019,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Write value
|
// Write value
|
||||||
writeMemory(cpu->X + COMBINE(high, low), value, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
@@ -1033,7 +1033,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t low = readMemory(_address, ram, rom);
|
uint8_t low = readMemory(_address, ram, rom);
|
||||||
uint8_t high = readMemory((uint8_t)(_address + 1), ram, rom);
|
uint8_t high = readMemory((uint8_t)(_address + 1), ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory(COMBINE(high, low), cpu->Accumulator, ram, rom);
|
writeMemory(COMBINE(high, low), cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1041,7 +1041,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get offset
|
// Get offset
|
||||||
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store Y at address
|
// Store Y at address
|
||||||
writeMemory(offset, cpu->Y, ram, rom);
|
writeMemory(offset, cpu->Y, ram);
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
@@ -1049,7 +1049,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get offset
|
// Get offset
|
||||||
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory(offset, cpu->Accumulator, ram, rom);
|
writeMemory(offset, cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
@@ -1057,7 +1057,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get offset
|
// Get offset
|
||||||
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store X at address
|
// Store X at address
|
||||||
writeMemory(offset, cpu->X, ram, rom);
|
writeMemory(offset, cpu->X, ram);
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
@@ -1082,7 +1082,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store Y at address
|
// Store Y at address
|
||||||
writeMemory(COMBINE(high, low), cpu->Y, ram, rom);
|
writeMemory(COMBINE(high, low), cpu->Y, ram);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1091,7 +1091,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory(COMBINE(high, low), cpu->Accumulator, ram, rom);
|
writeMemory(COMBINE(high, low), cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1100,7 +1100,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store X at address
|
// Store X at address
|
||||||
writeMemory(COMBINE(high, low), cpu->X, ram, rom);
|
writeMemory(COMBINE(high, low), cpu->X, ram);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1132,7 +1132,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get address
|
// Get address
|
||||||
uint16_t address = cpu->Y + COMBINE(high, low);
|
uint16_t address = cpu->Y + COMBINE(high, low);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory(address, cpu->Accumulator, ram, rom);
|
writeMemory(address, cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1140,7 +1140,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get offset
|
// Get offset
|
||||||
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory((uint8_t)(cpu->X + offset), cpu->Y, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), cpu->Y, ram);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1148,7 +1148,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get offset
|
// Get offset
|
||||||
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory((uint8_t)(cpu->X + offset), cpu->Accumulator, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1156,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
// Get offset
|
// Get offset
|
||||||
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t offset = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory((uint8_t)(cpu->Y + offset), cpu->X, ram, rom);
|
writeMemory((uint8_t)(cpu->Y + offset), cpu->X, ram);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@@ -1173,7 +1173,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory(cpu->Y + COMBINE(high, low), cpu->Accumulator, ram, rom);
|
writeMemory(cpu->Y + COMBINE(high, low), cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -1187,7 +1187,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t low = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
uint8_t high = readMemory(cpu->ProgrammeCounter++, ram, rom);
|
||||||
// Store accumulator at address
|
// Store accumulator at address
|
||||||
writeMemory(cpu->X + COMBINE(high, low), cpu->Accumulator, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), cpu->Accumulator, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -1533,7 +1533,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory(offset, value, ram, rom);
|
writeMemory(offset, value, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -1606,7 +1606,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory(COMBINE(high, low), value, ram, rom);
|
writeMemory(COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1672,7 +1672,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory((uint8_t)(cpu->X + offset), value, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1722,7 +1722,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory(cpu->X + COMBINE(high, low), value, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
@@ -1788,7 +1788,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory(offset, value, ram, rom);
|
writeMemory(offset, value, ram);
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
@@ -1848,7 +1848,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory(COMBINE(high, low), value, ram, rom);
|
writeMemory(COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1906,7 +1906,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory((uint8_t)(cpu->X + offset), value, ram, rom);
|
writeMemory((uint8_t)(cpu->X + offset), value, ram);
|
||||||
|
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
@@ -1948,7 +1948,7 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
cpu->Flags.ZeroFlag = value == 0;
|
cpu->Flags.ZeroFlag = value == 0;
|
||||||
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
cpu->Flags.NegativeFlag = (value & 0x80) != 0;
|
||||||
// Store at address
|
// Store at address
|
||||||
writeMemory(cpu->X + COMBINE(high, low), value, ram, rom);
|
writeMemory(cpu->X + COMBINE(high, low), value, ram);
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
@@ -1957,7 +1957,5 @@ uint8_t runCycle(CPU *cpu, uint8_t *ram, uint8_t *rom) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return sleep duration in microseconds to emulate cycle count of executed instruction
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
+4
-5
@@ -49,13 +49,15 @@ int main(void) {
|
|||||||
/* DEBUG */
|
/* DEBUG */
|
||||||
|
|
||||||
//FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
//FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
||||||
FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
//FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
||||||
|
FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
||||||
|
//FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
perror("fopen");
|
perror("fopen");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(ram, 1, 64 * 1024, fp);
|
fread(ram, 1, RAM_SIZE, fp);
|
||||||
if (ferror(fp)) {
|
if (ferror(fp)) {
|
||||||
perror("fread");
|
perror("fread");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -70,7 +72,6 @@ int main(void) {
|
|||||||
resetCPU(&cpu, rom);
|
resetCPU(&cpu, rom);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// printf("\tPC: 0x%x\tOP: 0x%x\n", cpu.ProgrammeCounter, ram[cpu.ProgrammeCounter]);
|
|
||||||
uint8_t sleep = runCycle(&cpu, ram, rom);
|
uint8_t sleep = runCycle(&cpu, ram, rom);
|
||||||
if (sleep == 1) {
|
if (sleep == 1) {
|
||||||
printf("opcode missing: 0x%X\n", ram[cpu.ProgrammeCounter - 1]);
|
printf("opcode missing: 0x%X\n", ram[cpu.ProgrammeCounter - 1]);
|
||||||
@@ -81,8 +82,6 @@ int main(void) {
|
|||||||
nanosleep(&sleepTime, NULL);
|
nanosleep(&sleepTime, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CPU WORK */
|
|
||||||
|
|
||||||
destroyRAM(ram);
|
destroyRAM(ram);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+20
-11
@@ -1,41 +1,50 @@
|
|||||||
#include "memoryMap.h"
|
#include "memoryMap.h"
|
||||||
|
|
||||||
uint8_t readMemory(uint16_t address, uint8_t *ram, uint8_t *rom) {
|
uint8_t readMemory(uint16_t address, uint8_t *ram, uint8_t *rom) {
|
||||||
if (address < RAM_SIZE || address >= IO_BASE + IO_SIZE) { // FIXME: Expanded for debug
|
if ((address < RAM_SIZE && address < IO_BASE) || address >= ROM_BASE) {
|
||||||
|
if (address >= ROM_BASE && ram[IO_BASE + ROM_BANKED_OUT] == 0) {
|
||||||
|
return rom[address - ROM_BASE];
|
||||||
|
}
|
||||||
|
|
||||||
return ram[address];
|
return ram[address];
|
||||||
} else if (address < RAM_SIZE + IO_SIZE) {
|
} else {
|
||||||
uint16_t _address = address - RAM_SIZE;
|
uint16_t _address = address - IO_BASE;
|
||||||
switch (_address) {
|
switch (_address) {
|
||||||
case KEYBOARD_ADDRESS: {
|
case KEYBOARD_ADDRESS: {
|
||||||
return getChar();
|
return getChar();
|
||||||
}
|
}
|
||||||
|
case ROM_BANKED_OUT: {
|
||||||
|
return ram[IO_BASE + ROM_BANKED_OUT];
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
|
||||||
return rom[address - RAM_SIZE - IO_SIZE];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeMemory(uint16_t address, uint8_t value, uint8_t *ram, uint8_t *rom) {
|
void writeMemory(uint16_t address, uint8_t value, uint8_t *ram) {
|
||||||
if (address < RAM_SIZE) {
|
if ((address < RAM_SIZE && address < IO_BASE) || address >= ROM_BASE) {
|
||||||
|
if (address < ROM_BASE && ram[IO_BASE + ROM_BANKED_OUT] != 0) {
|
||||||
ram[address] = value;
|
ram[address] = value;
|
||||||
} else if (address < RAM_SIZE + IO_SIZE || address >= IO_BASE + IO_SIZE) { // FIXME: Expanded for debug
|
}
|
||||||
uint16_t _address = address - RAM_SIZE;
|
} else {
|
||||||
|
uint16_t _address = address - IO_BASE;
|
||||||
switch (_address) {
|
switch (_address) {
|
||||||
case SCREEN_ADDRESS: {
|
case SCREEN_ADDRESS: {
|
||||||
putChar(value);
|
putChar(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ROM_BANKED_OUT: {
|
||||||
|
ram[IO_BASE + ROM_BANKED_OUT] = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
rom[address - RAM_SIZE - IO_SIZE] = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
#include "ram.h"
|
#include "ram.h"
|
||||||
|
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int createRAM(uint8_t **ram) {
|
int createRAM(uint8_t **ram) {
|
||||||
*ram = (uint8_t *)malloc(RAM_SIZE);
|
*ram = (uint8_t *)malloc(RAM_SIZE);
|
||||||
|
|
||||||
if (*ram == NULL) return -1;
|
if (*ram == NULL) return -1;
|
||||||
|
|
||||||
|
// Zero IO
|
||||||
|
for (size_t i = IO_BASE; i < IO_SIZE; i++) {
|
||||||
|
ram[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
#include "rom.h"
|
#include "rom.h"
|
||||||
|
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
uint8_t rom[ROM_SIZE] = {0};
|
uint8_t rom[ROM_SIZE] = {0};
|
||||||
|
|
||||||
void initRom(uint8_t *rom) {
|
void initRom(uint8_t *rom) {
|
||||||
|
|
||||||
|
|
||||||
rom[0] = 0xa9, // LDA
|
|
||||||
rom[1] = 'H', // H literal
|
|
||||||
rom[2] = 0x8d, // STA
|
|
||||||
rom[3] = (uint8_t)((IO_BASE + SCREEN_ADDRESS) & 0xFF), // Lower byte of screen
|
|
||||||
rom[4] = (uint8_t)((IO_BASE + SCREEN_ADDRESS) >> 8), // Upper byte of screen
|
|
||||||
rom[6] =
|
|
||||||
/* Reset Vector */
|
/* Reset Vector */
|
||||||
rom[0xFFFC - ROM_BASE] = 0x00, // Lower byte base of ROM
|
rom[0xFFFC - ROM_BASE] = 0x00; // Lower byte base of ROM
|
||||||
rom[0xFFFD - ROM_BASE] = 0x02, // Upper byte of base of ROM
|
rom[0xFFFD - ROM_BASE] = 0x04; // Upper byte of base of ROM
|
||||||
rom[0xFFFE - ROM_BASE] = 0x00, // Lower byte base of ROM
|
|
||||||
rom[0xFFFF - ROM_BASE] = 0x00; // Upper byte of base of ROM
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user