some handling for video output

This commit is contained in:
Thiago Auler 2017-11-14 19:42:36 -02:00
parent f23c89dfce
commit 10e4cbbdb5
6 changed files with 21 additions and 8 deletions

View File

@ -9,7 +9,7 @@ rm -f $EXEC_NAME
# build all source code # build all source code
for FILE in $SRC_FOLDER/*.c for FILE in $SRC_FOLDER/*.c
do do
cc -c $FILE cc -g -c $FILE
done done
# move all objects to appropriate folder # move all objects to appropriate folder
@ -17,4 +17,4 @@ mkdir -p $OBJ_FOLDER
mv *.o $OBJ_FOLDER mv *.o $OBJ_FOLDER
# create executable out of the objects # create executable out of the objects
cc -o $EXEC_NAME $OBJ_FOLDER/*.o cc -g -o $EXEC_NAME $OBJ_FOLDER/*.o

View File

@ -9,6 +9,12 @@ void init()
{ {
// pc is set using 0xFFFC // pc is set using 0xFFFC
pc = read_word(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() void fetch()
@ -32,12 +38,11 @@ void decode()
opcode_in_list = ir; opcode_in_list = ir;
opcode_in_table = aaacc; opcode_in_table = aaacc;
address_mode = bbb; address_mode = bbb;
if (cc == 0b01) if (cc == 0b01)
{ {
// correct the addressing mode for '01' opcodetype // correct the addressing mode for '01' opcode type
if (bbb == 0b000) if (bbb == 0b000)
{ {
address_mode = indirect_x; address_mode = indirect_x;

View File

@ -9,7 +9,7 @@ db x; // x register
db y; // y register db y; // y register
db sp; // stack pointer db sp; // stack pointer
db sr; // status register db sr; // status register
db ir; // intruction register db ir; // instruction register
enum opcodes_table enum opcodes_table
{ /// aaa00 aaa01 aaa10 { /// aaa00 aaa01 aaa10
@ -53,7 +53,7 @@ typedef enum address_mode am;
am address_mode; 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 and(); // and memory with accumulator
void asl(); // shift left one bit (memory or accumulator) void asl(); // shift left one bit (memory or accumulator)
void bcc(); // branch on carry clear 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 rol(); // rotate on bit left (memory or accumulator)
void ror(); // rotate on bit right (memory or accumulator) void ror(); // rotate on bit right (memory or accumulator)
void rti(); // return from interrupt void rti(); // return from interrupt
void rts(); // retrun from subroutine void rts(); // return from subroutine
void sbc(); // subtract memory from accumulator with borrow void sbc(); // subtract memory from accumulator with borrow
void sec(); // set carry flag void sec(); // set carry flag
void sed(); // set decimal flag void sed(); // set decimal flag

View File

@ -3,6 +3,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
setbuf(stdout, NULL);
printf("Apple-I Computer\n"); printf("Apple-I Computer\n");
init(); // start the processor init(); // start the processor

View File

@ -1,6 +1,7 @@
#include "inc/types.h" #include "inc/types.h"
#include "inc/rom.h" #include "inc/rom.h"
#include "inc/memory.h" #include "inc/memory.h"
#include <stdio.h>
/* /*
@ -77,6 +78,11 @@ void write_mem(dw address, db data)
// 4KB memory RAM // 4KB memory RAM
ram_memory[address] = data; ram_memory[address] = data;
} }
else if (address == 0xD010)
{
// output character to video
printf("%c", data);
}
// any other addressed memory will be ignored on write // any other addressed memory will be ignored on write
} }

View File

@ -38,6 +38,7 @@ void fetch_operand()
address = read_word(pc); address = read_word(pc);
operand = read_byte(address); operand = read_byte(address);
pc = pc + 2; pc = pc + 2;
break;
case absolute_x: case absolute_x:
address = read_word(pc); address = read_word(pc);
address = address + x; address = address + x;
@ -69,7 +70,7 @@ void fetch_operand()
void adc() void adc()
{ {
// add memory to accumalator with carry // add memory to accumulator with carry
fetch_operand(); fetch_operand();
ac = ac + operand + C_IS_SET; ac = ac + operand + C_IS_SET;
} }