diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-11-29 16:29:57 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-11-29 16:29:57 +1100 |
commit | 87966c53af716d34332e2ea6583ab9739bde935a (patch) | |
tree | 3f25b349e72a1865ecc8d2eee91032bfcead1e6d /src/apple.c | |
parent | 9dc65f84b480d5869265428c1957c50bdee3a1f5 (diff) |
various changes?
Diffstat (limited to 'src/apple.c')
-rw-r--r-- | src/apple.c | 25 |
1 files changed, 16 insertions, 9 deletions
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; + } } |