breakintoprogram / agon-bbc-basic-adl

Official AGON QUARK Firmware: BASIC Interpreter (ADL version)
zlib License
16 stars 0 forks source link

Add functionality to aid testing the assembler #17

Closed breakintoprogram closed 8 months ago

breakintoprogram commented 8 months ago

As a developer I want to be able to write assembly language tests So that I can quickly validate all instruction sets

Requirements:

  1. Be able to assemble an instruction contained within a BASIC string
  2. Call the existing assembler in BBC BASIC
  3. Throw any error messages and stop if the instruction is invalid

Idea:

breakintoprogram commented 8 months ago

Example test:

   10 DIM CODE% 16
   20 PROCasm("LD A,5","3E05")
   30 PROCasm("RET","C9")
   40 PROCasm("LDIR","42"): REM A deliberate error
  980 :
  990 STOP
 1000 DEF PROCasm(asm$,output$)
 1010 P%=CODE%
 1020 OSCLI("ASM "+asm$)
 1025 P%=CODE%
 1030 FOR I%=1 TO LEN(output$) STEP 2
 1040   H$=MID$(output$,I%,2)
 1050   B%=EVAL("&"+H$)
 1060   IF B%<>?P% THEN PRINT "ERROR! EXPECTED "+output$:STOP
 1070   P%=P%+1
 1080 NEXT
 1090 ENDPROC

Output:

>RUN
044F2E 3E 05          LD A,5
044F2E C9             RET
044F2E ED B0          LDIR
ERROR! EXPECTED 42

STOP at line 1060