diff --git a/basic/scripts/opcodes.py b/basic/scripts/opcodes.py index d6503ed28..ea9206123 100644 --- a/basic/scripts/opcodes.py +++ b/basic/scripts/opcodes.py @@ -75,7 +75,6 @@ CA dex 4 d8 cld 4 da phx 4 -db stp 4 e8 inx 4 EA nop 4 f8 sed 4 diff --git a/basic/sources/arithmetic/term.asm b/basic/sources/arithmetic/term.asm index a84c652e4..64f105a15 100644 --- a/basic/sources/arithmetic/term.asm +++ b/basic/sources/arithmetic/term.asm @@ -51,7 +51,7 @@ _ETKeyword: _ETShiftUnary: iny ; get the shifted value lda (codePtr),y - cmp #$D0 ; not a unary function + cmp #$E0 ; not a unary function bcc _ETSyntax phx asl a ; access address to jump diff --git a/basic/sources/assembler/assembler.asm b/basic/sources/assembler/6502/assembler.asm similarity index 98% rename from basic/sources/assembler/assembler.asm rename to basic/sources/assembler/6502/assembler.asm index a6a1f95eb..2fdffe986 100644 --- a/basic/sources/assembler/assembler.asm +++ b/basic/sources/assembler/6502/assembler.asm @@ -109,8 +109,11 @@ AssembleGroup3: jsr AccessParameters ; get and output opcode jsr AssemblerWriteByte - jsr CalculateOperand ; get a 16 bit operand - ; + jsr CalculateOperand ; get a 16 bit operand +; +; Assemble a relative branch. +; +AssembleRelativeBranch: lda XSNumber0 ; calculate the offset sec sbc VariableP diff --git a/basic/sources/assembler/constants.inc b/basic/sources/assembler/6502/constants.inc similarity index 100% rename from basic/sources/assembler/constants.inc rename to basic/sources/assembler/6502/constants.inc diff --git a/basic/sources/assembler/instruction.asm b/basic/sources/assembler/6502/instruction.asm similarity index 100% rename from basic/sources/assembler/instruction.asm rename to basic/sources/assembler/6502/instruction.asm diff --git a/basic/sources/assembler/operands.asm b/basic/sources/assembler/6502/operands.asm similarity index 100% rename from basic/sources/assembler/operands.asm rename to basic/sources/assembler/6502/operands.asm diff --git a/basic/sources/assembler/aswrite.asm b/basic/sources/assembler/common/aswrite.asm similarity index 100% rename from basic/sources/assembler/aswrite.asm rename to basic/sources/assembler/common/aswrite.asm diff --git a/basic/sources/assembler/label.asm b/basic/sources/assembler/common/label.asm similarity index 100% rename from basic/sources/assembler/label.asm rename to basic/sources/assembler/common/label.asm diff --git a/basic/sources/assembler/sweet/opcodes.asm b/basic/sources/assembler/sweet/opcodes.asm new file mode 100644 index 000000000..f3c19fd7c --- /dev/null +++ b/basic/sources/assembler/sweet/opcodes.asm @@ -0,0 +1,232 @@ +; ************************************************************************************************ +; ************************************************************************************************ +; +; 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 $50 + 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 +; +; 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_BS: ;; [BS] + .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 new file mode 100644 index 000000000..f1e0171f3 --- /dev/null +++ b/basic/sources/assembler/sweet/operands.asm @@ -0,0 +1,56 @@ +; ************************************************************************************************ +; ************************************************************************************************ +; +; 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/base/run.asm b/basic/sources/commands/base/run.asm index 6b75fbca9..3298c0f34 100644 --- a/basic/sources/commands/base/run.asm +++ b/basic/sources/commands/base/run.asm @@ -140,7 +140,7 @@ Command_Shift1_Handler: ;; [!!sh1] Command_Shift2_Handler: ;; [!!sh2] lda (codePtr),y ; get token shifted - cmp #$D0 ; D0 up are unary functions + cmp #$E0 ; E0 up are unary functions bcs _CS2Fail iny asl a ; double into X diff --git a/basic/test.bsc b/basic/test.bsc index 6e8ab1b51..75d228b69 100644 --- a/basic/test.bsc +++ b/basic/test.bsc @@ -1,16 +1,42 @@ ' -' BASIC Mouse cursor manipulation +' Assembler pair test ' -mouse show -mouse to 260,180 -repeat - b = mouse(x,y,s) - print chr$(20);x;" ";y;" ";b;" ";s;" " -until false -end -' -proc send.message(g,f) - while peek($FF00):wend - poke $FF01,f:poke $FF00,g - while peek($FF00):wend -endproc \ No newline at end of file +mem = alloc(512) +for pass = 0 to 1 + p = mem + o = pass * 3 + + rs + rtn + + set 5,32767 + ld 11 + st 12 + ld @13 + st @14 + + ldd @1 + std @2 + pop @3 + stp @4 + add 5 + sub 6 + popd @10 + cpr 7 + inr 8 + dcr 9 + + br p1 + bnc p1 +.p1 + bc p1 + bp p1 + bm p1 + bz p1 + bnz p1 + bm1 p1 + bnm1 p1 + bs p1 + bs p2 +.p2 +next diff --git a/documents/release/basic.pdf b/documents/release/basic.pdf new file mode 100644 index 000000000..217798155 Binary files /dev/null and b/documents/release/basic.pdf differ diff --git a/examples/basic/examples/mixedassembler.bsc b/examples/basic/examples/mixedassembler.bsc new file mode 100644 index 000000000..a91a04e18 --- /dev/null +++ b/examples/basic/examples/mixedassembler.bsc @@ -0,0 +1,47 @@ +' +' Assembler pair test +' +' Test of sweet 16 assembler, with a little 65C02 +' +mem = alloc(512) +for pass = 0 to 1 + p = mem + o = pass * 3 + + nop + + rs + rtn + + set 5,32767 + ld 11 + st 12 + ld @13 + st @14 + + ldd @1 + std @2 + pop @3 + stp @4 + add 5 + sub 6 + popd @10 + cpr 7 + inr 8 + dcr 9 + + br p1 + bnc p1 +.p1 + bc p1 + bp p1 + bm p1 + bz p1 + bnz p1 + bm1 p1 + bnm1 p1 + bs p1 + bs p2 +.p2 + nop +next