From 87966c53af716d34332e2ea6583ab9739bde935a Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Wed, 29 Nov 2023 16:29:57 +1100 Subject: various changes? --- src/apple.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/apple.c') diff --git a/src/apple.c b/src/apple.c index ec7769a..52ef358 100644 --- a/src/apple.c +++ b/src/apple.c @@ -1,17 +1,21 @@ #include"apple.h" -void AppleOn(){ +byte* ROM; + +void AppleOn() { Memory = calloc(MEMORY_SIZE, sizeof(byte)); + ROM = calloc(256, sizeof(byte)); InitInstructionTable(); // Load ROM. - FILE *ROM = fopen ("rom.bin", "rb"); - if (ROM == NULL) { + FILE *ROM_File = fopen ("rom.bin", "rb"); + if (ROM_File == NULL) { printf("\n\rROM does not exist.\n"); abort(); } for (int i = 0; i < 256; i++) { - Memory[0xFF00+i] = fgetc(ROM); + ROM[i] = fgetc(ROM_File); + printf("%x", ROM[i]); } } @@ -43,18 +47,21 @@ byte ToAscii(char x) byte GetMemory(address x){ switch(x) { - // I opted to make the kbd return successfully at all times for the sake of simplicity. - // This is not technically "accurate" behavior however. + // The keyboard does not act precisely as the real hardware, because there is no need to wait for the keyboard. + // So KBD_CR and DSP always return a high high-order bit, and when the keyboard data is requested it will wait for UserInput() to finish. case KBD: return 0b10000000 | UserInput(); case KBD_CR: case DSP: return 0b10000000; - default: - return Memory[x]; } + if (x >= 0xFF00 && x <= 0xFFFF) { + return ROM[0x00FF & x]; + } } void SetMemory(address x, byte y){ - Memory[x] = y; + if (x < MEMORY_SIZE) { + Memory[x] = y; + } } -- cgit v1.2.3