diff --git a/basic/scripts/tokens.py b/basic/scripts/tokens.py index 83705803..0be8b6f2 100644 --- a/basic/scripts/tokens.py +++ b/basic/scripts/tokens.py @@ -124,7 +124,7 @@ def create(self): LOAD CAT GOSUB GOTO RETURN RESTORE DIM FKEY CLS INK FRAME SOLID BY WHO PALETTE DRAW HIDE FLIP SOUND SFX ANCHOR GLOAD DEFCHR LEFT - RIGHT FORWARD TURTLE SWEET TILEMAP PENUP PENDOWN FAST + RIGHT FORWARD TURTLE !!UK0 TILEMAP PENUP PENDOWN FAST HOME LOCALE CURSOR RENUMBER DELETE EDIT MON OLD ON ERROR PIN OUTPUT WAIT IWRITE ANALOG ISEND SSEND IRECEIVE SRECEIVE ITRANSMIT STRANSMIT NEAL LIBRARY @@ -140,8 +140,6 @@ def create(self): PLX PLY ROL ROR RTI RTS SBC SEC SED SEI STA STX STY STZ TAX TAY TRB TSB TSX TXA TXS TYA - SET LD ST LDD STD POP STP ADD SUB POPD CPR INR DCR - RTN BR BNC BC BP BM BZ BNZ BM1 BNM1 BK RS BS BSL """,0x60) # # Additional Unary functions, less popular diff --git a/basic/sources/assembler/6502/assembler.asm b/basic/sources/assembler/assembler.asm similarity index 100% rename from basic/sources/assembler/6502/assembler.asm rename to basic/sources/assembler/assembler.asm diff --git a/basic/sources/assembler/common/aswrite.asm b/basic/sources/assembler/aswrite.asm similarity index 100% rename from basic/sources/assembler/common/aswrite.asm rename to basic/sources/assembler/aswrite.asm diff --git a/basic/sources/assembler/6502/constants.inc b/basic/sources/assembler/constants.inc similarity index 100% rename from basic/sources/assembler/6502/constants.inc rename to basic/sources/assembler/constants.inc diff --git a/basic/sources/assembler/6502/instruction.asm b/basic/sources/assembler/instruction.asm similarity index 100% rename from basic/sources/assembler/6502/instruction.asm rename to basic/sources/assembler/instruction.asm diff --git a/basic/sources/assembler/common/label.asm b/basic/sources/assembler/label.asm similarity index 100% rename from basic/sources/assembler/common/label.asm rename to basic/sources/assembler/label.asm diff --git a/basic/sources/assembler/6502/operands.asm b/basic/sources/assembler/operands.asm similarity index 100% rename from basic/sources/assembler/6502/operands.asm rename to basic/sources/assembler/operands.asm diff --git a/basic/sources/assembler/sweet/opcodes.asm b/basic/sources/assembler/sweet/opcodes.asm deleted file mode 100644 index 9c52a963..00000000 --- a/basic/sources/assembler/sweet/opcodes.asm +++ /dev/null @@ -1,236 +0,0 @@ -; ************************************************************************************************ -; ************************************************************************************************ -; -; Name: opcodes.asm -; Purpose: Opcode handling code -; Created: 9th April 2024 -; Reviewed: No -; Author: Paul Robson (paul@robsons.org.uk) -; -; ************************************************************************************************ -; ************************************************************************************************ - - .section code - -; ************************************************************************************************ -; -; Support Macros -; -; ************************************************************************************************ - -; -; Single register operand -; -sweetreg .macro - jsr SweetAsmGetRegister - ora #\1 - jsr AssemblerWriteByte - .endm -; -; Single byte opcodes. -; -sweetopc .macro - lda #\1 - jsr AssemblerWriteByte - .endm -; -; Short branch like 65C02 -; -sweetbra .macro - lda #\1 - bra ShortBranchCommon - .endm -; -; Check @ follows. May soften ? -; -checkat .macro - lda #KWD_AT - jsr ERRCheckA - .endm - -; ************************************************************************************************ -; -; Standard dispatcher -; -; ************************************************************************************************ - -; ************************************************************************************************ -; SET n, -; ************************************************************************************************ - -SweetAsm_SET: ;; [SET] - .sweetreg $10 ; $10+x - jsr ERRCheckComma - ldx #0 - jsr EXPEvalInteger16 ; operand - lda XSNumber0,x ; output it - jsr AssemblerWriteByte - lda XSNumber1,x - jsr AssemblerWriteByte - rts - -; ************************************************************************************************ -; n -; ************************************************************************************************ - -SweetAsm_LD: ;; [LD] - jsr SweetAsmGetAltRegister - clc - adc #$20 - jsr AssemblerWriteByte - rts - -SweetAsm_ST: ;; [ST] - jsr SweetAsmGetAltRegister - clc - adc #$30 - jsr AssemblerWriteByte - rts - -SweetAsm_LDD: ;; [LDD] - .checkat - .sweetreg $60 - rts - -SweetAsm_STD: ;; [STD] - .checkat - .sweetreg $70 - rts - -SweetAsm_POP: ;; [POP] - .checkat - .sweetreg $80 - rts - -SweetAsm_STP: ;; [STP] - .checkat - .sweetreg $90 - rts - -SweetAsm_ADD: ;; [ADD] - .sweetreg $A0 - rts - -SweetAsm_SUB: ;; [SUB] - .sweetreg $B0 - rts - -SweetAsm_POPD: ;; [POPD] - .checkat - .sweetreg $C0 - rts - -SweetAsm_CPR: ;; [CPR] - .sweetreg $D0 - rts - -SweetAsm_INR: ;; [INR] - .sweetreg $E0 - rts - -SweetAsm_DCR: ;; [DCR] - .sweetreg $F0 - rts - -; ************************************************************************************************ -; No operand -; ************************************************************************************************ - -SweetAsm_RTN: ;; [RTN] - .sweetopc $00 - rts - -SweetAsm_RS: ;; [RS] - .sweetopc $0B - rts - - -; ************************************************************************************************ -; 8 bit relative branch -; ************************************************************************************************ - -SweetAsm_BR: ;; [BR] - .sweetbra $01 - -SweetAsm_BNC: ;; [BNC] - .sweetbra $02 - -SweetAsm_BC: ;; [BC] - .sweetbra $03 - -SweetAsm_BP: ;; [BP] - .sweetbra $04 - -SweetAsm_BM: ;; [BM] - .sweetbra $05 - -SweetAsm_BZ: ;; [BZ] - .sweetbra $06 - -SweetAsm_BNZ: ;; [BNZ] - .sweetbra $07 - -SweetAsm_BM1: ;; [BM1] - .sweetbra $08 - -SweetAsm_BNM1: ;; [BNM1] - .sweetbra $09 - -SweetAsm_BK: ;; [BK] - .sweetbra $0A - -SweetAsm_BS: ;; [BS] - .sweetbra $0C - -; -; Branch common -; -ShortBranchCommon: - jsr AssemblerWriteByte ; output opcode - ldx #0 ; target address - jsr EXPEvalInteger16 - jsr AssembleRelativeBranch ; use 65C02 code. - rts - -; ************************************************************************************************ -; 16 bit relative subroutine call (added) -; ************************************************************************************************ - -SweetAsm_BSL: ;; [BSL] - .sweetopc $0D ; subroutine call - - ldx #0 ; target address - jsr EXPEvalInteger16 - - sec ; calculate target - P - lda XSNumber0 - sbc VariableP - pha - lda XSNumber1 - sbc VariableP+1 - tax - pla ; in X:A - - sec ; sub 2, 2 further back to allow for operand. - sbc #2 - php - jsr AssemblerWriteByte ; low offset - plp - txa - sbc #0 - jsr AssemblerWriteByte ; high offset - - rts - - .send code - -; ************************************************************************************************ -; -; Changes and Updates -; -; ************************************************************************************************ -; -; Date Notes -; ==== ===== -; -; ************************************************************************************************ diff --git a/basic/sources/assembler/sweet/operands.asm b/basic/sources/assembler/sweet/operands.asm deleted file mode 100644 index f1e0171f..00000000 --- a/basic/sources/assembler/sweet/operands.asm +++ /dev/null @@ -1,56 +0,0 @@ -; ************************************************************************************************ -; ************************************************************************************************ -; -; Name: operands.asm -; Purpose: Operands handling -; Created: 9th April 2024 -; Reviewed: No -; Author: Paul Robson (paul@robsons.org.uk) -; -; ************************************************************************************************ -; ************************************************************************************************ - - .section code - -; ************************************************************************************************ -; -; Get a single register to A -; -; ************************************************************************************************ - -SweetAsmGetRegister: - jsr EXPEvalInteger8 - cmp #16 - bcs _SAGRRange - rts -_SAGRRange: - .error_range - -; ************************************************************************************************ -; -; Get a single register to A n or @an -; -; ************************************************************************************************ - -SweetAsmGetAltRegister: - lda (codePtr),y ; check @x - cmp #KWD_AT - bne SweetAsmGetRegister ; just normal register - - iny ; consume @ - jsr SweetAsmGetRegister ; get register - ora #$20 ; indirect adjust - rts - - .send code - -; ************************************************************************************************ -; -; Changes and Updates -; -; ************************************************************************************************ -; -; Date Notes -; ==== ===== -; -; ************************************************************************************************ diff --git a/basic/sources/commands/extras/sweet16.asm b/basic/sources/commands/extras/sweet16.asm deleted file mode 100644 index 84993302..00000000 --- a/basic/sources/commands/extras/sweet16.asm +++ /dev/null @@ -1,64 +0,0 @@ -; ************************************************************************************************ -; ************************************************************************************************ -; -; Name: sweet16.asm -; Purpose: Execute Sweet 16 code. -; Created: 10th April 2024 -; Reviewed: No -; Author: Paul Robson (paul@robsons.org.uk) -; -; ************************************************************************************************ -; ************************************************************************************************ - -; ************************************************************************************************ -; -; SWEET Command -; -; ************************************************************************************************ - - .section code - -Command_SWEET: ;; [sweet] - ldx #0 ; register address. - jsr EXPEvalInteger16 - lda XSNumber0 ; copy register address to XA - ldx XSNumber1 - -_CSWExecute: - sta ControlParameters+0 ; set reg address parameters - stx ControlParameters+1 - pha ; save on stack - phx - DoSendMessage ; execute that code. - .byte 1,9 - DoWaitMessage - - lda ControlError ; reentrancy check ? - beq _CSWEnter - - plx ; throw register address - pla - rts - -_CSWEnter: - .byte $F3 ; this is right. It's an unused 1 byte 65c02 opcode - nop ; and it signals to the emulator to frame synchronise - nop ; the NOPs are for safety. On real hardware does nothing. - - plx ; restore XA - pla - bra _CSWExecute ; and restart. - - .send code - -; ************************************************************************************************ -; -; Changes and Updates -; -; ************************************************************************************************ -; -; Date Notes -; ==== ===== -; -; ************************************************************************************************ - diff --git a/documents/TODO b/documents/TODO deleted file mode 100644 index c544a4f7..00000000 --- a/documents/TODO +++ /dev/null @@ -1,6 +0,0 @@ -TODO List ---------- - -- write the new assembler as tasm is unusable almost - - diff --git a/documents/bytesweet16.pdf b/documents/bytesweet16.pdf deleted file mode 100644 index e2037f25..00000000 Binary files a/documents/bytesweet16.pdf and /dev/null differ diff --git a/documents/release/basic.md b/documents/release/basic.md index 018a9533..47db885c 100644 --- a/documents/release/basic.md +++ b/documents/release/basic.md @@ -166,7 +166,6 @@ Many of these are helpful for understanding specific API functions, as many BASI | stransmit \,\ | | | ssend \ | Send data to SPI device ; this is comma seperated data, numbers or strings. If a semicolon is used as a seperator e.g. 4137; then the constant is sent as a 16 bit value. | | stop | Halt program with error | -| sweet \ | Run Sweet 16 code using the registers at the given address ; the registers are a 32 byte block of memory, and can be accessed easily using the \[\] operators. | | sys \ | Call 65C02 machine code at given address. Passes contents of variables A,X,Y in those registers. | | tilemap addr,x,y | Define a tilemap. The tilemap data format is in the API. The tilemap is stored in memory at addr, and the offset into the | | uconfig \\[,\\] | Set the baud rate and protocol for the UART. Currently only 8N1 is supported. | @@ -214,7 +213,7 @@ You can also pass A X Y as variables. So you could delete line 150 and run it wi The \[\] operator is used like an array, but it is actually a syntactic equivalent of deek and doke, e.g. reading and writing 16 bytes. mem\[x\] means the 16 bit value in mem + x \* 2, so if mem = 813 then mem\[2\] = -1 writes a 16 bit word to 817 and 818, and print mem\[2\] reads it. The index can only be from 0..127 -The purpose of this is to provide a clean readable interface to data in 65C02, Sweet16 and other programs running under assembly language ; often accessing elements in the 'array' as a structure. +The purpose of this is to provide a clean readable interface to data in 65C02 and other programs running under assembly language ; often accessing elements in the 'array' as a structure. ### Zero Page Usage diff --git a/documents/release/source/api.gen.md b/documents/release/source/api.gen.md index 0d6c2014..3ea9a7d4 100644 --- a/documents/release/source/api.gen.md +++ b/documents/release/source/api.gen.md @@ -52,12 +52,6 @@ this also resets the 65C02. Do a MOS command (a '* command') these are specified in the Wiki as they will be steadily expanded. -## Function 9 : Sweet 16 Virtual Machine - -Execute Sweet 16 VM Code with the register set provided. The error return value is actually a re-entrant -call for Windows emulation ; if it returns non-zero it means the VM has been executed, if it returns zero -then the emulation can update as at the end of a normal frame. - ## Function 10 : Write character to debug Writes a single character to the debug port (the UART on the Pico, or stderr on the emulator). This allows diff --git a/documents/sweet 16.odt b/documents/sweet 16.odt deleted file mode 100644 index 9225e087..00000000 Binary files a/documents/sweet 16.odt and /dev/null differ diff --git a/documents/sweet 16.pdf b/documents/sweet 16.pdf deleted file mode 100644 index 56db3338..00000000 Binary files a/documents/sweet 16.pdf and /dev/null differ diff --git a/emulator/Makefile b/emulator/Makefile index 5ab569cf..e522ca78 100644 --- a/emulator/Makefile +++ b/emulator/Makefile @@ -24,7 +24,7 @@ COMMONOBJECTS = $(subst .cpp,.o,$(COMMONSOURCES)) SOURCES = src$(S)core$(S)sys_processor.o src$(S)core$(S)hardware.o src$(S)framework$(S)beeper.o \ src$(S)framework$(S)main.o src$(S)framework$(S)gfx.o src$(S)framework$(S)debugger.o \ src$(S)core$(S)sys_debugger.o \ - src$(S)core$(S)processors$(S)sweet16.o src$(S)core$(S)processors$(S)6502.o \ + src$(S)core$(S)6502.o \ $(COMMONOBJECTS) CC = g++ @@ -135,13 +135,6 @@ prebuild: $(PYTHON) scripts$(S)mapper.py >include$(S)hid2sdl.h $(CCOPY) $(BINDIR)*_binary.h include - $(CMAKEDIR) build - $(CCOPY) scripts$(S)*.py build - $(CCOPY) build$(S)swasm.py build$(S)__main__.py - $(CDEL) $(BINDIR)swasm.zip - zip -j $(BINDIR)swasm.zip build$(S)__main__.py - $(CDEL) build$(S)*.py - # *************************************************************************************** # # Force firmware rebuild diff --git a/emulator/cross-compile/Makefile b/emulator/cross-compile/Makefile index 459e08e2..a93335e8 100644 --- a/emulator/cross-compile/Makefile +++ b/emulator/cross-compile/Makefile @@ -25,7 +25,7 @@ COMMONSOURCES = $(wildcard $(IMPSRC)*.cpp) SOURCES = $(FRASRC)main.cpp $(FRASRC)gfx.cpp $(FRASRC)debugger.cpp $(FRASRC)beeper.cpp \ $(EMUSRC)core$(S)sys_processor.cpp $(EMUSRC)core$(S)sys_debugger.cpp $(EMUSRC)core$(S)hardware.cpp \ - $(EMUSRC)core$(S)processors$(S)6502.cpp $(EMUSRC)core$(S)processors$(S)sweet16.cpp \ + $(EMUSRC)core$(S)6502.cpp \ $(COMMONSOURCES) INCLUDES= -I ../include -I ../framework -I .. -I $(COMDIR)include diff --git a/emulator/include/sys_processor.h b/emulator/include/sys_processor.h index d377438a..c17f42bc 100644 --- a/emulator/include/sys_processor.h +++ b/emulator/include/sys_processor.h @@ -65,7 +65,6 @@ void CPUEndRun(void); void CPULoadBinary(char *fileName); void CPUExit(void); void CPUSaveArguments(int argc,char *argv[]); -BYTE8 CPUGetID(void); // ******************************************************************************************************************************* // @@ -85,15 +84,4 @@ CPUSTATUS65 *CPUGetStatus65(void); WORD16 CPUGetPC65(void); int CPUGetStep65(BYTE8 opcode); -// ******************************************************************************************************************************* -// -// Sweet 16 Prototypes -// -// ******************************************************************************************************************************* - -BYTE8 CPUExecute16(void); -void CPUReset16(void); -WORD16 CPUGetPC16(void); -int CPUGetStep16(BYTE8 opcode); - #endif diff --git a/emulator/scripts/swasm.py b/emulator/scripts/swasm.py deleted file mode 100644 index 4476558f..00000000 --- a/emulator/scripts/swasm.py +++ /dev/null @@ -1,236 +0,0 @@ -# ******************************************************************************************* -# ******************************************************************************************* -# -# Name : swasm.py -# Purpose : Sweet 16 Assembler -# Date : 30th April 2024 -# Author : Paul Robson (paul@robsons.org.uk) -# -# ******************************************************************************************* -# ******************************************************************************************* - -import os,re,sys - -class AssemblerError(Exception): - pass - -AssemblerError.__LINE__ = 0 -AssemblerError.__FILE__ = 0 - -# ******************************************************************************************* -# -# Evaluator class -# -# ******************************************************************************************* - -class Evaluator(object): - def __init__(self): - self.identifiers = {} - for i in range(0,16): - self.define("R{0:x}".format(i),i) - self.define("R{0}".format(i),i) - - def evaluate(self,expr,pass2): - v = 0 - try: - ex = expr.lower().replace("$","0x") - v = int(eval(ex,self.identifiers)) - except NameError: - if pass2: - raise AssemblerError("Unknown identifier in "+expr) - v = 0 - except SyntaxError: - raise AssemblerError("Bad expression "+expr) - return v - - def define(self,ident,value): - ident = ident.strip().lower() - if ident in self.identifiers and self.identifiers[ident] != value: - raise AssemblerError("Identifier "+ident+" redefined.") - self.identifiers[ident] = value - -# ******************************************************************************************* -# -# Memory Store -# -# ******************************************************************************************* - -class Memory(object): - def __init__(self): - self.memory = [ 0 ] * 0x10000 - self.lowMemory = None - self.highMemory = None - - def writeByte(self,addr,b): - assert addr >= 0 and addr < 0x10000 and b >= 0 and b < 256 - if self.lowMemory is None: - self.lowMemory = addr - self.highMemory = addr - self.memory[addr] = b - self.lowMemory = min(self.lowMemory,addr) - self.highMemory = max(self.highMemory,addr) - if False: - print("{0:04x} : {1:02x}".format(addr,b)) - - def writeList(self,addr,byteList): - for b in byteList: - self.writeByte(addr,b) - addr += 1 - - def writeMemory(self,fileName): - if self.lowMemory is not None: - h = open(fileName,"wb") - h.write(bytes(self.memory[self.lowMemory:self.highMemory+1])) - h.close() - -# ******************************************************************************************* -# -# Assembler -# -# ******************************************************************************************* - -class Assembler(object): - def __init__(self,memory,evaluator): - self.memory = memory - self.evaluator = evaluator - self.pc = None - self.apass = None - self.group0 = { "rtn":0x00,"bk":0x0A,"rs":0x0B } - self.group1 = { - "ld":0x20,"st":0x30, "ld@":0x40,"st@":0x50,"ldd@":0x60,"std@":0x70, - "pop@":0x80,"stp@":0x90,"add":0xA0,"sub":0xB0,"popd@":0xC0, - "cpr":0xD0,"inr":0xE0,"dcr":0xF0 - } - self.group2 = { - "br":0x01,"bnc":0x02,"bc":0x03,"bp":0x04,"bm":0x05,"bz":0x06, - "bnz":0x07,"bm1":0x08,"bnm1":0x09,"bs":0x0C - } - - def newPass(self,apass): - self.apass = apass - self.pc = None - AssemblerError.__LINE__ = 0 - AssemblerError.__FILE__ = "" - - def assemble(self,l,listing = None): - self.current = [] - if self.apass == 2 and listing is None: - listing = sys.stdout - s = l if l.find(";") < 0 else l[:l.find(";")] - s = s.replace("\t"," ").strip() - if s != "": - m = re.match('^([a-z1]+\\s*\\@?)(.*)$',s) - opcode = s.split(" ")[0].lower().strip() - opcode = "" if m is None else m.group(1).replace(" ","") - operand = "" if m is None else m.group(2).strip() - if s.endswith(":"): - self.checkInCode() - self.evaluator.define(s[:-1],self.pc) - elif s in self.group0: - self.current.append(self.group0[s]) - elif opcode in self.group1: - self.current.append(self.group1[opcode]+self.evaluateRegister(operand)) - elif opcode in self.group2: - self.relativeBranch(self.group2[opcode],operand,1) - elif opcode == "set": - operand = operand.split(",") - if len(operand) != 2: - raise AssemblerError("Syntax error "+l) - self.current.append(0x10+self.evaluateRegister(operand[0])) - v = self.evaluate(operand[1]) - self.current += [v & 0xFF,(v >> 8) & 0xFF] - elif opcode == "bsl": - self.relativeBranch(0x0D,operand,2) - else: - self.pseudoOperation(s) - if listing is not None and self.apass == 2: - b = " ".join(["{0:02x}".format(n) for n in self.current]) - listing.write("{0:04x} : {1:20} : {3}{2}\n".format(self.pc,b[:20],s,"" if s.endswith(":") else " ")) - if len(self.current) > 0 and self.apass == 2: - self.memory.writeList(self.pc,self.current) - self.pc += len(self.current) - - def relativeBranch(self,opcode,addr,size): - self.current.append(opcode) - offset = self.evaluate(addr) - if offset is not None: - offset = offset - (self.pc + size + 1) - else: - offset = 0 - offset = 0 if self.apass == 1 else offset - if size == 1: - if offset < -128 or offset > 127: - raise AssemblerError("Bad short offset "+addr) - self.current.append(offset & 0xFF) - else: - self.current += [offset & 0xFF,(offset >> 8) & 0xFF] - - def checkInCode(self): - if self.pc is None: - raise AssemblerError("No code origin set") - - def pseudoOperation(self,s): - if s.startswith("org"): - self.pc = self.evaluate(s[3:],True) - if self.pc < 0 or self.pc >= 0x10000: - raise AssemblerError("Bad Origin "+s) - elif s.startswith("byte"): - self.dataOperation(s[4:],1) - elif s.startswith("word"): - self.dataOperation(s[4:],2) - elif s.startswith("text"): - self.textOperation(s[4:]) - else: - raise AssemblerError("Syntax Error "+s) - - def dataOperation(self,data,size): - for b in data.split(","): - n = self.evaluate(b) - n = 0 if n is None else n - self.current.append(n & 0xFF) - if size == 2: - self.checkInCode() - self.current.append((n >> 8) & 0xFF) - - def textOperation(self,data): - for b in [x.strip() for x in data.split(",")]: - ok = (b[0] == '"' or b[0] == "'") and b[0] == b[-1] - if not ok: - raise AssemblerError("Bad text string "+data) - self.current += [ord(x) for x in b[1:-1]] - - def evaluate(self,e,check = None): - if check is None: - check = (self.apass == 2) - return self.evaluator.evaluate(e,check) - - def evaluateRegister(self,e): - reg = self.evaluate(e,True) - if reg < 0 or reg > 15: - raise AssemblerError("Bad register "+e) - return reg - - def assembleFile(self,file,l): - AssemblerError.__FILE__ = file - AssemblerError.__LINE__ = 0 - for s in open(file,"r").readlines(): - AssemblerError.__LINE__ += 1 - #print(AssemblerError.__LINE__,s) - try: - self.assemble(s.replace("\t"," "),l) - except AssemblerError as x: - print("Error '{0}' {1}:{2}".format(str(x),AssemblerError.__FILE__,AssemblerError.__LINE__)) - sys.exit(1) - - -if __name__ == "__main__": - m = Memory() - asm = Assembler(m,Evaluator()) - h = open("out.lst","w") - for p in range(1,3): - asm.newPass(p) - for f in sys.argv[1:]: - asm.assembleFile(f,h) - h.close() - m.writeMemory("out.bin") - sys.exit(0) diff --git a/emulator/scripts/test.asm b/emulator/scripts/test.asm deleted file mode 100644 index 5e661909..00000000 --- a/emulator/scripts/test.asm +++ /dev/null @@ -1,45 +0,0 @@ -; -; No direct addresses ¬! -; - - org $C000 -s2: - set r1,32767 - bk - set r0,42 - bs s1 - bsl s1 - bra s1 - bk - ld r1 - st r2 - ld @r3 - st @r4 - ldd @r5 - std @r6 - pop @r7 - stp @r8 - add r9 - sub r10 - popd @r11 - cpr r12 - inr r13 - dcr r14 - - rtn -s1: - rtn - bra s1 - bnc s1 - bc s1 - bp s1 - bm s1 - bz s1 - bnz s1 - bm1 s1 - bnm1 s1 - bk - rs - bs s1 - bsl s1 - diff --git a/emulator/src/core/processors/6502.cpp b/emulator/src/core/6502.cpp similarity index 100% rename from emulator/src/core/processors/6502.cpp rename to emulator/src/core/6502.cpp diff --git a/emulator/src/core/processors/sweet16.cpp b/emulator/src/core/processors/sweet16.cpp deleted file mode 100644 index c7c935c6..00000000 --- a/emulator/src/core/processors/sweet16.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// ******************************************************************************************************************************* -// ******************************************************************************************************************************* -// -// Name: sweet16.cpp -// Purpose: Sweet16 Processor Emulation. -// Created: 29th April 2024 -// Author: Paul Robson (paul@robsons.org.uk) -// -// ******************************************************************************************************************************* -// ******************************************************************************************************************************* - -#include -#include -#include -#include -#include -#include "sys_processor.h" -#include "sys_debug_system.h" -#include "hardware.h" -#include "common.h" - - -// ******************************************************************************************************************************* -// -// Reset Sweet16 -// -// ******************************************************************************************************************************* - -void CPUReset16(void) { - // Not possible ! -} - -// ******************************************************************************************************************************* -// -// Execute a single 6502 instruction -// -// ******************************************************************************************************************************* - -BYTE8 CPUExecute16(void) { - BYTE8 r = SW16ExecuteOne(0); - cycles++; - return 0; -} - -// ******************************************************************************************************************************* -// -// Get 6502 PC -// -// ******************************************************************************************************************************* - -WORD16 CPUGetPC16(void) { - return CPUReadMemory(30)+(CPUReadMemory(31) << 8); -} - -// ******************************************************************************************************************************* -// -// Handle skipping subroutine calls -// -// ******************************************************************************************************************************* - -int CPUGetStep16(BYTE8 opcode) { - if (opcode == 0x0C) return 2; - if (opcode == 0x0D) return 3; - return 0; -} diff --git a/emulator/src/core/sys_debugger.cpp b/emulator/src/core/sys_debugger.cpp index 83520631..170644a8 100644 --- a/emulator/src/core/sys_debugger.cpp +++ b/emulator/src/core/sys_debugger.cpp @@ -104,41 +104,6 @@ int DBGXDasm65(int addr, char* buffer) { return p; } -#define SW16_MNEMONICS -#include "data/sweet_opcodes.h" - -int DBGXDasm16(int addr, char* buffer) { - int p = addr; - int operand; - int opc = CPUReadMemory(p);p = (p + 1) & 0xFFFF; // Read opcode. - strcpy(buffer,sw16Mnemonics[opc]); // Work out the opcode. - char *at = strchr(buffer,'$'); // Look for '$' - if (at != NULL) { // Operand ? - char hex[16],temp[32]; - if (at[1] == '1') { - operand = CPUReadMemory(p); - if (operand & 0x80) operand = operand - 0x100; - sprintf(hex,"%04x",(operand+p+1) & 0xFFFF); - p = (p+1) & 0xFFFF; - } - if (at[1] == '2') { - operand = CPUReadMemory(p) + CPUReadMemory(p+1)*256; - if (opc == 0x0D) operand = (operand + 2 + p) & 0xFFFF; - sprintf(hex,"%04x",operand); - p = (p+2) & 0xFFFF; - } - if (at[1] == 'x') { - int f = CPUReadMemory(p); - sprintf(hex,"r%d,fn:%d",f & 15,f >> 4); - p = (p+1) & 0xFFFF; - } - strcpy(temp,buffer); - strcpy(temp+(at-buffer),hex); - strcat(temp,at+2); - strcpy(buffer,temp); - } - return p; -} // ******************************************************************************************************************************* // @@ -194,28 +159,13 @@ void DBGXRender(int *address,int showDisplay) { if (showDisplay == 0) { GFXSetCharacterSize(36,24); - if (CPUGetID() == 65) { - DBGVerticalLabel(21,0,labels,DBGC_ADDRESS,-1); // Draw the labels for the register + DBGVerticalLabel(21,0,labels,DBGC_ADDRESS,-1); // Draw the labels for the register - #define DN(v,w) GFXNumber(GRID(24,n++),v,16,w,GRIDSIZE,DBGC_DATA,-1) // Helper macro + #define DN(v,w) GFXNumber(GRID(24,n++),v,16,w,GRIDSIZE,DBGC_DATA,-1) // Helper macro - DN(s->a,2);DN(s->x,2);DN(s->y,2);DN(s->pc,4);DN(s->sp+0x100,4);DN(s->status,2);DN(s->cycles,4); - DN(s->sign,1);DN(s->overflow,1);DN(s->brk,1);DN(s->decimal,1);DN(s->interruptDisable,1);DN(s->zero,1);DN(s->carry,1); + DN(s->a,2);DN(s->x,2);DN(s->y,2);DN(s->pc,4);DN(s->sp+0x100,4);DN(s->status,2);DN(s->cycles,4); + DN(s->sign,1);DN(s->overflow,1);DN(s->brk,1);DN(s->decimal,1);DN(s->interruptDisable,1);DN(s->zero,1);DN(s->carry,1); - } else { - for (int i = 0;i < 16;i++) { - bool isTest = ((REG(14) >> 8) & 0x0F) == i; - sprintf(buffer,"R%d:",i); - GFXString(GRID(21,i),buffer,GRIDSIZE, DBGC_ADDRESS,-1); - sprintf(buffer,"%04X",REG(i)); - GFXString(GRID(26,i),buffer,GRIDSIZE, isTest ? DBGC_DATA:DBGC_HIGHLIGHT,-1); - GFXString(GRID(32,0),"ACC",GRIDSIZE,DBGC_ADDRESS,-1); - GFXString(GRID(32,12),"SP",GRIDSIZE,DBGC_ADDRESS,-1); - GFXString(GRID(32,13),"CMP",GRIDSIZE,DBGC_ADDRESS,-1); - GFXString(GRID(32,14),"STAT",GRIDSIZE,DBGC_ADDRESS,-1); - GFXString(GRID(32,15),"PCTR",GRIDSIZE,DBGC_ADDRESS,-1); - } - } n = 0; int a = address[1]; // Dump Memory. for (int row = 17;row < 24;row++) { @@ -236,11 +186,7 @@ void DBGXRender(int *address,int showDisplay) { int isBrk = (p == address[3]); GFXNumber(GRID(0,row),p,16,4,GRIDSIZE,isPC ? DBGC_HIGHLIGHT:DBGC_ADDRESS, // Display address / highlight / breakpoint isBrk ? 0xF00 : -1); - if (CPUGetID() == 65) { - p = DBGXDasm65(p, buffer); - } else { - p = DBGXDasm16(p, buffer); - } + p = DBGXDasm65(p, buffer); GFXString(GRID(5,row),buffer,GRIDSIZE,isPC ? DBGC_HIGHLIGHT:DBGC_DATA,-1); // Print the mnemonic } diff --git a/emulator/src/core/sys_processor.cpp b/emulator/src/core/sys_processor.cpp index 6bcb8658..ce415563 100644 --- a/emulator/src/core/sys_processor.cpp +++ b/emulator/src/core/sys_processor.cpp @@ -30,14 +30,9 @@ static int argumentCount; static char **argumentList; static bool useDebuggerKeys = false; // Use the debugger keys. static bool traceMode = false; // Dump each CPU instruction to stdout. -static bool use6502 = true; // CPU Selector WORD16 CPUGetPC(void) { - return use6502 ? CPUGetPC65():CPUGetPC16(); -} - -BYTE8 CPUGetID(void) { - return use6502 ? 65:16; + return CPUGetPC65(); } // ******************************************************************************************************************************* @@ -82,7 +77,6 @@ void CPUSaveArguments(int argc,char *argv[]) { void CPUReset(void) { char command[128]; - use6502 = true; // By default, run 6502 for (int i = 1;i < argumentCount;i++) { // Look for loads. strcpy(command,argumentList[i]); // Copy command @@ -102,8 +96,6 @@ void CPUReset(void) { printf("Run machine code from $%x\n",address); cpuMemory[0xFFFC] = address & 0xFF; // 6502 run. cpuMemory[0xFFFD] = address >> 8; - cpuMemory[30] = address & 0xFF; // Sweet 16 run. - cpuMemory[31] = address >> 8; } else { p = cpuMemory+address; // Load here. if (address == 0xFFFF) p = gfxObjectMemory; // Load to graphics memory @@ -138,17 +130,10 @@ void CPUReset(void) { if (strcmp(command,"trace") == 0) { // Dump every CPU instruction to stdout. traceMode = true; } - if (strcmp(command,"sweet") == 0) { // Use Sweet 16 rather than 65C02 - use6502 = false; - } } } HWReset(); // Reset Hardware - if (use6502) { // Reset whichever Processor - CPUReset6502(); - } else { - CPUReset16(); - } + CPUReset6502(); } // ******************************************************************************************************************************* @@ -176,7 +161,7 @@ BYTE8 CPUExecuteInstruction(void) { return FRAME_RATE; } - if (traceMode && use6502) { + if (traceMode) { char mem[10]; // "XX XX XX \0" char dasm[32]; DBGXDumpMem(CPUGetPC(), DBGXInstructionSize65(CPUGetPC()), mem); @@ -184,11 +169,7 @@ BYTE8 CPUExecuteInstruction(void) { printf("%04x %-10s %s\n", CPUGetPC(), mem, dasm); } - if (use6502) { - forceSync = CPUExecute6502(); - } else { - forceSync = CPUExecute16(); - } + forceSync = CPUExecute6502(); int cycleMax = CYCLES_PER_FRAME; if (cycles < cycleMax && forceSync == 0) return 0; // Not completed a frame. @@ -213,16 +194,6 @@ void CPUWriteMemory(WORD16 address,BYTE8 data) { #include "gfx.h" -// *************************************************************************************** -// -// Handle Sweet16 Sync -// -// *************************************************************************************** - -void TMRSweet16Sync(void) { - cycles = CYCLES_PER_FRAME; // If yields running via API do frame. -} - // ******************************************************************************************************************************* // // Execute chunk of code, to either of two break points or frame-out, return non-zero frame rate on frame, breakpoint 0 @@ -231,7 +202,7 @@ void TMRSweet16Sync(void) { BYTE8 CPUExecute(WORD16 breakPoint1,WORD16 breakPoint2) { BYTE8 next; - BYTE8 brk = use6502 ? 0x03: 0x0A; + BYTE8 brk = 0x03; do { BYTE8 r = CPUExecuteInstruction(); // Execute an instruction if (r != 0) return r; // Frame out. @@ -248,7 +219,7 @@ BYTE8 CPUExecute(WORD16 breakPoint1,WORD16 breakPoint2) { WORD16 CPUGetStepOverBreakpoint(void) { BYTE8 opcode = CPUReadMemory(CPUGetPC()); // Current opcode. - int offset = use6502 ? CPUGetStep65(opcode) : CPUGetStep16(opcode); // Get offset + int offset = CPUGetStep65(opcode); // Get offset if (offset != 0) offset = (CPUGetPC()+offset) & 0xFFFF; // Step over Subroutines return offset; // Do a normal single step } diff --git a/examples/basic/demos/sweetapi.bas b/examples/basic/demos/sweetapi.bas deleted file mode 100644 index fe765a46..00000000 Binary files a/examples/basic/demos/sweetapi.bas and /dev/null differ diff --git a/examples/basic/demos/sweetapi.bsc b/examples/basic/demos/sweetapi.bsc deleted file mode 100644 index 56f755df..00000000 --- a/examples/basic/demos/sweetapi.bsc +++ /dev/null @@ -1,39 +0,0 @@ -' -' Sweet 16 program showing calling API very simply. -' -mem = alloc(512):reg = alloc(32):stack = alloc(16) -count = 50 -print mem -for pass = 0 to 1 - o = pass*2:p = mem - - set 2,42 - bs printchar - set 2,65 - bs printchar - rtn - -.printchar - bs waitfree - set 1,$FF04 - ld 2 - st @1 - set 1,$FF02 - set 0,6 - stp @1 - set 0,2 - stp @1 - bs waitfree - rs - -.waitfree - set 1,$FF00 - ld @1 - add 0 - bnz waitfree - rs -next - -reg[15] = mem:reg[12] = stack - -sweet reg diff --git a/examples/basic/demos/sweetbm.bas b/examples/basic/demos/sweetbm.bas deleted file mode 100644 index 90ae6c2e..00000000 Binary files a/examples/basic/demos/sweetbm.bas and /dev/null differ diff --git a/examples/basic/demos/sweetbm.bsc b/examples/basic/demos/sweetbm.bsc deleted file mode 100644 index 141e3a3a..00000000 --- a/examples/basic/demos/sweetbm.bsc +++ /dev/null @@ -1,34 +0,0 @@ -' -' Sweet 16 test program ; about 6.7 MIPS. -' -mem = alloc(512):reg = alloc(32):stack = alloc(16) -count = 50 -print mem -for pass = 0 to 1 - o = pass*2:p = mem - set 1,count - set 2,0 - set 5,0 -.l1 - add 3 - dcr 2 - bnz l1 - inr 5 - dcr 1 - bnz l1 - rtn -next - -reg[15] = mem:reg[12] = stack - -t1 = time() -sweet reg -elapsed = time()-t1 -print reg[5],reg[15] -if elapsed <> 0 - print elapsed - elapsed = elapsed / 100 / 3 / 65535 / count - ips = 1 / elapsed - mips = ips / 1000000 - print mips -endif diff --git a/examples/basic/examples/mixedassembler.bas b/examples/basic/examples/mixedassembler.bas index 993eaecd..e4470839 100644 Binary files a/examples/basic/examples/mixedassembler.bas and b/examples/basic/examples/mixedassembler.bas differ diff --git a/firmware/common/Makefile b/firmware/common/Makefile index 7b90f06c..87b434c4 100644 --- a/firmware/common/Makefile +++ b/firmware/common/Makefile @@ -20,8 +20,6 @@ endif all: $(MAKE) -B -C bootdisplay - $(PYTHON) $(COMDIR)scripts$(S)sweet16.py $(COMDIR)scripts$(S)sweet16.gen >$(COMDIR)include$(S)data$(S)sweet_opcodes.h - $(PYTHON) $(COMDIR)scripts$(S)makedispatch.py dispatch.config >$(COMDIR)include$(S)data$(S)dispatch_code.h touch sources$(S)interface$(S)dispatch.cpp $(CCOPY) $(BINDIR)basic_binary.h include$(S)data diff --git a/firmware/common/config/system/group1_system.inc b/firmware/common/config/system/group1_system.inc index e3bf8bdc..81152fd0 100644 --- a/firmware/common/config/system/group1_system.inc +++ b/firmware/common/config/system/group1_system.inc @@ -71,13 +71,6 @@ GROUP 1 System DOCUMENTATION Do a MOS command (a '* command') these are specified in the Wiki as they will be steadily expanded. - FUNCTION 9 Sweet 16 Virtual Machine - *DERROR = SW16Execute(DSPGetInt16(DCOMMAND,4)) ? 1 : 0; - DOCUMENTATION - Execute Sweet 16 VM Code with the register set provided. The error return value is actually a re-entrant - call for Windows emulation ; if it returns non-zero it means the VM has been executed, if it returns zero - then the emulation can update as at the end of a normal frame. - FUNCTION 10 Write character to debug FDBWrite(DPARAMS[0]); DOCUMENTATION diff --git a/firmware/common/include/common.h b/firmware/common/include/common.h index b284f513..684a0bdc 100644 --- a/firmware/common/include/common.h +++ b/firmware/common/include/common.h @@ -67,7 +67,6 @@ #include "interface/blitter.h" #include "interface/gamepad.h" #include "interface/editor.h" -#include "interface/sweet16.h" #endif diff --git a/firmware/common/include/interface/sweet16.h b/firmware/common/include/interface/sweet16.h deleted file mode 100644 index 81da967b..00000000 --- a/firmware/common/include/interface/sweet16.h +++ /dev/null @@ -1,27 +0,0 @@ -// *************************************************************************************** -// *************************************************************************************** -// -// Name : sweet16.h -// Authors : Paul Robson (paul@robsons.org.uk) -// Date : 10th April 2024 -// Reviewed : No -// Purpose : Sweet 16 header. -// -// *************************************************************************************** -// *************************************************************************************** - -#ifndef _SWEET16_H -#define _SWEET16_H - -bool SW16Execute(uint16_t reg); -bool SW16ExecuteOne(uint16_t reg); -void SW16ExtendedRegister(uint8_t func,uint8_t reg); - -#endif - -// *************************************************************************************** -// -// Date Revision -// ==== ======== -// -// *************************************************************************************** diff --git a/firmware/common/scripts/sweet16.gen b/firmware/common/scripts/sweet16.gen deleted file mode 100644 index 023745d1..00000000 --- a/firmware/common/scripts/sweet16.gen +++ /dev/null @@ -1,234 +0,0 @@ -# *************************************************************************************** -# *************************************************************************************** -# -# Name : sweet16.gen -# Authors : Paul Robson (paul$Robsons.org.uk) -# Date : 10th April 2024 -# Reviewed : No -# Purpose : Sweet 16 emulation code source. -# -# *************************************************************************************** -# *************************************************************************************** - - -# *************************************************************************************** -# 1x ll hh : Load constant -# *************************************************************************************** - -1? "SET R$R,$2" - R($R) = FETCH16(); - SETCOMP($R); - -# *************************************************************************************** -# 2x : Load R0 from Rx -# *************************************************************************************** - -2? "LD R$R" - R(0) = R($R); - SETCOMP($R); - -# *************************************************************************************** -# 3x : Store R0 to Rx -# *************************************************************************************** - -3? "ST R$R" - R($R) = R(0); - SETCOMP($R); - -# *************************************************************************************** -# 4x : Load byte R0 from Rx, post increment -# *************************************************************************************** - -4? "LD @R$R" - R(0) = READ8(R($R)); - R($R)++; - SETCOMP($R); - -# *************************************************************************************** -# 5x : Store byte R0 to Rx, post increment -# *************************************************************************************** - -5? "LD @R$R" - WRITE8(R($R),R(0)); - R($R)++; - SETCOMP($R); - -# *************************************************************************************** -# 6x : Load word R0 from Rx, post increment -# *************************************************************************************** - -6? "LDD @R$R" - R(0) = READ16(R($R)); - R($R) += 2; - SETCOMP($R); - -# *************************************************************************************** -# 7x : Store word R0 to Rx, post increment -# *************************************************************************************** - -7? "STD @R$R" - WRITE16(R($R),R(0)); - R($R) += 2; - SETCOMP($R); - -# *************************************************************************************** -# 8x : Load byte R0 from Rx, pre decrement -# *************************************************************************************** - -8? "POP @R$R" - R($R)--; - R(0) = READ8(R($R)); - -# *************************************************************************************** -# 9x : Store byte R0 to Rx, pre decrement -# *************************************************************************************** - -9? "STP @R$R" - R($R)--; - WRITE8(R($R),R(0)); - SETCOMP($R); - -# *************************************************************************************** -# Ax : Add Rx to R0, carry out, test R0 -# *************************************************************************************** - -A? "ADD R$R" - R(0) = ADD16(R(0),R($R),0); - SETCOMP(0); - -# *************************************************************************************** -# Bx : Sub Rx from R0, carry out, test R0 -# *************************************************************************************** - -B? "SUB R$R" - R(0) = ADD16(R(0),R($R) ^ 0xFFFF,1); - SETCOMP(0); - -# *************************************************************************************** -# Cx : Load word R0 from Rx, pre decrement -# *************************************************************************************** - -C? "POPD @R$R" - R($R) -= 2; - R(0) = READ16(R($R)); - SETCOMP($R); - -# *************************************************************************************** -# Dx : Sub Rx from R0 to R13, carry out, test R13 -# *************************************************************************************** - -D? "CPR R$R" - R(13) = ADD16(R(0),R($R) ^ 0xFFFF,1); - SETCOMP(13); - -# *************************************************************************************** -# Ex : Increment Rx -# *************************************************************************************** - -E? "INR R$R" - R($R)++; - CLEARCARRY(); - SETCOMP($R); - -# *************************************************************************************** -# Fx : Decrement Rx -# *************************************************************************************** - -F? "DCR R$R" - R($R)--; - CLEARCARRY(); - SETCOMP($R); - -# *************************************************************************************** -# 00 RTN : exit to 6502 -# *************************************************************************************** - -00 "RTN" - bQuitSweet = true; - -# *************************************************************************************** -# 01-09 : Branches -# *************************************************************************************** - -01 "BR $1" - BRANCHIF(1); - -02 "BNC $1" - BRANCHIF(CARRY() == 0); - -03 "BC $1" - BRANCHIF(CARRY() != 0); - -04 "BP $1" - BRANCHIF((TESTVALUE() & 0x8000) == 0); - -05 "BM $1" - BRANCHIF((TESTVALUE() & 0x8000) != 0); - -06 "BZ $1" - BRANCHIF(TESTVALUE() == 0); - -07 "BNZ $1" - BRANCHIF(TESTVALUE() != 0); - -08 "BM1 $1" - BRANCHIF(TESTVALUE() == 0xFFFF); - -09 "BNM1 $1" - BRANCHIF(TESTVALUE() != 0xFFFF); - -# *************************************************************************************** -# 0A BK : debug dump -# *************************************************************************************** - -0A "BK" - ; - -# *************************************************************************************** -# 0B RS : subroutine return -# *************************************************************************************** - -0B "RS" - R(12) -= 2; - R(15) = READ16(R(12)); - -# *************************************************************************************** -# 0C BS : branch to subroutine (relative short) -# *************************************************************************************** - -0C "BS $1" - WRITE16(R(12),R(15)+1); - R(12) += 2; - BRANCHIF(1); - CLEARCARRY(); - SETCOMP(0); - -# *************************************************************************************** -# -# Extensions to the Sweet 16 standard -# -# *************************************************************************************** - -# *************************************************************************************** -# 0D BSL : branch to subroutine (relative long) -# *************************************************************************************** - -0D "BSL $2" - WRITE16(R(12),R(15)+2); - R(12) += 2; - temp = FETCH16(); - R(15) += temp; - CLEARCARRY(); - SETCOMP(0); - -# *************************************************************************************** -# 0E nr : Extended function on register Rn, function n. Comparison is n -# *************************************************************************************** - -0E "EXT $x" - temp = FETCH8(); - SW16ExtendedRegister(temp >> 4,temp & 15); - CLEARCARRY(); - SETCOMP(temp & 15); - - diff --git a/firmware/common/scripts/sweet16.py b/firmware/common/scripts/sweet16.py deleted file mode 100644 index bc58ca9d..00000000 --- a/firmware/common/scripts/sweet16.py +++ /dev/null @@ -1,65 +0,0 @@ -# *************************************************************************************** -# *************************************************************************************** -# -# Name : sweet16.py -# Authors : Paul Robson (paul@robsons.org.uk) -# Date : 10th April 2024 -# Reviewed : No -# Purpose : Sweet 16 emulation code generator. -# -# *************************************************************************************** -# *************************************************************************************** - -import sys,os,re - -def process(s,n): - s = s.replace("$R",str(n & 0x0F)) - return s - -mnemonics = [ None ] * 256 -code = [ "" ] * 256 -currentFirst = None -currentLast = None - -for f in sys.argv[1:]: - for s in [x.rstrip() for x in open(f).readlines() if not x.startswith("#") and x.strip() != ""]: - if (s[0] >= '0' and s[0] <= '9') or (s[0] >= 'A' and s[0] <= 'Z'): - m = re.match('^([0-9A-F\\?]+)\\s*\\"(.*)\\"\\s*$',s) - assert m is not None,"Bad line "+s - opcode = m.group(1) - if opcode[1] == '?': - currentFirst = int(opcode[0],16) << 4 - currentLast = currentFirst+15 - for i in range(currentFirst,currentLast+1): - assert mnemonics[i] is None,"Duplicate" - s = m.group(2).replace("\t"," ").split(" ") - s[0] = (s[0]+" ")[:4] - mnemonics[i] = process(" ".join(s),i) - else: - currentFirst = int(opcode,16) - currentLast = currentFirst - assert mnemonics[currentFirst] is None,"Duplicate" - s = m.group(2).replace("\t"," ").split(" ") - s[0] = (s[0]+" ")[:4] - mnemonics[currentFirst] = process(" ".join(s),i) - else: - assert currentFirst is not None,"Code outside definition" - for i in range(currentFirst,currentLast+1): - code[i] = code[i] + s.strip() - - -print("//\n//\tThis code is automatically generated.\n//") -print("#ifdef SW16_OPCODES") -for i in range(0,256): - if mnemonics[i] is not None: - m = process(mnemonics[i],i) - print("case 0x{0:02x}: // ${0:02x} {0:3d} {1}".format(i,m)) - print("\t{0};break;\n".format(process(code[i],i))) -print("#endif") - -print() - -s = ['"'+x.lower()+'"' if x is not None else '"?"' for x in mnemonics] -print("#ifdef SW16_MNEMONICS") -print("static const char *sw16Mnemonics[256] = {{ {0} }};\n".format(",".join(s))) -print("#endif") diff --git a/firmware/common/sources/interface/sweet16.cpp b/firmware/common/sources/interface/sweet16.cpp deleted file mode 100644 index 431cbf16..00000000 --- a/firmware/common/sources/interface/sweet16.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// *************************************************************************************** -// *************************************************************************************** -// -// Name : sweet16.cpp -// Authors : Paul Robson (paul@robsons.org.uk) -// Date : 10th April 2024 -// Reviewed : No -// Purpose : Sweet 16 virtual machine -// -// *************************************************************************************** -// *************************************************************************************** - -#include "common.h" - -// *************************************************************************************** -// -// Register values during emulation -// -// *************************************************************************************** - -static uint16_t default_sweet_registers[16]; - -static uint16_t *sweet_reg = default_sweet_registers; - -// *************************************************************************************** -// -// Helper macros/functions -// -// *************************************************************************************** - -#define R(r) sweet_reg[r] - -#define FETCH8() cpuMemory[sweet_reg[15]++] -#define FETCH16() _SWFetch16(); - -#define READ8(a) cpuMemory[a] -#define READ16(a) (READ8(a) | (READ8((a)+1) << 8)) - -#define WRITE8(a,d) _SWWrite8(a,(d) & 0xFF) -#define WRITE16(a,d) { WRITE8(a,d);WRITE8((a)+1,(d) >> 8); } - -#define SETCOMP(r) sweet_reg[14] = (sweet_reg[14] & 0x00FF) | (r << 8) -#define CLEARCARRY() sweet_reg[14] &= 0xFFFE -#define CARRY() (sweet_reg[14] & 0x1) -#define TESTVALUE() sweet_reg[(sweet_reg[14] >> 8) & 0x0F] - -#define BRANCHIF(t) _SW16ConditionalBranch(t) - -#define ADD16(a,b,c) _SWAdd16(a,b,c) - -// -// 8 bit write with system trigger. -// -static void _SWWrite8(uint16_t a,uint8_t d) { - cpuMemory[a] = d; - if (a == controlPort) DSPHandler(cpuMemory + controlPort, cpuMemory); -} -// -// 16 bit fetch -// -static inline uint16_t _SWFetch16(void) { - uint8_t v = FETCH8(); - return v | (FETCH8() << 8); -} - -// -// 16 bit 2's complement addition with carry in, used for add & subtract -// -static inline uint16_t _SWAdd16(uint16_t a,uint16_t b,uint16_t c) { - uint32_t result = a + b + c; - if (result & 0x10000) { - sweet_reg[14] |= 0x0001; - } else { - sweet_reg[14] &= 0xFFFE; - } - return result & 0xFFFF; -} - -// -// Short (e.g. 8 bit) conditional branch, same as 65C02 basically. -// -static inline void _SW16ConditionalBranch(bool test) { - if (test != 0) { - uint16_t offset = FETCH8(); - if (offset & 0x80) offset |= 0xFF00; - sweet_reg[15] += offset; - } else { - sweet_reg[15]++; - } -} - -// *************************************************************************************** -// -// Dump Registers (if not zero) -// -// *************************************************************************************** - -// static void _SW16Status() { -// for (int i = 0;i < 16;i++) { -// if (sweet_reg[i] != 0) { -// CONWriteString("R%-2d: $%04x (%d) $%02x\r",i,sweet_reg[i],sweet_reg[i],cpuMemory[sweet_reg[i]]); -// } -// } -// } - -// *************************************************************************************** -// -// Execute sweet 16 code. Returns true to exit, false to yield (for Windows) -// -// *************************************************************************************** - -#define SW16_OPCODES - -bool SW16Execute(uint16_t reg) { - bool bQuitSweet = false; // Set by RTN. - int32_t yieldCounter = 6000000/60; // 6 MIPS , 60 frames per second - uint16_t temp; // (set by the emulator) - sweet_reg = default_sweet_registers; // Execute using the memory allocated. - for (int i = 0;i < 16;i++) { // Copy cpu memory to working registers - sweet_reg[i] = cpuMemory[reg+i*2]+(cpuMemory[reg+i*2+1] << 8); - } - while (!bQuitSweet && yieldCounter-- > 0) { // Keep executing till quit or yield time. - switch(FETCH8()) { - #include "data/sweet_opcodes.h" - } - } - for (int i = 0;i < 16;i++) { // Copy working registers to CPU memory - cpuMemory[reg+i*2] = sweet_reg[i] & 0xFF; - cpuMemory[reg+i*2+1] = sweet_reg[i] >> 8; - } - TMRSweet16Sync(); // Sweet 16 Frame Sync - return bQuitSweet; -} - -// *************************************************************************************** -// -// Same code as above, does only one command -// -// *************************************************************************************** - -bool SW16ExecuteOne(uint16_t reg) { - bool bQuitSweet = false; // Set by RTN. - uint16_t temp; // (set by the emulator) - sweet_reg = (uint16_t *)(cpuMemory+reg); // This is non RISC so we can access directly. - switch(FETCH8()) { - #include "data/sweet_opcodes.h" - } - sweet_reg = default_sweet_registers; // Execute using the memory allocated. - return bQuitSweet; -} - -// *************************************************************************************** -// Extended register handler -// *************************************************************************************** - -void SW16ExtendedRegister(uint8_t func,uint8_t reg) { - switch (func) { - case 0: // 0 multiply by Rn - R(0) = R(0) * R(reg);break; - case 1: // 1 divide by Rn - R(0) = (R(reg) == 0) ? 0 :R(0) / R(reg);break; - case 2: // 2 and by Rn - R(0) = R(0) & R(reg);break; - case 3: // 3 or by Rn - R(0) = R(0) | R(reg);break; - case 4: // 4 xor by Rn - R(0) = R(0) ^ R(reg);break; - case 5: // 5 Shift Right Rn - R(reg) = R(reg) >> 1;break; - } -} - - -// *************************************************************************************** -// -// Date Revision -// ==== ======== -// -// *************************************************************************************** diff --git a/firmware/sources/hardware/timer.cpp b/firmware/sources/hardware/timer.cpp index a35b7da7..48e0688f 100644 --- a/firmware/sources/hardware/timer.cpp +++ b/firmware/sources/hardware/timer.cpp @@ -23,16 +23,6 @@ uint32_t TMRRead(void) { return (time32 * 210) >> 11; // Error of about 0.07% } -// *************************************************************************************** -// -// Handle Sweet16 Sync -// -// *************************************************************************************** - -void TMRSweet16Sync(void) { - DSPSync(); -} - // *************************************************************************************** // // Date Revision diff --git a/release/Makefile b/release/Makefile index 1e73222c..1f371a5d 100644 --- a/release/Makefile +++ b/release/Makefile @@ -38,7 +38,7 @@ BINARIES = $(BINDIR)*.uf2 $(BINDIR)*.elf \ # PYTHONAPPS = $(BINDIR)makebasic.zip $(BINDIR)listbasic.zip $(BINDIR)exec.zip \ $(BINDIR)createblanks.zip $(BINDIR)makeimg.zip $(BINDIR)cvimg.zip \ - $(BINDIR)nxmit.zip $(BINDIR)swasm.zip + $(BINDIR)nxmit.zip # *************************************************************************************** #