From f917afff6aae33a2853689373d9931bf3be76722 Mon Sep 17 00:00:00 2001 From: mooz Date: Sat, 10 Nov 2018 12:50:03 +0100 Subject: [PATCH] Added JRE instruction. --- l7801.lua | 6 +++--- samples/scv_hello.l65 | 4 ++-- samples/scv_test.l65 | 21 +++++++++++++++++++-- uPD7801.lua | 37 +++++++++++++++++++++++++++---------- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/l7801.lua b/l7801.lua index b080f16..874b7a1 100644 --- a/l7801.lua +++ b/l7801.lua @@ -40,7 +40,7 @@ local Keywords_data = { local Keywords_7801 = { 'aci','adi','adinc','ani', 'block','calb','calf','call','calt','clc','ei','eqi','daa','di','dcr','dcx', - 'ex','exx','gti','halt','inr','inx','jb','jmp','jr','lti','lxi','mov','mvi','nei','nop', + 'ex','exx','gti','halt','inr','inx','jb','jmp','jr','jre','lti','lxi','mov','mvi','nei','nop', 'offi','oni','ori','pen','per','pex','ret','reti','rets','rld','rrd','sio','softi','stc','stm', 'sbi','sui','suinb','table','xri', } @@ -72,10 +72,10 @@ local opcode_implied = lookupify{ } local opcode_immediate = lookupify{ - 'calf', 'calt','call','jmp' + 'calf','calt','call','jmp' } local opcode_relative = lookupify{ - 'jr', + 'jr','jre' } local opcode_reg = lookupify{ 'dcr','dcx','inr','inx' diff --git a/samples/scv_hello.l65 b/samples/scv_hello.l65 index 1129fa1..725e08b 100644 --- a/samples/scv_hello.l65 +++ b/samples/scv_hello.l65 @@ -14,7 +14,7 @@ section{"rom", org=0x8000} block lxi hl,message - lxi de,0x3043 + lxi de,0x3044 lxi bc,0x01ff @loop_0 @@ -34,7 +34,7 @@ section{"vdc_data", org=0x8030} dc.b 0xC0,0x00,0x00,0xF2 section{"message", org=0x8040} - dc.b "hello world" + dc.b "\t\t\t\t Hello world! \t\t\t\t" dc.b 0x00 writebin(filename .. '.bin') \ No newline at end of file diff --git a/samples/scv_test.l65 b/samples/scv_test.l65 index 3a1f3cd..edd5877 100644 --- a/samples/scv_test.l65 +++ b/samples/scv_test.l65 @@ -76,6 +76,23 @@ section{"rom", org=0x8000} mov e,a mov h,a mov l,a - - +@l0 jre l0 +@l1 nop + jre l1 +@l2 nop nop + jre l2 +@l3 nop nop nop + jre l3 +@l4 nop nop nop nop + jre l4 + jre l5 +@l5 jre l6 + nop +@l6 jre l7 + nop nop +@l7 jre l8 + nop nop nop +@l8 jre l9 + nop nop nop nop +@l9 writebin(filename .. '.bin') \ No newline at end of file diff --git a/uPD7801.lua b/uPD7801.lua index 4df0675..5bf0ee7 100644 --- a/uPD7801.lua +++ b/uPD7801.lua @@ -207,6 +207,33 @@ M.jr = function(label) table.insert(M.section_current.instructions, op) end +M.jre = function(label) + local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local parent,offset = M.label_current + local section,rorg = M.section_current,M.location_current.rorg + local op = { cycles=17 } + op.size = function() + offset = section.size + label = M.size_dc(label) + return 2 + end + op.bin = function() + local l65dbg=l65dbg + local x,l = label,label + if type(x) == 'function' then x=x() end + if type(x) == 'string' then + if x:sub(1,1) == '_' then x=parent..x l=x end + x = symbols[x] + end + if type(x) ~= 'number' then error("unresolved branch target: " .. tostring(x)) end + x = x-2 - offset - rorg(section.org) + if x < -128 or x > 127 then error("branch target out of range for " .. l .. ": " .. x) end + local opcode = x >= 0 and 0x4e or 0x4f + return { opcode, x&0xff } + end + table.insert(M.section_current.instructions, op) +end + local op48imp = { ei=M.op(0x20,8), di=M.op(0x24,8), @@ -228,8 +255,6 @@ return M --[[ [todo] 8 bits instructions: - JRE+ 0x4e xx 17 - JRE- 0x4f xx 17 -- d ldaxm=M.op(0x2e,7), @@ -257,14 +282,6 @@ return M bit6=M.op(0x5e,10), bit7=M.op(0x5f,10) - -- hhll - call=M.op(0x44,16), - jmp=M.op(0x54,10), - lxisp=M.op(0x04,10), - lxibc=M.op(0x14,10), - lxide=M.op(0x24,10), - lxihl=M.op(0x34,10) - -- (r16),hhll mvixbc=M.op(0x49,10), mvixde=M.op(0x4a,10),