public void globals2() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; string lines = " nop\n nop\n nop\ntest: ld hl,test \n nop\n"; z.parse(lines, ""); z.link(); z.partialreset(); Assert.IsFalse(wasCalled); lines = " .extern test \n nop\n nop\n nop\n ld hl,(test) \n nop\n"; z.parse(lines, ""); z.link(); Assert.IsFalse(wasCalled); z.finallink(); Assert.IsTrue(wasCalled); }
public void labelmath2() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; string lines = " .global test\n nop\n nop\ntest: .db 10,20,30"; z.parse(lines, ""); Assert.IsFalse(wasCalled); z.link(); Assert.IsFalse(wasCalled); lines = " .extern test\n nop\n nop\n ld a,(test+1)"; z.partialreset(); z.parse(lines, ""); Assert.IsFalse(wasCalled); z.link(); Assert.IsFalse(wasCalled); z.finallink(); Assert.IsFalse(wasCalled); }
public void labels() { z80assembler z = new z80assembler(); z.loadcommands(); z.reset(); //Check labels work z.pushcommand("nop", "", "", ""); z.pushcommand("nop", "", "", ""); z.pushcommand("nop", "", "", ""); z.pushcommand("nop", "", "", ""); z.pushcommand("nop", "", "", ""); z.pushlabel("test"); z.fixlabel("test"); z.pushcommand("LD", "A", "(test)", " LD A,(test)"); z.link(); // Test is at address 5 so expect 05 00 jump address Assert.AreEqual(z.bytes[6], 05); Assert.AreEqual(z.bytes[7], 00); z.parse(" LD HL,test", ""); Assert.AreEqual(0x21, z.bytes[8]); Assert.AreEqual(00, z.bytes[9]); Assert.AreEqual(00, z.bytes[10]); z.link(); Assert.AreEqual(z.bytes[9], 0x05); Assert.AreEqual(z.bytes[10], 00); z.parse(" LD HL,5+5", ""); Assert.AreEqual(z.bytes[11], 0x21); Assert.AreEqual(z.bytes[12], 0x0A); Assert.AreEqual(z.bytes[13], 0x00); //z.matchbreak = true; z.parse(" LD HL,(test+5)", ""); z.link(); Assert.AreEqual(z.bytes[14], 0x2A); Assert.AreEqual(z.bytes[15], 0x0A); Assert.AreEqual(z.bytes[16], 0x00); // DD CB oo C6+8*b //z.parse( " SET 3, (IX+5)",""); //Assert.AreEqual(z.bytes[17] , 0xDD); //Assert.AreEqual(z.bytes[18] , 0xCB); //Assert.AreEqual(z.bytes[19] , 0x05); //Assert.AreEqual(z.bytes[20] , 0xC6+8*3); z.link(); }
public void definedata1() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; string lines = "test: .db 10h,20h,30h,40h\ntest1: .db 'Hello World',0"; z.parse(lines, ""); Assert.IsFalse(wasCalled); Assert.AreEqual(0x10, z.bytes[0]); Assert.AreEqual(0x20, z.bytes[1]); Assert.AreEqual(0x30, z.bytes[2]); Assert.AreEqual(0x40, z.bytes[3]); Assert.AreEqual('H', z.bytes[4]); Assert.AreEqual('e', z.bytes[5]); Assert.AreEqual('l', z.bytes[6]); Assert.AreEqual('l', z.bytes[7]); Assert.AreEqual('o', z.bytes[8]); Assert.AreEqual(' ', z.bytes[9]); Assert.AreEqual('W', z.bytes[10]); Assert.AreEqual('o', z.bytes[11]); Assert.AreEqual('r', z.bytes[12]); Assert.AreEqual('l', z.bytes[13]); Assert.AreEqual('d', z.bytes[14]); Assert.AreEqual(0, z.bytes[15]); }
public void labelmath1() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; //string lines = "test: .db 10,20,30,40\n ld hl,(test+1) \n "; string lines = " ld hl,(test+1) \ntest: .db 10,20,30,40"; z.parse(lines, ""); Assert.IsFalse(wasCalled); z.link(); Assert.IsFalse(wasCalled); //33 nn case Assert.AreEqual(42, z.bytes[0]); Assert.AreEqual(04, z.bytes[1]); Assert.AreEqual(00, z.bytes[2]); Assert.AreEqual(10, z.bytes[3]); Assert.AreEqual(20, z.bytes[4]); }
public void ramlabels() { //NB ramstart will only take effect on a reset() //and will be reset by each call to parse //so to test ramlabels you need to feed in all the data in one go //as if it is read from a file z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); string lines = " .DATA \ntest: .db \ntest2: .db \n .CODE \n .ORG 0000\n ld hl,test \n ld hl,(test2)"; z.parse(lines, ""); z.link(); z.finallink(); Assert.AreEqual(0x21, z.bytes[0]); Assert.AreEqual(0x00, z.bytes[1]); Assert.AreEqual(0x40, z.bytes[2]); Assert.AreEqual(0x2A, z.bytes[3]); Assert.AreEqual(0x01, z.bytes[4]); Assert.AreEqual(0x40, z.bytes[5]); }
public bool build() { error = false; assembler_Msg(" -------- BUILD STARTING -------------"); assembler.basepath = solution.getbasepath(); //assembler.ramstart = solution.details.ramstart; assembler.ramstart = 0x4000; assembler.Msg += new z80assembler.MsgHandler(assembler_Msg); assembler.reset(); foreach (file f in solution.details.files) { if (f.assemblefile == true) { assembler_Msg("\r\n Staring file " + f.name); assembler.partialreset(); assembler.parse(solution.loadfile(f.name), f.name); assembler.link(); // This is the per file link } } assembler_Msg(" \r\n-------- LINKING -------------\r\n "); assembler.finallink(); // This is the per file link assembler_Msg("\r\n --------DONE -------------"); return(error); }
public void labels2() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; string lines = "test: .db 10h,20h,30h,40h\n ld ix,test"; z.parse(lines, ""); Assert.IsFalse(wasCalled); z.link(); Assert.IsFalse(wasCalled); }
public void labelmath3() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; string lines = "CHLEVS: .ds 5\n ld DE,CHLEVS+1"; z.parse(lines, ""); Assert.IsFalse(wasCalled); z.link(); Assert.IsFalse(wasCalled); z.finallink(); Assert.IsFalse(wasCalled); }
public void equsmath2() { z80assembler z = new z80assembler(); z.loadcommands(); z.ramstart = 0x4000; z.reset(); var wasCalled = false; z.DoErr += delegate(string file, int line, string description) { wasCalled = true; }; string lines = "meh equ 5\nmeh2 .equ 6 nop\n nop\n nop\n ld a,meh + 2 * 2\n ld a,meh2+1*2\n"; z.parse(lines, ""); Assert.IsFalse(wasCalled); //33 nn case Assert.AreEqual(0x3e, z.bytes[0]); Assert.AreEqual(0x09, z.bytes[1]); Assert.AreEqual(0x3e, z.bytes[2]); Assert.AreEqual(0x08, z.bytes[3]); }