diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-03 11:32:39 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-03 11:32:39 +1100 |
commit | 991c09b01e6b099a5b00d7a9236d252b85a714b5 (patch) | |
tree | bee9445cbd318bbf7a805c80b5bc4b94517b44df | |
parent | 7a5672d085399d0de9d2c77431ea7a2f089faacb (diff) |
half-fixed infinite loop; new debug util, old one out
-rw-r--r-- | log/log-readable.cpp | 68 | ||||
-rw-r--r-- | log/rom-code-lines | 128 | ||||
-rw-r--r-- | log/rom-hex-positions | 128 | ||||
-rw-r--r-- | src/apple.h | 2 | ||||
-rw-r--r-- | src/cpu/instructions.c | 2 | ||||
-rw-r--r-- | src/debug.h | 58 | ||||
-rw-r--r-- | src/interpreter.c | 122 | ||||
-rw-r--r-- | src/main.c | 14 |
8 files changed, 338 insertions, 184 deletions
diff --git a/log/log-readable.cpp b/log/log-readable.cpp new file mode 100644 index 0000000..82e263d --- /dev/null +++ b/log/log-readable.cpp @@ -0,0 +1,68 @@ +// log-readable.cpp +// A simple utility which makes the runtime log files into a more readable +// format by adding commented code lines from wozmon. + +#include <iostream> +#include <fstream> +#include <sstream> +#include <string> +#include <map> + +using namespace std; + +int main() +{ + ifstream RomLine ("rom-hex-positions"); + ifstream Code ("rom-code-lines"); + + map<string, string> Convert; + + string x; + string y; + + for (int i = 0; i < 128; i++) + { + getline (RomLine, x); + getline (Code, y, (char)0x0d); + if (i != 0) + y.erase(0,1); + Convert[x] = y; + + cout << x << " : " << Convert[x] << endl; + } + + RomLine.close(); + Code.close(); + + ifstream Log("log.raw"); + ofstream Output("log.new"); + + Output << "Time PC Label Instruction Comment\n" << endl; + while(!Log.eof()) + { + string t; + // Expects time counter, and prints. + Log >> t; + Output << t; + // Expecting a delimiter surrounded with space. + Log >> t; + Output << " : "; + // Expecting program counter + Log >> t; + Output << t; + // If a mapping exists, print out the program counter and line code. + try { + string s = Convert[t]; + Output << t << " : "; + Output << s; + } + // Otherwise, don't do anything. + catch (out_of_range) { } + // Newline + Output << endl; + } + + Log.close(); + Output.close(); + return 0; +} diff --git a/log/rom-code-lines b/log/rom-code-lines new file mode 100644 index 0000000..2ed13e6 --- /dev/null +++ b/log/rom-code-lines @@ -0,0 +1,128 @@ +RESET CLD Clear decimal arithmetic mode
+ CLI
+ LDY #%0111.1111 Mask for DSP data direction reg
+ STY DSP (DDR mode is assumed after reset)
+ LDA #%1010.0111 KBD and DSP control register mask
+ STA KBDCR Enable interrupts, set CA1, CB1 for
+ STA DSPCR positive edge sense/output mode.
+NOTCR CMP #BS Backspace key?
+ BEQ BACKSPACE Yes
+ CMP #ESC ESC?
+ BEQ ESCAPE Yes
+ INY Advance text index
+ BPL NEXTCHAR Auto ESC if line longer than 127
+ESCAPE LDA #PROMPT Print prompt character
+ JSR ECHO Output it.
+GETLINE LDA #CR Send CR
+ JSR ECHO
+ LDY #0+1 Start a new input line
+BACKSPACE DEY Backup text index
+ BMI GETLINE Oops, line's empty, reinitialize
+NEXTCHAR LDA KBDCR Wait for key press
+ BPL NEXTCHAR No key yet!
+ LDA KBD Load character. B7 should be '1'
+ STA IN,Y Add to text buffer
+ JSR ECHO Display character
+ CMP #CR
+ BNE NOTCR It's not CR!
+ LDY #-1 Reset text index
+ LDA #0 Default mode is XAM
+ TAX X=0
+SETSTOR ASL Leaves $7B if setting STOR mode
+SETMODE STA MODE Set mode flags
+BLSKIP INY Advance text index
+NEXTITEM LDA IN,Y Get character
+ CMP #CR
+ BEQ GETLINE We're done if it's CR!
+ CMP #"."
+ BCC BLSKIP Ignore everything below "."!
+ BEQ SETMODE Set BLOCK XAM mode ("." = $AE)
+ CMP #":"
+ BEQ SETSTOR Set STOR mode! $BA will become $7B
+ CMP #"R"
+ BEQ RUN Run the program! Forget the rest
+ STX L Clear input value (X=0)
+ STX H
+ STY YSAV Save Y for comparison
+NEXTHEX LDA IN,Y Get character for hex test
+ EOR #$B0 Map digits to 0-9
+ CMP #9+1 Is it a decimal digit?
+ BCC DIG Yes!
+ ADC #$88 Map letter "A"-"F" to $FA-FF
+ CMP #$FA Hex letter?
+ BCC NOTHEX No! Character not hex
+DIG ASL
+ ASL Hex digit to MSD of A
+ ASL
+ ASL
+ LDX #4 Shift count
+HEXSHIFT ASL Hex digit left, MSB to carry
+ ROL L Rotate into LSD
+ ROL H Rotate into MSD's
+ DEX Done 4 shifts?
+ BNE HEXSHIFT No, loop
+ INY Advance text index
+ BNE NEXTHEX Always taken
+NOTHEX CPY YSAV Was at least 1 hex digit given?
+ BEQ ESCAPE No! Ignore all, start from scratch
+ BIT MODE Test MODE byte
+ BVC NOTSTOR B6=0 is STOR, 1 is XAM or BLOCK XAM
+ LDA L LSD's of hex data
+ STA (STL,X) Store current 'store index'(X=0)
+ INC STL Increment store index.
+ BNE NEXTITEM No carry!
+ INC STH Add carry to 'store index' high
+TONEXTITEM JMP NEXTITEM Get next command item.
+RUN JMP (XAML) Run user's program
+NOTSTOR BMI XAMNEXT B7 = 0 for XAM, 1 for BLOCK XAM
+ LDX #2 Copy 2 bytes
+SETADR LDA L-1,X Copy hex data to
+ STA STL-1,X 'store index'
+ STA XAML-1,X and to 'XAM index'
+ DEX Next of 2 bytes
+ BNE SETADR Loop unless X = 0
+NXTPRNT BNE PRDATA NE means no address to print
+ LDA #CR Print CR first
+ JSR ECHO
+ LDA XAMH Output high-order byte of address
+ JSR PRBYTE
+ LDA XAML Output low-order byte of address
+ JSR PRBYTE
+ LDA #":" Print colon
+ JSR ECHO
+PRDATA LDA #" " Print space
+ JSR ECHO
+ LDA (XAML,X) Get data from address (X=0)
+ JSR PRBYTE Output it in hex format
+XAMNEXT STX MODE 0 -> MODE (XAM mode).
+ LDA XAML See if there's more to print
+ CMP L
+ LDA XAMH
+ SBC H
+ BCS TONEXTITEM Not less! No more data to output
+ INC XAML Increment 'examine index'
+ BNE MOD8CHK No carry!
+ INC XAMH
+MOD8CHK LDA XAML If address MOD 8 = 0 start new line
+ AND #%0000.0111
+ BPL NXTPRNT Always taken.
+PRBYTE PHA Save A for LSD
+ LSR
+ LSR
+ LSR MSD to LSD position
+ LSR
+ JSR PRHEX Output hex digit
+ PLA Restore A
+PRHEX AND #%0000.1111 Mask LSD for hex print
+ ORA #"0" Add "0"
+ CMP #"9"+1 Is it a decimal digit?
+ BCC ECHO Yes! output it
+ ADC #6 Add offset for letter A-F
+ECHO BIT DSP DA bit (B7) cleared yet?
+ BMI ECHO No! Wait for display ready
+ STA DSP Output character. Sets DA
+ RTS
+ .DA $0000 Unused, what a pity
+NMI_VEC .DA $0F00 NMI vector
+RESET_VEC .DA RESET RESET vector
+IRQ_VEC .DA $0000 IRQ vector
\ No newline at end of file diff --git a/log/rom-hex-positions b/log/rom-hex-positions new file mode 100644 index 0000000..6d77f3a --- /dev/null +++ b/log/rom-hex-positions @@ -0,0 +1,128 @@ +ff00 +ff01 +ff02 +ff04 +ff07 +ff09 +ff0c +ff0f +ff11 +ff13 +ff15 +ff17 +ff18 +ff1a +ff1c +ff1f +ff21 +ff24 +ff26 +ff27 +ff29 +ff2c +ff2e +ff31 +ff34 +ff37 +ff39 +ff3b +ff3d +ff3f +ff40 +ff41 +ff43 +ff44 +ff47 +ff49 +ff4b +ff4d +ff4f +ff51 +ff53 +ff55 +ff57 +ff59 +ff5b +ff5d +ff5f +ff62 +ff64 +ff66 +ff68 +ff6a +ff6c +ff6e +ff6f +ff70 +ff71 +ff72 +ff74 +ff75 +ff77 +ff79 +ff7a +ff7c +ff7d +ff7f +ff81 +ff83 +ff85 +ff87 +ff89 +ff8b +ff8d +ff8f +ff91 +ff94 +ff97 +ff99 +ff9b +ff9d +ff9f +ffa1 +ffa2 +ffa4 +ffa6 +ffa8 +ffab +ffad +ffb0 +ffb2 +ffb5 +ffb7 +ffba +ffbc +ffbf +ffc1 +ffc4 +ffc6 +ffc8 +ffca +ffcc +ffce +ffd0 +ffd2 +ffd4 +ffd6 +ffd8 +ffda +ffdc +ffdd +ffde +ffdf +ffe0 +ffe1 +ffe4 +ffe5 +ffe7 +ffe9 +ffeb +ffed +ffef +fff2 +fff4 +fff7 +fff8 +fffa +fffc +fffe
\ No newline at end of file diff --git a/src/apple.h b/src/apple.h index d423074..244f1b3 100644 --- a/src/apple.h +++ b/src/apple.h @@ -4,7 +4,7 @@ #include <stdio.h> #include <stdlib.h> -#define MEMORY_SIZE 4096 +#define MEMORY_SIZE 0x0400 #define XAML 0x24 #define XAMH 0x25 diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index da093ec..2d4fc9e 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -309,7 +309,7 @@ void fPLP(Addressing addr, address val){ void fJSR(Addressing addr, address val){ SetStack((PC+3) >> 8); SetStack((PC+3) & 0x00FF); - PC = idata.add; + PC = idata.add; PC -= 3; } void fRTS(Addressing addr, address val){ diff --git a/src/debug.h b/src/debug.h deleted file mode 100644 index 59e3c47..0000000 --- a/src/debug.h +++ /dev/null @@ -1,58 +0,0 @@ -// debug.h -// Various functions useful for use during development. - -#include"stdio.h" -#include"cpu/6502.h" -#include"cpu/addressing.h" -#include"cpu/core.h" -#include"cpu/instructions.h" -#include"cpu/table.h" - - - -// Converts a single character to hexadecimal -int dCharToNum(char c){ - // 0x0 - 0x9 - if (c != 0x20 && (c >= 0x30 && c <= 0x39)){ - return (c - 0x30); - } - // 0xA - 0xF - else if (c != 0x20 && (c >= 0x41 && c <= 0x46)){ - return (c - 0x37); - // 0xa - 0xf - }else if (c != 0x20 && (c >= 0x61 && c <= 0x66)){ - return (c - 0x57); - // Invalid - }else{ - return -1; - } -} - -// Dump page m from memory to stdout. -void dPageDump(short m){ - m <<= 8; - for(int i = 0; i < 256; i+=16){ - printf("\t"); - for(int j = 0; j < 16; j+=1){ - if ((j+1) % 4 == 0){ - printf("%02x ", GetMemory((m+(i+j)))); - } - else { - printf("%02x ", GetMemory((m+(i+j)))); - } - } - printf("\n"); - } -} - -// Dump CPU values -void dStatusDump(void){ -printf("\ -\t..acc:\t%x\tcycles:\t%d\n\ -\t....X:\t%x\tlength:\t%d\n\ -\t....Y:\t%x\t...add:\t%x\n\ -\tstack:\t%x\t.value:\t%x\n\ -\tflags:\t%x\t....PC:\t%x\n\ -\n\ -", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P, PC); -} diff --git a/src/interpreter.c b/src/interpreter.c deleted file mode 100644 index 6dc7178..0000000 --- a/src/interpreter.c +++ /dev/null @@ -1,122 +0,0 @@ -// interpreter.c -// Useful for carrying out tests of the CPU instructions. -// Refer to interpreter.md for the manual - -#include"apple.h" -#include"debug.h" - -//Write a custom getc function here which ignores spaces - - -int main(int argc, char *argv[]){ - AppleOn(); - - byte c; - - // Interpreter loop - while(1){ - - // Retrieve first character of a line - do { - c = getc(stdin); - } while (c == '\n' || c == ' ' || c == '\t'); - - // The following are special debug commands. - - // Quit program - if (c == 'Q' || c == 'q'){ - break; - } - - if (c == 'R' || c == 'r'){ - AppleReset(); //need to flesh out this function - continue; - } - - // Dump processor status - if (c == 'P' || c == 'p'){ - dStatusDump(); - continue; - } - - // FIXME!!! PAGE IS CLAMPED TO 00 ON THE LONG MODE - // Dump a page of memory - if (c == 'M' || c == 'm'){ - address x = 0; - do { - c = getc(stdin); - } while(c == ' ' || c == '\n'); - x = dCharToNum(c) << 4; - x += dCharToNum(getc(stdin)); - c = getc(stdin); - if (c != '\n'){ - x <<= 8; - x += dCharToNum(c) << 4; - x += dCharToNum(getc(stdin)); - printf("@%04x:%02x\n", x, GetMemory(x)); - } - else{ - printf("Page %02x", x); - dPageDump(x); - } - continue; - } - - // Print out a statement - if (c == '/'){ - do { - c = getc(stdin); - printf("%c", c); - } while(c != '\n'); - continue; - } - - // Comment, so ignores until newline. - if (c == '#'){ - do { - c = getc(stdin); - } while(c != '\n'); - continue; - } - - if (c == 'S' || c == 's'){ - address x = 0; - byte y = 0; - - for(int i = 3; i >= 0; i--){ - x += (dCharToNum(getc(stdin)) << (4*i)); - } - - c = getc(stdin); - if (c != '.'){ - printf("Error assigning memory to 0x%x\n", x); - break; - } - - for(int i = 1; i >= 0; i--){ - y += (dCharToNum(getc(stdin)) << (4*i)); - } - Memory[x] = y; - continue; - } - - // From here on it is expected input will be an instruction - c = dCharToNum(c) << 4; - c += dCharToNum(getc(stdin)); - address x = 0x0000; - char z = 0x00; - for(int i = ((getInstructionLength(c) * 2) - 2); i > 0; i--) { - do { - z = getc(stdin); - } while (z == ' ' || z == '\t'); - - //if (z != '\n'){ - x += dCharToNum(z) << ((4 * (i - 1))); - /*}else{ - i++; - }*/ - } - CallInstructionTable(c, x); - } - -} @@ -3,6 +3,8 @@ #include <ncurses.h> #include <unistd.h> + + int main() { @@ -10,11 +12,19 @@ int main() { DisplayInit(); + FILE *Log = fopen("log/log.raw", "w+"); + int Time = 0; + while(1) { + // Logging + fprintf(Log, "%04x : %04x\n", Time, PC); + fflush(Log); + // Computing CallInstructionTable(GetMemory(PC), 0); + // Display information PrintInfo(); - //sleep(3); - //getch(); + // Logging + Time++; } DisplayClose(); |