arm32: 16-bit color (555)

This commit is contained in:
Steven Hugg 2021-06-10 17:04:15 -05:00
parent e74e506f4f
commit d79f3c3da9
2 changed files with 39 additions and 15 deletions

View File

@ -37,9 +37,10 @@ interface AddressFunction extends Function {
interface ARMIRQInterface {
clear() : void;
swi(v: number) : void;
swi32(v: number) : void;
swi(opcode : number) : void;
swi32(opcode : number) : void;
updateTimers() : void;
testIRQ() : void;
}
interface ARMMemoryRegion {
@ -135,6 +136,9 @@ interface ARMCoreType {
resetCPU(startOffset : number) : void;
freeze() : ARMCoreState;
defrost(state: ARMCoreState) : void;
raiseIRQ() : void;
raiseTrap(irqType? : number) : void;
}
export enum ARMMode {
@ -4164,7 +4168,7 @@ export class ARM32CPU implements CPU, InstructionBased, ARMMMUInterface, ARMIRQI
return this.bus.read(a) | (this.bus.read(a+1) << 8);
}
load32(a: number): number {
return this.loadU16(a) | (this.loadU16(a+2) << 16);
return this.bus.read(a) | (this.bus.read(a+1) << 8) | (this.bus.read(a+2) << 16) | (this.bus.read(a+3) << 24);
}
store8(a: number, v: number): void {
this.bus.write(a, v & 0xff);
@ -4174,8 +4178,10 @@ export class ARM32CPU implements CPU, InstructionBased, ARMMMUInterface, ARMIRQI
this.bus.write(a+1, (v >> 8) & 0xff);
}
store32(a: number, v: number): void {
this.store16(a, v);
this.store16(a+2, v >> 16);
this.bus.write(a, v & 0xff);
this.bus.write(a+1, (v >> 8) & 0xff);
this.bus.write(a+2, (v >> 16) & 0xff);
this.bus.write(a+3, (v >> 24) & 0xff);
}
// TODO
wait(a: number): void {
@ -4224,14 +4230,19 @@ export class ARM32CPU implements CPU, InstructionBased, ARMMMUInterface, ARMIRQI
return page;
}
swi(v: number): void {
swi(opcode: number): void {
this.core.raiseTrap();
}
swi32(v: number): void {
swi32(opcode: number): void {
this.swi(opcode >> 16);
}
clear() : void {
}
updateTimers() : void {
}
testIRQ() : void {
}
isThumb() : boolean {
return this.core.instructionWidth == 2;
}

View File

@ -23,10 +23,8 @@ const ROM2_START= 0xff800000;
const ROM_SIZE = 0x80000;
const RAM_START = 0x20000000;
const RAM_SIZE = 0x80000;
const VID_START = 0x40000000;
const VID_SIZE = 0x20000;
const CPU_FREQ = 4000000;
const CPU_FREQ = 4000000; // 4 MHz
export class ARM32Machine extends BasicScanlineMachine implements Debuggable {
@ -39,8 +37,12 @@ export class ARM32Machine extends BasicScanlineMachine implements Debuggable {
sampleRate = 1;
cpu: ARM32CPU = new ARM32CPU();
ram = new Uint8Array(512*1024);
ram = new Uint8Array(96*1024);
ram16 = new Uint16Array(this.ram.buffer);
pixels32 : Uint32Array;
pixels8 : Uint8Array;
vidbase : number = 0;
brightness : number = 255;
constructor() {
super();
@ -50,10 +52,13 @@ export class ARM32Machine extends BasicScanlineMachine implements Debuggable {
connectVideo(pixels:Uint32Array) : void {
super.connectVideo(pixels);
this.pixels32 = pixels;
this.pixels8 = new Uint8Array(pixels.buffer);
//this.pixels.fill(0xff000000);
}
// TODO: 32-bit bus?
read = newAddressDecoder([
[ROM_START, ROM_START+ROM_SIZE-1, ROM_SIZE-1, (a) => {
return this.rom ? this.rom[a] : 0;
@ -70,18 +75,26 @@ export class ARM32Machine extends BasicScanlineMachine implements Debuggable {
[RAM_START, RAM_START+RAM_SIZE-1, RAM_SIZE-1, (a, v) => {
this.ram[a] = v;
}],
[VID_START, VID_START+VID_SIZE-1, VID_SIZE-1, (a, v) => {
this.pixels8[a] = v;
}],
]);
startScanline() {
}
drawScanline() {
// at end of scanline
}
postFrame() {
var p32 = this.pixels32;
var vbase = (this.vidbase >> 1) & 0xfffff;
var mask = this.brightness << 24;
for (var i=0; i<p32.length; i++) {
var col = this.ram16[i + vbase];
// rrrrrgggggbbbbb0 ->
// 000rrrrr000ggggg000bbbbb00011111111
p32[i] = mask | ((col&31)<<3) | (((col>>5)&31)<<11) | (((col>>10)&31)<<19);
}
}
getDebugCategories() {
return ['CPU'];
}