diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-04 15:12:17 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-04 15:12:17 +1100 |
commit | 5bb10fc4121a8c8434dcd367f2e611599a11e12e (patch) | |
tree | 8fcac1461a50fca6bec6ccd2246f7515ad26099a | |
parent | 78d3f650b2ca507e3d5376d3cad4d93df1901569 (diff) |
removed stuff; various instruction improvements
-rw-r--r-- | AppleI_Manual.pdf | bin | 1775046 -> 0 bytes | |||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/cpu/addressing.c | 6 | ||||
-rw-r--r-- | src/cpu/instructions.c | 115 | ||||
-rw-r--r-- | test/01-LDA | 34 | ||||
-rw-r--r-- | test/02-Stack | 59 | ||||
-rw-r--r-- | test/03-Arithmetic | 2 | ||||
-rw-r--r-- | test/99-WozMon | 260 |
8 files changed, 81 insertions, 399 deletions
diff --git a/AppleI_Manual.pdf b/AppleI_Manual.pdf Binary files differdeleted file mode 100644 index 346c348..0000000 --- a/AppleI_Manual.pdf +++ /dev/null diff --git a/src/Makefile b/src/Makefile index d12972c..22cf4fc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,10 +11,6 @@ BUILD_STATIC_LIBRARY = ar -rcs $@ $^ default: computer.a video.a gcc -g -o ../apple-c -lncurses main.c $^ -interpreter: computer.a video.a - gcc -o ../interpreter -lncurses interpreter.c $^ - - # Internal Libraries diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c index fd9bf7e..e5625fa 100644 --- a/src/cpu/addressing.c +++ b/src/cpu/addressing.c @@ -18,7 +18,7 @@ address fAddressGetAddress(Addressing mode, short x) { case eAbsolute: return x; case eIndirectAbsolute: - return GetMemory(x) + ((address)GetMemory(x+1) << 8); + return (address)GetMemory(x) + ((address)GetMemory(x+1) << 8); case eAbsoluteIndexedX: return x + X; case eAbsoluteIndexedY: @@ -30,9 +30,9 @@ address fAddressGetAddress(Addressing mode, short x) { case eZeroPageIndexedY: return ((x + Y) & 0x00FF); case eIndexedIndirect: - return ((GetMemory(x+X+1))<<8) + (GetMemory(x+X)); + return ((address)(GetMemory(x+X+1))<<8) + (address)(GetMemory(x+X)); case eIndirectIndexed: - return ((GetMemory(x+1))<<8) + (GetMemory(x)) + Y; + return ((address)(GetMemory(x+1))<<8) + (address)(GetMemory(x)) + Y; } } diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index 5f4000a..b4daf6e 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -75,7 +75,7 @@ void fSBC(Addressing addr, address val){ //Increment and Decrement Instructions void fINC(Addressing addr, address val){ - byte a = GetMemory(idata.add); + byte a = idata.value; SetMemory(idata.add, ++a); SetFlagN(a); SetFlagZ(a); @@ -94,7 +94,7 @@ void fINY(Addressing addr, address val){ } void fDEC(Addressing addr, address val){ - byte a = GetMemory(idata.add); + byte a = idata.value; SetMemory(idata.add, --a); SetFlagN(a); SetFlagZ(a); @@ -139,35 +139,35 @@ void fJMP(Addressing addr, address val){ } void fBCC(Addressing addr, address val){ - if (getFlag(flag_C) == 0) PC += (char)val; + if (getFlag(flag_C) == 0) PC += (char)idata.value; } void fBCS(Addressing addr, address val){ - if (getFlag(flag_C) == 1) PC += (char)val; + if (getFlag(flag_C) == 1) PC += (char)idata.value; } void fBEQ(Addressing addr, address val){ - if (getFlag(flag_Z) == 1) PC += (char)val; + if (getFlag(flag_Z) == 1) PC += (char)idata.value; } void fBNE(Addressing addr, address val){ - if (getFlag(flag_Z) == 0) PC += (char)val; + if (getFlag(flag_Z) == 0) PC += (char)idata.value; } void fBMI(Addressing addr, address val){ - if (getFlag(flag_N) == 1) PC += (char)val; + if (getFlag(flag_N) == 1) PC += (char)idata.value; } void fBPL(Addressing addr, address val){ - if (getFlag(flag_N) == 0) PC += (char)val; + if (getFlag(flag_N) == 0) PC += (char)idata.value; } void fBVS(Addressing addr, address val){ - if (getFlag(flag_V) == 1) PC += (char)val; + if (getFlag(flag_V) == 1) PC += (char)idata.value; } void fBVC(Addressing addr, address val){ - if (getFlag(flag_V) == 0) PC += (char)val; + if (getFlag(flag_V) == 0) PC += (char)idata.value; } void fCMP(Addressing addr, address val){ @@ -197,33 +197,73 @@ void fBIT(Addressing addr, address val){ // Shift and Rotate Instructions void fASL(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x80)); - acc = (idata.value << 1); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (acc & 0x80)); + acc = (idata.value << 1) & 0xFE; + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x80)); + byte m = ((idata.value << 1) & 0xFE); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } void fLSR(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x01)); - acc = (idata.value >> 1); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (acc & 0x01)); + acc = (idata.value >> 1) & 0x7F; + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x01)); + byte m = ((idata.value >> 1) & 0x7F); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } void fROL(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x80)); - acc = (idata.value << 1); - acc |= (getFlag(flag_C)?1:0); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (idata.value & 0x80)); + acc = (idata.value << 1) & 0xFE; + acc |= ((getFlag(flag_C) != 0) ? 0x01 : 0x00); + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x80)); + byte m = + (((idata.value << 1) & 0xFE) + | ((getFlag(flag_C) != 0) ? 0x01 : 0x00)); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } void fROR(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x01)); - acc = (idata.value >> 1); - acc |= (getFlag(flag_C)?0x80:0); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (idata.value & 0x01)); + acc = (idata.value >> 1) & 0x7F; + acc |= ((getFlag(flag_C) != 0) ? 0x80 : 0x00); + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x01)); + byte m = + (((idata.value >> 1) & 0x7F) + | ((getFlag(flag_C) != 0) ? 0x80 : 0x00)); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } // Transfer Instructions @@ -283,13 +323,14 @@ void fPLP(Addressing addr, address val){ void fJSR(Addressing addr, address val){ SetStack((PC+3) >> 8); SetStack((PC+3) & 0x00FF); - PC = idata.add; PC -= 3; + PC = idata.add; + PC -= idata.length; } void fRTS(Addressing addr, address val){ PC = (address)(GetStack()); PC += ((address)(GetStack())) << 8; - PC -= 1; + PC -= idata.length; } void fRTI(Addressing addr, address val){ @@ -301,31 +342,31 @@ void fRTI(Addressing addr, address val){ // Set/Reset Insutrctions void fCLC(Addressing addr, address val){ - flagClear(flag_C); + SetFlag(flag_C, 0); } void fCLD(Addressing addr, address val){ - flagClear(flag_D); + SetFlag(flag_D, 0); } void fCLI(Addressing addr, address val){ - flagClear(flag_I); + SetFlag(flag_I, 0); } void fCLV(Addressing addr, address val){ - flagClear(flag_V); + SetFlag(flag_V, 0); } void fSEC(Addressing addr, address val){ - flagSet(flag_C); + SetFlag(flag_C, 1); } void fSED(Addressing addr, address val){ - flagSet(flag_D); + SetFlag(flag_D, 1); } void fSEI(Addressing addr, address val){ - flagSet(flag_I); + SetFlag(flag_I, 1); } // NOP/BRK Instructions diff --git a/test/01-LDA b/test/01-LDA deleted file mode 100644 index 3c55624..0000000 --- a/test/01-LDA +++ /dev/null @@ -1,34 +0,0 @@ -# 01-LDA -#This test verifies if each addressing mode works, using the LDA instruction. - -#Init Memory - -s0007.10 -s0008.02 -s0009.02 -s000a.64 -s000b.48 -s000c.32 -s0202.11 -s0212.22 - -#Init Registers - -a201 #LDX $1 -a002 #LDY $2 - -#Tests - -a9ff 8510 #LDA Immediate store in 0010 -a50a 8511 #LDA ZP 0a store in 0011 -b50a 8512 #LDA ZP+X 0a store in 0012 -ad000a 8513 #LDA Abs store in 0013 -bd000a 8514 #LDA Abs+X store in 0014 -b9000a 8515 #LDA Abs+Y store in 0015 -a107 8517 #LDA In. X store in 0018 -b107 8518 #LDA In. Y store in 0019 - -#Print 00 Page -m00 -m02 -q diff --git a/test/02-Stack b/test/02-Stack deleted file mode 100644 index 50c760c..0000000 --- a/test/02-Stack +++ /dev/null @@ -1,59 +0,0 @@ -# 02-Stack -#This test checks whether each stack operation functions as expected. - -#MNEMONIC HEX -#TXS (Transfer X to Stack ptr) $9A -#TSX (Transfer Stack ptr to X) $BA -#PHA (PusH Accumulator) $48 -#PLA (PuLl Accumulator) $68 -#PHP (PusH Processor status) $08 -#PLP (PuLl Processor status) $28 - -p - -/Push/Pull Accumulator Test - -a9 01 - -48 - -a9 10 - -48 - -68 - -68 - -p - -m01 - -/~~~~TXS/TSX Test - -a27f - -/Status after LDX 7f -p - -9a - -/Status after TXS -p - -68 - -68 - -/Status after 2 PLA -p - -ba - -/Status after TSX -p - -q - - - diff --git a/test/03-Arithmetic b/test/03-Arithmetic deleted file mode 100644 index 72b40e1..0000000 --- a/test/03-Arithmetic +++ /dev/null @@ -1,2 +0,0 @@ -# 03-Arithmetic -#Tests ADC, SBC, and all increment operations for value and flag correctness. diff --git a/test/99-WozMon b/test/99-WozMon deleted file mode 100644 index 2ddbb24..0000000 --- a/test/99-WozMon +++ /dev/null @@ -1,260 +0,0 @@ -;------------------------------------------------------------------------- -; -; The WOZ Monitor for the Apple 1 -; Written by Steve Wozniak 1976 -; -;------------------------------------------------------------------------- - - .CR 6502 - .OR $FF00 - .TF WOZMON.HEX,HEX,8 - -;------------------------------------------------------------------------- -; Memory declaration -;------------------------------------------------------------------------- - -XAML .EQ $24 Last "opened" location Low -XAMH .EQ $25 Last "opened" location High -STL .EQ $26 Store address Low -STH .EQ $27 Store address High -L .EQ $28 Hex value parsing Low -H .EQ $29 Hex value parsing High -YSAV .EQ $2A Used to see if hex value is given -MODE .EQ $2B $00=XAM, $7F=STOR, $AE=BLOCK XAM - -IN .EQ $0200,$027F Input buffer - -KBD .EQ $D010 PIA.A keyboard input -KBDCR .EQ $D011 PIA.A keyboard control register -DSP .EQ $D012 PIA.B display output register -DSPCR .EQ $D013 PIA.B display control register - -; KBD b7..b0 are inputs, b6..b0 is ASCII input, b7 is constant high -; Programmed to respond to low to high KBD strobe -; DSP b6..b0 are outputs, b7 is input -; CB2 goes low when data is written, returns high when CB1 goes high -; Interrupts are enabled, though not used. KBD can be jumpered to IRQ, -; whereas DSP can be jumpered to NMI. - -;------------------------------------------------------------------------- -; Constants -;------------------------------------------------------------------------- - -BS .EQ $DF Backspace key, arrow left key -CR .EQ $8D Carriage Return -ESC .EQ $9B ESC key -PROMPT .EQ "\" Prompt character - -;------------------------------------------------------------------------- -; Let's get started -; -; Remark the RESET routine is only to be entered by asserting the RESET -; line of the system. This ensures that the data direction registers -; are selected. -;------------------------------------------------------------------------- - -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. - -; Program falls through to the GETLINE routine to save some program bytes -; Please note that Y still holds $7F, which will cause an automatic Escape - -;------------------------------------------------------------------------- -; The GETLINE process -;------------------------------------------------------------------------- - -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! - -; Line received, now let's parse it - - 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 - -; Here we're trying to parse a new hex value - -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 - -; STOR mode, save LSD of new hex byte - - 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 user's program from last opened location -;------------------------------------------------------------------------- - -RUN JMP (XAML) Run user's program - -;------------------------------------------------------------------------- -; We're not in Store mode -;------------------------------------------------------------------------- - -NOTSTOR BMI XAMNEXT B7 = 0 for XAM, 1 for BLOCK XAM - -; We're in XAM mode now - - 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 - -; Print address and data from this address, fall through next BNE. - -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. - -;------------------------------------------------------------------------- -; Subroutine to print a byte in A in hex form (destructive) -;------------------------------------------------------------------------- - -PRBYTE PHA Save A for LSD - LSR - LSR - LSR MSD to LSD position - LSR - JSR PRHEX Output hex digit - PLA Restore A - -; Fall through to print hex routine - -;------------------------------------------------------------------------- -; Subroutine to print a hexadecimal digit -;------------------------------------------------------------------------- - -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 - -; Fall through to print routine - -;------------------------------------------------------------------------- -; Subroutine to print a character to the terminal -;------------------------------------------------------------------------- - -ECHO BIT DSP DA bit (B7) cleared yet? - BMI ECHO No! Wait for display ready - STA DSP Output character. Sets DA - RTS - -;------------------------------------------------------------------------- -; Vector area -;------------------------------------------------------------------------- - - .DA $0000 Unused, what a pity -NMI_VEC .DA $0F00 NMI vector -RESET_VEC .DA RESET RESET vector -IRQ_VEC .DA $0000 IRQ vector - -;------------------------------------------------------------------------- - - .LI OFF - |