Fixed color modes
This commit is contained in:
+143
-21
@@ -17,7 +17,8 @@ export type uxn = struct {
|
||||
console_vector: u16,
|
||||
screen_vector: u16,
|
||||
mouse_vector: u16,
|
||||
ram: [0x10000] u8,
|
||||
controller_vector: u16,
|
||||
ram: [BANKS_CAP] u8,
|
||||
dev: [0x100] u8,
|
||||
ptr: [2] u8,
|
||||
stk: [2][0x100] u8,
|
||||
@@ -34,6 +35,12 @@ export def SCREENRATE = 60;
|
||||
//Screen consists of two layers of 2-bit pixels
|
||||
export type uxn_screen = ([MAXWIDTH][MAXHEIGHT]u8, [MAXWIDTH][MAXHEIGHT]u8);
|
||||
|
||||
def NUMBANKS = 0x10;
|
||||
def BANKSIZE = 0x10000;
|
||||
def BANKS_CAP = NUMBANKS * BANKSIZE;
|
||||
const banksize: u32 = BANKSIZE;
|
||||
const numbanks: u16 = NUMBANKS;
|
||||
|
||||
const reset_vector: u16 = 0x0100;
|
||||
|
||||
const colormodes: [4][16] u8 = [
|
||||
@@ -48,6 +55,7 @@ fn initialize_uxn_mem() *uxn = {
|
||||
console_vector = 0,
|
||||
screen_vector = 0,
|
||||
mouse_vector = 0,
|
||||
controller_vector = 0,
|
||||
ram = [0...],
|
||||
dev = [0...],
|
||||
ptr = [0...],
|
||||
@@ -156,6 +164,10 @@ fn emu_deo(port: u8, value: u8, state: *uxn) void = {
|
||||
draw_pixel(value,state);
|
||||
case 0x2f =>
|
||||
draw_sprite(value,state);
|
||||
case 0x81 =>
|
||||
let high = state.dev[0x80];
|
||||
let low = value;
|
||||
state.controller_vector = short_from_bytes(high,low);
|
||||
case 0x91 =>
|
||||
let high = state.dev[0x90];
|
||||
let low = value;
|
||||
@@ -176,6 +188,41 @@ fn emu_deo(port: u8, value: u8, state: *uxn) void = {
|
||||
};
|
||||
};
|
||||
|
||||
fn deo_expansion(addr: u16, state: *uxn) void = {
|
||||
const op = state.ram[addr];
|
||||
const length = short_from_bytes(state.ram[addr+1],state.dev[addr+2]);
|
||||
switch(op) {
|
||||
case 0x00 => //fill
|
||||
const bank = short_from_bytes(state.ram[addr+3],state.dev[addr+4]);
|
||||
const addr = short_from_bytes(state.ram[addr+5],state.dev[addr+6]);
|
||||
const value = state.ram[addr+7];
|
||||
if(bank < numbanks) for(let i: u16 =0; i < length; i+=1){
|
||||
state.ram[bank * banksize + addr + i] = value;
|
||||
};
|
||||
case 0x01 => //cpyl
|
||||
const srcbank = short_from_bytes(state.ram[addr+3],state.dev[addr+4]);
|
||||
const srcaddr = short_from_bytes(state.ram[addr+5],state.dev[addr+6]);
|
||||
const dstbank = short_from_bytes(state.ram[addr+7],state.dev[addr+8]);
|
||||
const dstaddr = short_from_bytes(state.ram[addr+9],state.dev[addr+10]);
|
||||
if(srcbank < numbanks && dstbank < numbanks) for(let i: u16 =0; i < length; i+=1){
|
||||
const readval = state.ram[srcbank * banksize + srcaddr + i];
|
||||
state.ram[dstbank * banksize + dstaddr + i] = readval;
|
||||
};
|
||||
case 0x02 => //cpr TODO are these actually different?? Either way need to not use for loop
|
||||
const srcbank = short_from_bytes(state.ram[addr+3],state.dev[addr+4]);
|
||||
const srcaddr = short_from_bytes(state.ram[addr+5],state.dev[addr+6]);
|
||||
const dstbank = short_from_bytes(state.ram[addr+7],state.dev[addr+8]);
|
||||
const dstaddr = short_from_bytes(state.ram[addr+9],state.dev[addr+10]);
|
||||
if(srcbank < numbanks && dstbank < numbanks) for(let i: u16 =0; i < length; i+=1){
|
||||
const readval = state.ram[srcbank * banksize + srcaddr + i];
|
||||
state.ram[dstbank * banksize + dstaddr + i] = readval;
|
||||
};
|
||||
case =>
|
||||
fmt::fatalf("Unknown expansion op: 0x{:x}",op);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
export fn set_mouse_motion(x: u16, y: u16, state: *uxn) void = {
|
||||
state.dev[0x92] = (x >> 8): u8;
|
||||
state.dev[0x93] = (x): u8;
|
||||
@@ -194,7 +241,24 @@ export fn set_mouse_up(button: u8, state: *uxn) void = {
|
||||
const new = cur & invbutton;
|
||||
state.dev[0x96] = new;
|
||||
};
|
||||
export fn set_controller_down(button: u8, state: *uxn) void = {
|
||||
const cur = state.dev[0x82];
|
||||
const new = cur | button;
|
||||
state.dev[0x82] = new;
|
||||
};
|
||||
export fn set_controller_up(button: u8, state: *uxn) void = {
|
||||
const cur = state.dev[0x82];
|
||||
const invbutton = 0xff ^ button;
|
||||
const new = cur & invbutton;
|
||||
state.dev[0x82] = new;
|
||||
};
|
||||
|
||||
export fn set_key_down(key: u8, state: *uxn) void = {
|
||||
state.dev[0x83] = key;
|
||||
};
|
||||
export fn clear_key_down(state: *uxn) void = {
|
||||
state.dev[0x83] = 0;
|
||||
};
|
||||
fn regenerate_palettes(state: *uxn) void = {
|
||||
const r = short_from_bytes(state.dev[0x08],state.dev[0x09]);
|
||||
const g = short_from_bytes(state.dev[0x0a],state.dev[0x0b]);
|
||||
@@ -347,21 +411,26 @@ fn copy_sprite_to_screen(bpp2: bool, colors: u8, x: u16, y: u16, addr: u16, flip
|
||||
|
||||
let xoff: u16 = if(flipx){ yield 7; } else { yield 0; };
|
||||
let yoff: u16 = if(flipy){ yield 7; } else { yield 0; };
|
||||
|
||||
const drawZero = ((colors%5 != 0));
|
||||
|
||||
|
||||
const pixels: []u8 = if(bpp2) { yield get_pixels_from_2bpp_sprite(addr,state); }
|
||||
else {yield get_pixels_from_1bpp_sprite(addr,state);};
|
||||
|
||||
for(let p .. pixels){
|
||||
const color = colormodes[p][colors];
|
||||
|
||||
if((x < MAXWIDTH) && (y < MAXHEIGHT)){
|
||||
if(layer1) { state.screen.1[x+xoff][y+yoff] = color; }
|
||||
else {state.screen.0[x+xoff][y+yoff] = color; };
|
||||
let color = colormodes[p][colors];
|
||||
|
||||
|
||||
if(drawZero || p > 0){
|
||||
if((x < MAXWIDTH) && (y < MAXHEIGHT)){
|
||||
if(layer1) {
|
||||
state.screen.1[x+xoff][y+yoff] = color;
|
||||
} else {
|
||||
state.screen.0[x+xoff][y+yoff] = color;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
if(flipx){
|
||||
xoff -= 1;
|
||||
}else {
|
||||
@@ -760,10 +829,23 @@ export fn uxn_step(state: *uxn) (done | error) = {
|
||||
let bot = pop_or_get(equ_inst,1,state);
|
||||
|
||||
//TODO, I think this works, but it feels unclean with the casting
|
||||
let val: u8 = if(top: u16 == bot: u16){
|
||||
yield 1;
|
||||
// let val: u8 = if(top: u16 == bot: u16){
|
||||
// yield 1;
|
||||
// } else {
|
||||
// yield 0;
|
||||
// };
|
||||
let val: u8 = if(!equ_inst.short){
|
||||
yield if(bot: u8 == top: u8){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
} else {
|
||||
yield 0;
|
||||
yield if(bot: u16 == top: u16){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
};
|
||||
push_to_stack(equ_inst.ret, val, state);
|
||||
// /* NEQ */ OPC(0x09,POx(a,d) POx(b,d),PUx(b != a,0,r))
|
||||
@@ -772,10 +854,23 @@ export fn uxn_step(state: *uxn) (done | error) = {
|
||||
let bot = pop_or_get(neq_inst,1,state);
|
||||
|
||||
//TODO, I think this works, but it feels unclean with the casting
|
||||
let val: u8 = if(top: u16 != bot: u16){
|
||||
yield 1;
|
||||
// let val: u8 = if(top: u16 != bot: u16){
|
||||
// yield 1;
|
||||
// } else {
|
||||
// yield 0;
|
||||
// };
|
||||
let val: u8 = if(!neq_inst.short){
|
||||
yield if(bot: u8 != top: u8){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
} else {
|
||||
yield 0;
|
||||
yield if(bot: u16 != top: u16){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
};
|
||||
push_to_stack(neq_inst.ret, val, state);
|
||||
// /* GTH */ OPC(0x0a,POx(a,d) POx(b,d),PUx(b > a,0,r))
|
||||
@@ -784,10 +879,23 @@ export fn uxn_step(state: *uxn) (done | error) = {
|
||||
let bot = pop_or_get(gth_inst,1,state);
|
||||
|
||||
//TODO, I think this works, but it feels unclean with the casting
|
||||
let val: u8 = if(bot: u16 > top: u16){
|
||||
yield 1;
|
||||
// let val: u8 = if(bot: u16 > top: u16){
|
||||
// yield 1;
|
||||
// } else {
|
||||
// yield 0;
|
||||
// };
|
||||
let val: u8 = if(!gth_inst.short){
|
||||
yield if(bot: u8 > top: u8){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
} else {
|
||||
yield 0;
|
||||
yield if(bot: u16 > top: u16){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
};
|
||||
push_to_stack(gth_inst.ret, val, state);
|
||||
// /* LTH */ OPC(0x0b,POx(a,d) POx(b,d),PUx(b < a,0,r))
|
||||
@@ -796,10 +904,23 @@ export fn uxn_step(state: *uxn) (done | error) = {
|
||||
let bot = pop_or_get(lth_inst,1,state);
|
||||
|
||||
//TODO, I think this works, but it feels unclean with the casting
|
||||
let val: u8 = if(bot: u16 < top: u16){
|
||||
yield 1;
|
||||
// let val: u8 = if(bot: u16 < top: u16){
|
||||
// yield 1;
|
||||
// } else {
|
||||
// yield 0;
|
||||
// };
|
||||
let val: u8 = if(!lth_inst.short){
|
||||
yield if(bot: u8 < top: u8){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
} else {
|
||||
yield 0;
|
||||
yield if(bot: u16 < top: u16){
|
||||
yield 1;
|
||||
} else {
|
||||
yield 0;
|
||||
};
|
||||
};
|
||||
push_to_stack(lth_inst.ret, val, state);
|
||||
// /* JMP */ OPC(0x0c,POx(a,d),MOV)
|
||||
@@ -951,6 +1072,7 @@ export fn uxn_step(state: *uxn) (done | error) = {
|
||||
let res = if(!add_inst.short){
|
||||
yield (top: u8 + bot: u8);
|
||||
} else {
|
||||
// fmt::printfln("ADD2 0x{:x} + 0x{:x} = 0x{:x}",bot,top,top: u16 + bot: u16)!;
|
||||
yield (top: u16 + bot: u16);
|
||||
};
|
||||
push_to_stack(add_inst.ret, res, state);
|
||||
@@ -1077,7 +1199,7 @@ export fn uxn_init(path: str) ( *uxn | error ) = {
|
||||
};
|
||||
let state: *uxn = initialize_uxn_mem();
|
||||
//Copy rom into ram
|
||||
let bytesread = match (io::read(romfile,state.ram[0x100..0xff00])){
|
||||
let bytesread = match (io::read(romfile,state.ram[0x100..(BANKS_CAP - 0x100)])){
|
||||
case let bytes: size =>
|
||||
yield bytes;
|
||||
case let eof: io::EOF =>
|
||||
|
||||
Reference in New Issue
Block a user