Merge remote-tracking branch 'origin/master'

This commit is contained in:
Thiago Auler dos Santos 2017-11-25 21:17:39 -02:00
commit 9bce392e65
8 changed files with 87 additions and 61 deletions

View File

@ -17,4 +17,4 @@ mkdir -p $OBJ_FOLDER
mv *.o $OBJ_FOLDER
# create executable out of the objects
cc -g -o $EXEC_NAME $OBJ_FOLDER/*.o
cc -g -o $EXEC_NAME $OBJ_FOLDER/*.o -lcurses

View File

@ -1,14 +1,15 @@
#include <stdio.h>
#include "inc/types.h"
#include "inc/memory.h"
#include "inc/opcodes.h"
#include "inc/interface.h"
ocl opcode_in_list;
oct opcode_in_table;
void init()
{
io_init();
// pc is set using 0xFFFC
pc = read_word(0xFFFC);
sp = 0xFF;
@ -81,7 +82,7 @@ void execute()
case BMI: return bmi();
case BNE: return bne();
case BPL: return bpl();
case BRK: return bkk();
case BRK: return brk();
case BVC: return bvc();
case BVS: return bvs();
case CLC: return clc();
@ -139,25 +140,6 @@ 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)
@ -166,8 +148,8 @@ void run()
decode();
execute();
display();
read_input();
input();
output();
}
}

8
src/inc/interface.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _APPLE_I_INTERFACE_H_
#define _APPLE_I_INTERFACE_H_
void io_init(void);
void input(void);
void output(void);
#endif

View File

@ -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 bkk(void); // force break
void brk(void); // force break
void bvc(void); // branch on overflow clear
void bvs(void); // branch on overflow set
void clc(void); // clear carry flag

41
src/interface.c Normal file
View File

@ -0,0 +1,41 @@
#include <curses.h>
#include "inc/interface.h"
#include "inc/memory.h"
void io_init()
{
initscr();
noecho();
cbreak();
nodelay(stdscr, TRUE);
keyboard_control = 0x00;
}
void input()
{
int ch = getch();
if (ch == '\n') { ch = '\r'; }
if (ch == '\r' || ch == '.' || ch == ':' ||
(ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'Z'))
{
keyboard_buffer = ch | 0x80;
keyboard_control = 0xFF;
}
}
void output()
{
// display is ready to ouptup
if (display_buffer & 0x80)
{
// outputs the buffer character
display_buffer = display_buffer & 0x7F;
if (display_buffer == '\r')
{
display_buffer = '\n';
}
addch(display_buffer);
}
}

View File

@ -1,11 +1,7 @@
#include <stdio.h>
#include "inc/6502.h"
int main(int argc, char **argv)
{
setbuf(stdout, NULL);
printf("Apple-I Computer\n");
init(); // start the processor
run(); // and runs it

View File

@ -48,6 +48,7 @@ db read_byte(dw address)
}
else if (address == 0xD010)
{
keyboard_control = 0x00;
return keyboard_buffer;
}
else if (address == 0xD011)
@ -58,10 +59,10 @@ db read_byte(dw address)
{
return display_buffer;
}
/*else if (address == 0xD013)
else if (address == 0xD013)
{
return display_control;
}*/
}
else if (address >= 0xFF00 && address <= 0xFFFF)
{
// wozmon ROM
@ -98,22 +99,22 @@ void write_mem(dw address, db data)
// 4KB memory RAM
ram_memory[address] = data;
}
/*else if (address == 0xD010)
else if (address == 0xD010)
{
keyboard_buffer = data;
}*/
/*else if (address == 0xD011)
}
else if (address == 0xD011)
{
keyboard_control = data;
}*/
}
else if (address == 0xD012)
{
display_buffer = data;
}
/*else if (address == 0xD013)
else if (address == 0xD013)
{
display_control = data;
}*/
}
// any other addressed memory will be ignored on write
}

View File

@ -95,22 +95,22 @@ void fetch_operand()
void adjustNZ(db r)
{
if (r == 0) { Z_SET; } else { Z_UNSET;}
if (r == 0) { Z_SET; } else { Z_UNSET; }
r = r >> 7;
if (r == 1) { N_SET; } else { N_UNSET; }
}
db adder(db a, db b)
{
db r = a + b;
db c = (a + b) >> 8;
db r = a + b + C_IS_SET;
db c = (a + b + C_IS_SET) >> 8;
a = a & 0b01111111;
b = b & 0b01111111;
db cc = (a + b) >> 7;
db v = c ^ cc;
a = a & 0x7F;
b = b & 0x7F;
db z = (a + b + C_IS_SET) >> 7;
db v = c ^ z;
if (c == 1) { C_SET; } else { C_UNSET;}
if (c == 1) { C_SET; } else { C_UNSET; }
if (v == 1) { V_SET; } else { V_UNSET; }
adjustNZ(r);
@ -118,15 +118,6 @@ db adder(db a, db b)
return r;
}
db subtractor(db a, db b)
{
// negate b operand using 2's complement
b = b ^ 0xFF;
b = b + 1;
return adder(a, b);
}
void push_byte(db data)
{
write_mem(sp, data);
@ -161,7 +152,7 @@ void adc()
{
// add memory to accumulator with carry
fetch_operand();
ac = adder(ac, operand + C_IS_SET);
ac = adder(ac, operand);
}
void and()
@ -261,7 +252,7 @@ void bpl()
}
}
void bkk()
void brk()
{
// force break
I_SET;
@ -316,22 +307,28 @@ void clv()
void cmp()
{
// compare memory with accumulator
C_SET;
fetch_operand();
subtractor(ac, operand);
operand = operand ^ 0xFF;
adder(ac, operand);
}
void cpx()
{
// compare memory and index x
C_SET;
fetch_operand();
subtractor(x, operand);
operand = operand ^ 0xFF;
adder(x, operand);
}
void cpy()
{
// compare memory and index y
C_SET;
fetch_operand();
subtractor(y, operand);
operand = operand ^ 0xFF;
adder(y, operand);
}
void dec()
@ -557,7 +554,8 @@ void sbc()
{
// subtract memory from accumulator with borrow
fetch_operand();
ac = subtractor(ac, operand - C_IS_SET);
operand = operand ^ 0xFF;
ac = adder(ac, operand);
}
void sec()