diff --git a/.gitignore b/.gitignore index b415d9c..bc3994c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ obj apple1 +.DS_Store diff --git a/apple1.xcodeproj/project.xcworkspace/xcuserdata/thiago.xcuserdatad/UserInterfaceState.xcuserstate b/apple1.xcodeproj/project.xcworkspace/xcuserdata/thiago.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..7b6f5b3 Binary files /dev/null and b/apple1.xcodeproj/project.xcworkspace/xcuserdata/thiago.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/apple1.xcodeproj/project.xcworkspace/xcuserdata/thiago.xcuserdatad/xcdebugger/Expressions.xcexplist b/apple1.xcodeproj/project.xcworkspace/xcuserdata/thiago.xcuserdatad/xcdebugger/Expressions.xcexplist new file mode 100644 index 0000000..15796f7 --- /dev/null +++ b/apple1.xcodeproj/project.xcworkspace/xcuserdata/thiago.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..8363e3d --- /dev/null +++ b/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcschemes/apple1.xcscheme b/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcschemes/apple1.xcscheme new file mode 100644 index 0000000..d0cf35f --- /dev/null +++ b/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcschemes/apple1.xcscheme @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcschemes/xcschememanagement.plist b/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..f3553e4 --- /dev/null +++ b/apple1.xcodeproj/xcuserdata/thiago.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + apple1.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + AFF1A1DE1FBD2A490069B921 + + primary + + + + + diff --git a/src/6502.c b/src/6502.c index 9ba0c5a..0b7a2f7 100644 --- a/src/6502.c +++ b/src/6502.c @@ -1,3 +1,5 @@ +#include + #include "inc/types.h" #include "inc/memory.h" #include "inc/opcodes.h" @@ -79,7 +81,7 @@ void execute() case BMI: return bmi(); case BNE: return bne(); case BPL: return bpl(); - case BRK: return brk(); + case BRK: return bkk(); case BVC: return bvc(); case BVS: return bvs(); case CLC: return clc(); @@ -137,6 +139,25 @@ void execute() } } +void display() +{ + //if (display_control == 0xA7) + { + // display is ready to ouptup + if (display_buffer & 0x80) + { + // outputs the buffer character + display_buffer = display_buffer & 0x7F; + printf("%c", display_buffer); + } + } +} + +void read_input() +{ + // verifies if the keyboard is being pressed... +} + void run() { while (1) @@ -144,6 +165,9 @@ void run() fetch(); decode(); execute(); + + display(); + read_input(); } } diff --git a/src/inc/memory.h b/src/inc/memory.h index fc8e90f..7b78347 100644 --- a/src/inc/memory.h +++ b/src/inc/memory.h @@ -2,8 +2,14 @@ #define _APPLE_I_MEMORY_H_ #include "types.h" + db read_byte(dw address); dw read_word(dw address); void write_mem(dw address, db data); +extern db keyboard_buffer; // 0xD010 +extern db keyboard_control; // 0xD011 +extern db display_buffer; // 0xD012 +extern db display_control; // 0xD013 + #endif diff --git a/src/inc/opcodes.h b/src/inc/opcodes.h index 3c73ac8..b6990e4 100644 --- a/src/inc/opcodes.h +++ b/src/inc/opcodes.h @@ -64,7 +64,7 @@ void bit(void); // test bits in memory with accumulator void bmi(void); // branch on result minus void bne(void); // branch on result not zero void bpl(void); // branch on result plus -void brk(void); // force break +void bkk(void); // force break void bvc(void); // branch on overflow clear void bvs(void); // branch on overflow set void clc(void); // clear carry flag diff --git a/src/memory.c b/src/memory.c index df6d515..f57f291 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,7 +1,6 @@ #include "inc/types.h" #include "inc/rom.h" #include "inc/memory.h" -#include /* @@ -33,7 +32,12 @@ */ -db ram_memory[4096]; // total memory: 4KB +db ram_memory[4096]; // total memory: 4KB + +db keyboard_buffer; // 0xD010 +db keyboard_control; // 0xD011 +db display_buffer; // 0xD012 +db display_control; // 0xD013 db read_byte(dw address) { @@ -42,6 +46,22 @@ db read_byte(dw address) // 4KB memory RAM return ram_memory[address]; } + else if (address == 0xD010) + { + return keyboard_buffer; + } + else if (address == 0xD011) + { + return keyboard_control; + } + else if (address == 0xD012) + { + return display_buffer; + } + /*else if (address == 0xD013) + { + return display_control; + }*/ else if (address >= 0xFF00 && address <= 0xFFFF) { // wozmon ROM @@ -78,11 +98,22 @@ void write_mem(dw address, db data) // 4KB memory RAM ram_memory[address] = data; } + /*else if (address == 0xD010) + { + keyboard_buffer = data; + }*/ + /*else if (address == 0xD011) + { + keyboard_control = data; + }*/ else if (address == 0xD012) { - // output character to video - printf("%c", data & 0x7F); + display_buffer = data; } + /*else if (address == 0xD013) + { + display_control = data; + }*/ // any other addressed memory will be ignored on write } diff --git a/src/opcodes.c b/src/opcodes.c index 324fd44..29bc5d7 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -150,9 +150,9 @@ db pull_byte() dw pull_word() { - db high = pull_byte() << 8; + db high = pull_byte(); db low = pull_byte(); - dw data = high | low; + dw data = high << 8 | low; return data; } @@ -261,7 +261,7 @@ void bpl() } } -void brk() +void bkk() { // force break I_SET; @@ -583,7 +583,6 @@ void sta() // store accumulator in memory fetch_operand(); write_mem(address, ac); - //adjustNZ(y); } void stx() @@ -591,7 +590,6 @@ void stx() // store index x in memory fetch_operand(); write_mem(address, x); - //adjustNZ(x); } void sty() @@ -599,7 +597,6 @@ void sty() // store index y in memory fetch_operand(); write_mem(address, y); - //adjustNZ(y); } void tax()