mostly done gigantic switch statement
This commit is contained in:
parent
5f3f5e2ecc
commit
31de9c94f4
1 changed files with 316 additions and 91 deletions
407
src/main.zig
407
src/main.zig
|
@ -82,37 +82,268 @@ pub const Uxn = struct {
|
|||
pub fn loop(self: *Uxn) void {
|
||||
switch (self.mem[self.pc]) {
|
||||
0x00 => {}, // BRK
|
||||
0x01 => inc(&self.ws, false, false), // INC
|
||||
0x02 => pop(&self.ws, false, false), // POP
|
||||
0x03 => nip(&self.ws, false, false), // NIP
|
||||
0x04 => swp(&self.ws, false, false), // SWP
|
||||
0x05 => rot(&self.ws, false, false), // ROT
|
||||
0x06 => dup(&self.ws, false, false), // DUP
|
||||
0x07 => ovr(&self.ws, false, false), // OVR
|
||||
0x08 => equ(&self.ws, false, false), // EQU
|
||||
0x09 => neq(&self.ws, false, false), // NEQ
|
||||
0x0A => gth(&self.ws, false, false), // GTH
|
||||
0x0B => lth(&self.ws, false, false), // LTH
|
||||
0x01 => inc(&self.ws, u8, false), // INC
|
||||
0x02 => pop(&self.ws, u8, false), // POP
|
||||
0x03 => nip(&self.ws, u8, false), // NIP
|
||||
0x04 => swp(&self.ws, u8, false), // SWP
|
||||
0x05 => rot(&self.ws, u8, false), // ROT
|
||||
0x06 => dup(&self.ws, u8, false), // DUP
|
||||
0x07 => ovr(&self.ws, u8, false), // OVR
|
||||
0x08 => equ(&self.ws, u8, false), // EQU
|
||||
0x09 => neq(&self.ws, u8, false), // NEQ
|
||||
0x0A => gth(&self.ws, u8, false), // GTH
|
||||
0x0B => lth(&self.ws, u8, false), // LTH
|
||||
0x0C => self.jmp(&self.ws, u8, false), // JMP
|
||||
0x0D => self.jcn(&self.ws, u8, false), // JCN
|
||||
0x0E => self.jsr(&self.ws, u8, false), // JSR
|
||||
0x0F => self.sth(false, u8, false), // STH
|
||||
0x10 => {}, // LDZ
|
||||
0x11 => {}, // STZ
|
||||
0x12 => {}, // LDR
|
||||
0x13 => {}, // STR
|
||||
0x14 => {}, // LDA
|
||||
0x15 => {}, // STA
|
||||
0x16 => {}, // DEI
|
||||
0x17 => {}, // DEO
|
||||
0x18 => {}, // ADD
|
||||
0x19 => {}, // SUB
|
||||
0x1A => {}, // MUL
|
||||
0x1B => {}, // DIV
|
||||
0x1C => {}, // AND
|
||||
0x1D => {}, // ORA
|
||||
0x1E => {}, // EOR
|
||||
0x1F => {}, // SFT
|
||||
0x10 => self.ldz(&self.ws, u8, false), // LDZ
|
||||
0x11 => self.stz(&self.ws, u8, false), // STZ
|
||||
0x12 => self.ldr(&self.ws, u8, false), // LDR
|
||||
0x13 => self.str(&self.ws, u8, false), // STR
|
||||
0x14 => self.lda(&self.ws, u8, false), // LDA
|
||||
0x15 => self.sta(&self.ws, u8, false), // STA
|
||||
0x16 => dei(&self.ws, u8, false), // DEI
|
||||
0x17 => deo(&self.ws, u8, false), // DEO
|
||||
0x18 => add(&self.ws, u8, false), // ADD
|
||||
0x19 => sub(&self.ws, u8, false), // SUB
|
||||
0x1A => mul(&self.ws, u8, false), // MUL
|
||||
0x1B => div(&self.ws, u8, false), // DIV
|
||||
0x1C => @"and"(&self.ws, u8, false), // AND
|
||||
0x1D => ora(&self.ws, u8, false), // ORA
|
||||
0x1E => eor(&self.ws, u8, false), // EOR
|
||||
0x1F => sft(&self.ws, u8, false), // SFT
|
||||
|
||||
0x20 => {}, // JCI
|
||||
0x21 => inc(&self.ws, u16, false), // INC2
|
||||
0x22 => pop(&self.ws, u16, false), // POP2
|
||||
0x23 => nip(&self.ws, u16, false), // NIP2
|
||||
0x24 => swp(&self.ws, u16, false), // SWP2
|
||||
0x25 => rot(&self.ws, u16, false), // ROT2
|
||||
0x26 => dup(&self.ws, u16, false), // DUP2
|
||||
0x27 => ovr(&self.ws, u16, false), // OVR2
|
||||
0x28 => equ(&self.ws, u16, false), // EQU2
|
||||
0x29 => neq(&self.ws, u16, false), // NEQ2
|
||||
0x2A => gth(&self.ws, u16, false), // GTH2
|
||||
0x2B => lth(&self.ws, u16, false), // LTH2
|
||||
0x2C => self.jmp(&self.ws, u16, false), // JMP2
|
||||
0x2D => self.jcn(&self.ws, u16, false), // JCN2
|
||||
0x2E => self.jsr(&self.ws, u16, false), // JSR2
|
||||
0x2F => self.sth(false, u16, false), // STH2
|
||||
0x30 => self.ldz(&self.ws, u16, false), // LDZ2
|
||||
0x31 => self.stz(&self.ws, u16, false), // STZ2
|
||||
0x32 => self.ldr(&self.ws, u16, false), // LDR2
|
||||
0x33 => self.str(&self.ws, u16, false), // STR2
|
||||
0x34 => self.lda(&self.ws, u16, false), // LDA2
|
||||
0x35 => self.sta(&self.ws, u16, false), // STA2
|
||||
0x36 => dei(&self.ws, u16, false), // DEI2
|
||||
0x37 => deo(&self.ws, u16, false), // DEO2
|
||||
0x38 => add(&self.ws, u16, false), // ADD2
|
||||
0x39 => sub(&self.ws, u16, false), // SUB2
|
||||
0x3A => mul(&self.ws, u16, false), // MUL2
|
||||
0x3B => div(&self.ws, u16, false), // DIV2
|
||||
0x3C => @"and"(&self.ws, u16, false), // AND2
|
||||
0x3D => ora(&self.ws, u16, false), // ORA2
|
||||
0x3E => eor(&self.ws, u16, false), // EOR2
|
||||
0x3F => sft(&self.ws, u16, false), // SFT2
|
||||
|
||||
0x40 => {}, // JMI
|
||||
0x41 => inc(&self.rs, u8, false), // INCr
|
||||
0x42 => pop(&self.rs, u8, false), // POPr
|
||||
0x43 => nip(&self.rs, u8, false), // NIPr
|
||||
0x44 => swp(&self.rs, u8, false), // SWPr
|
||||
0x45 => rot(&self.rs, u8, false), // ROTr
|
||||
0x46 => dup(&self.rs, u8, false), // DUPr
|
||||
0x47 => ovr(&self.rs, u8, false), // OVRr
|
||||
0x48 => equ(&self.rs, u8, false), // EQUr
|
||||
0x49 => neq(&self.rs, u8, false), // NEQr
|
||||
0x4A => gth(&self.rs, u8, false), // GTHr
|
||||
0x4B => lth(&self.rs, u8, false), // LTHr
|
||||
0x4C => self.jmp(&self.rs, u8, false), // JMPr
|
||||
0x4D => self.jcn(&self.rs, u8, false), // JCNr
|
||||
0x4E => self.jsr(&self.rs, u8, false), // JSRr
|
||||
0x4F => self.sth(true, u8, false), // STHr
|
||||
0x50 => self.ldz(&self.rs, u8, false), // LDZr
|
||||
0x51 => self.stz(&self.rs, u8, false), // STZr
|
||||
0x52 => self.ldr(&self.rs, u8, false), // LDRr
|
||||
0x53 => self.str(&self.rs, u8, false), // STRr
|
||||
0x54 => self.lda(&self.rs, u8, false), // LDAr
|
||||
0x55 => self.sta(&self.rs, u8, false), // STAr
|
||||
0x56 => dei(&self.rs, u8, false), // DEIr
|
||||
0x57 => deo(&self.rs, u8, false), // DEOr
|
||||
0x58 => add(&self.rs, u8, false), // ADDr
|
||||
0x59 => sub(&self.rs, u8, false), // SUBr
|
||||
0x5A => mul(&self.rs, u8, false), // MULr
|
||||
0x5B => div(&self.rs, u8, false), // DIVr
|
||||
0x5C => @"and"(&self.rs, u8, false), // ANDr
|
||||
0x5D => ora(&self.rs, u8, false), // ORAr
|
||||
0x5E => eor(&self.rs, u8, false), // EORr
|
||||
0x5F => sft(&self.rs, u8, false), // SFTr
|
||||
|
||||
0x60 => {}, // JSI
|
||||
0x61 => inc(&self.rs, u16, false), // INC2r
|
||||
0x62 => pop(&self.rs, u16, false), // POP2r
|
||||
0x63 => nip(&self.rs, u16, false), // NIP2r
|
||||
0x64 => swp(&self.rs, u16, false), // SWP2r
|
||||
0x65 => rot(&self.rs, u16, false), // ROT2r
|
||||
0x66 => dup(&self.rs, u16, false), // DUP2r
|
||||
0x67 => ovr(&self.rs, u16, false), // OVR2r
|
||||
0x68 => equ(&self.rs, u16, false), // EQU2r
|
||||
0x69 => neq(&self.rs, u16, false), // NEQ2r
|
||||
0x6A => gth(&self.rs, u16, false), // GTH2r
|
||||
0x6B => lth(&self.rs, u16, false), // LTH2r
|
||||
0x6C => self.jmp(&self.rs, u16, false), // JMP2r
|
||||
0x6D => self.jcn(&self.rs, u16, false), // JCN2r
|
||||
0x6E => self.jsr(&self.rs, u16, false), // JSR2r
|
||||
0x6F => self.sth(true, u16, false), // STH2r
|
||||
0x70 => self.ldz(&self.rs, u16, false), // LDZ2r
|
||||
0x71 => self.stz(&self.rs, u16, false), // STZ2r
|
||||
0x72 => self.ldr(&self.rs, u16, false), // LDR2r
|
||||
0x73 => self.str(&self.rs, u16, false), // STR2r
|
||||
0x74 => self.lda(&self.rs, u16, false), // LDA2r
|
||||
0x75 => self.sta(&self.rs, u16, false), // STA2r
|
||||
0x76 => dei(&self.rs, u16, false), // DEI2r
|
||||
0x77 => deo(&self.rs, u16, false), // DEO2r
|
||||
0x78 => add(&self.rs, u16, false), // ADD2r
|
||||
0x79 => sub(&self.rs, u16, false), // SUB2r
|
||||
0x7A => mul(&self.rs, u16, false), // MUL2r
|
||||
0x7B => div(&self.rs, u16, false), // DIV2r
|
||||
0x7C => @"and"(&self.rs, u16, false), // AND2r
|
||||
0x7D => ora(&self.rs, u16, false), // ORA2r
|
||||
0x7E => eor(&self.rs, u16, false), // EOR2r
|
||||
0x7F => sft(&self.rs, u16, false), // SFT2r
|
||||
|
||||
0x80 => {}, // LIT
|
||||
0x81 => inc(&self.ws, u8, true), // INCk
|
||||
0x82 => pop(&self.ws, u8, true), // POPk
|
||||
0x83 => nip(&self.ws, u8, true), // NIPk
|
||||
0x84 => swp(&self.ws, u8, true), // SWPk
|
||||
0x85 => rot(&self.ws, u8, true), // ROTk
|
||||
0x86 => dup(&self.ws, u8, true), // DUPk
|
||||
0x87 => ovr(&self.ws, u8, true), // OVRk
|
||||
0x88 => equ(&self.ws, u8, true), // EQUk
|
||||
0x89 => neq(&self.ws, u8, true), // NEQk
|
||||
0x8A => gth(&self.ws, u8, true), // GTHk
|
||||
0x8B => lth(&self.ws, u8, true), // LTHk
|
||||
0x8C => self.jmp(&self.ws, u8, true), // JMPk
|
||||
0x8D => self.jcn(&self.ws, u8, true), // JCNk
|
||||
0x8E => self.jsr(&self.ws, u8, true), // JSRk
|
||||
0x8F => self.sth(false, u8, true), // STHk
|
||||
0x90 => self.ldz(&self.ws, u8, true), // LDZk
|
||||
0x91 => self.stz(&self.ws, u8, true), // STZk
|
||||
0x92 => self.ldr(&self.ws, u8, true), // LDRk
|
||||
0x93 => self.str(&self.ws, u8, true), // STRk
|
||||
0x94 => self.lda(&self.ws, u8, true), // LDAk
|
||||
0x95 => self.sta(&self.ws, u8, true), // STAk
|
||||
0x96 => dei(&self.ws, u8, true), // DEIk
|
||||
0x97 => deo(&self.ws, u8, true), // DEOk
|
||||
0x98 => add(&self.ws, u8, true), // ADDk
|
||||
0x99 => sub(&self.ws, u8, true), // SUBk
|
||||
0x9A => mul(&self.ws, u8, true), // MULk
|
||||
0x9B => div(&self.ws, u8, true), // DIVk
|
||||
0x9C => @"and"(&self.ws, u8, true), // ANDk
|
||||
0x9D => ora(&self.ws, u8, true), // ORAk
|
||||
0x9E => eor(&self.ws, u8, true), // EORk
|
||||
0x9F => sft(&self.ws, u8, true), // SFTk
|
||||
|
||||
0xA0 => {}, // LIT2
|
||||
0xA1 => inc(&self.ws, u16, true), // INC2k
|
||||
0xA2 => pop(&self.ws, u16, true), // POP2k
|
||||
0xA3 => nip(&self.ws, u16, true), // NIP2k
|
||||
0xA4 => swp(&self.ws, u16, true), // SWP2k
|
||||
0xA5 => rot(&self.ws, u16, true), // ROT2k
|
||||
0xA6 => dup(&self.ws, u16, true), // DUP2k
|
||||
0xA7 => ovr(&self.ws, u16, true), // OVR2k
|
||||
0xA8 => equ(&self.ws, u16, true), // EQU2k
|
||||
0xA9 => neq(&self.ws, u16, true), // NEQ2k
|
||||
0xAA => gth(&self.ws, u16, true), // GTH2k
|
||||
0xAB => lth(&self.ws, u16, true), // LTH2k
|
||||
0xAC => self.jmp(&self.ws, u16, true), // JMP2k
|
||||
0xAD => self.jcn(&self.ws, u16, true), // JCN2k
|
||||
0xAE => self.jsr(&self.ws, u16, true), // JSR2k
|
||||
0xAF => self.sth(false, u16, true), // STH2k
|
||||
0xB0 => self.ldz(&self.ws, u16, true), // LDZ2k
|
||||
0xB1 => self.stz(&self.ws, u16, true), // STZ2k
|
||||
0xB2 => self.ldr(&self.ws, u16, true), // LDR2k
|
||||
0xB3 => self.str(&self.ws, u16, true), // STR2k
|
||||
0xB4 => self.lda(&self.ws, u16, true), // LDA2k
|
||||
0xB5 => self.sta(&self.ws, u16, true), // STA2k
|
||||
0xB6 => dei(&self.ws, u16, true), // DEI2k
|
||||
0xB7 => deo(&self.ws, u16, true), // DEO2k
|
||||
0xB8 => add(&self.ws, u16, true), // ADD2k
|
||||
0xB9 => sub(&self.ws, u16, true), // SUB2k
|
||||
0xBA => mul(&self.ws, u16, true), // MUL2k
|
||||
0xBB => div(&self.ws, u16, true), // DIV2k
|
||||
0xBC => @"and"(&self.ws, u16, true), // AND2k
|
||||
0xBD => ora(&self.ws, u16, true), // ORA2k
|
||||
0xBE => eor(&self.ws, u16, true), // EOR2k
|
||||
0xBF => sft(&self.ws, u16, true), // SFT2k
|
||||
|
||||
0xC0 => {}, // LITr
|
||||
0xC1 => inc(&self.rs, u8, true), // INCkr
|
||||
0xC2 => pop(&self.rs, u8, true), // POPkr
|
||||
0xC3 => nip(&self.rs, u8, true), // NIPkr
|
||||
0xC4 => swp(&self.rs, u8, true), // SWPkr
|
||||
0xC5 => rot(&self.rs, u8, true), // ROTkr
|
||||
0xC6 => dup(&self.rs, u8, true), // DUPkr
|
||||
0xC7 => ovr(&self.rs, u8, true), // OVRkr
|
||||
0xC8 => equ(&self.rs, u8, true), // EQUkr
|
||||
0xC9 => neq(&self.rs, u8, true), // NEQkr
|
||||
0xCA => gth(&self.rs, u8, true), // GTHkr
|
||||
0xCB => lth(&self.rs, u8, true), // LTHkr
|
||||
0xCC => self.jmp(&self.rs, u8, true), // JMPkr
|
||||
0xCD => self.jcn(&self.rs, u8, true), // JCNkr
|
||||
0xCE => self.jsr(&self.rs, u8, true), // JSRkr
|
||||
0xCF => self.sth(true, u8, true), // STHkr
|
||||
0xD0 => self.ldz(&self.rs, u8, true), // LDZkr
|
||||
0xD1 => self.stz(&self.rs, u8, true), // STZkr
|
||||
0xD2 => self.ldr(&self.rs, u8, true), // LDRkr
|
||||
0xD3 => self.str(&self.rs, u8, true), // STRkr
|
||||
0xD4 => self.lda(&self.rs, u8, true), // LDAkr
|
||||
0xD5 => self.sta(&self.rs, u8, true), // STAkr
|
||||
0xD6 => dei(&self.rs, u8, true), // DEIkr
|
||||
0xD7 => deo(&self.rs, u8, true), // DEOkr
|
||||
0xD8 => add(&self.rs, u8, true), // ADDkr
|
||||
0xD9 => sub(&self.rs, u8, true), // SUBkr
|
||||
0xDA => mul(&self.rs, u8, true), // MULkr
|
||||
0xDB => div(&self.rs, u8, true), // DIVkr
|
||||
0xDC => @"and"(&self.rs, u8, true), // ANDkr
|
||||
0xDD => ora(&self.rs, u8, true), // ORAkr
|
||||
0xDE => eor(&self.rs, u8, true), // EORkr
|
||||
0xDF => sft(&self.rs, u8, true), // SFTkr
|
||||
|
||||
0xE0 => {}, // LIT2r
|
||||
0xE1 => inc(&self.rs, u16, true), // INC2kr
|
||||
0xE2 => pop(&self.rs, u16, true), // POP2kr
|
||||
0xE3 => nip(&self.rs, u16, true), // NIP2kr
|
||||
0xE4 => swp(&self.rs, u16, true), // SWP2kr
|
||||
0xE5 => rot(&self.rs, u16, true), // ROT2kr
|
||||
0xE6 => dup(&self.rs, u16, true), // DUP2kr
|
||||
0xE7 => ovr(&self.rs, u16, true), // OVR2kr
|
||||
0xE8 => equ(&self.rs, u16, true), // EQU2kr
|
||||
0xE9 => neq(&self.rs, u16, true), // NEQ2kr
|
||||
0xEA => gth(&self.rs, u16, true), // GTH2kr
|
||||
0xEB => lth(&self.rs, u16, true), // LTH2kr
|
||||
0xEC => self.jmp(&self.rs, u16, true), // JMP2kr
|
||||
0xED => self.jcn(&self.rs, u16, true), // JCN2kr
|
||||
0xEE => self.jsr(&self.rs, u16, true), // JSR2kr
|
||||
0xEF => self.sth(true, u16, true), // STH2kr
|
||||
0xF0 => self.ldz(&self.rs, u16, true), // LDZ2kr
|
||||
0xF1 => self.stz(&self.rs, u16, true), // STZ2kr
|
||||
0xF2 => self.ldr(&self.rs, u16, true), // LDR2kr
|
||||
0xF3 => self.str(&self.rs, u16, true), // STR2kr
|
||||
0xF4 => self.lda(&self.rs, u16, true), // LDA2kr
|
||||
0xF5 => self.sta(&self.rs, u16, true), // STA2kr
|
||||
0xF6 => dei(&self.rs, u16, true), // DEI2kr
|
||||
0xF7 => deo(&self.rs, u16, true), // DEO2kr
|
||||
0xF8 => add(&self.rs, u16, true), // ADD2kr
|
||||
0xF9 => sub(&self.rs, u16, true), // SUB2kr
|
||||
0xFA => mul(&self.rs, u16, true), // MUL2kr
|
||||
0xFB => div(&self.rs, u16, true), // DIV2kr
|
||||
0xFC => @"and"(&self.rs, u16, true), // AND2kr
|
||||
0xFD => ora(&self.rs, u16, true), // ORA2kr
|
||||
0xFE => eor(&self.rs, u16, true), // EOR2kr
|
||||
0xFF => sft(&self.rs, u16, true), // SFT2kr
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,30 +352,17 @@ pub const Uxn = struct {
|
|||
fn inc(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a +% 1);
|
||||
// if (keep) {
|
||||
// stack.s[stack.sp +% 1] = stack.s[stack.sp] +% 1;
|
||||
// stack.sp +%= 1;
|
||||
// } else {
|
||||
// stack.s[stack.sp] +%= 1;
|
||||
// }
|
||||
}
|
||||
|
||||
fn pop(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
if (keep) return;
|
||||
_ = stack.pop(T);
|
||||
// if (!keep) {
|
||||
// if (short) stack.sp -%= 2 else stack.sp -%= 1;
|
||||
// }
|
||||
}
|
||||
|
||||
fn nip(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, b);
|
||||
// if (!keep) {
|
||||
// stack.sp -%= 1;
|
||||
// stack.s[stack.sp] = stack.s[stack.sp +% 1];
|
||||
// }
|
||||
}
|
||||
|
||||
fn swp(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
|
@ -152,14 +370,6 @@ pub const Uxn = struct {
|
|||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, b);
|
||||
stack.push(T, a);
|
||||
// if (keep) {
|
||||
// stack.s[stack.sp +% 1] = stack.s[stack.sp];
|
||||
// stack.s[stack.sp +% 2] = stack.s[stack.sp -% 1];
|
||||
// } else {
|
||||
// const a = stack.s[stack.sp -% 1];
|
||||
// stack.s[stack.sp -% 1] = stack.s[stack.sp];
|
||||
// stack.sp = a;
|
||||
// }
|
||||
}
|
||||
|
||||
fn rot(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
|
@ -174,11 +384,6 @@ pub const Uxn = struct {
|
|||
fn dup(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a);
|
||||
// stack.s[stack.sp +% 1] = stack.s[stack.sp];
|
||||
// if (keep) {
|
||||
// stack.s[stack.sp +% 2] = stack.s[stack.sp];
|
||||
// stack.sp +%= 2;
|
||||
// } else stack.sp +%= 1;
|
||||
}
|
||||
|
||||
fn ovr(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
|
@ -187,28 +392,12 @@ pub const Uxn = struct {
|
|||
stack.push(T, a);
|
||||
stack.push(T, b);
|
||||
stack.push(T, a);
|
||||
// if (keep) {
|
||||
// stack.s[stack.sp +% 1] = stack.s[stack.sp -% 1];
|
||||
// stack.s[stack.sp +% 2] = stack.s[stack.sp];
|
||||
// stack.s[stack.sp +% 3] = stack.s[stack.sp -% 1];
|
||||
// stack.sp +%= 3;
|
||||
// } else {
|
||||
// stack.s[stack.sp +% 1] = stack.s[stack.sp -% 1];
|
||||
// stack.sp +%= 1;
|
||||
// }
|
||||
}
|
||||
|
||||
fn equ(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
if (a == b) stack.push(T, 1) else stack.push(T, 0);
|
||||
// if (keep) {} else {
|
||||
// if (stack.s[stack.sp -% 1] == stack.s[stack.sp])
|
||||
// stack.s[stack.sp +% 1] = 1
|
||||
// else
|
||||
// stack.s[stack.sp +% 1] = 0;
|
||||
// stack.sp +%= 1;
|
||||
// }
|
||||
}
|
||||
|
||||
fn neq(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
|
@ -266,67 +455,103 @@ pub const Uxn = struct {
|
|||
dst.push(T, a);
|
||||
}
|
||||
|
||||
fn ldz(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
fn ldz(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const addr = if (keep) stack.peek(u8) else stack.pop(u8);
|
||||
switch (T) {
|
||||
u8 => stack.push(T, self.mem[addr]),
|
||||
u16 => {},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
fn stz(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
fn stz(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const addr = if (keep) stack.peek(u8) else stack.pop(u8);
|
||||
const val = if (keep) stack.peek(T) else stack.pop(T);
|
||||
self.mem[addr] = val;
|
||||
}
|
||||
|
||||
fn ldr(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
fn ldr(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const addr = if (keep) stack.peek(u8) else stack.pop(u8);
|
||||
const val = self.mem[self.pc +% @as(i8, @intCast(addr))];
|
||||
stack.push(T, val);
|
||||
}
|
||||
|
||||
fn str(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
fn str(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const addr = if (keep) stack.peek(u8) else stack.pop(u8);
|
||||
const val = if (keep) stack.peek(T) else stack.pop(T);
|
||||
self.mem[self.pc +% @as(i8, @bitCast(addr))] = val;
|
||||
}
|
||||
|
||||
fn lda(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
fn lda(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const addr = if (keep) stack.peek(u16) else stack.pop(u16);
|
||||
stack.push(T, self.mem[addr]);
|
||||
}
|
||||
|
||||
fn sta(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
fn sta(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
const addr = if (keep) stack.peek(u16) else stack.pop(u16);
|
||||
const val = if (keep) stack.peek(T) else stack.pop(T);
|
||||
self.mem[addr] = val;
|
||||
}
|
||||
|
||||
fn dei(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
_ = stack;
|
||||
_ = T;
|
||||
_ = keep;
|
||||
}
|
||||
|
||||
fn deo(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
_ = stack;
|
||||
_ = T;
|
||||
_ = keep;
|
||||
}
|
||||
|
||||
fn add(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a +% b);
|
||||
}
|
||||
|
||||
fn sub(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a -% b);
|
||||
}
|
||||
|
||||
fn mul(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a *% b);
|
||||
}
|
||||
|
||||
fn div(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a / b);
|
||||
}
|
||||
|
||||
fn @"and"(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a & b);
|
||||
}
|
||||
|
||||
fn ora(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a | b);
|
||||
}
|
||||
|
||||
fn eor(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
stack.push(T, a ^ b);
|
||||
}
|
||||
|
||||
fn sft(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||
_ = short;
|
||||
const a = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const b = if (keep) stack.peek(T) else stack.pop(T);
|
||||
const right = b & 0b00001111;
|
||||
const left = (b & 0b11110000) >> 4;
|
||||
stack.push(T, (a >> right) << left);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue