diff --git a/build.sh b/build.sh index 6fc22eb..6086375 100755 --- a/build.sh +++ b/build.sh @@ -9,7 +9,7 @@ rm -f $EXEC_NAME # build all source code for FILE in $SRC_FOLDER/*.c do - cc -c $FILE + cc -g -c $FILE done # move all objects to appropriate folder @@ -17,4 +17,4 @@ mkdir -p $OBJ_FOLDER mv *.o $OBJ_FOLDER # create executable out of the objects -cc -o $EXEC_NAME $OBJ_FOLDER/*.o +cc -g -o $EXEC_NAME $OBJ_FOLDER/*.o diff --git a/src/6502.c b/src/6502.c index ee9e39f..6ef6820 100644 --- a/src/6502.c +++ b/src/6502.c @@ -9,6 +9,12 @@ void init() { // pc is set using 0xFFFC pc = read_word(0xFFFC); + + write_mem(0xD010, 'T'); + write_mem(0xD010, 'E'); + write_mem(0xD010, 'S'); + write_mem(0xD010, 'T'); + write_mem(0xD010, 'S'); } void fetch() @@ -32,12 +38,11 @@ void decode() opcode_in_list = ir; opcode_in_table = aaacc; - address_mode = bbb; if (cc == 0b01) { - // correct the addressing mode for '01' opcodetype + // correct the addressing mode for '01' opcode type if (bbb == 0b000) { address_mode = indirect_x; diff --git a/src/inc/opcodes.h b/src/inc/opcodes.h index f089276..9f832e6 100644 --- a/src/inc/opcodes.h +++ b/src/inc/opcodes.h @@ -9,7 +9,7 @@ db x; // x register db y; // y register db sp; // stack pointer db sr; // status register -db ir; // intruction register +db ir; // instruction register enum opcodes_table { /// aaa00 aaa01 aaa10 @@ -53,7 +53,7 @@ typedef enum address_mode am; am address_mode; -void adc(); // add memory to accumalator with carry +void adc(); // add memory to accumulator with carry void and(); // and memory with accumulator void asl(); // shift left one bit (memory or accumulator) void bcc(); // branch on carry clear @@ -96,7 +96,7 @@ void plp(); // pull processor status from stack void rol(); // rotate on bit left (memory or accumulator) void ror(); // rotate on bit right (memory or accumulator) void rti(); // return from interrupt -void rts(); // retrun from subroutine +void rts(); // return from subroutine void sbc(); // subtract memory from accumulator with borrow void sec(); // set carry flag void sed(); // set decimal flag diff --git a/src/main.c b/src/main.c index 3986ddb..07ee6e1 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ int main(int argc, char **argv) { + setbuf(stdout, NULL); printf("Apple-I Computer\n"); init(); // start the processor diff --git a/src/memory.c b/src/memory.c index 85fa906..a0c8da1 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,6 +1,7 @@ #include "inc/types.h" #include "inc/rom.h" #include "inc/memory.h" +#include /* @@ -77,6 +78,11 @@ void write_mem(dw address, db data) // 4KB memory RAM ram_memory[address] = data; } + else if (address == 0xD010) + { + // output character to video + printf("%c", data); + } // any other addressed memory will be ignored on write } diff --git a/src/opcodes.c b/src/opcodes.c index 9ea9e6e..7683f07 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -38,6 +38,7 @@ void fetch_operand() address = read_word(pc); operand = read_byte(address); pc = pc + 2; + break; case absolute_x: address = read_word(pc); address = address + x; @@ -69,7 +70,7 @@ void fetch_operand() void adc() { - // add memory to accumalator with carry + // add memory to accumulator with carry fetch_operand(); ac = ac + operand + C_IS_SET; }